Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 how to make AI for connect four
Index -> Programming, Turing -> Turing Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
zylum




PostPosted: Fri May 28, 2004 4:13 pm   Post subject: (No subject)

try making a recursive procedure that goes a certain depth (how many move forward). for for each move you have a weight ie:

connect 4 = +infinity
block 4 = 1000000
make 3 = 100000
block 3 = 50000
make 2 = 30000
block 2 = 10000

then for each move the computer makes search through all the possiblities and add those points to the total score of that particular move "branch" then do the same for the human and assume he makes the best move aswell but this time subtract the score... while the procedure is sorting the moves, keep track of the best scoreing branch. once the procedure is done then make the move that lead to the best scoring branch... you dont really need to worry about making your algorithm efficient like chess since there is only a possiblity of a max of 8 moves per turn unlike chess which averages 38... so you can make your AI look like 10 moves ahead while only taking a few seconds to think...
Sponsor
Sponsor
Sponsor
sponsor
fatboy316




PostPosted: Fri May 28, 2004 8:44 pm   Post subject: (No subject)

if you get the opponents move and subtract it, wouldn't that reduce the score and make the move that will be played will assume that the opponent makes the worst move? I think the objective is to have the opponent make the BEST move.
zylum




PostPosted: Sat May 29, 2004 1:24 pm   Post subject: (No subject)

but if the opponent wins it will make the final score huge and the AI will choose it making IT lose... therefore you subtract the score and after you search through all the possible moves for that turn, only go int that branch... hmm, i dunno... then you would be going through all the possible outcomes like in chess, you might make a gambit (a sort of "bad move" which leads to a good move) but the AI would skip it since its not the best possible move for that turn... i dunno...
SuperGenius




PostPosted: Sat May 29, 2004 6:14 pm   Post subject: (No subject)

one situation that you have to place high in the ranking scheme would be a setup like this:

o
xx o

assuming it is x's turn, the game is over because he will play on one side of the two x s to make three in a row, with a blank space on either side of the row, and o has only one move, and therefore can't block them both, and x wins.
guruguru




PostPosted: Sat May 29, 2004 7:27 pm   Post subject: (No subject)

The test for SuperGenious example would be something like

code:

if rowLength = 2 and rightSideOfRow + 1 = emptyCell and leftSideOfRow - 1 = empyCell then
    % make high importance
end if
fatboy316




PostPosted: Sat May 29, 2004 10:34 pm   Post subject: (No subject)

the way i did it was if the it was going to set the opponent up for a win, it would -100000000 points or something but if it was doing something good, like blocking them from making 3, then it would add
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 21 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: