Othello/Reversi is a board game in which players take turn placing pieces of a color (dark or light) on the 8x8 board. The possible moves are positions where there are one or more pieces of the opponent's color in a straight (horizontal, vertical, or diagonal) line between that position and a piece of the player's color.
For example, on this board, the numbers on the left mark the row, the letters on the bottom mark the column, the empty spaces are marked .
, the dark pieces are marked D
, the light pieces are marked L
, and the possible moves for dark are marked *
:
1........
2........
3...D....
4...DD...
5.*LLLD..
6.****L..
7.....**.
8........
abcdefgh
Your task is to take a board as input and output the positions of the possible moves dark can make.
Rules
- Input and output can be in any convenient format. Possible input formats include as a string separated by newlines, as a matrix, and as a flattened list of numbers. Output positions can be in a format like
b5
, a list of two numbers, or a complex number. You may also choose to modify the input. - The output may be in any order but cannot contain duplicates.
- You may use different values to represent
D
,L
, and.
, as long as they are distinct. - You may assume that at least one move exists.
- Standard loopholes apply.
- This is code-golf, so the shortest code in bytes in each language wins.
Test cases
........
........
...D....
...DD...
..LLLD..
.....L..
........
........
b5 b6 c6 d6 e6 f7 g7
[[1, 4], [1, 5], [2, 5], [3, 5], [4, 5], [5, 6], [6, 6]]
........
........
........
...LD...
...DL...
........
........
........
c4 d3 e6 f5
[[2, 3], [3, 2], [4, 5], [5, 4]]
.....L..
...LL...
.DDDD.L.
.LDDDLL.
.LLDLLL.
.L.LD...
..LLL...
.L...L..
a4 a5 a6 a7 b7 c1 c6 c8 d1 d8 e1 e8 f6 g6 h3 h4 h5 h6
[[0, 3], [0, 4], [0, 5], [0, 6], [1, 6], [2, 0], [2, 5], [2, 7], [3, 0], [3, 7], [4, 0], [4, 7], [5, 5], [6, 5], [7, 2], [7, 3], [7, 4], [7, 5]]