Write a program for playing the game of Nim. The game of Nim starts with three h
ID: 3633969 • Letter: W
Question
Write a program for playing the game of Nim. The game of Nim starts with threeheaps and a fixed number of objects in each heap. Two players take turns removing
objects from the heaps. On a players turn, she chooses a heap and removes one or
more objects from that heap. She can remove all the objects from the heap. In our
version of the game of Nim, the player who takes the last object from the heaps (so
that all heaps are empty) wins.
(1) Prompt and read number of elements in each heap;(heap must be greater than zero)
(2) Draw the heaps;
(3) while (some heap is NOT empty) do
(4) Prompt and read the next player move. (Prompt and read the heap to modify and
the number of elements to remove from the heap.);
(5) Remove the specified number of elements from the specified heap;
(6) if (all heaps are empty) then
(7) Print a message congratulating the winning player.
(8) Else
(9) Redraw the heaps;
(10)Change to the other player;
(11)end
(12)end
Explanation / Answer
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.