Digital Academic Solutions

C++ Connect6 Game Code

SOLUTION AVAILABLE AT: http://libraay.com/downloads/java-connect6-game-code/

Problem:

The objective of this assignment is to practice the use of 2-D arrays with loops. You will write a program to play a game called Connect6 (AAlt), which is played on a 19 x 19 game board by two players Black and White. Black plays first, by placing a black piece on an empty position of the board. Then, White and Black take turns, placing two pieces of their colors to empty positions each turn. The player who first connects six or more consecutive pieces of his/her color in a line (horizontally E—>, vertically $, or diagonally NZ) wins the game. When the board is full and no player connects six or more, it is a draw game. Figure 1 shows an example game board. The characters ‘B’, ‘W’, and denote black piece, white piece, and empty position respectively. The rows and columns are named in numbers 0,1,2,… and uppercase letters A,B,C,… respectively.

Game Board

A two-dimensional array of char is used to represent the game board.

const int N = 19;

char board[N][N];

The array elements board [0] [0], board[0] [N-1], board[N-1 ] [0 ], and board[N-1] [N-1] denote the top-left, top-right, bottom-left, and bottom-right corners of the board respectively. When N is 19, this means positions AO, SO, A18, and 518 respectively.

Game Flow

■ The game starts with an empty board. Black moves first by placing one black piece on an empty position in the board. Subsequently, White and Black alternately put two of their pieces on two empty positions.

In each move, the input is a character followed by an integer, e.g., A5, to denote the input position. (Hint: You can use c in >>  >> …; to read an input. The column letter and row number can be read appropriately even they are typed immediately together.)

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. You should warn the player about invalid inputs and prompt the same player to enter again until a valid input is entered. Check the vertical, horizontal, and diagonal winning conditions. If the game is over, print the messages “Black wins!”, “White wins!”, or “Draw game!” accordingly.

Special Requirements

Global variables (variables declared outside any functions) are not allowed. Nonetheless, con st ones (e.g., N) do not count. Your program should be decomposed into at least four functions (including main( )). At least two functions should have array parameter(s). Your program should be scalable to other values for the named constant N. That is, your program should still work normally for board size other than 19. When grading, we may modify your program by changing N to other values ranging 6-26 for testing.

Sample Run

In the following sample run, the blue text is user input and the other text is the program printout. More sample runs are provided in Blackboard. Besides, you can try the provided sample program for other input. Your program output should be exactly the same as the sample program (same text, symbols, letter case, spacings, etc.). Note that there is a space after the ‘: ‘ in the program printout.

SOLUTION AVAILABLE AT: http://libraay.com/downloads/java-connect6-game-code/

Leave a Reply

Your email address will not be published. Required fields are marked *



Solutions Authored by 15+ Years Experienced Industry Expert