Problem 2565. Determine the Result of a Move in Reversi
Note: This is closely related to Problem 2538, Find the Next Legal Move in Reversi.
Reversi, also known as Othello, is a game in which reversible white/black chips are placed on a grid. The goal is to have the most pieces once the board is full (i.e. there are no more legal moves). A move, to be legal, must flip at least one opponent's chip by flanking it. "Flanking" occurs by surrounding a line of opposing chips with two of your own. It can occur on straight lines and diagonals.
We represent a small 4x4 board this way, with 0 for empty squares, 1 for black chips, and 2 for white chips,
[ 0 0 0 0 0 1 2 0 0 2 1 0 0 0 0 0 ]
Now assume black now moves where the asterisk (*) is placed. This is column-wise matrix index position 14.
[ 0 0 0 0 0 1 2 * 0 2 1 0 0 0 0 0 ]
Your Cody challenge is to determine the state of the board once the appropriate chips have been flipped over. In this case the correct answer would be
[ 0 0 0 0 0 1 1 1 0 2 1 0 0 0 0 0 ]
Example
For the inputs boardIn, side, and move
boardIn = ... [ 0 0 0 0 0 0 1 1 2 2 0 2 1 1 0 0 0 2 1 0 0 0 0 0 0 ] side = 1 (black) move = 9 (matrix index of black's next move)
The correct answer is
boardOut = ... [ 0 0 0 0 0 0 1 1 2 2 0 1 1 1 0 0 1 1 1 0 0 0 0 0 0 ]
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers19
Suggested Problems
-
Return elements unique to either input
769 Solvers
-
9735 Solvers
-
118 Solvers
-
Mirror Image matrix across anti-diagonal
187 Solvers
-
1363 Solvers
More from this Author50
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!