Skip to content

Commit

Permalink
Merge pull request #15 from dykstrom/14-exceptions-and-crashes
Browse files Browse the repository at this point in the history
Fix time management bug
  • Loading branch information
dykstrom authored Jun 15, 2024
2 parents 4023802 + de01e6a commit f04af7f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface. It is highly recommended that you run it from a chess GUI like

* Ronja versions 0.7.0 and earlier require Java 8.
* Ronja versions 0.8.x require Java 11.
* Ronja versions 0.9.0 and later require Java 17.
* Ronja versions 0.9.0 and later require Java 17+.


## Installation
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/se/dykstrom/ronja/engine/time/TimeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static TimeControl parseLevelText(final String text) throws ParseExceptio
} catch (NumberFormatException nfe) {
throw new ParseException("invalid time increment", 0);
}
return new TimeControl(numberOfMoves, baseTime, increment, (increment == 0) ? CLASSIC : INCREMENTAL);
return new TimeControl(numberOfMoves, baseTime, increment, (numberOfMoves != 0) ? CLASSIC : INCREMENTAL);
}

private static long getIncrementAsMillis(final String[] parts) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class TimeUtilsTest {

private static final TimeControl TC_10_01_00 = new TimeControl(10, 60 * 1000, 0, CLASSIC);
private static final TimeControl TC_40_05_00 = new TimeControl(40, 5 * 60 * 1000, 0, CLASSIC);
// Incremental time with an increment of 0
private static final TimeControl TC_0_03_00 = new TimeControl(0, 3 * 60 * 1000, 0, INCREMENTAL);
private static final TimeControl TC_0_30_05 = new TimeControl(0, 30 * 60 * 1000, 5 * 1000, INCREMENTAL);
private static final TimeControl TC_0_00_10 = new TimeControl(0, 0, 10 * 1000, INCREMENTAL);
private static final TimeControl TC_10_1_30_00 = new TimeControl(10, 90 * 1000, 0, CLASSIC);
Expand All @@ -62,6 +64,7 @@ public void testFormatTime() {
public void testParseLevelText() throws Exception {
assertEquals(TC_40_05_00, parseLevelText("40 5 0"));
assertEquals(TC_10_01_00, parseLevelText("10 0:60 0"));
assertEquals(TC_0_03_00, parseLevelText("0 3 0"));
assertEquals(TC_0_30_05, parseLevelText("0 30 5"));
assertEquals(TC_0_00_10, parseLevelText("0 0 10"));
assertEquals(TC_10_1_30_00, parseLevelText("10 1:30 0"));
Expand Down

0 comments on commit f04af7f

Please sign in to comment.