コード例 #1
0
    def test__rotate(self):
        paths = [('s1', 'e2'), ('s2', 'w1'), ('e1', 'n2'), ('n1', 'w2')]
        hand_tile = HandTile(paths)
        hand_tile_rotated_clockwise = HandTile([('w1', 's1'), ('w2', 'n2'),
                                                ('s2', 'e2'), ('e1', 'n1')])
        hand_tile_rotated_counter = HandTile([('e2', 'n2'), ('e1', 's1'),
                                              ('n1', 'w1'), ('w2', 's2')])
        hand_tile_rotated_180 = HandTile([('n2', 'w1'), ('n1', 'e2'),
                                          ('w2', 's1'), ('s2', 'e1')])

        self.assertAlmostEqual(hand_tile.paths, paths)

        hand_tile.rotate(1)

        self.assertAlmostEqual(hand_tile.paths,
                               hand_tile_rotated_counter.paths)

        hand_tile.rotate(1)

        self.assertAlmostEqual(hand_tile.paths, hand_tile_rotated_180.paths)

        hand_tile.rotate(1)

        self.assertAlmostEqual(hand_tile.paths,
                               hand_tile_rotated_clockwise.paths)

        hand_tile.rotate(1)

        self.assertAlmostEqual(hand_tile.paths, paths)
コード例 #2
0
    def is_player_death_avoidable(self, board, player):
        all_tile_options = []
        for tile in player.tiles:
            rotations_left = 4
            while rotations_left > 0:
                rotations_left = rotations_left - 1
                temp_tile = HandTile(tile.paths)
                temp_tile.rotate(rotations_left)
                all_tile_options.append(temp_tile)

        for tile in all_tile_options:
            board_coordinate = get_connecting_coordinate(
                player.current_tile, player.current_port)
            would_player_die = self.check_player_dead(board, tile,
                                                      board_coordinate, player)
            if not would_player_die:
                return True

        return False