Example #1
0
  /** modify the player scores after this rule was matched */
  public void addScores(Context context) throws Exception {
    GameState gs = context.getState();

    for (int i = 0; i < scorePlayer.size(); i++) {
      int player = scorePlayer.get(i).eval(context).getInt();
      int amount = scoreAmount.get(i).eval(context).getInt();
      gs.playerScores[player - 1] += amount;
    }
  }
Example #2
0
 /** verifies whether the specified move conforms to this rule in the provided context */
 public boolean matches(Move move, Context context) throws Exception {
   GameState st = context.getState();
   if (element.matches(move.element, context))
     if ((state == null) || (state.matches(st.elementStates.get(move.element), context)))
       if ((currentPlayer == null) || (currentPlayer.matches(st.currentPlayer, context)))
         if (from.matches(move.from, context))
           if (to.matches(move.to, context)) return condition.eval(context).isTrue();
   return false;
 }
Example #3
0
 /**
  * list of moves that can be performed from this state with the element specified in the first
  * argument
  *
  * @return the list or null, if no such moves exist
  */
 public ArrayList<Move> getMatchingMoves(Element el, GameSpecification specs, Context context)
     throws Exception {
   GameState st = context.getState();
   ArrayList<Move> moves = new ArrayList<Move>();
   if (element.matches(el.name.fullName, context))
     if ((state == null) || (state.matches(st.elementStates.get(el.name.fullName), context)))
       if ((currentPlayer == null) || (currentPlayer.matches(st.currentPlayer, context))) {
         String tryFrom = st.elementLocations.get(el.name.fullName);
         if (from.matches(tryFrom, context))
           for (Location tryTo : specs.locations.values())
             if (st.locationElements.get(tryTo.name.fullName) == null)
               if (to.matches(tryTo.name.fullName, context))
                 if (condition.eval(context).isTrue())
                   moves.add(new Move(tryFrom, tryTo.name.fullName, el.name.fullName, specs));
       }
   if (moves.size() > 0) return moves;
   return null;
 }