Prog 3: Nine Man's Morris

[See course schedule for due date.]

Write a program in C to play the ancient game of Nine Man's Morris, where your program allows two human players to play against each other, verifying input.  Not only does Shakespeare reference this game in a Midsummer Night's Dream, but there are records of this game in ancient Egypt, from over 3000 years ago. See more information at http://www.tradgames.org.uk/games/Nine-Mens-Morris.htm.

Running your program will look like the following, except you should have your own name and TA information. The boldfaced text is something that you type in.

[reed@ernie]$  ~reed/141/morris/morris  Author: Dale Reed Assignment: #3, Nine Men's Morris TA: Popre Tires, Mon 1:00-1:05  Each player has nine pieces. The players take turns putting their  pieces (one at a time) on the board at places where lines meet.  Each player tries to get three pieces in a row (a "mill") while  preventing her opponent from doing the same.   When a player gets three pieces in a row then she may take one of her  opponent's pieces off the board. After both players have put all of  their pieces on the board, a piece is moved by sliding it from its  space to a neighboring empty space.   Players keep trying to get three pieces in a row so they can take  away an opponent's piece. The game is over when one player  is left with two pieces.  Moves are made by referencing a row and column, e.g. A1 is the upper left corner.      1   2   3  4  5   6   7   A  .......................  A     .          .          .  B  .   ...............   .  B        .   .      .      .   .  C  .   .   .......   .   .  C     .   .   .     .   .   .  D  .........     .........  D     .   .   .     .   .   .  E  .   .   .......   .   .  E     .   .      .      .   .  F  .   ...............   .  F        .          .          .  G  .......................  G      1   2   3  4  5   6   7 Player X has 9 pieces to place.  Enter a move position: A1       1   2   3  4  5   6   7   A  X......................  A     .          .          .  B  .   ...............   .  B        .   .      .      .   .  C  .   .   .......   .   .  C     .   .   .     .   .   .  D  .........     .........  D     .   .   .     .   .   .  E  .   .   .......   .   .  E     .   .      .      .   .  F  .   ...............   .  F        .          .          .  G  .......................  G      1   2   3  4  5   6   7 Player O has 9 pieces to place.  Enter a move position: B4       1   2   3  4  5   6   7   A  X......................  A     .          .          .  B  .   .......O.......   .  B        .   .      .      .   .  C  .   .   .......   .   .  C     .   .   .     .   .   .  D  .........     .........  D     .   .   .     .   .   .  E  .   .   .......   .   .  E     .   .      .      .   .  F  .   ...............   .  F        .          .          .  G  .......................  G      1   2   3  4  5   6   7 Player X has 8 pieces to place.  Enter a move position: a2 Sorry, that is invalid.  Enter a move position: b4 Sorry, that is invalid.  Enter a move position: a4       1   2   3  4  5   6   7   A  X..........X...........  A     .          .          .  B  .   .......O.......   .  B        .   .      .      .   .  C  .   .   .......   .   .  C     .   .   .     .   .   .  D  .........     .........  D     .   .   .     .   .   .  E  .   .   .......   .   .  E     .   .      .      .   .  F  .   ...............   .  F        .          .          .  G  .......................  G      1   2   3  4  5   6   7 Player O has 8 pieces to place.  Enter a move position: b6       1   2   3  4  5   6   7   A  X..........X...........  A     .          .          .  B  .   .......O......O   .  B        .   .      .      .   .  C  .   .   .......   .   .  C     .   .   .     .   .   .  D  .........     .........  D     .   .   .     .   .   .  E  .   .   .......   .   .  E     .   .      .      .   .  F  .   ...............   .  F        .          .          .  G  .......................  G      1   2   3  4  5   6   7 Player X has 7 pieces to place.  Enter a move position: a7       1   2   3  4  5   6   7   A  X..........X..........X  A     .          .          .  B  .   .......O......O   .  B        .   .      .      .   .  C  .   .   .......   .   .  C     .   .   .     .   .   .  D  .........     .........  D     .   .   .     .   .   .  E  .   .   .......   .   .  E     .   .      .      .   .  F  .   ...............   .  F        .          .          .  G  .......................  G      1   2   3  4  5   6   7 *** Player X formed 3 in a row!  Enter opponent's piece to remove: b4      1   2   3  4  5   6   7   A  X..........X..........X  A     .          .          .  B  .   ..............O   .  B        .   .      .      .   .  C  .   .   .......   .   .  C     .   .   .     .   .   .  D  .........     .........  D     .   .   .     .   .   .  E  .   .   .......   .   .  E     .   .      .      .   .  F  .   ...............   .  F        .          .          .  G  .......................  G      1   2   3  4  5   6   7 Player O has 7 pieces to place.  Enter a move position: d6       1   2   3  4  5   6   7   A  X..........X..........X  A     .          .          .  B  .   ..............O   .  B        .   .      .      .   .  C  .   .   .......   .   .  C     .   .   .     .   .   .  D  .........     ....O....  D     .   .   .     .   .   .  E  .   .   .......   .   .  E     .   .      .      .   .  F  .   ...............   .  F        .          .          .  G  .......................  G      1   2   3  4  5   6   7 Player X has 6 pieces to place.  Enter a move position: d6     .    .    .    (and so on, until both players have placed all their pieces)    .    .    .       1   2   3  4  5   6   7   A  X..........X..........X  A     .          .          .  B  .   X......O......O   .  B        .   .      .      .   .  C  .   .   .......   .   .  C     .   .   .     .   .   .  D  O...X...O     X...O....  D     .   .   .     .   .   .  E  .   .   .......   .   .  E     .   .      .      .   .  F  .   O......O......X   .  F        .          .          .  G  O..........X..........X  G      1   2   3  4  5   6   7 Player X to move.  Enter positions moving from and to: A7 D7       1   2   3  4  5   6   7   A  X..........X...........  A     .          .          .  B  .   X......O......O   .  B        .   .      .      .   .  C  .   .   .......   .   .  C     .   .   .     .   .   .  D  O...X...O     X...O...X  D     .   .   .     .   .   .  E  .   .   .......   .   .  E     .   .      .      .   .  F  .   O......O......X   .  F        .          .          .  G  O..........X..........X  G      1   2   3  4  5   6   7 Player O to move.  Enter positions moving from and to: f4 e4       1   2   3  4  5   6   7   A  X..........X...........  A     .          .          .  B  .   X......O......O   .  B        .   .      .      .   .  C  .   .   .......   .   .  C     .   .   .     .   .   .  D  O...X...O     X...O...X  D     .   .   .     .   .   .  E  .   .   ...O...   .   .  E     .   .      .      .   .  F  .   O.............X   .  F        .          .          .  G  O..........X..........X  G      1   2   3  4  5   6   7 Player X to move.  Enter positions moving from and to: a4 a7       1   2   3  4  5   6   7   A  X.....................X  A     .          .          .  B  .   X......O......O   .  B        .   .      .      .   .  C  .   .   .......   .   .  C     .   .   .     .   .   .  D  O...X...O     X...O...X  D     .   .   .     .   .   .  E  .   .   ...O...   .   .  E     .   .      .      .   .  F  .   O.............X   .  F        .          .          .  G  O..........X..........X  G      1   2   3  4  5   6   7 *** Player X formed 3 in a row!  Enter opponent's piece to remove: f2       1   2   3  4  5   6   7   A  X.....................X  A     .          .          .  B  .   X......O......O   .  B        .   .      .      .   .  C  .   .   .......   .   .  C     .   .   .     .   .   .  D  O...X...O     X...O...X  D     .   .   .     .   .   .  E  .   .   ...O...   .   .  E     .   .      .      .   .  F  .   ..............X   .  F        .          .          .  G  O..........X..........X  G      1   2   3  4  5   6   7 Player O to move.  Enter positions moving from and to: b4 a4     .    .    .    (and so on, until one player has only two pieces left)    .    .    .       1   2   3  4  5   6   7   A  X..........X..........X  A     .          .          .  B  .   ...............   .  B        .   .      .      .   .  C  .   .   O......   .   .  C     .   .   .     .   .   .  D  O...O....     ....X....  D     .   .   .     .   .   .  E  .   .   .......   .   .  E     .   .      .      .   .  F  .   ...............   .  F        .          .          .  G  ......................X  G      1   2   3  4  5   6   7 *** Player X formed 3 in a row!  Enter opponent's piece to remove: d1       1   2   3  4  5   6   7   A  X..........X..........X  A     .          .          .  B  .   ...............   .  B        .   .      .      .   .  C  .   .   O......   .   .  C     .   .   .     .   .   .  D  ....O....     ....X....  D     .   .   .     .   .   .  E  .   .   .......   .   .  E     .   .      .      .   .  F  .   ...............   .  F        .          .          .  G  ......................X  G      1   2   3  4  5   6   7  Player X wins!  Thanks for playing.  Exiting program... 

[reed@ernie]$

 

The description of moves for this program was based on http://www.plimoth.org/Education/ninemens.htm.

You need to know the following concepts in order to write this program:

Everything from prior programs; How to use functions, including reference parameters. 

Notes: