Lab 6: Othello

This assignment assumes that you have read up through Chapter 6. Please bring your book to lab, as you will need it as a reference. Each lab assignment is more work than the previous one, so get started early.

The objectives for this assignment are for you to:

  • Demonstrate mastery of using arrays.
  • Get more practice in decomposing programs into small functions.
  • Learn about basic algorithms for sorting and game playing.
  • Getting Started

    As in the previous lab, start by creating a directory just for this assignment, and changing to that directory:
    mkdir cse20211/lab6
    cd cse20211/lab6
    

    Part 1: Othello

    Write a program (othello.c) that allows two human players to play the game of Othello by taking turns. The computer should keep track of the contents of the board, prevent either player from making illegal moves, and declare a winner (or a tie) when the game is done.

    The Rules

    Othello is a traditional board game played with pieces that have black (X) on one side, and white (O) on the other. There are several variations on the game, but we will play with the following rules:
  • Regardless of the size of the board, the game begins with this configuration at the middle of the board:
    . . . .
    . X O .
    . O X .
    . . . .
    
  • Player X goes first.
  • Players take turns placing one piece onto the board, until it is full.
  • Each piece must be played adjacent -- horizontally, vertically, or diagonally -- to another piece on the board.
  • Any pieces of the opposing color in any straight line that ends in the newly-placed piece and another piece of the same color are flipped to become the other color.
  • The player with the most pieces on the board at the end of the game wins. An equal number of pieces indicates a tie.
  • Example

    Here are the first few moves in a game with BOARD_SIZE=4:
    % ./othello
    
    starting board:
    
       0 1 2 3
     0 . . . .
     1 . X O .
     2 . O X .
     3 . . . .
    
    player X moves: 2 0
    
       0 1 2 3
     0 . . X .
     1 . X X .
     2 . O X .
     3 . . . .
    
    player O moves: 3 0
    
       0 1 2 3
     0 . . X O
     1 . X O .
     2 . O X .
     3 . . . .
    
    player X moves: 0 2
    
       0 1 2 3
     0 . . X O
     1 . X O .
     2 X X X .
     3 . . . .
    
    player O moves: 1 0
    
       0 1 2 3
     0 . O O O
     1 . X O .
     2 X X X .
     3 . . . .
    
    Your program must define a constant BOARD_SIZE at the beginning, and use it throughout, so that your code works for a board of any size. We suggest that you use a small board size when initially writing your code, so that it is easy to check for illegal moves, winning conditions, and so forth. However, you should test with varying board sizes, and then set BOARD_SIZE to the standard size of 8 before turning in.

    Use functions extensively. Define a function to display the board, to obtain the input, to check if a move is valid, etc etc. A correct program should consist of a number of short functions of no more than 5-10 lines each, all combined in simple ways. If any one function fills the screen, then it is time to break it up into pieces.

    Part 2: Computer Opponent

    (Part 2 is worth 10% of the overall assignment.)

    Copy your two-player code from othello.c to computer.c. Modify the program so that it allows one human player to play against an automatic computer player. For partial credit on this section, implement a computer player that always picks a valid (if not ideal) move. For full credit on this section, implement a computer player that always picks that move that flips over the most pieces.

    (A really clever computer player would look many moves ahead by using the Minimax algorithm. You don't have to be that clever (yet).)

    Turning In

    Please review the general instructions for lab reports.

    Turn in othello.c, computer.c, and report.txt. Your lab report should explain the final part of the assignment, explaning how it works from the user perspective, how the program works internally, and how you verified that the output of the program is correct.

    Turning In

    This assignment is due on Monday, October 28th Tuesday, October 29th at noon. Late assignments are not accepted.

    Please review the general instructions for turning in.