Lab 9: Tic Tac Toe (4 pts)

Due Friday 4/17/2020

Overview

The purpose of this lab two-fold. First, it will give students practice with 2D arrays. At least as importantly, though, no starter code has been provided, so students will need to start from scratch and think a little bit more about how to organize their code from the ground up. Therefore, this lab will worth 4 points instead of 2, and it will span 2 weeks.

The Game

Students will write a program that simulates a game of Tic-Tac-Toe. The Tic-Tac-Toe game is played on a 3x3 grid with two players who take turns. The first player marks moves with an X, and the second player marks moves with an O. The first player to form a horizontal, vertical, or diagonal sequence of three marks wins the game. Your program should do the following in order:

  1. Draw the game board
  2. As the user for the (zero-indexed) coordinates of the next mark, and record the appropriate mark at those coordinates
  3. Change the players after every successful move
  4. End the game and declare the winner once that happens, or declare that there has been a draw (i.e. the board has filled up with no winner)

Example Run

Slight variations on the input/output prompts are fine, but it should be clear to the user where they are in the game and what they need to input next.

Welcome to Tic-Tac-Toe!

Current Board:

- - -
- - -
- - -

Player X Give Coordinates: 2, 2
Current Board:
- - -
- - -
- - X
Player O Give Coordinates: 1,1
Current Board:
- - -
- O -
- - X

This back and forth should continue until someone wins or until there is a tie.

Code

You should have at least the five methods below in your code. You may create other methods to help you, but you need to have at least these

  1. Create and initialize the board. You should definitely be returning a 2D array of some sort here.
  2. Make the current user's move
  3. Determine if there is a winner
  4. Determine if there is a tie
  5. Put everything together and play the game (this could possibly happen in a main, but for style, try not to have a sprawling main)

Grading (Out of 4)

Points will be awarded in the following categories

  • Board generation/printing (1 point)
  • Play Loop (1 Points)
  • Win/Tie Detection (1 Point)
  • Style/Code Organization (1 Point)
  • Extra Credit (+1 Point): Changeable Board size; that is, prompt the user at the beginning for an odd number N and use this to generate an NxN grid on which to play. For instance, you should be able to play on a 7x7 grid.

What To Submit

You must submit a .zip file of your NetBeans project to Canvas. Click here to review instructions for how to do this.