Exemplo n.º 1
0
  @Override
  public Set<Move> getPossibleMoves(State state) {
    ArrayList<Move> temp = new ArrayList<Move>();
    Set<Move> result = new HashSet<Move>();
    temp = possibleMovePosition(state.getTurn(), state);
    if (state.getGameResult() != null) return result;

    for (int i = 0; i < temp.size(); i++) {
      result.add(temp.get(i));
    }

    return result;
  }
Exemplo n.º 2
0
 @Override
 public Set<Position> getPossibleStartPositions(State state) {
   Color color = state.getTurn();
   Set<Position> result = new HashSet<Position>();
   if (state.getGameResult() != null) return result;
   for (int i = 0; i <= 7; i++) {
     for (int j = 0; j <= 7; j++) {
       Piece piece = state.getPiece(i, j);
       if ((piece != null) && (piece.getColor().equals(color))) {
         PieceKind pk = piece.getKind();
         if (pk.equals(PAWN)) {
           ArrayList<Move> temp = new ArrayList<Move>();
           addPossiPawnMove(color, new Position(i, j), state, temp);
           if (temp.size() > 0) result.add(new Position(i, j));
         }
         if (pk.equals(KNIGHT)) {
           ArrayList<Move> temp = new ArrayList<Move>();
           addPossiKnightMove(color, new Position(i, j), state, temp);
           if (temp.size() > 0) result.add(new Position(i, j));
         }
         if (pk.equals(QUEEN)) {
           ArrayList<Move> temp = new ArrayList<Move>();
           addPossiQueenMove(color, new Position(i, j), state, temp);
           if (temp.size() > 0) result.add(new Position(i, j));
         }
         if (pk.equals(ROOK)) {
           ArrayList<Move> temp = new ArrayList<Move>();
           addPossiRookMove(color, new Position(i, j), state, temp);
           if (temp.size() > 0) result.add(new Position(i, j));
         }
         if (pk.equals(BISHOP)) {
           ArrayList<Move> temp = new ArrayList<Move>();
           addPossiBishopMove(color, new Position(i, j), state, temp);
           if (temp.size() > 0) result.add(new Position(i, j));
         }
         if (pk.equals(KING)) {
           ArrayList<Move> temp = new ArrayList<Move>();
           addPossiKingMove(color, new Position(i, j), state, temp);
           if (temp.size() > 0) result.add(new Position(i, j));
         }
       }
     }
   }
   return result;
 }
Exemplo n.º 3
0
  @Override
  public Set<Move> getPossibleMovesFromPosition(State state, Position start) {
    ArrayList<Move> temp = new ArrayList<Move>();
    Set<Move> result = new HashSet<Move>();
    if (state.getGameResult() != null) return result;
    Piece piece = state.getPiece(start);
    if (piece != null) {
      PieceKind piecekind = piece.getKind();
      Color color = piece.getColor();

      switch (piecekind) {
        case PAWN:
          addPossiPawnMove(color, start, state, temp);
          break;
        case KNIGHT:
          addPossiKnightMove(color, start, state, temp);
          break;
        case QUEEN:
          addPossiQueenMove(color, start, state, temp);
          break;
        case ROOK:
          addPossiRookMove(color, start, state, temp);
          break;
        case BISHOP:
          addPossiBishopMove(color, start, state, temp);
          break;
        case KING:
          addPossiKingMove(color, start, state, temp);
          break;
      }
      for (int i = 0; i < temp.size(); i++) {
        result.add(temp.get(i));
      }

      return result;

    } else return result;
  }