NoCheckmateOnDrop.java :  » Game » sysboard » condition » Java Open Source

Java Open Source » Game » sysboard 
sysboard » condition » NoCheckmateOnDrop.java
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;
    }
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.