Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

SJEM2280

APPRECIATION OF MATHEMATICS
STRATEGY OF CONNECT 4

INSTITUTE OF MATHEMATICAL
SCIENCES
FACULTY OF SCIENCE
UNIVERSITY OF MALAYA
SEMESTER 2 SESSION 2016/2017

GROUP 4
Instructor: Dr. Onn Shea Ming

Name Matrix Number

Ivy Ngau Mei Yee SER 130006

Kang Yuan Shing SER 130007

Tan Tzer Harn SER 130033


Table of Contents
1.0 Introduction.................................................................3
2.0 History........................................................................ 4
3.0 The Strategy for Connect Four...........................................5
3.1 The Nomenclature...............................................................5
3.2 The Possible Positions of the Game.........................................5
3.3 Knowledge-Based Approach..................................................6
3.4 Some Strategies Rules..........................................................7
4.0 Conclusion.................................................................12
5.0 References.................................................................13

1.0 Introduction

2
Connect-Four is a tic-tac-toe-like two-player game in which players
alternately place pieces on a vertical board 7 columns across and 6 rows
high. Each player uses pieces of a particular colour (commonly black and red,
or sometimes yellow and red), and the objective is to be the first to obtain four
pieces in a horizontal, vertical, or diagonal line. Because the board is vertical,
pieces inserted in a given column always drop to the lowest unoccupied row
of that column. As soon as a column contains 6 pieces, it is full and no other
piece can be placed in the column.

Both players begin with 21 identical pieces, and the first player to
achieve a line of four connected pieces wins the game. If all 42 men are
played and no player has places four pieces in a row, the game is drawn.

The game has been completely analysed, so it is known that if both


players play with optimal strategies, the first player can always win (Allis
1988). The numbers of possible positions after n=0, 1, 2, ... have been played
is 1, 7, 56, 252, 1260, 4620, 18480, 59815, 206780, . In this report we
explore the different strategies involved in playing connect four. Moreover, we
show that in certain positions a few strategic rules are strong enough to make
a player at least draw the game.

3
2.0 History
Connect 4, or commonly known by the popular version name Four in a
row is a game with a mysterious origin as precursor existed that date back to
the beginning of 20th century. Connect 4 with 6 by 7 grid design can host up
to over 4 trillion positions, 4,531,985,219,092 to be specific.

Connect 4's origin has been ambiguous as the earliest story regarding
the game is revolved around an explorer name Captain Cook, who has spent
excessive amount of time playing this game against travellers earned the
game name "Captain's Mistress". Milton Bradley trademarked a version of the
game called Connect 4 and distributed in the states in 1974, however there
are versions of Four in a Row described in Robbie Bell's book that dates to
Edwardian time near the beginning of 20th century.

Classic version of Four in a Row consist of a 6 by 7 board design, with


2 sets of colour tokens. The objective of the game is to connect four tokens of
the chosen colour before your opponent does. Rules vary depending on the
variation of the board used, and game can be started in mid positions as well.
Today the game is a popular hit with family and kids alike, it is a game with
easy engagement and quick pace fun.

4
3.0 The Strategy for Connect Four
3.1 The Nomenclature

In order to be able to talk about a position, it is useful to give each


square a name. We have chosen to use a nomenclature as used by chess
players. The 7 columns are labelled a through g, while the rows are
numbered 1 through 6. For simplicity we let O (white) as first player to start
the moves and X (black) as second player moves to start after first player.
6
5
4
X 3

X 2
X O O O O 1

a b c d e f g

It is now possible to make a list of the moves made during a game. For the
game of diagram above this could have been:
1. d1, d2
2. c1, d3
3. e1, b1
4. f1, O wins.

3.2 The Possible Positions of the Game

In order to get an idea about the complexity of the game an estimate is


presented of the number of different positions which can be achieved, if the
game is played according to the rules. A position which can occur during a
game is called a legal position, while a position which cannot be achieved is
called illegal.
Since there are 6 X 7 squares and each square can be in one of three
states : empty, X or O. Hence, the number of possible positions is at most

342 1020 . If we take a closer look to remove some illegal positions, we

would have better upper bound of possible position( 7.1 1013 ).


Examples for illegal position are :

