Prev: ~~~~~~~~~~~~~~ CAT CONDO ~~~~~~~~~~~~~~
Next: Help required in programing the legal move generation of Connect-4 game.
From: mandar on 25 Dec 2009 11:23 I have programed a connect four in java using GUI. I have already coded a snippet that uses 2-d array(My board representation) for evaluation the winning conditions. i have declared a 2d array named board[width][height], where width is 7 and height is 6. and initialized all the elements to 0. Now I am planning to program an AI for it, for which I am planning to break the entire process into small parts(methods.) The first part will be consisting of all the legal moves which are allowed for the current position. In a position there are maximum 7 possible moves(towards the end there might be less than 7 but not more than 7 in any state of the game.). I will call this array as int legalMoves[]=new int[7]. So to describe in words, I can say: Traverse the board array from the last row first column and see the empty spaces for the last row. If a space is filled on last row then see a row above it. check this for entire array. Put all the empty spaces from the last row and the empty spaces which are just above the filled spaces in the legalMoves[] . This array would be then passed to the decision making algorithm.(probably I will make use of negamax+abp) Now i am stuck in filling this array. I tried to make use of 'for' loop, but the problem is that all the empty spaces are not legal moves. and that is where I am stuck to fill this array. I just require the looping for generation of legal moves. please if possible help me with it. If you want to verify whether I have the GUI by my self or not, for that I am posting this screen shot (The code for GUI is too big to post it here.) ,verify i has my email Id on top. here is the link for screen shot. http://www.fileducky.com/mSIIeBcx/
From: Beej Jorgensen on 25 Dec 2009 14:23 > The first part will be consisting of all the legal moves which are > allowed for the current position. > In a position there are maximum 7 possible moves(towards the end there > might be less than 7 but not more than 7 in any state of the game.). I > will call this array as int legalMoves[]=new int[7]. I might not be understanding clearly, but what if legalMoves[] just contained the row of the next move for a given column? That is, in Connect-4 pieces are never removed from the game, so the next legal move for a particular column is always the next row above it. Game start: Initialize all legalMoves[i] = 0 During play: Let move m be a column number If legalMoves[m] < height, then the move is legal If the move is legal, then: board[m][legalMoves[m]] = cur_player_color legalMoves[m]++ > (probably I will make use of negamax+abp) It would be fun to pit Negamax against Monte Carlo in this. :) So... I don't know if this post is useful, but there we are! Merry Christmas! -Beej
From: James Dow Allen on 26 Dec 2009 07:33
On Dec 25, 11:54 pm, Moi <r...(a)invalid.address.org> wrote: > On Fri, 25 Dec 2009 08:23:20 -0800, mandar wrote: > > I have programed a connect four in java. You'll want to decide whether to maximize readability and modularity of software, or to use techniques like bit-twiddling for speed. If the latter is of interest you'll be richly rewarded by studying John Tromp's Fhourstones. By the way, I *did* click for the screen shot but all I got was * picture of very pretty Maria who wants me to "join her" * the text string "connect4.JPG" * prob. some more viruses and spybots. (Do I get discount on anti-virus software if I wait till my machine has 100 viruses or more?) > 2d arrays is always a bad choice in board game programming, IMHO. > For small boards like this it is easy to use bit maps. If speed is irrelevant to you, an obvious advantage of bit maps might disappear. Nevertheless, I agree that a 2d array might contribute little or no utility. > > I tried to make use of 'for' > > loop, but the problem is that all the empty spaces are not legal > > moves. and that is where I am stuck to fill this array. This "problem" has easy solutions; simplest may be to keep the set of legal moves at constant-size 7 but add a Legal/Illegal bit. By the way, Hasbro is now marketing a set with new rules: "Connect Four Popout". I *think* First-player has an easier victory with these rules than with standard rules, but if you hurry you might be first to complete a computer proof/disproof of that! James Dow Allen |