# HG changeset patch # User Jaroslav Tulach # Date 1253994422 -7200 # Node ID ed560bfe37f067f8acb68ceb4401ab39c04a7e65 # Parent 25b00d888853a169ba9ddfe6076240530caa28c2 Line can contain only black move diff -r 25b00d888853 -r ed560bfe37f0 webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java Sat Sep 26 00:06:58 2009 +0200 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java Sat Sep 26 21:47:02 2009 +0200 @@ -230,6 +230,10 @@ GameId id = new GameId(f.getName(), white, black, new Date(f.lastModified()), new Date(f.lastModified()), GameStatus.whiteMove); g = new Game(id); } + int hash = line.indexOf('#'); + if (hash >= 0) { + line = line.substring(0, hash); + } if (line.equals("finish")) { break; } @@ -241,7 +245,9 @@ throw new IOException("Too much moves on line: " + line); } try { - g.apply(white, Move.valueOf(moves[0]), null); + if (!"...".equals(moves[0])) { + g.apply(white, Move.valueOf(moves[0]), null); + } if (moves.length == 2) { g.apply(black, Move.valueOf(moves[1]), null); } diff -r 25b00d888853 -r ed560bfe37f0 webidor/src/test/java/cz/xelfi/quoridor/webidor/GamesTest.java --- a/webidor/src/test/java/cz/xelfi/quoridor/webidor/GamesTest.java Sat Sep 26 00:06:58 2009 +0200 +++ b/webidor/src/test/java/cz/xelfi/quoridor/webidor/GamesTest.java Sat Sep 26 21:47:02 2009 +0200 @@ -90,4 +90,26 @@ assertEquals("Last move is last touch of the file", middle, g.getId().getModified()); } + @Test public void testLoadGameWithComments() throws Exception { + File f = new File(dir, "x"); + f.getParentFile().mkdirs(); + FileOutputStream os = new FileOutputStream(f); + os.write("# white: W\n# black: B\n# status: IN_PROGRESS\nN #good move\n... S # ok move\n\n".getBytes("UTF-8")); + os.close(); + + Thread.sleep(1000); + + long middle = f.lastModified(); + + Thread.sleep(1000); + + Games games = new Games(dir, new Quoridor()); + Game g = games.getBoardInfo("x", -1); + assertNotNull("Game found", g); + assertNotNull("Board found", g.getBoard()); + assertEquals("List of moves has two", 2, g.getMoves().size()); + + assertEquals("Last move is last touch of the file", middle, g.getId().getModified()); + } + }