//  File board.h
#ifndef _BOARD_H_
#define _BOARD_H_

//  Tic-tac-toe is played by two players, X (CROSS) and O (NOUGHT).
//  A position on the board can be occupied by either player or
//  neither player (EMPTY).  These are constants because their
//  values should never change.
//
//  These constants are used in the following ways:
//      - return value of the look function
//      - return value of the current_player function

const int NOUGHT = 2,  //  Player O's mark
          CROSS  = 1,  //  Player X's mark
          EMPTY  = 0;  //  Neither player; the location has no mark


//  The Tic-tac-toe board consists of nine locations:
//
//   0 | 1 | 2
//  ---+---+---
//   7 | 8 | 3
//  ---+---+---
//   6 | 5 | 4
//
//  We will use nine global constants to represent conveniently
//  those nine locations. The constant names are chosen from  
//  the points on a compass:
//
//            |        |
//  NORTHWEST | NORTH  | NORTHEAST
//            |        |
//  ----------+--------+----------
//            |        |
//    WEST    | CENTER |   EAST
//            |        |
//  ----------+--------+----------
//            |        |
//  SOUTHWEST | SOUTH  | SOUTHEAST
//            |        |
//
//  These constants are used in the following ways:
//      - parameter to the move function
//      - parameter to the look function

const int NORTHWEST = 0,  // left-top corner  (northwest)
          NORTH     = 1,  // center-top       (north)
          NORTHEAST = 2,  // right-top corner (northeast)
          EAST      = 3,  // right-center     (east)
          SOUTHEAST = 4,  // right-bottom     (southeast)
          SOUTH     = 5,  // center-bottom    (south)
          SOUTHWEST = 6,  // left-bottom      (southwest)
          WEST      = 7,  // left-center      (west)
          CENTER    = 8;  // center square


//  Board status values.
//  There are seven winning board cofigurations.  In addition,
//  there is one way for the game to end in a draw.  If the game is
//  not over yet because moves are available, then no one has won
//  or tied.  We encode these possible scenarios into the following
//  integer constants representing the status of the board
//
//  These constants are used as the return value of the 
//  check_status function

const int PLAYING     = 100,  //  No one has won and a move is available
          WIN_NW_NE   = 101,  //  Win across top row, 0-1-2
          WIN_W_E     = 102,  //  Win across middle row, 7-8-3
          WIN_SW_SE   = 103,  //  Win across bottom row, 6-5-4
          WIN_NW_SW   = 104,  //  Win along left column, 0-7-6
          WIN_N_S     = 105,  //  Win along center column, 7-8-3
          WIN_NE_SE   = 106,  //  Win along right column, 2-3-4
          WIN_NW_SE   = 107,  //  Win from left-top corner to right-bottom 
                            //  corner, 0-8-4
          WIN_NE_SW   = 108,  //  Win from right-top corner to left-bottom 
                            //  corner, 2-8-6
          DRAW        = 109;  //  All squares filled with no winner

const int NO_POSITION = 1000;

//  check_status checks to see if either player has won or if the
//  board is filled.  The function returns the status of the board.
//  The status is one of PLAYING, WIN_NW_NE, WIN_W_E, etc. 
int check_status();

//  Places the current player's mark at the given location, if possible.
//  The function returns true if the move can be made.  The move is
//  only possible if the location is currently empty.  If a player
//  attempts to move to an occupied location, the function does not
//  change the board and it returns false.  If the location is
//  available (empty), the player's mark is placed in the location
//  and the function returns true.  
//  The move function also controls alteranting to the next player
//  if the move was successful.
bool move(int location);

//  Returns the player whose turn it is to move.  This allows the
//  presentation to report whose turn it is.
//  Return value is one of the constants NOUGHT or CROSS
int current_player();

//  Returns the mark at the given location.
//  Returns EMPTY if neither player has marked 
//  the given location.  The function's valid return
//  values are EMPTY, CROSS, or NOUGHT.
//  This function allows the presentation to draw the contents
//  of the Tic-Tac-Toe board.
int look(int location);

//  Make all the board locations empty and set current player to X
//  (that is, reset to the start of a new game)
void clear_board();

#endif

