Question
php / * We are going to create a game of tic-tac-toe and we need to control the state of the board. To do this, we will create a function.
Suppose the board comes in the form of a 3x3 array, in which the value is 0 if the box is empty, 1 if it is an X and 2 if it is an O, such like this:
[[0,0,1], [0,1,2], [2,1,0]]
What we want is for our function to return -1 if the board is not resolved, 1 if X have won, 2 if O have won and 0 if tie.
We will assume that the board passed as input is always valid, given that we are within the context of our game. * / function boardState (array $ board): int {
}
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