From aceb0d301274962289d62a41421e3cf0c8738053 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Sun, 14 Sep 2014 12:23:55 +0200 Subject: Extract initial player from goban --- qml/pages/Goban.qml | 5 ++++- qml/python/board.py | 1 + qml/python/game.py | 12 +++++++++--- qml/python/tests/test_game.py | 4 +++- qml/python/transformations.py | 6 +++--- qml/tsumego.qml | 1 - 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/qml/pages/Goban.qml b/qml/pages/Goban.qml index 5c86700..c1e81bd 100644 --- a/qml/pages/Goban.qml +++ b/qml/pages/Goban.qml @@ -36,7 +36,7 @@ Item { */ function start() { - currentPlayer = true; + //currentPlayer = true; for (var i = 0; i < goban.rows * goban.columns; i++) { repeater.itemAt(i).remove(false); @@ -88,6 +88,9 @@ Item { caseSize = maxWidth; } + console.log("Current player:", ret.current_player); + currentPlayer = (ret.current_player === 'W'); + /* * Put the initials stones */ diff --git a/qml/python/board.py b/qml/python/board.py index 48f3ff0..5bc0ac5 100644 --- a/qml/python/board.py +++ b/qml/python/board.py @@ -54,4 +54,5 @@ def getGame(n): "tree": game.tree, "size": game.get_size(), "side": game.side, + "current_player": game.current_player, } diff --git a/qml/python/game.py b/qml/python/game.py index f4cb929..de7842a 100644 --- a/qml/python/game.py +++ b/qml/python/game.py @@ -1,7 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import random from transformations import * @@ -29,6 +28,8 @@ class Game(object): self.min_x, self.min_y = 19, 19 self.max_x, self.max_y = 0, 0 + self.current_player = None + # Get the board size from the whole possibles positions and create the # game tree self.tree = Game.create_tree(cursor, self.extend_board_size, []) @@ -41,6 +42,7 @@ class Game(object): self.max_y = min(19, self.max_y + y_space) self.max_x = min(19, self.max_x + x_space) + self.side = { "TOP": self.min_y == 1, "LEFT": self.min_x == 1, @@ -49,9 +51,13 @@ class Game(object): } - def extend_board_size(self, pos): + def extend_board_size(self, pos, action = None): """ Extend the board size to include the position given. """ + + if self.current_player == None and action in ['B', 'W']: + self.current_player = action + x, y = Game.conv_coord(pos) self.min_x = min(x, self.min_x) self.max_x = max(x, self.max_x) @@ -72,7 +78,7 @@ class Game(object): node = cursor.currentNode().copy() for key in ['AB', 'AW', 'B', 'W']: if key in node: - node[key] = [fun(pos) for pos in node[key]] + node[key] = [fun(pos, key) for pos in node[key]] acc.append(node) childs = cursor.noChildren() diff --git a/qml/python/tests/test_game.py b/qml/python/tests/test_game.py index 737e55b..31ff355 100644 --- a/qml/python/tests/test_game.py +++ b/qml/python/tests/test_game.py @@ -23,7 +23,7 @@ class TestBoard(unittest.TestCase): def test_createTree(self): - def fun(pos): + def fun(pos, action): return pos with open("python/tests/test.sgf") as f: @@ -73,3 +73,5 @@ class TestBoard(unittest.TestCase): currentgame.normalize() + self.assertEqual('W', currentgame.current_player) + diff --git a/qml/python/transformations.py b/qml/python/transformations.py index adf0395..3bb9383 100644 --- a/qml/python/transformations.py +++ b/qml/python/transformations.py @@ -18,7 +18,7 @@ class Translation(object): """ return self.board.min_x != 0 or self.board.min_y != 0 - def apply_points(self, coord): + def apply_points(self, coord, name = None): """ Move the points to the lower position. """ x, y = coord @@ -56,7 +56,7 @@ class Rotation(object): return random.randint(0, 1) == 1 return should < 0 - def apply_points(self, coord): + def apply_points(self, coord, name = None): """ Apply the transformation on a point. """ x, y = coord @@ -93,7 +93,7 @@ class Symmetry(object): direction. """ return self.x_flip or self.y_flip - def apply_points(self, coord): + def apply_points(self, coord, name = None): """ Flip in both directions. """ x, y = coord diff --git a/qml/tsumego.qml b/qml/tsumego.qml index 6b61613..9ead16a 100644 --- a/qml/tsumego.qml +++ b/qml/tsumego.qml @@ -35,7 +35,6 @@ import "pages" ApplicationWindow { - initialPage: Component { id:app -- cgit v1.2.3