Connect Four

You do not have Java installed or you have an outdated version of Java. You must install the latest version of Java in order to play this game. Click here to install Java

Instructions

Source code of the above game


Connect Four is a board games which players try to align four disks to win. The game is played on a board, in which one drops a disc to the lowest unoccupied square. Discs stack up on top of one another, white both players compete in this game to align four discs first.

Winning occurs if four adjacent disks align vertically, horzontally, or diagonally. If the board is filled with no player aliging four, the game is automatically draw.

The game looks simple but surprisingly challenging amatuars, but might get boring after a while. It is proved that the first player has a better chance to win.

History

The term Connect Four originated as a registered trademark of Milton Bradley, who published this game in 1974.

Connect-Four is also known as The Captain's Mistress. There is a legend on a storythat said on his three major voyages, in the H.M.S Endeavour, and two in the H.M.S. Resolution, Captain James Cook was absent on an evening so the crew joked that he must have a mistress in the cabin. Then the crew recognized that he was playing this game with the ship's naturalist Sir Joseph Banks and botanist Daniel Solander. Cook spent excessively amounts of time playing this game; it became known as "The Captain's Mistress". Connect-Four has also been commonly called connect 4, and 4 in a row. However, it is rarely called "The Captain's Mistress".

Strategy

These are a few tips for beginners:

  • The center is the best first move for the first player.
  • Do not place pieces in useless spots.
  • Always think that your opponent will play the best move.

You must think ahead to win, especially in tactical situations. When you have 2-in-a-row, you can make it 3-in-a-row, your opponent must block your 3-in-a-row to win. Therefore, you can force your opponent to play on certain squares, by making 3-in-a-rows, which might make two threats simultaneously for you, and you will win. It's a good idea to think ahead that way. However, this is very hard to do this when playing against strong players.

Assume that yellow is the first player, and red is the second player. Threats are places where you place a disk, you will win in Connect-Four. They are places where three disks are in a four-disk line that have an empty square. Beginners usually make two threats simultaneously to win. It's very hard to do this when playing against strong players. Therefore, beginners usually count all of the empty squares, if he or she has the time to count, which person will win after. It could be done a much simpler way, tell whether it's an odd threat or an even threat.

When the board is almost full, there are rows that are not completely filled that have threats. To make a move in the beginning so you have a threat at the end of the game so that you can win, you have to know where to put the piece. There are odd and even rows on the board. The first row is odd. If there is a threat in the first row, it is an odd threat. The second row is even. If there is a threat in the second row, it is an even threat, and the same for the other rows. To make a move, the first player and the second play have different strategies of winning the game.

The first player has to get the odd threats below the second player's even threats to win. The first player also has to block even threats from the second player below the first player's odd threat.

The second player has to get the even threats below the first player's odd threats to win. The second player also has to block odd threats from the first player below the second player's even threat.

Yellow to play. Red will win because red has an even threat, and he or she is the second player, but yellow will not win, unless he or she has an odd threat:

empty.gif empty.gif empty.gif empty.gif empty.gif empty.gif empty.gif
empty.gif empty.gif empty.gif empty.gif empty.gif empty.gif empty.gif
empty.gif empty.gif empty.gif red.gif empty.gif empty.gif empty.gif
empty.gif empty.gif empty.gif yellow.gif red.gif empty.gif empty.gif
empty.gif empty.gif empty.gif yellow.gif yellow.gif empty.gif yellow.gif
empty.gif empty.gif red.gif yellow.gif red.gif empty.gif red.gif

Yellow to play. Yellow will win because yellow has two odd threats in the same line so that yellow will win. Yellow will put disks on c5 and e3 because c5 and e3 are odd threats:

empty.gif empty.gif empty.gif empty.gif empty.gif empty.gif empty.gif
empty.gif empty.gif empty.gif empty.gif empty.gif empty.gif empty.gif
empty.gif empty.gif empty.gif yellow.gif empty.gif empty.gif empty.gif
empty.gif empty.gif red.gif yellow.gif empty.gif red.gif empty.gif
empty.gif empty.gif yellow.gif red.gif empty.gif yellow.gif yellow.gif
empty.gif empty.gif red.gif yellow.gif empty.gif red.gif red.gif

Yellow to play. Red will win because red has two even threats in the same line so that red will win unless yellow will have an odd threat. Red will put disks on c4 and e2 because c4 and e2 are even threats.

