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 Solvers21
Suggested Problems
-
1678 Solvers
-
257 Solvers
-
GJam 2014 China Rd B: Sudoku Checker
61 Solvers
-
Factorions: Numbers that equal the sum of the factorials of their digits
76 Solvers
-
Big numbers, least significant digits
95 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!