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.
If 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 ]
then black has 4 legal moves shown by b.
[ 0 0 b 0 0 1 2 b b 2 1 0 0 b 0 0 ]
Any of these moves will flank (surround) a white chip and cause it to be flipped.
Your Cody challenge is to take the given board (always square) and side (1 or 2) and locate all the legal moves. Return all legal moves as a vector of column-wise indices into the matrix. If there are no legal moves, return empty.
Example.
For the board shown above,
side = 1 (black) moves = [3 8 9 14]
Note: See also Problem 2565, Determine the Result of a Move in Reversi.
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers20
Suggested Problems
-
Check to see if a Sudoku Puzzle is Solved
321 Solvers
-
881 Solvers
-
462 Solvers
-
76 Solvers
-
Triangular matrices in 3D array
121 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!