package condition;
import java.awt.Point;
import java.util.ArrayList;
import base.Engine;
import base.Piece;
public class NoCheckmateOnDrop extends DropRule {
private ArrayList<String> applicableTypes;
private boolean isApplicableType(Piece piece) {
for (String type : this.applicableTypes) {
if (piece.getRuleType().equals(type)) {
return true;
}
}
return false;
}
public NoCheckmateOnDrop(Engine engine, ArrayList<String> applicableTypes) {
super(engine);
this.applicableTypes = applicableTypes;
}
@Override
public boolean isValidDrop(Piece piece, Point destination) {
if (this.isApplicableType(piece)) {
Engine virtualEngine = new Engine(this.getEngine().getVirtualBoard(), this.getEngine().getTypes(), this.getEngine().getRules());
return !virtualEngine.putsSomeoneElseInCheckmate(piece, destination);
}
else {
return true;
}
}
}
|