Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# IntelliJ IDEA #
.idea
*.iws
*.iml
*.ipr
14 changes: 14 additions & 0 deletions src/main/java/com/rockstar/internal/Comparison.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ public boolean compare(Value lhs, Value rhs) {
double r=rhs.getValue(Double.class);
return l>r;
}
},ASLOW {
@Override
public boolean compare(Value lhs, Value rhs) {
double l=lhs.getValue(Double.class);
double r=rhs.getValue(Double.class);
return l<=r;
}
},ASHIGH {
@Override
public boolean compare(Value lhs, Value rhs) {
double l=lhs.getValue(Double.class);
double r=rhs.getValue(Double.class);
return l>=r;
}
};

public final boolean compare(Program state,String lhs,String rhs) {
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/com/rockstar/parser/ConditionParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public class ConditionParser {
private final static List<String> IS_IDS=Arrays.asList(" is ");
private final static Set<String> HIGHER_IDS=ImmutableSet.of("higher","greater","bigger","stronger");
private final static Set<String> LOWER_IDS=ImmutableSet.of("lower","less","smaller","weaker");

private final static Set<String> ASHIGH_IDS=ImmutableSet.of("as high","as great","as big","as strong");
private final static Set<String> ASLOW_IDS=ImmutableSet.of("as low","as little","as small","as weak");

public static Condition parseCondition(String str) {
// "Is not" must be tried before "is" because "is not" includes "is".
for (String notId:IS_NOT_IDS) if (str.contains(notId)) return new InvertedCondition(parseCondition(str,notId));
Expand All @@ -34,6 +36,14 @@ public static Condition parseCondition(String str,String id) {
if (HIGHER_IDS.contains(resplit[0])) return new ComparisonCondition(lhs,resplit[1],Comparison.HIGHER);
else if (LOWER_IDS.contains(resplit[0])) return new ComparisonCondition(lhs,resplit[1],Comparison.LOWER);
else throw new RockstarException("Malformed condition.");
} else return new ComparisonCondition(lhs,split[1],Comparison.EQUAL);
}
else if (split[1].contains(" as ")) {
String[] resplit=split[1].split(" as ");
if (ASHIGH_IDS.contains(resplit[0])) return new ComparisonCondition(lhs,resplit[1],Comparison.ASHIGH);
else if (ASLOW_IDS.contains(resplit[0])) return new ComparisonCondition(lhs,resplit[1],Comparison.ASLOW);
else throw new RockstarException("Malformed condition.");
}

else return new ComparisonCondition(lhs,split[1],Comparison.EQUAL);
}
}