예제 #1
0
def test_rolltree():
    board = Board()
    board.board = [[
        9, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        1, 0
    ],
                   [
                       0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                       0, 0, 0, 0, 0, 14, 0
                   ]]
    player = ComputerPlayer(1)
    dice = Dice()
    dice.set_dice(1, 1)
    rulebook = RuleBook(board, player, dice)
    rolltree = RollTree([], Move(1, 8, 7), rulebook, 1, 4)

    test_dice = Dice()
    test_dice.set_dice(1, 0)
    assert rolltree.rulebook.dice == test_dice

    rolltree.activate()
    assert len(rolltree.children) == 1
    assert rolltree.traverse_roll_tree(rolltree, []) == [[
        Move(1, 8, 7),
        Move(1, 7, 6),
        Move(1, 6, 5),
        Move(1, 5, 4)
    ]]

    rulebook.board.board = [[
        9, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        1, 0
    ],
                            [
                                0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                0, 0, 0, 0, 0, 0, 0, 0, 14, 0
                            ]]
    rolltree = RollTree([], Move(1, 2, 1), rulebook, 1, 4)
    rolltree.activate()
    assert rolltree.traverse_roll_tree(rolltree,
                                       []) == [[Move(1, 2, 1),
                                                Move(1, 1, 0)]]

    rulebook.board.board = [[
        9, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        1, 0
    ],
                            [
                                3, 7, 3, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                0, 0, 0, 0, 0, 0, 0, 0, 0, 0
                            ]]
    rulebook.dice.set_dice(1, 6)

    assert rulebook.generate_legal_ply_list() == [
        [Move(1, 1, 0), Move(1, 5, 0)], [Move(1, 5, 4),
                                         Move(1, 4, 0)],
        [Move(1, 4, 3), Move(1, 5, 0)], [Move(1, 3, 2),
                                         Move(1, 5, 0)],
        [Move(1, 2, 1), Move(1, 5, 0)]
    ]
예제 #2
0
def test_highest():
    game = HumanGame('HUMAN', 'COMPUTER')
    highest_board = [[0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0],
                     [0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 4, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 2, 0, 0]]
    game.board.board = highest_board
    game.dice.set_dice(1, 5)
    return RuleBook(game.board, game.player1, game.dice)
예제 #3
0
def test_bearoff():
    board = Board()
    board.board = [[0, 2, 2, 3, 2, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
                   [0, 0, 0, 0, 0, 5, 0, 3, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0]]
    player = HumanPlayer(0)
    dice = Dice()
    return RuleBook(board, player, dice)
예제 #4
0
def create_rule_book(color, bingo=Bingo.DOUBLE_BINGO, black=6):
    is_left = True
    bonus = 1
    color = color
    block_circle = BlockCirclesCoordinate(is_left, bonus, color, black)
    cross_circle = CrossCirclesCoordinate()

    return RuleBook(block_circle, cross_circle, bingo=bingo)
예제 #5
0
    def next_move(self, board, dice):
        user_input = input("What is your move? ").split(" ")

        if len(user_input) == 2 and int(user_input[0]) in list(range(0, 27)) and \
                int(user_input[1]) in list(range(0, 27)):
            move = Move(self.colour, int(user_input[0]), int(user_input[1]))

            possible_moves = RuleBook(board, self, dice).get_legal_moves()

            if move in possible_moves:
                return move

        else:
            return user_input
예제 #6
0
def test_alternative():
    game = HumanGame('HUMAN', 'COMPUTER')
    game.board.board = [[2, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0],
                        [2, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0]]
    game.dice.set_dice(6, 5)
    return RuleBook(game.board, game.player1, game.dice)
예제 #7
0
def test_rulebook():
    board = Board()
    player = HumanPlayer(0)
    dice = Dice()
    return RuleBook(board, player, dice)
    def solve(self, bingo=Bingo.DOUBLE_BINGO):
        """
        ブロックビンゴ攻略とボーナスサークル設置を成立させるための運搬経路を計算する。

        Parameters
        ----------
        bingo : Bingo
            ビンゴ状態
        """
        # ゲームの終了判定クラス
        rule_book = RuleBook(self.block_circles, self.cross_circles, bingo)
        # コマンド変換クラス
        commands = Commands(self.block_circles, self.cross_circles)
        
        while rule_book.achivement() != True:
            # ブロックビンゴ攻略のために運搬するブロックサークル番号
            quota = rule_book.get_quota()
            colors = self.block_circles.colors(quota)
            # ボーナスサークル設置が2個成立していないときは、運搬するブロック色に黒色を加える
            if rule_book.bonus < 2:
                colors.append(Color.BLACK)

            src_index = self.cross_circles.start_node(self.position, colors)
            if src_index is None:
                #   ブロックの運搬経路が計算できなかったとき、計算を中断してそれまで計算済みの経路を送信するようにする
                break
            (src, index) = src_index
            # 走行体の現在地からブロックがある交点サークルまで移動する経路を求める
            path = self.a_star(self.position, src)
            # ブロックがある交点サークルからブロックを取得する
            self.cross_circles.move_block(src)
            self.position = src
            self.direction = commands.convert(self.direction, path)

            if colors[index] != Color.BLACK:
                placed_circle = self.block_circles.get(quota[index])
                dst = self.cross_circles.goal_node(src, placed_circle)
                rule_book.put_color_block(index)
            else:
                placed_circle = self.block_circles.get(self.block_circles.bonus_circle)
                dst = self.cross_circles.goal_node(src, placed_circle)
                rule_book.put_black_block()
            
            # ブロックがある交点サークルからブロックサークルまで移動する経路を求める
            path = self.a_star(src, dst)
            self.position = dst
            self.direction = commands.convert(self.direction, path)
            self.direction = commands.put(self.position, placed_circle, self.direction)
        
        # ガレージに行くまでの運搬経路を計算する
        if self.block_circles.is_left:
            # Lコースの場合、(2,3)まで移動する
            path = self.a_star(self.position, (2,3))
            self.direction = commands.convert(self.direction, path)
            # ガレージ方向(座標(2,2.5)から座標(2,4)方向)に回頭する
            commands.spin((2,2.5), (2,3), self.direction, False)
        else:
            # Rコースの場合、(1,0)まで移動する
            path = self.a_star(self.position, (1,0))
            self.direction = commands.convert(self.direction, path)
            # ガレージ方向(座標(1,0.5)から座標(1,0)方向)に回頭する
            commands.spin((1,0.5), (1,0), self.direction, path)
        return commands.get()
예제 #9
0
 def next_move(self, board, dice):
     """Returns a random ply from the list of legal plies"""
     rulebook = RuleBook(board, self, dice)
     legal_plies = rulebook.generate_legal_ply_list()
     return random.choice(legal_plies)
예제 #10
0
 def next_move(self, board, dice):
     return RuleBook(board, self, dice).get_legal_moves()
예제 #11
0
 def next_move(self, board, dice):
     """Returns the best ply for the player from the list of possible plies"""
     rulebook = RuleBook(board, self, dice)
     plies = rulebook.generate_legal_ply_list()
     return self.pick_best_move(plies, board)