Advertisement
Mirembe

Nim

Nov 23rd, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Nim
  3. {
  4.     public static void main(String[] args)
  5.     { Scanner scan = new Scanner(System.in); //to scan input
  6.         System.out.println ("Welcome to the game of Nim!");
  7.         System.out.println ("The game begins with a heap containing from 10 to 20 stones. Two players take turns to remove from 1 to 4 stones from the heap. The player who removes the last stone wins.");
  8.         int heapSize = (int)((Math.random() * 20) + 10);
  9.         boolean player1 = true;
  10.         while (heapSize > 0)
  11.         {
  12.             System.out.println ("The heap contains " + heapSize + "stones" + PLAYER (see mis muutuma peab iga kord) + " choose how many stones you want to remove (1-4)");
  13.             int input = scan.nextInt();
  14.             heapSize = heapSize - input;
  15.  
  16.             if (heapSize > 0)
  17.             {
  18.                 player1 = false;
  19.             }
  20.         } System.out.println ("The winner is " + player (peab teadma, kumb viimasena v6ttis) + "!");
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement