fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. package nim;
  13.  
  14. public class Nim {
  15.  
  16. private static int [] _piles;
  17.  
  18. public String toString(){
  19. return "Pile 0 has: " + getPile(0) + " bricks left. | Pile 1 has: " + getPile(1) + " bricks left | Pile 2 has: " + getPile(2) + " bricks left.";
  20. }
  21.  
  22. //Sette antall brikker
  23. public Nim(){
  24. _piles = new int [3];
  25. _piles[0] = 10;
  26. _piles[1] = 10;
  27. _piles[2] = 10;
  28. }
  29.  
  30. public Nim(int pileSize){
  31. _piles = new int [3];
  32. _piles[0] = pileSize;
  33. _piles[1] = pileSize;
  34. _piles[2] = pileSize;
  35. }
  36.  
  37. public static boolean isValidPile(int pile){
  38. if ((pile!=0||pile!=1||pile!=2)){
  39. return false;
  40. }else
  41. return true;
  42. }
  43.  
  44.  
  45. void removePieces(int number, int targetPile){
  46. if (!(isValidMove(number,targetPile))){
  47. throw new IllegalArgumentException("number or targetPile is not valid: " + number + "|" + targetPile );
  48. }else{
  49. _piles[targetPile] -= number;
  50. }
  51. }
  52.  
  53. boolean isValidMove(int number, int targetPile){
  54. if ((number >= 1) && (!isValidPile(targetPile))){
  55. return true;
  56. }else{
  57. throw new IllegalArgumentException("Number has to be 1 or higher or target pile was not viable: num = " + number + "targetPile = " + targetPile);
  58. }
  59. }
  60.  
  61. static boolean isGameOver(){
  62. for(int i=0; i < 3; i++){
  63. if (getPile(i) != 0){
  64. return false;
  65. }
  66. }
  67. return true;
  68. }
  69.  
  70. static int getPile(int targetPile){
  71. if (isValidPile(targetPile)){
  72. throw new IllegalArgumentException("Target Pile is not valid: " + targetPile);
  73. }else{
  74. return _piles[targetPile];
  75. }
  76. }
  77.  
  78.  
  79.  
  80. }
  81. }
  82. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:12: error: illegal start of expression
	package nim;
	^
Main.java:12: error: not a statement
	package nim;
	        ^
Main.java:14: error: illegal start of expression
public class Nim {
^
3 errors
stdout
Standard output is empty