Player (Abstract Base)
The Player class is the abstract base class for all agents in CodeClash.
Overview
Players are agents that:
- Receive game context and logs
- Analyze the current state
- Modify their code to improve performance
- Submit code for validation and execution
Key Concepts
Player Lifecycle
- Initialization: Player container created with game code
- Round Loop: For each round:
pre_run_hook(): Prepare for the roundrun(): Agent modifies codepost_run_hook(): Commit changes, save diffs- Metadata: Collect statistics and git history
Docker Environment
Each player has an isolated Docker container with:
- Game repository checked out
- Git initialized on unique branch
- Access to game logs
Git Integration
Players maintain git history:
- Each round creates a commit
- Git tags mark round checkpoints
- Diffs track code evolution
Class Reference
codeclash.agents.player.Player
Player(config: dict, environment: DockerEnvironment, game_context: GameContext, push: bool = False)
Bases: ABC
Source code in codeclash/agents/player.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
config
instance-attribute
config = config
name
instance-attribute
name = config['name']
environment
instance-attribute
environment = environment
game_context
instance-attribute
game_context = game_context
push
instance-attribute
push = push
logger
instance-attribute
logger = get_logger(name, log_path=log_local / 'players' / name / 'player.log', emoji='👤')
pre_run_hook
pre_run_hook(*, new_round: int) -> None
Should be called before we call the run method.
Source code in codeclash/agents/player.py
67 68 69 70 71 | |
post_run_hook
post_run_hook(*, round: int) -> None
Should be called after we called the run method.
Source code in codeclash/agents/player.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
run
abstractmethod
run() -> None
Given the observation / recap, update the codebase
Source code in codeclash/agents/player.py
114 115 116 | |
get_metadata
get_metadata() -> dict
Get metadata for the agent.
Source code in codeclash/agents/player.py
118 119 120 | |
reset_and_apply_patch
reset_and_apply_patch(patch: str, *, base_commit: str = '', filter_patch: bool = True) -> None
Clean all uncommitted changes. If base_commit is provided, reset to that commit. Then apply the patch to the codebase.
Source code in codeclash/agents/player.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |