Skip to content

Commit

Permalink
Crash fix and v0.4.7.1b release
Browse files Browse the repository at this point in the history
  • Loading branch information
jay@sif committed Mar 8, 2018
1 parent 5e79598 commit c5bb1eb
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 12 deletions.
5 changes: 4 additions & 1 deletion README.txt
Expand Up @@ -291,7 +291,10 @@ http://manywords.press/other-stuff/opentafl/opentafl-notation-spec.txt (notation


13. VERSION HISTORY -----------------------------------------------------------
v0.4.7.0b (released 11/3/17):
v0.4.7.1b (released 03/07/18):
- Fix crash bug in 'rules' command output

v0.4.7.0b (released 11/03/17):
- Add mercenary taflmen, which switch sides when captured
- Add Linnaean capture
- If a defender is next to the king, who is on the throne and surrounded
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -20,7 +20,7 @@ dependencies {

jar {
baseName = 'OpenTafl'
version = 'v0.4.6.4b'
version = 'v0.4.7.1b'
manifest {
attributes ('Main-Class': mainClassName, "Class-Path": configurations.compile.collect { it.getName() }.join(' '))
}
Expand Down
2 changes: 1 addition & 1 deletion src/com/manywords/softworks/tafl/OpenTafl.java
Expand Up @@ -40,7 +40,7 @@ private static enum Mode {
READ_JSON, HELP
}

public static final String CURRENT_VERSION = "v0.4.7.0b";
public static final String CURRENT_VERSION = "v0.4.7.1b";
public static final int NETWORK_PROTOCOL_VERSION = 7;

public static boolean devMode = false;
Expand Down
4 changes: 3 additions & 1 deletion src/com/manywords/softworks/tafl/test/Test.java
Expand Up @@ -19,14 +19,16 @@ public static void run() {
List<TaflTest> tests = new ArrayList<TaflTest>();

// Initial tests (debug only)
tests.add(new TaflmanCoordMapTest());


// Mechanics tests
tests.add(new TaflmanCoordMapTest());
tests.add(new RepetitionHashTableTest());
tests.add(new MoveRecordRotationMirrorTest());
tests.add(new MoveAddressTest());
tests.add(new ReplayGameTest());
tests.add(new KingMissingPositionRecordTest());
tests.add(new RulesPrinterCrashTest());

// Consistency tests
tests.add(new GameSerializerConsistencyTest());
Expand Down
@@ -0,0 +1,20 @@
package com.manywords.softworks.tafl.test.mechanics;

import com.manywords.softworks.tafl.rules.Rules;
import com.manywords.softworks.tafl.rules.Variants;
import com.manywords.softworks.tafl.test.TaflTest;
import com.manywords.softworks.tafl.ui.HumanReadableRulesPrinter;

public class RulesPrinterCrashTest extends TaflTest {
@Override
public void run() {
try {
for(Rules r : Variants.availableRules) {
HumanReadableRulesPrinter.getHumanReadableRules(r);
}
}
catch(Exception e) {
assert false;
}
}
}
30 changes: 22 additions & 8 deletions src/com/manywords/softworks/tafl/ui/HumanReadableRulesPrinter.java
Expand Up @@ -6,9 +6,7 @@
import com.manywords.softworks.tafl.rules.Rules;
import com.manywords.softworks.tafl.rules.Taflman;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.regex.Pattern;

/**
Expand Down Expand Up @@ -744,21 +742,37 @@ else if(attackerString.contains("no") && defenderString.contains("no")) {
}
}

private static boolean validateTaflmanPattern(String spec) {
Pattern taflmanSpecChars = Pattern.compile("\\s*[tcnkmTCNKM]*\\s*");
if(!taflmanSpecChars.matcher(spec).matches()) return false;

Map<Character, Integer> counts = new HashMap<>();

for(char c : spec.toCharArray()) {
counts.put(c, counts.getOrDefault(c, 0) + 1);
}

for(int i : counts.values()) {
if(i > 1) return false;
}

return true;
}

private static String getTaflmanTypeStringFromSpec(Rules r, boolean attackingSide, String spec) {
Pattern taflmanSpecPattern = Pattern.compile("\\s*t?c?n?k?T?C?N?K?\\s*");
if(!taflmanSpecPattern.matcher(spec).matches()) throw new IllegalArgumentException("Bad taflman spec");
if(!validateTaflmanPattern(spec)) throw new IllegalArgumentException("Bad taflman spec");

String taflmenString = (attackingSide ? "attacking " : "defending ");

if(spec.equals("tcnkTCNK")) {
if(spec.equals("tcnkmTCNKM")) {
return "all " + (attackingSide ? "attacking" : "defending") + " taflmen";
}

if(attackingSide) {
spec = spec.replaceAll("[TCNK]", "");
spec = spec.replaceAll("[TCNKM]", "");
}
else {
spec = spec.replaceAll("[tcnk]", "");
spec = spec.replaceAll("[tcnkm]", "");
}

if(!r.getAttackers().hasKnights()) {
Expand Down

0 comments on commit c5bb1eb

Please sign in to comment.