示例#1
0
  private static void move_random_piece_at(int row, int col) {
    ArrayList<Position> moves = Move.getPieceMoves(_board.getPieceAt(row, col));
    Random r = new Random();
    while (moves != null && moves.size() != 0) {
      System.out.println("\nTurn #" + turn_number++ + "\n");
      Piece p = _board.getPieceAt(row, col);
      System.out.println(
          "Move from " + p.getPiece().toString() + " at row " + row + " and col " + col);
      moves = Move.getPieceMoves(p);
      if (moves.size() != 0) {
        System.out.println("Number of possible moves = " + moves.size());
        for (Position move : moves) {
          System.out.print("Move(" + move.getrow() + "," + move.getcol() + ") ");
        }
        System.out.println("");
        Position relative_nextpos = moves.get(r.nextInt(moves.size()));

        row = p.getPos().getrow() + relative_nextpos.getrow();
        col = p.getPos().getcol() + relative_nextpos.getcol();
        System.out.println("To row " + row + " and col " + col);
        Move.move(
            p,
            p.getPos().getrow() + relative_nextpos.getrow(),
            p.getPos().getcol() + relative_nextpos.getcol());
      }
      moves = Move.getPieceMoves(_board.getPieceAt(row, col));
      _board.printBoard();
      try {
        Thread.sleep(100);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }
示例#2
0
  public static void main(String[] args) {
    _board = new Board();
    System.out.println("Turn #" + turn_number++); // should be 0
    _board.printBoard();

    // move_random_piece_at(1,0);
    move_random_piece_at(0, 2);
  }