40 lines
840 B
Java
40 lines
840 B
Java
package chess.simulator;
|
|
|
|
import java.util.List;
|
|
|
|
import chess.controller.CommandExecutor;
|
|
import chess.controller.commands.MoveCommand;
|
|
import chess.controller.event.GameAdaptator;
|
|
import chess.model.Move;
|
|
import common.Signal0;
|
|
|
|
public abstract class Simulator extends GameAdaptator {
|
|
|
|
protected final CommandExecutor commandExecutor;
|
|
|
|
public final Signal0 onComplete = new Signal0();
|
|
private int currentMove = 0;
|
|
|
|
public Simulator(CommandExecutor commandExecutor) {
|
|
this.commandExecutor = commandExecutor;
|
|
}
|
|
|
|
@Override
|
|
public void onGameStart() {
|
|
for (Move move : getMoves()) {
|
|
this.commandExecutor.executeCommand(new MoveCommand(move));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onBoardUpdate() {
|
|
currentMove++;
|
|
if (currentMove == getMoves().size()) {
|
|
onComplete.emit();
|
|
}
|
|
}
|
|
|
|
protected abstract List<Move> getMoves();
|
|
|
|
}
|