In the game of Nim, you have three piles of five stones. During each turn, each player can remove any number of stones from a single pile (a player cannot take stones from more than one pile). The player who removes the last stone from all of the heaps wins.
Here is a sample game:
Pile A | Pile B | Pile C | Action |
---|---|---|---|
5 | 5 | 5 | Game starts |
2 | 5 | 5 | Alice removes 3 stones from Pile A |
2 | 5 | 0 | Bob removes 5 stones from Pile C |
2 | 1 | 0 | Alice removes 4 stones from Pile B |
2 | 0 | 0 | Bob removes 1 stone from Pile B |
2 | 0 | 0 | Alice removes 2 stones from Pile A and wins! |
Create a version of the game of Nim that you can play against the computer. Use a JavaScript prompt() to prompt the user to select a pile and number of stones to remove from the pile. For example, if the user enters a3 then you should remove 3 stones from Pile A. If the user enters c5 then 5 stones should be removed from Pile C.
The computer should make smart decisions. For example, if the computer can win in a turn then the computer should make the winning move.
Draw the current state of the piles after each turn. Use console.log() to draw the piles:
Pile A: ooooo Pile B: ooo Pile C: ooooo
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more