コード例 #1
0
ファイル: paranoid.py プロジェクト: fpoli/astar
 def successor(status):
     actions = list(Action)
     shuffle(actions)
     children = []
     for action in actions:
         next_status = simulate(status, action)
         children.append((next_status, action))
     return children
コード例 #2
0
ファイル: maxn.py プロジェクト: fpoli/astar
        def successor(status):
            children = []

            if status.turn >= turn_limit:
                return children

            actions = list(Action)
            shuffle(actions)
            for action in actions:
                next_status = simulate(status, action)
                children.append((next_status, action))
            return children
コード例 #3
0
ファイル: simulator_test.py プロジェクト: fpoli/astar
    def perform_test(self, status_dict):
        """Test that simulate returns a new object"""

        # Build models
        map_obj = Map(status_dict["game"]["board"]["tiles"])
        status = Status(status_dict["game"], map_obj)

        original_status = status.clone()
        next_status = simulate(status, Action.north)

        if original_status != next_status:
            self.assertNotEqual(id(status), id(next_status))
コード例 #4
0
ファイル: simulator_test.py プロジェクト: fpoli/astar
    def perform_test(self, status_dict):
        """Test that simulate returns a new object"""

        # Build models
        map_obj = Map(status_dict["game"]["board"]["tiles"])
        status = Status(status_dict["game"], map_obj)

        # Simulate the last turn
        status.turn = status.max_turns

        next_status = simulate(status, Action.north)

        self.assertEqual(status, next_status)
コード例 #5
0
ファイル: benchmark.py プロジェクト: fpoli/astar
game_maps = {}
for status_dict in get_status_samples():
    game_id = status_dict["game"]["id"]
    if game_id not in game_maps:
        game_maps[game_id] = Map(status_dict["game"]["board"]["tiles"])
    status = Status(status_dict["game"], game_maps[game_id])
    samples_status.append(status)

#
# 1. Measure simulation speed
#
print("(*) Client simulation speed")
t = Timer(
    lambda: simulate(
        # a random state
        random.choice(samples_status),
        # a random action
        random.choice(list(Action))
    )
)
measurements = t.repeat(repeat=5000, number=1)
print(report(measurements))

#
# 2. Measure Bot speed
#
bots = [
    (bots.RandomBot, None),
    (bots.SimpleGoalBot, None),
    (bots.MaxnBot, heuristics.GoldHeuristic),
    (bots.MaxnBot, heuristics.EloGoldHeuristic),
    (bots.MaxnBot, heuristics.MineGoldHeuristic),