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 Solvers22
Suggested Problems
-
28091 Solvers
-
Right Triangle Side Lengths (Inspired by Project Euler Problem 39)
2118 Solvers
-
275 Solvers
-
Split bread like the Pharaohs - Egyptian fractions and greedy algorithm
97 Solvers
-
Mersenne Primes vs. All Primes
850 Solvers
More from this Author54
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!