There are 2 players (player Black and player White) and an empty square game board (N*N). players take turn to place their pieces on empty cells of the boardC++ Programming

Computer Principles and C++ Programming

  • Requirements:
    • Filename: cpp;
    • Insert your name, student ID, and e-mail address as comments at the beginning of your source file;
    • Include suitable comments as documentation;
    • Free of compilation errors and warnings;
    • Only constant global variables allowed;
    • At least four functions (including main());

At least two functions should have array parameter(s).

Game Description

    Start condition:

  • There are 2 players (player Black and player White) and an empty square

game board (N*N).

  • Game stage:

    • The players take turn to place their pieces on empty cells of the board. (Player Black first place one black piece, then White and Black take turns, placing two pieces of their colors to empty positions each )

•     End condition:

  • The player who first connects six or more consecutive pieces of his/her color in a line (horizontally ↔, vertically ↕, or diagonally ⤡⤢) wins the game

  • When the board is full and no player connects six or more, it is a draw

game

Board Representation

  • Square board of size N*N where N is a constant integer

  • In each position, “B” means black piece; “W” means white piece; and “.” indicates an empty

  • The rows and columns are named in numbers 0, 1, 2,… and uppercase letters A, B, C, …

  • Code representation:

N = 19

•     board[0][0] => top-left

  • board[0][N-1] => top-right

  • board[N-1][0] => bottom-left

  • board[N-1][N-1] => bottom-right

  • When N is 19, the above refers to

A0, S0, A18, and S18 respectively.

  • We can simply modify the board

size by change a single variable N.

  1. Handle B’s inputs

When handling the input:

  • If the input is valid, update the board and

print it.

  • Else ask for correct input again by printing “Invalid Enter again!” until a valid input is entered.

A user input is valid if: (a) it is a proper board location within bounds, and (b) the input position is empty. Note that column letters must be uppercase. Lowercase letters are considered invalid.

Recall that N is not always 19 => The right

most column / bottom row is not always S

e.g.,

  • H14 will be invalid in the rest of this

game since it’s been occupied

  • H300 will be invalid since it’s out of

the boundary

  • b4 will be invalid since it is in

lowercase

  1. Ask white player to place the first

piece in this turn, handle W’s input,

check

  • (1) if the game hasn’t met the ending

condition, continue to step 4;

  • (2) else we end the game and

announce result.

  1. Ask white player to place the second

piece in this turn, handle W’s input,

check

  • (1) if the game hasn’t met the ending

condition, continue to step 5;

  • (2) else we end the game and

announce result. 

Program Flow

  1. Ask black player to place the first

piece in this turn, handle B’s input,

check

  • (1) if the game hasn’t met the ending

condition, continue to step 6;

  • (2) else we end the game and

announce result.

Attachments:

Instructions Files

Expert's Answer

OR

C++ Programming Experts

expert
Dinh Hong P.
C++ Programming

20 Answers

expert
Eric Bell
C++ Programming

88 Answers

View More Experts
Disclaimer

The ready solutions purchased from Library are already used solutions. Please do not submit them directly as it may lead to plagiarism. Once paid, the solution file download link will be sent to your provided email. Please either use them for learning purpose or re-write them in your own language. In case if you haven't get the email, do let us know via chat support.

Get Free Quote!

250 Experts Online