
You
will write a program to allow a
person to play the game Connect Four.
You should allow them to choose before each game whether they
want to
play the computer or another person, and then whether they wish to go
first or
not. After the game, they should be
allowed the opportunity to play again.
After they no longer wish to play, a tally of how many games the
player wins
out of the total number of games played, should be printed. For presentation, you should ask the person
their name and refer to them by name in all subsequent messages. You should also explain the rules of the
game with appropriate diagrams and detail, before play begins. During play, only legal moves should be
allowed, and the end of the game should be detected.
You can check out an online
version of this game
to get some idea for a graphical user interface (GUI).
The
game has seven columns in which
a black or a red checker can be placed.
A checker placed in a given column falls
to the bottom of that column and lands on top of the previously played
checker
in that column. Your program should not
refresh the whole picture of the board after each move, but instead
should add
the new checkers as each is played. A
player should indicate the column he is playing, by clicking on or in
that
column. When four in a row of a given
color is achieved either vertically, or horizontally or diagonally, the
game is
over. Note that the maximum number
of checkers
allowed in any column is six.
In any GUI
program there is usually an underlying data structure that keeps track
of the information that is displayed. It is important to realize
that just the picture that the computer draws on the screen is
not the same as this data structure. For example, for this
program a data structure of 13
lists is helpful: one for each column (6 all together), and one
for each row (7 all together). Each
list contains a sequence of letters:
B(black), R(red) and E(empty).
At the start, all thirteen lists contain nothing but E’s. As the game progresses, these lists must
be
changed and updated to reflect the current state of the board, and you will need to write procedure to do these updates.
These lists are accessed in
order to:
The minimum requirements
for this assignment, is to have the computer play random legal moves. You can earn up to 40 points extra credit by
adding extra features. One convenient feature is an "undo"
option that lets a person take back a mov ein case of a typo.
Another much fancier feature is programming the computer to make smart
moves. Strategies for doing this can be
discussed with me. Other possible extra features include various
graphics features like highlighting on a mouseover. Feel free to
add your own features for extra credit, but first get the main game
working and then discuss your ideas with me first before implementing
them.