Latrunculi, or Ludus Latrunculorum, is a two-player strategy board game that dates back to the Roman Empire and is believed to be a variant of Pessoi, an ancient Greek game. No historical evidence regarding its rules has ever been found and thus there is no definitive version. There are many variants based on various reconstructions by historians who have analyzed ancient texts and iconographies. The variations have different mechanics regarding board setup, capturing rules, etc., but they all share the same structure. Each player's pieces are placed on the far sides of the board (Figure 1.), in a manner very similar to chess, and play in turns with the goal of capturing the opponents pieces.
The goal is to either capture all the opponent's pieces or to completely immobilize the Duke.
All pieces (including the Duke) have the same movement capabilities, move either horizontally or vertically for any number of squares as long as no other piece (friendly or not) is blocking the way. The movement is identical to that of the rook in chess.
In order to capture a piece, it must be flanked vertically or horizontally. This is illustrated in Figure 2, where we can see three different ways black can capture white. A special case is when a piece is placed in a corner, and it must be flanked in the only two viable directions.
Figure 1 and 2: see image.
The flanking must have been completed by the piece that just moved, for the capture to take place. This means that suicide is not possible. In Figure 3, black can move between the two white pieces and it is safe because neither of the two white pieces was the last to move. Similarly, In Figure 5, black has voluntarily moved to a flanked position and is safe. White moving on his right flank does not trigger a capture, since the last moved piece does not complete any flanking. On the other hand, Figure 4 does lead to a capture because black's piece is immobilized.
Figure 3, 4, and 5: see image.
A piece is immobilized if it has nowhere to move. In Figure 4, white has moved to immobilize without flanking. This still leads to a capture.
In order to immobilize the Duke, it must be flanked from all four directions (or all viable directions). If it is placed in a corner, the capturing mechanics are identical for both duke and piece (Figure 6). The Duke's flanking doesnt have to be based on the opponents pieces entirely, since a Dukes movement can be blocked by its own pieces as well. But as long as one enemy piece is involved in the Dukes encirclement then the Duke is immobilized, and the game is lost. Therefore, Duke suicide is possible. In Figure 7, if white moves on the Dukes left flank, he blocks the last open direction and since black is involved in the encirclement by being on the top flank, the Duke is immobilized. If A duke is surrounded by his own pieces, he is not immobilized and thus the game is not lost.
Figure 6 and 7: see image.
You are to implement the variant of Latrunculi described in the section above, for two human players. The game should not permit illegal moves. You must implement three ADTs, one for a player, one for the board, and one for the referee.
At each turn, your program should prompt the appropriate player, to select a piece (grid position) and its destination. If an incorrect move is inputted (selected immobilized piece, selected opponent's, piece) the program should recognize the error and continue to request correct input until the user provides it.
When a player wins, the game should stop and a message indicating which player is victorious must be printed on the screen.