Advertisement

Small question about connect 4 AI

Started by October 18, 2004 08:14 PM
1 comment, last by alvaro 20 years, 1 month ago
Have a question for anybody who is familiar with strong connect 4 strategy. First off, so there's no confusion, couple of definitions for words I'm gonna use: ENDGAME: The point in the game where many columns are full and there is no possibility for traps. This is the stage where players start wasting moves. ODD/EVEN: Counting from the bottom up, rows 1, 3, 5 are odd and rows 2,4,6 are even. Player 1 is odd since in the endgame his pieces will land on odd rows. Player 2 is even for the same reason. CONTROL A COLUMN: Player 1 controls a column if theres a win on an odd row for him. Player 2 controls a column if theres a win on an even row for him. If both players control a column, the lower win has control since his win will occur first. Ok, any confusion on those terms, don't hesitate to ask. I'm trying to write an AI for connect 4 and was wondering if the following logic was correct: "Assume the players play perfectly. During the endgame, if player 1 controls any columns he will always win. Player 2 always wins if he controls a column and player 1 controls no columns. If neither control a column it will always be a draw." Anyone know if this is a correct conclusion?
Nevermind all, did some test games against a strong AI I downloaded and realized that not only is my conclusion wrong, but also controlling the correct row depending on if you are player one/odd or player two/even isn't as important as I originally thought...
Advertisement
Player 1's odd threats are much more important than player 2's even threats. Let me do my own definitions:

ODD THREAT: A column where there is a win for a given player on an odd row, if the opponent doesn't have one.

EVEN_THREAT_FOR_PLAYER_2: The fact that player 2 has a win on an even row somewhere.

ODD KILLER: A column where both players have odd wins. Note that if both wins are in the same spot, the game can't be a draw. Let's not distinguish between the cases where they happen in the same spot or not.

ODD_DIFF: Number of odd threats by player 2 minus number of odd threats by player 1

NUM_KILL: Number of killer odd threats.

Theorem (I think).- If we are in an endgame position (where no new threats can be formed):
if (ODD_DIFF < 0) player 1 wins
else if (ODD_DIFF >= 2) player 2 wins
else if (ODD_DIFF+NUM_KILL is odd) player 1 wins
else if (ODD_DIFF+NUM_KILL > 0) player 2 wins
else if (EVEN_THREAT_FOR_PLAYER_2) player 2 wins
else it's a draw

This topic is closed to new replies.

Advertisement