In: Electrical Engineering
Programming assignment for ENSC 3213
NIM
The program is to be written in Matlab. Program must be liberally commented.
The program is a game played by a human versus the machine.
At the start, the prompt asks the human to enter three non-zero integers. These will constitute how many counters are in each Pile.
The machine then asks who goes first.
A turn consists of selecting a Pile and taking a number of counters from that pile.
For example, if the Piles contain 3, 7 and 12 counters, a legal move consists of taking from 1 to 3 from Pile 1, or 1, 2, … 7 from Pile2 etc.
The object of the game is to be the player to take the last counter(s). So if Piles contain 0 2 0, the player whose turn it is will take 2 from Pile 2 and win.
The program must play and optimal strategy so if it has a winning position it will win the game. If it does not have a winning position it should try to extend the game.
At the end of the game, the program must declare the winner.