Programming assignment for ENSC 3213
NIM
The program is to be written in Matlab. Program must beliberally 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-zerointegers. These will constitute how many counters are in eachPile.
The machine then asks who goes first.
A turn consists of selecting a Pile and taking a number ofcounters from that pile.
For example, if the Piles contain 3, 7 and 12 counters, a legalmove consists of taking from 1 to 3 from Pile 1, or 1, 2, … 7 fromPile2 etc.
The object of the game is to be the player to take the lastcounter(s). So if Piles contain 0 2 0, the player whose turn it iswill take 2 from Pile 2 and win.
The program must play and optimal strategy so if it has awinning position it will win the game. If it does not have awinning position it should try to extend the game.
At the end of the game, the program must declare the winner.