Project: Square Game

Two players A and B play the following game. Starting with a stack of rows of squares, they take turns with player A first in removing squares. In each turn the player
• identifies one row with at least one square
• remove(eat) any number>0 of squares from that row (all if so desired), but do not remove them from any other row.
The player who removes the last square wins.


Part A

Describe a main idea ("invariant") of the state of the board you leave after your move, so that you have a winning strategy no matter what your opponent does. In other words you can preserve the invariant property (requires math proof). You see yourself as player B, playing after our opponent player A.

Part B

Pseudocode: Write a procedure on paper (bullet points, english) for your move
• on how to manage the state of the board, including an opponent mistake
• how to identify the row for your move
• how many squares to eat


Part C

Write a computer program that can play the game optimally (wins if there is a winning strategy). Your program must allow for the opponent input, turn-based.
Implement the option to read the board from a file, or to generate a random board with params n=number of rows, m= max squares per row.
You dont have to implement any graphic display of the game, but at the minimum you must print on the console the state of the board and your assessment, in a way that is readable.

See this screenshot for running a jar-implementation
See this website for a graphical version.

Test cases: test1    test2    test3    test4    test5    test6    test7    test8