Maurice Tutor

(5)

$15/per page/Negotiable

About Maurice Tutor

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Algebra,Applied Sciences See all
Algebra,Applied Sciences,Biology,Calculus,Chemistry,Economics,English,Essay writing,Geography,Geology,Health & Medical,Physics,Science Hide all
Teaching Since: May 2017
Last Sign in: 398 Weeks Ago, 5 Days Ago
Questions Answered: 66690
Tutorials Posted: 66688

Education

  • MCS,PHD
    Argosy University/ Phoniex University/
    Nov-2005 - Oct-2011

Experience

  • Professor
    Phoniex University
    Oct-2001 - Nov-2016

Category > Computer Science Posted 27 Aug 2017 My Price 12.00

human players

Implement a text-based Tic-Tac-Toe game for two human players. However, you will be expanding your program to include computer players at a later date, so please realize that you are required to implement exactly the methods below even if you will only use the "human" options in this assignment. This program emphasizes two-dimensional arrays and methods.

Requirements

  1. Board: You must use a 3 x 3 two-dimensional array of chars to store the game board information. Valid values for each square on the board are:
    1. ‘ ’ (space) -- meaning this square is empty (not yet chosen)
    2. ‘X’ -- meaning this square is taken by player 1 (always ‘X’)
    3. ‘O’ -- meaning this square is taken by player 2 (always ‘O’).
  2. Player Options: For each game, your program should prompt the user to determine whether each player is human or computer, and you will just choose human for both. Player 1 always goes first and uses the ‘X’ symbol.
  3. Input and Output: The output of the board should be in text format, as shown below. Please use a fixed-width font (like Courier) so that things line up. Allow a human player to enter an integer to choose an empty square (see example below). Whenever an invalid square is chosen by a human player (already filled, or out of range), print an error message and have the human player try again. Sample output is shown below.
  4. End of Game: When a player wins, print out a message declaring the winner as shown below. If the game ends with no winner, print out a message declaring it a draw.

 

  1. Methods:You are required to define the following methods with these parameter profiles and return types. Assume the board is a 3x3 character array.
    1. void main():run a single game.
    2. void takeTurn(board, int playerNum, boolean human): Call the humanTurn method below with the correct player number and the board based on whether the boolean variable human is true or false.
    3. void humanTurn(board, int playerNum): Update the board by consulting the user, and announce the move.
    4. void announceMove(int playerNum, boolean human, int move)Print a line announcing which player of which type took which move. See sample output below.
    5. boolean horizontalWin(board, playerNum): Return true if this board has a horizontal win, false otherwise.
    6. boolean verticalWin(board, playerNum): Return true if this board has a vertical win, false otherwise.
    7. boolean diagonalWin(board, playerNum): Return true if this card has a diagonal win, false otherwise.
    8. int Winner(board):Return player’s number (1 or 2) if they win, zero otherwise.
    9. int availableSquares(board): Return the number of squares still available on the board.
    10. boolean isFull(board): Return true if this board has no empty squares.
    11. void printBoard(board): Print the current board and reminder board as shown below.
  2. Test Cases: Please test your program by playing each of the following games:
    1. human vs. human: draw
    2. human vs. human: Player2 wins.
    3. human vs. human: Player1 wins.

 

Sample Output: Be sure to print output in a fixed-width font so things line up.

 

Is player one human?(yes or no): yes

Is player two human?(yes or no): yes

 

Game Board: Positions:

| | 1 | 2 | 3

----------- -----------

| | 4 | 5 | 6

----------- -----------

| | 7 | 8 | 9

 

Player 1, please enter a number(1-9): 1

Player 1 chooses position 1.

X | | 1 | 2 | 3

----------- -----------

| | 4 | 5 | 6

----------- -----------

| | 7 | 8 | 9

 

Player 2, please enter a number(1-9): 6

Player 2 chooses position 6.

X | | 1 | 2 | 3

----------- -----------

| | O 4 | 5 | 6

----------- -----------

| | 7 | 8 | 9

 

Player 1, please enter a number(1-9): 3

Player 1 chooses position 3.

X | | X 1 | 2 | 3

----------- -----------

| | O 4 | 5 | 6

----------- -----------

| | 7 | 8 | 9

 

Player 2, please enter a number(1-9): 2

Player 2 chooses position 2.

X | O | X 1 | 2 | 3

----------- -----------

| | O 4 | 5 | 6

----------- -----------

| | 7 | 8 | 9

 

Player 1, please enter a number(1-9): 7

Player 1 chooses position 7.

X | O | X 1 | 2 | 3

----------- -----------

| | O 4 | 5 | 6

----------- -----------

X | | 7 | 8 | 9

 

Player 2, please enter a number(1-9): 4

Player 2 chooses position 4.

X | O | X 1 | 2 | 3

----------- -----------

O | | O 4 | 5 | 6

----------- -----------

X | | 7 | 8 | 9

 

Player 1, please enter a number(1-9): 5

Player 1 chooses position 5.

X | O | X 1 | 2 | 3

----------- -----------

O | X | O 4 | 5 | 6

----------- -----------

X | | 7 | 8 | 9

 

Game over! Player 1 has won the game!

BUILD SUCCESSFUL (total time: 1 minute 21 seconds)

Answers

(5)
Status NEW Posted 27 Aug 2017 01:08 PM My Price 12.00

Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll

Not Rated(0)