5
1) If we are assuming the O moves first, then some game configurations,
such as a stack in one column with X from bottom is impossible.

O 6
X 5
O 4
X 3
O 2
2) If the total number X 1 of occupied squares is
a b c d e f g
odd, the number of O is one more than
the number of X, otherwise it is an illegal position.
3) If a column contais an empty square, all squares above this empty square
are also empty.
4) Since the last move ended the game, at least one of the four squares in
the connected group must be the highest filled square in its column. If this
is not the case, or both players have connected four men, the position is
illegal.

3.3 Knowledge-Based Approach

Instead of a brute force search, we can try a knowledge-based


approach. Instead of searching entire game space , we can formulate general
rules that tell which player will win or draw in which situations. Suppose we
play on a board of n columns, which are each only 2 squares high. The
following strategy will ensure X at least a draw :
Suppose n is even. Group the columns in pairs, giving pairs of column
1&2, 3&4, , (n-1)&n. Each time O is in one column of a pair of columns,
X plays in the other column of the pair. For n is odd, groups are made in the
same way, leaving the n-th column as a single column. The same rules apply
to this position. Only if O plays in the n-th column, X plays in that column
too.
We have shown that it is sometimes possible to give a set of strategic
rules with which one of the players will never lose. This result shows that a
knowledge-based approach in at least some cases can give results which
cannot be obtained using brute force only. Therefore, it is useful to investigate
the possibilities of this approach for the standard board of 7 columns and 6
rows.

6
Let us consider a set of strategic rules for the well-known game tic-tac-
toe, which some players might like to use. The rules have priority in the order
given:

1. If there is a winning move, take it.


2. If the opponent can win at a square by his next move, play that move.
3. Taking the central square is more important than taking other squares.
4. Taking corner squares is more important than taking squares on the
edges.
These four rules seem all to be very reasonable. Now let us see what
happens if we use these rules to play against a human player(white), who
does not use the rules. The human player starts playing.

This game shows that the four strategic rules do not always assure that
the best result possible (draw) can be reached, although the rules look
perfectly reasonable. In general, we must classify these sorts of rules into two
classes:
1. Rules that guarantee a certain results.
2. Rules that are generally advantageous but are not without downfall (like
the strategy of tic-tac-toe given above)

3.4 Some Strategies Rules

Well explore possible strategies to follow for Connect Four below. First
well learn some terminology associated with describing the strategy.
A. Threat

7
A threat is a square that if taken by opponent forms a game-winning
group of four. For example, in the game below O has threats at b1 and
f1:

6
5
4
X 3

X 2
O O O 1

a b c d e f g

B. Useless Threat
A useless threat is a threat that will never be able to be carried out by
the opponent. The diagram below illustrate the concept of a useless threat.
X X X X 6
X O O O 5
O O O O 4
X O O O 3
X X X X 2
X O O X 1
a b c d e f g

The possibilities of both players to get a group of four connected


square will both involve square b2 and f2. Whoever fill up the squares
(b2&f2) first will win the game. Suppose the game continue with O moves
first and the player fills up g1. Then this results in the position of diagram
below :

X X X X X 6
X O O O O 5
O O O O X 4
X O O O O 3
X X X X X 2
X O O X O 1
a b c d e f g

Now the time has come that O has to move in the b-column or the f-
column. As soon as this has been done, X will take the square in the
second row and win the game. Therefore, it is clear that in this game no
square of b3-b6 and f3-f6 will be used. Therefore, most of O s unfinished

8
groups are useless, as well as some of X groups. We have found two
serious threats: b2 and f2, while all other threats were useless. In the
position of diagram 3.4.1, it was already easy to count the empty squares
to see that eventually O would have to play b1 or f1. Moreover, suppose
we have, like in diagram 3.4.2, five columns filled up completely and the
two other columns empty. Without knowing anything about the way the
columns are filled, it is easy to see that it is Os turn. This does not
depend on the way the players filled the board, but depends only on the
number of moves (also known as number of squares) made. If an even
number of square are played, it is always Os turn, while X has to move
after an odd number of square played. Since five full columns consist of
thirty men, it must be Os turn. Therefore, in any position where some
columns are completely filled and the others are still empty, the number of
square played is always even and therefore it is Os turn.

