Skip to content

Commit

Permalink
assumes a "*" for prior if there was a build prior in the turn.
Browse files Browse the repository at this point in the history
  • Loading branch information
philihp committed May 2, 2012
1 parent 46af748 commit 73b322f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
23 changes: 17 additions & 6 deletions src/main/java/com/philihp/weblabora/model/CommandParameters.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@ public class CommandParameters {
/** /**
* Everything in the middle * Everything in the middle
*/ */
private List<String> params = new ArrayList<String>(2); //default it to an capacity of 2, since that's what it usually is private List<String> params = new ArrayList<String>(2); // default it to an
// capacity of 2,
// since that's what
// it usually is


/** /**
* The last token. * The last token.
*/ */
private String suffix; private String suffix;

private boolean placeClergyman; private boolean placeClergyman;


public CommandParameters() { private boolean mustBePrior;

public CommandParameters(boolean mustBePrior) {
this.mustBePrior = mustBePrior;
} }


public char getCommand() { public char getCommand() {
Expand All @@ -48,20 +54,25 @@ public String getSuffix() {
public void setSuffix(String suffix) { public void setSuffix(String suffix) {
this.suffix = suffix; this.suffix = suffix;
} }

public String get(int i) { public String get(int i) {
return params.get(i); return params.get(i);
} }

public int size() { public int size() {
return params.size(); return params.size();
} }


public void setPlaceClergyman(boolean placeClergyman) { public void setPlaceClergyman(boolean placeClergyman) {
this.placeClergyman = placeClergyman; this.placeClergyman = placeClergyman;
} }

public boolean getPlaceClergyman() { public boolean getPlaceClergyman() {
return this.placeClergyman; return this.placeClergyman;
} }

public boolean isMustBePrior() {
return mustBePrior;
}

} }
2 changes: 1 addition & 1 deletion src/main/java/com/philihp/weblabora/model/CommandUse.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void execute(Board board, CommandParameters params)


String buildingId = params.get(0); String buildingId = params.get(0);
UsageParam usageParam = null; UsageParam usageParam = null;
boolean usingPrior = params.getSuffix().contains("*"); boolean usingPrior = params.getSuffix().contains("*") || params.isMustBePrior();


if(params.size() == 1) { if(params.size() == 1) {
usageParam = new UsageParamSingle(""); usageParam = new UsageParamSingle("");
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/philihp/weblabora/model/MoveHistory.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public class MoveHistory { public class MoveHistory {
private boolean previousUse = false; private boolean previousUse = false;
private boolean settling; private boolean settling;
private boolean previousBuild = false;


public MoveHistory(boolean settling) { public MoveHistory(boolean settling) {
this.settling = settling; this.settling = settling;
Expand All @@ -12,15 +13,19 @@ public boolean isSettling() {
return settling; return settling;
} }


public String toString() { public boolean isPreviousBuild() {
return "{previousUse=" + previousUse + "}"; return previousBuild;
}

public void setPreviousBuild(boolean previousBuild) {
this.previousBuild = this.previousBuild || previousBuild;
} }


public boolean isPreviousUse() { public boolean isPreviousUse() {
return previousUse; return previousUse;
} }


public void setPreviousUse(boolean isPreviousUse) { public void setPreviousUse(boolean isPreviousUse) {
this.previousUse = isPreviousUse; this.previousUse = this.previousUse || isPreviousUse;
} }
} }
7 changes: 3 additions & 4 deletions src/main/java/com/philihp/weblabora/model/MoveProcessor.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public static void processMoves(Board board, Iterable<String> allMoves) throws W
board.preMove(move); board.preMove(move);
processActions(board,move); processActions(board,move);
board.postMove(); board.postMove();
System.out.println("Testing Validity");
board.testValidity();
} }
} }


Expand All @@ -39,7 +37,7 @@ public static void processActions(Board board, String actions)


public static void processSingleAction(Board board, String move, MoveHistory history) public static void processSingleAction(Board board, String move, MoveHistory history)
throws WeblaboraException { throws WeblaboraException {
CommandParameters params = new CommandParameters(); CommandParameters params = new CommandParameters(history.isPreviousBuild());


String prefix = move.substring(0, move.indexOf('(')); String prefix = move.substring(0, move.indexOf('('));
String inner = move.substring(move.indexOf('(')+1, move.indexOf(')')); String inner = move.substring(move.indexOf('(')+1, move.indexOf(')'));
Expand All @@ -62,7 +60,8 @@ public static void processSingleAction(Board board, String move, MoveHistory his
MoveCommand moveCommand = pickCommand(params.getCommand(), history); MoveCommand moveCommand = pickCommand(params.getCommand(), history);
moveCommand.execute(board, params); moveCommand.execute(board, params);


history.setPreviousUse(moveCommand instanceof CommandUse); history.setPreviousUse(moveCommand instanceof CommandUse);
history.setPreviousBuild(moveCommand instanceof CommandBuild);
} }


public static MoveCommand pickCommand(char commandChar, MoveHistory history) throws WeblaboraException { public static MoveCommand pickCommand(char commandChar, MoveHistory history) throws WeblaboraException {
Expand Down

0 comments on commit 73b322f

Please sign in to comment.