empty.gif empty.gif empty.gif empty.gif empty.gif empty.gif empty.gif
empty.gif empty.gif empty.gif empty.gif empty.gif empty.gif empty.gif
empty.gif empty.gif empty.gif empty.gif empty.gif empty.gif empty.gif
empty.gif empty.gif empty.gif red.gif empty.gif empty.gif empty.gif
empty.gif red.gif yellow.gif yellow.gif empty.gif yellow.gif empty.gif
empty.gif red.gif yellow.gif yellow.gif empty.gif red.gif empty.gif

When you have a threat that you could win and the other player has a threat that the person can win, but the threat is on top of your threat, you don't have to block the other person's threat because you can win on the bottom.

When the second player has two odd threats in different columns of the board and in different winning lines, the second player will win. The second player will win because the sum of two columns that all have odd empty squares is an even number of empty squares. Therefore, the second player has an even threat and will win.

Yellow to play. Red will win because red have two even threats, but yellow have two odd threats:

red.gif red.gif empty.gif red.gif empty.gif yellow.gif red.gif
yellow.gif yellow.gif empty.gif red.gif empty.gif yellow.gif yellow.gif
red.gif red.gif empty.gif red.gif empty.gif red.gif red.gif
yellow.gif yellow.gif empty.gif yellow.gif empty.gif yellow.gif yellow.gif
red.gif yellow.gif empty.gif red.gif empty.gif yellow.gif red.gif
yellow.gif yellow.gif red.gif yellow.gif red.gif red.gif yellow.gif

When the first player has two even threats in different columns of the board, the first player will not win at those even threats. The first player will not win because the sum of two columns that all have even empty squares is still an even number of empty squares. Therefore, the first player has an even threat and will not win.

Red to play. Yellow will not win at those even threats because yellow has two even threats and yellow will lose.

yellow.gif empty.gif red.gif yellow.gif empty.gif yellow.gif yellow.gif
red.gif empty.gif red.gif red.gif empty.gif red.gif red.gif
yellow.gif empty.gif yellow.gif yellow.gif empty.gif yellow.gif yellow.gif
red.gif empty.gif red.gif red.gif empty.gif yellow.gif red.gif
yellow.gif empty.gif red.gif yellow.gif empty.gif yellow.gif red.gif
yellow.gif yellow.gif red.gif yellow.gif empty.gif red.gif red.gif

Red to play. Yellow will win because yellow has an odd threat, even though red has an even threat.

When the first player has an odd threat and the second player has an even threat in different columns, the first player will win. The first player will win because the sum of one column that has odd empty squares and one column that has even empty squares is an odd number of empty squares. Therefore, the first player has an odd threat and will win.

yellow.gif empty.gif red.gif red.gif red.gif empty.gif yellow.gif
red.gif empty.gif yellow.gif yellow.gif yellow.gif empty.gif red.gif
red.gif empty.gif red.gif red.gif red.gif empty.gif yellow.gif
yellow.gif empty.gif yellow.gif yellow.gif red.gif empty.gif red.gif
yellow.gif empty.gif yellow.gif red.gif yellow.gif empty.gif yellow.gif
yellow.gif red.gif yellow.gif yellow.gif red.gif empty.gif red.gif

Computer Players

Connect-Four is solved by L. Victor Allis, using a knowledge-based approach, using nine strategic rules, and simultaneously by James D. Allen, determined the game-theroretic value using a brute-force depth-first search with alpha-beta pruning, a transposition table and killer-move heuristics. Allen proved Connect-Four to be a first player win. It's a win for the first player. Allen weakly solved Connect-Four on a Sun-4/200-series workstation in about 300 hours. Allis also weakly solved the game, also on a Sun-4 in about 350 hours. The combinations nine rules were specified and Allis implanted the nine rules to the program called Victor. Victor provided a knowledge-based component for an explanation why a position is won. Victor solved games on different boards smaller than 7×6. All of the boards are based on an even number of rows, because Victor is based on the control of the zugzwang. The boards resulted in a draw.

There are some people who can play Connect-Four perfectly, although there's no such strategy. They play perfectly by memorizing some openings and thinking ahead.

Links

Play Connect Four Online

Connect Four Programs

Mustrum is an exceptionally well-built program that has a very strong engine. It has several features, such as a large opening book. You can load and save positions. Highly recommonded!

Mustrum

4 in a row is a game where you can adjust levels, so even a beginner will learn. You can load and save positions, plus other additional features such as bitboard search. Martiz Fierz is kind enough to offer the source code to his program, so programmers may learn from it.

4 in a Row

Velena is a MS-DOS program, which claims to play Connect Four perfectly. Unfortunately, you will get bored playing it for too long because every move it makes is the same.

Velena

References