C. Odd and Even Threats


The odd/evenness of a threat is determined by the row number. So d1
is an odd threat, etc. In normal game play, O is most likely to get odd
squares, while X is most likely to get even squares. In general, we see
the following patterns:
1) O has an odd threat, X has even threat O wins.
The column in which the O threat lies will remain empty for an
odd number of squares. Besides O will get even squares and X will
get odd squares.
O X O X X 6
X O X O O 5
O X O O X 4
X O X O X 3
In this O O X X O 2 case, O has threat at
X O X O X O 1
b3 and X has a b c d e f g threat at e2. Now X
has to move.
2) Both O and X have even threats. X wins
Since there is no column where odd number of squares can be
played, O will get odd squares and X will get even squares. Hence
X can refute O s threat and win. See example in Useless Threat.
3) O has even threat, and X has odd threat draw
X will get even squares and O gets odd squares. Therefore,
the game will be drawn.

9
4) O has an odd threat and X has an odd threat.
Usually neither of these threats end up working and depend on
other threats.
X X O X O 6
O O X O X 5
X X O X O 4
O O X O X 3
In this X O X O O 2 case O has threat at
X O O O X X X 1
f3 and X has a b c d e f g threat at c3. Now O
has to move. O will only can fill up column f in order not to lose.
Hence, O will fill f2 instead of f3. When column f fully filled, now X
has to move and can fill up column c only. Thus again X will fill c2
instead of c3. Both threat c3 and f3 are not working. In this particular
example, X eventually fills up f5 and creates threat at c2. After the
column f fully filled, X can win the game by filling c2.

D. Zugzwang
The formal definition of this strange German word: A situation where a
player is forced to make a move when he would rather make no move at
all. In connect four, a player is able to control the zugzwang if the player
is able to guide the way odd and even squares are divided up among
players. As an example, we look at the following game situation, where O
is about to move:
X 6
O 5
O O 4
O O 3
X X X X 2
X O O X 1
Note that all a b c d e f g columns contain an
even number of pieces, so O will never fill up a column since it must take
only odd squares (row 1,3,5). So X can just play follow-up and mimic
O every move. This will result in the following position:

X X X X X 6
O O O O O 5
X O O X X 4
O O O O O 3
X X X X X 2
X O O X O 1
a b c d e f g
10
Now O must play either b1 or f1, which X will follow, and win the
game with a group of four on the second row. So in conclusion, Zugzwang
involves being able to divide up how even and odd squares are distributed
to the two players. X wanted only even squares because eventually it
would be able to fulfil its even threat at either b2 or f2. But if it had wanted
odd squares, it could have just stopped playing follow up and played in a
different column. In this diagram, to play follow-up was a winning strategy
for X . Concluding this, we see that X is able to take all even squares,
without O being able to do anything about it, while X can take some odd
squares if he wants to, the price of which is the loss of some even
squares. Hence X controls the zugzwang.

4.0 Conclusion

Connect 4 also known as Captains Mistress, Four Up, Plot Four, Find Four,
Fourplay, Four in a Row and Four in a Line. It is a zero sum game which is one
player will always have an advantage whereas the another player will have a
disadvantage. As well as the basic benefits of playing games like practice following
rules, how to be a good sport winning or losing, the Connect Four game also will
have advantages.

11
Firstly, the Connect 4 games will build skills such as problem solving and
basic math. By playing Connect 4, It will encourage player to plan ahead, looking
opportunities to connect 4 discs and provide opportunity to detects patterns. Besides
that, playing Connect 4 also manage to improve players investigation of prediction of
the outcome of alternative moves for your own play as well as your opponents by
keeping an eye on their moves keeps your one step ahead.

In conclusion, the rules of the game are easy to learn and understand, but
difficult to master. That is the beauty of Connect 4.

12
5.0 References
Bertoletti. G Conenct 4 Tutorial (2017, February, 14) Retrived from:
http://www.ce.unipr.it/~gbe/cn4rules.html

Jelvis,T (2014, February, 23) What is the winning strategy for the first player in
Connect Four games? Retrived from: https://www.quora.com/What-is-the-winning-
strategy-for-the-first-player-in-Connect-Four-games

13

You might also like