-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame_interface.py
More file actions
81 lines (68 loc) · 2.32 KB
/
Copy pathgame_interface.py
File metadata and controls
81 lines (68 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import abc
import numpy as np # For type hinting numpy arrays
class BaseGameAI(abc.ABC):
"""
Abstract Base Class for game environments to be used with the AI agent.
All concrete game implementations (e.g., SnakeGameAI, PongGameAI)
must inherit from this class and implement its abstract methods.
"""
@abc.abstractmethod
def reset(self) -> None:
"""Resets the game state to its initial configuration."""
pass
@abc.abstractmethod
def get_state(self) -> np.ndarray:
"""
Returns the current state of the game as a NumPy array.
The format (e.g., feature vector, pixel array) depends on the game.
"""
pass
@abc.abstractmethod
def play_step(self, action_index: int) -> tuple[float, bool, int]:
"""
Performs one step in the game given an action.
Args:
action_index (int): An integer representing the chosen action.
Returns:
tuple[float, bool, int]: (reward, game_over, score)
"""
pass
@abc.abstractmethod
def is_game_over(self) -> bool:
"""Checks if the game has ended."""
pass
@abc.abstractmethod
def get_action_space_size(self) -> int:
"""Returns the number of possible discrete actions."""
pass
@abc.abstractmethod
def get_state_shape(self) -> tuple[int, ...]:
"""
Returns the shape of the game's state representation.
For feature vectors: (num_features,)
For image data: (channels, height, width)
"""
pass
@abc.abstractmethod
def get_state_is_image(self) -> bool:
"""
Returns True if the game's state representation is pixel-based (image),
False if it's a feature vector.
"""
pass
@abc.abstractmethod
def get_score(self) -> int:
"""Returns the current score of the agent in the game."""
pass
@abc.abstractmethod
def render(self) -> None:
"""Updates the game's graphical user interface."""
pass
@abc.abstractmethod
def close(self) -> None:
"""Performs any necessary cleanup when the game is closed (e.g., pygame.quit())."""
pass
@abc.abstractmethod
def set_speed(self, new_speed: int) -> None:
"""Sets the game's simulation speed (e.g., FPS)."""
pass