You are writing part of a board-game engine. Given a board layout and a player, you must enumerate every legal move for that player.
The game is played on an $8 \times 8$ grid of identical squares. Rows are labeled A through H from top to bottom, and columns are labeled 1 through 8 from left to right, so each square is named by its row letter followed by its column number (for example, A1 is the top-left square and H8 is the bottom-right square).
There are two players, whose pieces are written X and O (the letter "oh", not the digit zero). At any moment each player has between 1 and 12 pieces on the board. A move obeys the following rules:
The input contains one or more board layouts. Each layout is 8 lines of 8 characters; every character is X, O, or . (a period), where X and O mark occupied squares and . marks an empty square. Immediately after each board comes a single line containing one character, X or O, naming the player whose moves must be listed. The input ends at end of file.
For each board, print every legal move for the named player, one move per line. Each line gives the origin square and the destination square, in that order, joined by a single hyphen - (for example, A1-B2); each square is written as its row letter followed by its column number. If the player has no legal move on that board, print No moves are possible instead. Separate the output of consecutive boards with a single blank line.
So that the output is uniquely determined, list the moves in this exact order: scan the squares of the board top to bottom, and within each row from left to right; for each of the named player's pieces, test the eight directions in this clockwise order — up, up-right, right, down-right, down, down-left, left, up-left — and emit each legal move in the order it is found.