pacai.gridworld.game

 1import argparse
 2import random
 3
 4import pacai.core.agentinfo
 5import pacai.core.board
 6import pacai.core.game
 7import pacai.core.gamestate
 8import pacai.gridworld.gamestate
 9import pacai.gridworld.mdp
10
11class Game(pacai.core.game.Game):
12    """
13    A game following the standard rules of GridWorld.
14    """
15
16    def get_initial_state(self,
17            rng: random.Random,
18            board: pacai.core.board.Board,
19            agent_infos: dict[int, pacai.core.agentinfo.AgentInfo]) -> pacai.core.gamestate.GameState:
20        return pacai.gridworld.gamestate.GameState(board = board, agent_infos = agent_infos)
21
22    def process_args(self, args: argparse.Namespace) -> None:
23        self.game_info.extra_info['noise'] = args.noise
24        self.game_info.extra_info['living_reward'] = args.living_reward
25
26    def _call_state_process_turn_full(self,
27            state: pacai.core.gamestate.GameState,
28            action: pacai.core.action.Action,
29            rng: random.Random) -> None:
30        mdp = pacai.gridworld.mdp.GridWorldMDP(
31                noise = self.game_info.extra_info['noise'],
32                living_reward = self.game_info.extra_info['living_reward'])
33        mdp.game_start(state)
34
35        state.process_turn_full(action, rng, mdp = mdp)
class Game(pacai.core.game.Game):
12class Game(pacai.core.game.Game):
13    """
14    A game following the standard rules of GridWorld.
15    """
16
17    def get_initial_state(self,
18            rng: random.Random,
19            board: pacai.core.board.Board,
20            agent_infos: dict[int, pacai.core.agentinfo.AgentInfo]) -> pacai.core.gamestate.GameState:
21        return pacai.gridworld.gamestate.GameState(board = board, agent_infos = agent_infos)
22
23    def process_args(self, args: argparse.Namespace) -> None:
24        self.game_info.extra_info['noise'] = args.noise
25        self.game_info.extra_info['living_reward'] = args.living_reward
26
27    def _call_state_process_turn_full(self,
28            state: pacai.core.gamestate.GameState,
29            action: pacai.core.action.Action,
30            rng: random.Random) -> None:
31        mdp = pacai.gridworld.mdp.GridWorldMDP(
32                noise = self.game_info.extra_info['noise'],
33                living_reward = self.game_info.extra_info['living_reward'])
34        mdp.game_start(state)
35
36        state.process_turn_full(action, rng, mdp = mdp)

A game following the standard rules of GridWorld.

def get_initial_state( self, rng: random.Random, board: pacai.core.board.Board, agent_infos: dict[int, pacai.core.agentinfo.AgentInfo]) -> pacai.core.gamestate.GameState:
17    def get_initial_state(self,
18            rng: random.Random,
19            board: pacai.core.board.Board,
20            agent_infos: dict[int, pacai.core.agentinfo.AgentInfo]) -> pacai.core.gamestate.GameState:
21        return pacai.gridworld.gamestate.GameState(board = board, agent_infos = agent_infos)

Create the initial state for this game.

def process_args(self, args: argparse.Namespace) -> None:
23    def process_args(self, args: argparse.Namespace) -> None:
24        self.game_info.extra_info['noise'] = args.noise
25        self.game_info.extra_info['living_reward'] = args.living_reward

Process any special arguments from the command-line.