feat: add ai castling (Fixes #4)
All checks were successful
Linux arm64 / Build (push) Successful in 41s
All checks were successful
Linux arm64 / Build (push) Successful in 41s
This commit is contained in:
@@ -3,15 +3,9 @@ package chess.ai;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import chess.ai.actions.AIAction;
|
||||
import chess.controller.CommandExecutor;
|
||||
import chess.controller.commands.CastlingCommand;
|
||||
import chess.controller.commands.GetAllowedCastlingsCommand.CastlingResult;
|
||||
import chess.controller.commands.MoveCommand;
|
||||
import chess.controller.commands.PromoteCommand;
|
||||
import chess.controller.commands.PromoteCommand.PromoteType;
|
||||
import chess.model.Color;
|
||||
import chess.model.Coordinate;
|
||||
import chess.model.Move;
|
||||
|
||||
public class DumbAI extends AI {
|
||||
|
||||
@@ -23,39 +17,11 @@ public class DumbAI extends AI {
|
||||
|
||||
@Override
|
||||
protected void play() {
|
||||
CastlingResult castlings = getAllowedCastlings();
|
||||
List<Move> moves = getAllowedMoves();
|
||||
List<AIAction> actions = getAllowedActions();
|
||||
|
||||
switch (castlings) {
|
||||
case Both: {
|
||||
int randomMove = this.random.nextInt(moves.size() + 2);
|
||||
if (randomMove < moves.size() - 2)
|
||||
break;
|
||||
sendCommand(new CastlingCommand(randomMove == moves.size()));
|
||||
return;
|
||||
}
|
||||
int randomAction = this.random.nextInt(actions.size());
|
||||
|
||||
case Small:
|
||||
case Big: {
|
||||
int randomMove = this.random.nextInt(moves.size() + 1);
|
||||
if (randomMove != moves.size())
|
||||
break;
|
||||
sendCommand(new CastlingCommand(castlings == CastlingResult.Big));
|
||||
return;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
int randomMove = this.random.nextInt(moves.size());
|
||||
sendCommand(new MoveCommand(moves.get(randomMove)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void promote(Coordinate pawnCoords) {
|
||||
int promote = this.random.nextInt(PromoteType.values().length);
|
||||
sendCommand(new PromoteCommand(PromoteType.values()[promote]));
|
||||
actions.get(randomAction).applyAction();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user