Skip to content

Commit 849414d

Browse files
authored
Rename class agent_selector -> AgentSelector (Farama-Foundation#1194)
1 parent 45f7f14 commit 849414d

File tree

23 files changed

+63
-51
lines changed

23 files changed

+63
-51
lines changed

docs/api/utils.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ Base class which is used by [CaptureStdoutWrapper](https://pettingzoo.farama.org
165165

166166
The agent selector utility allows for easy cycling of agents in an AEC environment. At any time it can be reset or reinitialized with a new order, allowing for changes in turn order or handling a dynamic number of agents (see [Knights-Archers-Zombies](https://pettingzoo.farama.org/environments/butterfly/knights_archers_zombies/) for an example of spawning/killing agents)
167167

168-
Note: while many PettingZoo environments use agent_selector to manage agent cycling internally, it is not intended to be used externally when interacting with an environment. Instead, use `for agent in env.agent_iter()` (see [AEC API Usage](https://pettingzoo.farama.org/api/aec/#usage)).
168+
Note: while many PettingZoo environments use AgentSelector to manage agent cycling internally, it is not intended to be used externally when interacting with an environment. Instead, use `for agent in env.agent_iter()` (see [AEC API Usage](https://pettingzoo.farama.org/api/aec/#usage)).
169169

170170
```{eval-rst}
171171
.. currentmodule:: pettingzoo.utils

docs/code_examples/aec_rps.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from gymnasium.spaces import Discrete
66

77
from pettingzoo import AECEnv
8-
from pettingzoo.utils import agent_selector, wrappers
8+
from pettingzoo.utils import AgentSelector, wrappers
99

1010
ROCK = 0
1111
PAPER = 1
@@ -156,9 +156,9 @@ def reset(self, seed=None, options=None):
156156
self.observations = {agent: NONE for agent in self.agents}
157157
self.num_moves = 0
158158
"""
159-
Our agent_selector utility allows easy cyclic stepping through the agents list.
159+
Our AgentSelector utility allows easy cyclic stepping through the agents list.
160160
"""
161-
self._agent_selector = agent_selector(self.agents)
161+
self._agent_selector = AgentSelector(self.agents)
162162
self.agent_selection = self._agent_selector.next()
163163

164164
def step(self, action):

docs/content/environment_creation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ The utils directory also contain some classes which are only helpful for develop
6262

6363
### Agent selector
6464

65-
The `agent_selector` class steps through agents in a cycle
65+
The `AgentSelector` class steps through agents in a cycle
6666

6767
It can be used as follows to cycle through the list of agents:
6868

6969
```python
70-
from pettingzoo.utils import agent_selector
70+
from pettingzoo.utils import AgentSelector
7171
agents = ["agent_1", "agent_2", "agent_3"]
72-
selector = agent_selector(agents)
72+
selector = AgentSelector(agents)
7373
agent_selection = selector.reset()
7474
# agent_selection will be "agent_1"
7575
for i in range(100):

pettingzoo/butterfly/cooperative_pong/cooperative_pong.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
from pettingzoo.butterfly.cooperative_pong.manual_policy import ManualPolicy
8080
from pettingzoo.butterfly.cooperative_pong.paddle import Paddle
8181
from pettingzoo.utils import wrappers
82-
from pettingzoo.utils.agent_selector import agent_selector
82+
from pettingzoo.utils.agent_selector import AgentSelector
8383
from pettingzoo.utils.conversions import parallel_wrapper_fn
8484

8585
FPS = 15
@@ -370,7 +370,7 @@ def __init__(self, **kwargs):
370370

371371
self.agents = self.env.agents[:]
372372
self.possible_agents = self.agents[:]
373-
self._agent_selector = agent_selector(self.agents)
373+
self._agent_selector = AgentSelector(self.agents)
374374
self.agent_selection = self._agent_selector.reset()
375375
# spaces
376376
self.action_spaces = dict(zip(self.agents, self.env.action_space))

pettingzoo/butterfly/knights_archers_zombies/knights_archers_zombies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@
194194
from pettingzoo.butterfly.knights_archers_zombies.src.players import Archer, Knight
195195
from pettingzoo.butterfly.knights_archers_zombies.src.weapons import Arrow, Sword
196196
from pettingzoo.butterfly.knights_archers_zombies.src.zombie import Zombie
197-
from pettingzoo.utils import agent_selector, wrappers
197+
from pettingzoo.utils import AgentSelector, wrappers
198198
from pettingzoo.utils.conversions import parallel_wrapper_fn
199199

200200
sys.dont_write_bytecode = True
@@ -370,7 +370,7 @@ def __init__(
370370
self.floor_patch3 = get_image(os.path.join("img", "patch3.png"))
371371
self.floor_patch4 = get_image(os.path.join("img", "patch4.png"))
372372

373-
self._agent_selector = agent_selector(self.agents)
373+
self._agent_selector = AgentSelector(self.agents)
374374
self.reinit()
375375

376376
def observation_space(self, agent):

pettingzoo/butterfly/pistonball/pistonball.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989

9090
from pettingzoo import AECEnv
9191
from pettingzoo.butterfly.pistonball.manual_policy import ManualPolicy
92-
from pettingzoo.utils import agent_selector, wrappers
92+
from pettingzoo.utils import AgentSelector, wrappers
9393
from pettingzoo.utils.conversions import parallel_wrapper_fn
9494

9595
_image_library = {}
@@ -180,7 +180,7 @@ def __init__(
180180
self.agents = ["piston_" + str(r) for r in range(self.n_pistons)]
181181
self.possible_agents = self.agents[:]
182182
self.agent_name_mapping = dict(zip(self.agents, list(range(self.n_pistons))))
183-
self._agent_selector = agent_selector(self.agents)
183+
self._agent_selector = AgentSelector(self.agents)
184184

185185
self.observation_spaces = dict(
186186
zip(

pettingzoo/classic/chess/chess.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
from pettingzoo import AECEnv
117117
from pettingzoo.classic.chess import chess_utils
118118
from pettingzoo.utils import wrappers
119-
from pettingzoo.utils.agent_selector import agent_selector
119+
from pettingzoo.utils.agent_selector import AgentSelector
120120

121121

122122
def env(**kwargs):
@@ -144,7 +144,7 @@ def __init__(self, render_mode: str | None = None, screen_height: int | None = 8
144144
self.agents = [f"player_{i}" for i in range(2)]
145145
self.possible_agents = self.agents[:]
146146

147-
self._agent_selector = agent_selector(self.agents)
147+
self._agent_selector = AgentSelector(self.agents)
148148

149149
self.action_spaces = {name: spaces.Discrete(8 * 8 * 73) for name in self.agents}
150150
self.observation_spaces = {
@@ -238,7 +238,7 @@ def reset(self, seed=None, options=None):
238238

239239
self.board = chess.Board()
240240

241-
self._agent_selector = agent_selector(self.agents)
241+
self._agent_selector = AgentSelector(self.agents)
242242
self.agent_selection = self._agent_selector.reset()
243243

244244
self.rewards = {name: 0 for name in self.agents}

pettingzoo/classic/connect_four/connect_four.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969

7070
from pettingzoo import AECEnv
7171
from pettingzoo.utils import wrappers
72-
from pettingzoo.utils.agent_selector import agent_selector
72+
from pettingzoo.utils.agent_selector import AgentSelector
7373

7474

7575
def get_image(path):
@@ -220,7 +220,7 @@ def reset(self, seed=None, options=None):
220220
self.truncations = {i: False for i in self.agents}
221221
self.infos = {i: {} for i in self.agents}
222222

223-
self._agent_selector = agent_selector(self.agents)
223+
self._agent_selector = AgentSelector(self.agents)
224224

225225
self.agent_selection = self._agent_selector.reset()
226226

pettingzoo/classic/go/go.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
from pettingzoo import AECEnv
120120
from pettingzoo.classic.go import coords, go_base
121121
from pettingzoo.utils import wrappers
122-
from pettingzoo.utils.agent_selector import agent_selector
122+
from pettingzoo.utils.agent_selector import AgentSelector
123123

124124

125125
def get_image(path):
@@ -191,7 +191,7 @@ def __init__(
191191
[spaces.Discrete(self._N * self._N + 1) for _ in range(self.num_agents)]
192192
)
193193

194-
self._agent_selector = agent_selector(self.agents)
194+
self._agent_selector = AgentSelector(self.agents)
195195

196196
self.board_history = np.zeros((self._N, self._N, 16), dtype=bool)
197197

pettingzoo/classic/hanabi/hanabi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171

172172
from pettingzoo import AECEnv
173173
from pettingzoo.utils import wrappers
174-
from pettingzoo.utils.agent_selector import agent_selector
174+
from pettingzoo.utils.agent_selector import AgentSelector
175175

176176

177177
def env(**kwargs):
@@ -441,7 +441,7 @@ def reset(self, seed=None, options=None):
441441
self.truncations = self.hanabi_env.truncations
442442
self.infos = self.hanabi_env.infos
443443

444-
self._agent_selector = agent_selector(self.agents)
444+
self._agent_selector = AgentSelector(self.agents)
445445
self.agent_selection = self._agent_selector.reset()
446446

447447
def step(

0 commit comments

Comments
 (0)