#!/usr/bin/env python3 import argparse import time from server.GameBoard import GameBoard from snakes.BestBattleSnake import BestBattleSnake def build_game_state() -> dict: return { "game": { "id": "bench-best-snake", "ruleset": { "name": "standard", "version": "v1.0.0", "settings": {"hazardDamagePerTurn": 14}, }, "source": "custom", "map": "standard", }, "turn": 42, "board": { "height": 11, "width": 11, "food": [{"x": 1, "y": 9}, {"x": 9, "y": 1}], "hazards": [], "snakes": [ { "id": "me", "name": "me", "health": 74, "length": 8, "head": {"x": 5, "y": 5}, "body": [ {"x": 5, "y": 5}, {"x": 5, "y": 4}, {"x": 5, "y": 3}, {"x": 4, "y": 3}, {"x": 3, "y": 3}, {"x": 3, "y": 4}, {"x": 3, "y": 5}, {"x": 4, "y": 5}, ], }, { "id": "enemy", "name": "enemy", "health": 70, "length": 8, "head": {"x": 7, "y": 7}, "body": [ {"x": 7, "y": 7}, {"x": 7, "y": 6}, {"x": 7, "y": 5}, {"x": 8, "y": 5}, {"x": 9, "y": 5}, {"x": 9, "y": 6}, {"x": 9, "y": 7}, {"x": 8, "y": 7}, ], }, ], }, "you": { "id": "me", "name": "me", "health": 74, "length": 8, "head": {"x": 5, "y": 5}, "body": [ {"x": 5, "y": 5}, {"x": 5, "y": 4}, {"x": 5, "y": 3}, {"x": 4, "y": 3}, {"x": 3, "y": 3}, {"x": 3, "y": 4}, {"x": 3, "y": 5}, {"x": 4, "y": 5}, ], }, } def main() -> None: parser = argparse.ArgumentParser() parser.add_argument("--iterations", type=int, default=1000) args = parser.parse_args() game_state = build_game_state() board = GameBoard( game_id=game_state["game"]["id"], width=game_state["board"]["width"], height=game_state["board"]["height"], ruleset=game_state["game"]["ruleset"], source=game_state["game"]["source"], map=game_state["game"]["map"], snake_class=BestBattleSnake(), ) start = time.perf_counter() for i in range(args.iterations): game_state["turn"] = i + 1 board.read_game_data(game_state) board.snake_neat_make_a_move() elapsed = time.perf_counter() - start avg_ms = (elapsed / max(1, args.iterations)) * 1000.0 print(f"BestBattleSnake benchmark: {args.iterations} moves in {elapsed:.4f}s ({avg_ms:.3f} ms/move)") if __name__ == "__main__": main()