Project Objectives

  • Basic input and output
  • Basic input and output
  • Two-dimensional arrays
  • Modularizing program with functions

Problem Specification

Write a C program to play a game of Othello (also called Reversi). The objective and the rules of Ohello game can be found on Wikipedia here: http://en.wikipedia.org/wiki/Reversi:

You can play this game online here: http://www.mathsisfun.com/games/reversi.html

The program starts the game with the following board configuration: see image.

Note:

  • Players take alternate turns.
  • A player is only allowed to make valid moves. A valid move is one where at least one disc of the opponent is reversed.
  • If a player cannot make a valid move, then that player loses his/her turn.
  • The game ends when neither player can move or when the board is full.
  • The player with the most pieces (discs) on the board at the end wins the game.

Project Files

You are provided with the following three files. Keep these files in a folder designated for this project.

  • othello.h: This header file contains constant definitions and function declarations used in the rest of the program. DO NOT MODIFY THIS FILE.
  • main.c: This file contains the main driver code to play the game. DO NOT MODIFY THIS FILE.
  • othello.c: This file contains the implementation of the functions declared in the header file othello.h. The function displayBoard() is already completed for you and do not make any changes to this function. Your job is to implement the rest of the functions in this file.

Compiling and Running the Program

Use the following command to compile the files:

$ gcc -Wall -std=c99 -o main *.c

Run the program as follows (Player 1 to start the game using black disc):

$ ./main 1 B
<<<<< Welcome to the game of Othello >>>>>
Player 1: B Player 2: W
Player 1 starts the game...

1 2 3 4 5 6 7 8
1 - - - - - - - -
2 - - - - - - - -
3 - - - - - - - -
4 - - - B W - - -
5 - - - W B - - -
6 - - - - - - - -
7 - - - - - - - -
8 - - - - - - - -

Turn> Player 1(B) - Enter location to place your disc (row col): 4 6

1 2 3 4 5 6 7 8
1 - - - - - - - -
2 - - - - - - - -
3 - - - - - - - -
4 - - - B B B - -
5 - - - W B - - -
6 - - - - - - - -
7 - - - - - - - -
8 - - - - - - - -
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.