Skip to content

Commit d4abc64

Browse files
authored
add google footbal evaluation support
add google footbal evaluation support
2 parents 7df4dc1 + 22020a1 commit d4abc64

11 files changed

Lines changed: 55 additions & 8 deletions

File tree

examples/gfootball/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
This is the guidance for [Google Research Football](https://github.com/google-research/football).
2+
3+
### Installation
4+
5+
- `pip install gfootball`
6+
- `pip install tizero`
7+
- test the installation by `python3 -m gfootball.play_game --action_set=full`.
8+
9+
### Evaluate JiDi submissions locally
10+
11+
If you want to evaluate your JiDi submissions locally, please try to use tizero as illustrated [here](https://github.com/OpenRL-Lab/TiZero#evaluate-jidi-submissions-locally).
12+
13+
14+
### Convert dump file to video
15+
16+
After the installation, you can use tizero to convert a dump file to a video file.
17+
The usage is `tizero dump2video <dump_file> <output_dir> --episode_length <the length> --render_type <2d/3d>`.
18+
19+
You can download an example dump file from [here](http://jidiai.cn/daily_6484285/daily_6484285.dump).
20+
And then execute `tizero dump2video daily_6484285.dump ./` in your terminal. By default, the episode length is 3000 and the render type is 2d.
21+
Wait a minute, you will get a video file named `daily_6484285.avi` in your current directory.

examples/snake/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11

22
This is the example for the snake game.
33

4+
## Installation
5+
6+
```bash
7+
pip install "openrl[selfplay]"
8+
```
9+
410
## Usage
511

612
```bash

openrl/algorithms/dqn.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ def prepare_loss(
167167
)
168168

169169
q_targets = rewards_batch + self.gamma * max_next_q_values * next_masks_batch
170-
q_loss = torch.mean(F.mse_loss(q_values, q_targets.detach())) # 均方误差损失函数
170+
q_loss = torch.mean(
171+
F.mse_loss(q_values, q_targets.detach())
172+
) # 均方误差损失函数
171173

172174
loss_list.append(q_loss)
173175

openrl/algorithms/vdn.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ def prepare_loss(
211211
rewards_batch = rewards_batch.reshape(-1, self.n_agent, 1)
212212
rewards_batch = torch.sum(rewards_batch, dim=1, keepdim=True).view(-1, 1)
213213
q_targets = rewards_batch + self.gamma * max_next_q_values * next_masks_batch
214-
q_loss = torch.mean(F.mse_loss(q_values, q_targets.detach())) # 均方误差损失函数
214+
q_loss = torch.mean(
215+
F.mse_loss(q_values, q_targets.detach())
216+
) # 均方误差损失函数
215217

216218
loss_list.append(q_loss)
217219
return loss_list

openrl/arena/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
""""""
1818
from typing import Callable, Optional
1919

20+
import openrl
2021
from openrl.arena.two_player_arena import TwoPlayerArena
2122
from openrl.envs import pettingzoo_all_envs
2223

@@ -27,8 +28,12 @@ def make_arena(
2728
render: Optional[bool] = False,
2829
**kwargs,
2930
):
31+
print(openrl.envs.PettingZoo.registration.pettingzoo_env_dict.keys())
3032
if custom_build_env is None:
31-
if env_id in pettingzoo_all_envs:
33+
if (
34+
env_id in pettingzoo_all_envs
35+
or env_id in openrl.envs.PettingZoo.registration.pettingzoo_env_dict.keys()
36+
):
3237
from openrl.envs.PettingZoo import make_PettingZoo_env
3338

3439
render_mode = None

openrl/arena/base_arena.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def reset(
4747
total_games: int,
4848
max_game_onetime: int = 5,
4949
seed: int = 0,
50+
dispatch_func: Optional[Callable] = None,
5051
):
5152
self.seed = seed
5253
if self.pbar:
@@ -57,6 +58,10 @@ def reset(
5758
self.max_game_onetime = max_game_onetime
5859
self.agents = agents
5960
assert isinstance(self.game, BaseGame)
61+
62+
if dispatch_func is not None:
63+
self.dispatch_func = dispatch_func
64+
6065
self.game.reset(seed=seed, dispatch_func=self.dispatch_func)
6166

6267
def close(self):

openrl/envs/PettingZoo/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424

2525

2626
def PettingZoo_make(id, render_mode, disable_env_checker, **kwargs):
27+
kwargs.__setitem__("id", id)
2728
if id.startswith("snakes_"):
2829
from openrl.envs.snake.snake_pettingzoo import SnakeEatBeansAECEnv
2930

30-
kwargs.__setitem__("id", id)
3131
register(id, SnakeEatBeansAECEnv)
3232
if id in pettingzoo_env_dict.keys():
3333
env = pettingzoo_env_dict[id](render_mode=render_mode, **kwargs)

openrl/envs/snake/snake.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,9 @@ class Snake:
677677
def __init__(self, player_id, board_width, board_height, init_len):
678678
self.actions = [-2, 2, -1, 1]
679679
self.actions_name = {-2: "up", 2: "down", -1: "left", 1: "right"}
680-
self.direction = random.choice(self.actions) # 方向[-2,2,-1,1]分别表示[上,下,左,右]
680+
self.direction = random.choice(
681+
self.actions
682+
) # 方向[-2,2,-1,1]分别表示[上,下,左,右]
681683
self.board_width = board_width
682684
self.board_height = board_height
683685
x = random.randrange(0, board_height)

openrl/envs/snake/snake_3v3.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,9 @@ class Snake:
794794
def __init__(self, player_id, board_width, board_height, init_len):
795795
self.actions = [-2, 2, -1, 1]
796796
self.actions_name = {-2: "up", 2: "down", -1: "left", 1: "right"}
797-
self.direction = random.choice(self.actions) # 方向[-2,2,-1,1]分别表示[上,下,左,右]
797+
self.direction = random.choice(
798+
self.actions
799+
) # 方向[-2,2,-1,1]分别表示[上,下,左,右]
798800
self.board_width = board_width
799801
self.board_height = board_height
800802
x = random.randrange(0, board_height)

openrl/selfplay/opponents/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ def load_opponent_from_jidi_path(
101101
assert opponent_path.exists()
102102
try:
103103
sys.path.append(str(opponent_path.parent))
104+
105+
module_name = ".".join(opponent_path.parts)
104106
submission_module = __import__(
105-
"{}.submission".format(opponent_path.name), fromlist=["submission"]
107+
f"{module_name}.submission", fromlist=["submission"]
106108
)
107109
opponent_id = get_opponent_id(opponent_info)
108110
opponent = JiDiOpponent(

0 commit comments

Comments
 (0)