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.
This code is referenced in the following blog post: http://blogs.mathworks.com/community/2015/01/19/robot-game-playing-in-matlab-part-2/
650 Solvers
Make one big string out of two smaller strings
1070 Solvers
Back to basics 8 - Matrix Diagonals
707 Solvers
Rotate and display numbered tile
221 Solvers
Get the length of a given vector
1371 Solvers