
-----------------------------------
fatboy316
Tue Apr 27, 2004 12:27 pm

how to make AI for connect four
-----------------------------------
i've searched for ways to make AI for connect four but i can't seem to understand, is there a method to use in turing for alpha-beta pruning or the minmax algorithm?

-----------------------------------
Tony
Tue Apr 27, 2004 12:35 pm


-----------------------------------
there's nothing build into turing, so you'd have to program the entire thing yourself - if that's what you asking. If you ned help encoding your AI, start off with posting your pseudoalgorythm

-----------------------------------
fatboy316
Tue Apr 27, 2004 1:28 pm


-----------------------------------
wats a pseudoalgorythm

-----------------------------------
Cervantes
Tue Apr 27, 2004 1:50 pm


-----------------------------------
its an algorythm in pseudo code. pseudo code is code, but not of a specific language.  
so your pseudoalgorythm is basically how you plan to do it.

-----------------------------------
omni
Tue Apr 27, 2004 2:32 pm


-----------------------------------
also called pseudocode. Its your plan on how to program your specific algorithm, this case AI. You go through and decide what the AI will do. 
ex: if it sees a place to get a connect four, then place the piece there, otherwise do something else. Then you transfer it to code.
ex: if connectfour =true then
     /*place piece there*/
else
/*do something else*/
end if
....

-----------------------------------
fatboy316
Sat May 15, 2004 5:15 pm


-----------------------------------
i don't no where to start for my connect four ai, i've been reading sites around and there seems to be an algorithm to weigh each move and give it a number, then the highest number will be the action taken. Rite now my program checks for win, if can't win then block, if can't block then connect3, if can't connect3 then block3, else it'lld o a random move. its easily beaten rite now

-----------------------------------
omni
Sat May 15, 2004 5:58 pm


-----------------------------------
really? what you said right there seems pretty good. Ya its hard to get a program to think like a human does. 
Can your AI look ahead one move?

-----------------------------------
SuperGenius
Sat May 15, 2004 9:52 pm


-----------------------------------
I made a connect 4 game a while back, and I was thinking of developing an AI for it, but I gave up on it because it seemed pretty hard. I would like to see some code if you manage to come up with something.

-----------------------------------
Tony
Sun May 16, 2004 1:17 pm


-----------------------------------
fatboy316 - its nice to see you getting somewhere with your AI, but don't make too many threads on the same topic... or atleast keep them [url=http://www.compsci.ca/v2/viewtopic.php?t=4983]linked

-----------------------------------
fatboy316
Thu May 27, 2004 3:45 pm


-----------------------------------
i've sorta got my ai, but how can i make it better and possibly look ahead into the game? my program and the other thread i posted is at http://www.compsci.ca/v2/viewtopic.php?t=4983

please help! this is due in a week!

-----------------------------------
guruguru
Thu May 27, 2004 4:19 pm


-----------------------------------
A weeks a lot of time don't worry! Unless you want to get into a little recursion or more advanced algorithsm (or really long if statements  :P ) I suggest you leave the AI as it is. It seems pretty good from what you've said, so dun worry. 

Connect 4 can't really be much more advanced. Make powerups like extra move if you go in a certain column? I dunno...

-----------------------------------
fatboy316
Thu May 27, 2004 4:28 pm


-----------------------------------
thx for help but i was wondering about the AI and how to make it better, would it be better if i was able to make a procedure to play the game out, and then determine the winner and if you end up as the winner, continue with that move or if u end up a loser, then go onto the next best move

-----------------------------------
s_climax
Thu May 27, 2004 6:05 pm


-----------------------------------
But how can you predict what the other person will do?

-----------------------------------
Cervantes
Thu May 27, 2004 6:35 pm


-----------------------------------
i think better AI would be:

connect4
block 4
place one to create two 3 ina rows
block 3
build a 2inarow near to another 2 in a row
build 2 (anywhere on screen)
block 2
random move

and have a predefined starting move in the centre. 

just a suggestion

-----------------------------------
fatboy316
Thu May 27, 2004 6:53 pm


-----------------------------------
But how can you predict what the other person will do?

i can basically create a game scenario where it plays the game using the AI as 2 separate players. The AI chooses the best moves for each player and assumes that the REAL player will make the best move as well


other AI suggestions are welcome on how i can improve it

-----------------------------------
zylum
Fri May 28, 2004 4:13 pm


-----------------------------------
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...

-----------------------------------
fatboy316
Fri May 28, 2004 8:44 pm


-----------------------------------
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
Sat May 29, 2004 1:24 pm


-----------------------------------
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
Sat May 29, 2004 6:14 pm


-----------------------------------
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
Sat May 29, 2004 7:27 pm


-----------------------------------
The test for SuperGenious example would be something like


if rowLength = 2 and rightSideOfRow + 1 = emptyCell and leftSideOfRow - 1 = empyCell then
    % make high importance
end if


-----------------------------------
fatboy316
Sat May 29, 2004 10:34 pm


-----------------------------------
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
