Question
Compete the function checkBoard that we began in lecture earlier this week for checking a 3-by-3 Tic-Tac-Toe board. If needed, you can review the rules
Compete the function checkBoard that we began in lecture earlier this week for checking a 3-by-3 Tic-Tac-Toe board. If needed, you can review the rules of Tic-tac-toe here.
Your function will receive a 3-by-3 two-dimensional array of characters, with each space containing an X, O, or a . if nobody has played in that position. You should return the char X if X has won the game, O if O has won the game, and . if neither player has won. Note that you should only check for vertical and horizontal winners, not diagonals. (Checking for diagonals will actually cause your submission to fail our tests.)
The passed board may be null. In that case you should return that neither player has won.
Starting Code:
char[][] currentBoard = {{'X', 'O', '.'}, {'O', 'X', '.'}, {'O', '.', 'X'}};
// Return the winner if the game is over, '.' otherwise static char checkBoard(char[][] board) {
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started