def compute_score(self): has_winner = self.has_winner() if has_winner: winner_scores = { Board.NOUGHT_WINNER: 1, Board.CROSS_WINNER: -1, Board.DRAW: 0 } return winner_scores[has_winner] n1 = Node(self) board = Tree() board.root = n1 right_board = left_board = copy.deepcopy(self) left_move, right_move = left_board.make_random_move( ), right_board.make_random_move() board.root.left = Node(left_move) board.root.right = Node(right_move) return left_board.compute_score() + right_board.compute_score()
def count_score(self): has_winner = self.has_winner() if has_winner: scores = { Board.NOUGHT_WINNER: 1, Board.CROSS_WINNER: -1, Board.DRAW: 0 } return scores[has_winner] else: board = Tree() board.root = Node(self) board_left = copy.deepcopy(self) board_right = copy.deepcopy(self) move_L = board_left.make_random_move() move_R = board_right.make_random_move() board.root.left = Node(move_L) board.root.right = Node(move_R) result = board_left.count_score() + board_right.count_score() return result
def compute_score(self): """ Chooses better move :return: int """ has_winner = self.has_winner() if has_winner: winner_scores = { Board.NOUGHT_WINNER: 1, Board.CROSS_WINNER: -1, Board.DRAW: 0 } return winner_scores[has_winner] board = Tree() board.root = Node(self) left_board = copy.deepcopy(self) right_board = copy.deepcopy(self) left_move = left_board.make_random_move() right_move = right_board.make_random_move() board.root.left = Node(left_move) board.root.right = Node(right_move) return left_board.compute_score() + right_board.compute_score()