@Override public Set<Move> generateMoves(Position curPos) { Set<Move> moves = new HashSet<>(); int curCol = curPos.getCol(); int curRow = curPos.getRow(); for (int i = -1; i <= 1; i++) { int destCol = curCol + i; int destRow = curRow + dy; if (ChessUtils.posBoundsTest(destRow, destCol)) { boolean mustCapture = destCol != curCol; boolean cannotCapture = destCol == curCol; Move moveToAdd; if (destRow == 0 || destRow == 7) { moveToAdd = new PromotionMove( curPos, new Position(destRow, destCol), false, cannotCapture, mustCapture); } else if (mustCapture) { moveToAdd = new PawnCaptureMove( curPos, new Position(destRow, destCol), false, cannotCapture, mustCapture); } else { moveToAdd = new Move(curPos, new Position(destRow, destCol), false, cannotCapture, mustCapture); } moves.add(moveToAdd); } } if (curRow == initialRow) { moves.add(new Move(curPos, new Position(curRow + dy * 2, curCol), false, true, false)); } return moves; }
@Override public Set<Move> generateMoves(Position curPos) { Set<Move> moves = new HashSet<>(); int curCol = curPos.getCol(); int curRow = curPos.getRow(); for (int dx = -1; dx <= 1; dx++) { for (int dy = -1; dy <= 1; dy++) { if (dx != 0 || dy != 0) { int destCol = curCol + dx; int destRow = curRow + dy; if (ChessUtils.posBoundsTest(destRow, destCol)) { Position destPos = new Position(destRow, destCol); moves.add(new Move(curPos, destPos)); } } } } return moves; }