Ejemplo n.º 1
0
 public static void main(String[] args) {
   Reversi reversiGame = null;
   try {
     reversiGame = (Reversi) new Configuration(args[0]).getGame();
   } catch (ClassNotFoundException c) {
     throw new Error(c);
   } catch (FileNotFoundException e) {
     throw new RuntimeException(e);
   }
   String input;
   Value prim;
   reversiGame.setStartingPosition(0);
   while (true) {
     System.out.println(reversiGame.displayState());
     prim = reversiGame.primitiveValue();
     if (prim != Value.UNDECIDED) break;
     System.out.println(prim.toString());
     TierState[] moves = reversiGame.newStateArray(16);
     int y = reversiGame.validMoves(moves);
     System.out.print("Valid Moves: ");
     for (int x = 0; x < y; x++) {
       System.out.print(reversiGame.getStringMoves()[x] + ",");
     }
     System.out.println();
     System.out.print("Hashes: ");
     for (int x = 0; x < y; x++) {
       System.out.print(moves[x].hash + ",");
     }
     System.out.println();
     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
     try {
       input = br.readLine();
     } catch (IOException e) {
       throw new Error(e);
     }
     int index = 0;
     for (index = 0; index < reversiGame.getStringMoves().length; index++)
       if (reversiGame.getStringMoves()[index].equals(input)) break;
     if (index == reversiGame.getStringMoves().length) {
       System.out.println("Invalid Move");
       break;
     }
     reversiGame.setState(moves[index]);
   }
   System.out.println("Game Over");
   if (prim == Value.LOSE)
     System.out.println((reversiGame.turn == BLACK ? "White wins" : "Black wins"));
   else if (prim == Value.TIE) System.out.println("Tie");
   else if (prim == Value.LOSE)
     System.out.println((reversiGame.turn == BLACK ? "Black wins" : "White wins"));
   else System.out.println("Bad result");
 }