Skip to content

Commit

Permalink
Real parsers in use now
Browse files Browse the repository at this point in the history
  • Loading branch information
beremaran committed Mar 6, 2018
1 parent 7b80e23 commit c8faa5f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
35 changes: 17 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,28 @@ See also __Useful Resources__ which also contains link to _GTP Command Reference
**Warning**: The name `gtester` conflicts with GLib unit test tool. You may want to run gtester with `python -m gtester`

### Usage
usage: gtester [-h] [-v] [--goban_args GOBAN_ARGS] [--gnugo GNUGO] [--sgf SGF]
[--clear-cache]
goban_path

Tests your goban implementation by playing with both gnugo and your
implementation.

positional arguments:
goban_path Path to executable of your implementation of goban
* Implement a board parser for your implementation by extending `gtester.parser.Parser` class.
* If your output is compatible with gnugo output it is not required.
* If you omit `goban_X_parser` parameter in `GobanTester` constructor, `GnuGoParser` will be used

```python
from gtester import GNU_GO_COMMAND
from gtester.parser import Parser
from gtester.tester import GobanTester

optional arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
--goban_args GOBAN_ARGS
Goban arguments
--gnugo GNUGO Path to gnugo binary
--sgf SGF Test board with specific SGF file
--clear-cache Deletes downloaded games
class ExampleParser(Parser):
...

# GobanTester(goban_1, goban_2, goban_1_parser=None, goban_2_parser=None ...
tester = GobanTester(["example_goban", ["--mode gtp"]], GNU_GO_COMMAND, ExampleParser())
```


Test gnugo goban implementation against itself:

python main.py gnugo --goban_args "--mode gtp"
```bash
python main.py gnugo --goban_args "--mode gtp"
```


## Utilities
Expand Down
21 changes: 18 additions & 3 deletions gtester/tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
import gtester.sgf as sgflib
from gtester.gtp import GTPMetaMachine, InvalidGTPResponse
from gtester.taskmaster import start_process
from gtester.parser import GnuGoParser


class GobanTester:
def __init__(self, goban_1, goban_2, sgf_file=None,
def __init__(self, goban_1, goban_2, goban_1_parser=None,
goban_2_parser=None,
sgf_file=None,
sgf_str=None):
self.meta = GTPMetaMachine()

Expand All @@ -36,6 +39,16 @@ def __init__(self, goban_1, goban_2, sgf_file=None,
self.goban_1 = self.meta.register_goban(goban_1)
self.goban_2 = self.meta.register_goban(goban_2)

if goban_1_parser is not None:
self.goban_1_parser = goban_1_parser
else:
self.goban_1_parser = GnuGoParser()

if goban_2_parser is not None:
self.goban_2_parser = goban_2_parser
else:
self.goban_2_parser = GnuGoParser()

# ====
if sgf_file is not None:
self.games = [sgflib.parse_file(sgf_file)]
Expand Down Expand Up @@ -95,14 +108,16 @@ def kill_gobans(self):
for goban in [self.goban_1, self.goban_2]:
self.meta.send(goban, 'quit')

@staticmethod
def _compare_boards(board_1, board_2):
def _compare_boards(self, board_1, board_2):
"""
Compares boards and returns different indexes
:param board_1:
:param board_2:
:return:
"""
board_1 = self.goban_1_parser.parse(board_1)
board_2 = self.goban_2_parser.parse(board_2)

board_1 = [ord(c) for c in board_1]
board_2 = [ord(c) for c in board_2]

Expand Down

0 comments on commit c8faa5f

Please sign in to comment.