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
-
336 Solvers
-
Return unique values without sorting
925 Solvers
-
Find a subset that divides the vector into equal halves
387 Solvers
-
Count letters occurence in text, specific to words with a given length.
165 Solvers
-
Check that number is whole number
4327 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!