Skip to content

Commit

Permalink
Merge pull request #18 from huangshiyu13/main
Browse files Browse the repository at this point in the history
update
  • Loading branch information
huangshiyu13 authored Sep 1, 2023
2 parents a0d057d + e70cae9 commit 233e420
Show file tree
Hide file tree
Showing 12 changed files with 354 additions and 144 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test:
lint:
$(call check_install, ruff)
ruff ${PYTHON_FILES} --select=E9,F63,F7,F82 --show-source
ruff ${PYTHON_FILES} --exit-zero
ruff ${PYTHON_FILES} --exit-zero | grep -v '501\|405\|401\|402\|403\|722'

format:
$(call check_install, isort)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ For example, you can evaluate tizero with random agent as below:
tizero eval --left_agent submission/tizero --right_agent submission/random_agent --total_game 10
```

For evaluations for JiDi submissions on other games, please refer to the [Arena](https://openrl-docs.readthedocs.io/en/latest/arena/index.html) of OpenRL
and this [example](https://github.com/OpenRL-Lab/openrl/tree/main/examples/snake) for the snake game.

### Show a saved dump file

Expand Down
38 changes: 37 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,47 @@ Installation
____________

* Follow the instructions in `gfootball <https://github.com/google-research/football#on-your-computer>`_ to set up the environment.
* ``pip install gfootball``
* ``pip install gfootball openrl "openrl[selfplay]"``
* ``pip install tizero`` (or clone this repo and ``pip install -e .`` ).
* test the installation by ``python3 -m gfootball.play_game --action_set=full`` .


Evaluate JiDi submissions locally
____________

You can evaluate your agent locally using tizero:

.. code-block:: bash
tizero eval --left_agent submission_dir1 --right_agent submission_dir2 --total_game 10
For example, you can evaluate tizero with random agent as below:

.. code-block:: bash
tizero eval --left_agent submission/tizero --right_agent submission/random_agent --total_game 10
For evaluations for JiDi submissions on other games, please refer to the `Arena <https://openrl-docs.readthedocs.io/en/latest/arena/index.html>`_ of OpenRL
and this `example <https://github.com/OpenRL-Lab/openrl/tree/main/examples/snake>`_ for the snake game.

Show a saved dump file
____________

* show detailed infomation of a match via: ``tizero show dump_file``
* show keypoints of a mactch via: ``tizero keypoint dump_file``

You can download an example dump file from `here <http://jidiai.cn/daily_6484285/daily_6484285.dump>`_.

Then execute: ``tizero show daily_6484285.dump`` or ``tizero keypoint daily_6484285.dump`` . Then you will see a GUI as below:

.. image::
_static/images/show_dump.png
:width: 1000
:align: center


Convert dump file to video
____________

Expand Down
2 changes: 1 addition & 1 deletion tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def raw_env():
from tizero.football_env.football_jidi_eval import FootballJiDiEnv

env = FootballJiDiEnv("11_vs_11_jidi_eval")
reset_obs = env.reset()
env.reset()

single_action = np.zeros(20)
single_action[-1] = 1
Expand Down
2 changes: 1 addition & 1 deletion tizero/football_env/football_jidi_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def reset(self):

def add_control_index(self, raw_obs):
for i, o in enumerate(raw_obs):
if not "controlled_player_index" in o:
if "controlled_player_index" not in o:
o["controlled_player_index"] = i % 11
return raw_obs

Expand Down
1 change: 1 addition & 0 deletions tizero/football_env/football_pettingzoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class FootballAECEnv(AECEnv):
@property
def agent_num(self):
return self.player_each_side

def __init__(self, render_mode: Optional[str] = None, id: str = None):
self.env = FootballJiDiEnv(scenario_name=id.split("/")[-1])

Expand Down
4 changes: 2 additions & 2 deletions tizero/football_env/scenarios/football_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ def test_scenario():
for i in range(200):
obs = raw_o[0]
active_position = obs["left_team"][obs["active"]]
sticky_actions = obs["sticky_actions"][:10]
active_direction = obs["left_team_direction"][obs["active"]]
# sticky_actions = obs["sticky_actions"][:10]
# active_direction = obs["left_team_direction"][obs["active"]]
relative_ball_position = obs["ball"][:2] - active_position
all_directions_vecs = [
np.array(v) / np.linalg.norm(np.array(v)) for v in ALL_DIRECTION_VECS
Expand Down
20 changes: 10 additions & 10 deletions tizero/utils/script_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ def load_dump(self, dump_file):
return dump
dump.append(step)

def dump_to_txt(self, dump_file, output, include_debug):
with open(output, "w") as out_fd:
dump = self.load_dump(dump_file)
if not include_debug:
for s in dump:
if "debug" in s:
del s["debug"]
with open(output, "w") as f:
f.write(str(dump))
# def dump_to_txt(self, dump_file, output, include_debug):
# with open(output, "w") as out_fd:
# dump = self.load_dump(dump_file)
# if not include_debug:
# for s in dump:
# if "debug" in s:
# del s["debug"]
# with open(output, "w") as f:
# f.write(str(dump))

def dump_to_video(self, dump_file, directory=None, episode_length=None):
dump_path = Path(dump_file)
Expand Down Expand Up @@ -124,7 +124,7 @@ def dump_to_video(self, dump_file, directory=None, episode_length=None):
processor.update(dump[step])

del processor
processor = None
# processor = None

avi_files = []
try_time = 0
Expand Down
6 changes: 3 additions & 3 deletions tizero/utils/visualize_tools/game_graph/game_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ def s_step(self):
def e_step(self):
return self.subgames[-1].e_step if len(self) > 0 else None

@property
def n_steps(self):
return self.e_step - self.s_step + 1
# @property
# def n_steps(self):
# return self.e_step - self.s_step + 1

@property
def n_left(self):
Expand Down
4 changes: 2 additions & 2 deletions tizero/utils/visualize_tools/visualizer/team_info_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ def get_df(self, obs, team, step):

if team == "left":
roles = self.left_team_roles
n = self.n_left
# n = self.n_left
else:
roles = self.right_team_roles
n = self.n_right
# n = self.n_right

roles = [SIMPLE_ROLES(r) + str(idx) for idx, r in enumerate(roles)]

Expand Down
216 changes: 152 additions & 64 deletions tizero/utils/visualize_tools/visualizer/translation_cn.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,67 +11,155 @@
# See the License for the specific language governing permissions and
# limitations under the License.

TEAMS = lambda x: [
"左", # left
"右", # right
"无", # free
][x]

ROLES = lambda x: ["GK", "CB", "LB", "RB", "DM", "CM", "LM", "RM", "AM", "CF"][x]

SIMPLE_ROLES = lambda x: ["G", "c", "l", "r", "D", "C", "L", "R", "A", "F"][x]

GAME_MODES = lambda x: ["正常", "开球", "球门球", "任意球", "角球", "边线球", "点球"][x]

ACTIONS = lambda x: [
"空",
"\u2190", # 左 1
"\u2196", # 上左
"\u2191", # 上
"\u2197", # 上右
"\u2192", # 右
"\u2198", # 下右
"\u2193", # 下
"\u2199", # 下左 8
"长传", # 9
"高传", # 10
"短传", # 11
"射门", # 12
"冲刺", # 13
"释放方向", # 14
"释放冲刺", # 15
"滑铲", # 16
"盘球", # 17
"释放盘球", # 18
"内置AI", # 19
"门将出击", # 20
"施压", # 21
"全队施压", # 22
"切换", # 23
"释放长传", # 24
"释放高传", # 25
"释放短传", # 26
"释放射门", # 27
"释放出击", # 28
"释放铲球", # 29
"释放施压", # 30
"释放全压", # 31
"释放切换", # 32
"-", # not controlled
][x]

DIRECTIONS = lambda x: [
"\u2190", # 左
"\u2196", # 上左
"\u2191", # 上
"\u2197", # 上右
"\u2192", # 右
"\u2198", # 下右
"\u2193", # 下
"\u2199", # 下左
"-",
][x]

INSTRUCTIONS = lambda x: ["跑动", "传球", "射门", "铲球"][x]

USE_NEW_INSTRUCTIONS = lambda x: ["旧指令", "新指令"][x]
# TEAMS = lambda x: [
# "左", # left
# "右", # right
# "无", # free
# ][x]


def TEAMS(x):
return [
"左", # left
"右", # right
"无", # free
][x]


# ROLES = lambda x: ["GK", "CB", "LB", "RB", "DM", "CM", "LM", "RM", "AM", "CF"][x]


def TEROLESAMS(x):
return ["GK", "CB", "LB", "RB", "DM", "CM", "LM", "RM", "AM", "CF"][x]


# SIMPLE_ROLES = lambda x: ["G", "c", "l", "r", "D", "C", "L", "R", "A", "F"][x]


def SIMPLE_ROLES(x):
return ["G", "c", "l", "r", "D", "C", "L", "R", "A", "F"][x]


# GAME_MODES = lambda x: ["正常", "开球", "球门球", "任意球", "角球", "边线球", "点球"][x]


def GAME_MODES(x):
return ["正常", "开球", "球门球", "任意球", "角球", "边线球", "点球"][x]


# ACTIONS = lambda x: [
# "空",
# "\u2190", # 左 1
# "\u2196", # 上左
# "\u2191", # 上
# "\u2197", # 上右
# "\u2192", # 右
# "\u2198", # 下右
# "\u2193", # 下
# "\u2199", # 下左 8
# "长传", # 9
# "高传", # 10
# "短传", # 11
# "射门", # 12
# "冲刺", # 13
# "释放方向", # 14
# "释放冲刺", # 15
# "滑铲", # 16
# "盘球", # 17
# "释放盘球", # 18
# "内置AI", # 19
# "门将出击", # 20
# "施压", # 21
# "全队施压", # 22
# "切换", # 23
# "释放长传", # 24
# "释放高传", # 25
# "释放短传", # 26
# "释放射门", # 27
# "释放出击", # 28
# "释放铲球", # 29
# "释放施压", # 30
# "释放全压", # 31
# "释放切换", # 32
# "-", # not controlled
# ][x]


def ACTIONS(x):
return [
"空",
"\u2190", # 左 1
"\u2196", # 上左
"\u2191", # 上
"\u2197", # 上右
"\u2192", # 右
"\u2198", # 下右
"\u2193", # 下
"\u2199", # 下左 8
"长传", # 9
"高传", # 10
"短传", # 11
"射门", # 12
"冲刺", # 13
"释放方向", # 14
"释放冲刺", # 15
"滑铲", # 16
"盘球", # 17
"释放盘球", # 18
"内置AI", # 19
"门将出击", # 20
"施压", # 21
"全队施压", # 22
"切换", # 23
"释放长传", # 24
"释放高传", # 25
"释放短传", # 26
"释放射门", # 27
"释放出击", # 28
"释放铲球", # 29
"释放施压", # 30
"释放全压", # 31
"释放切换", # 32
"-", # not controlled
][x]


# DIRECTIONS = lambda x: [
# "\u2190", # 左
# "\u2196", # 上左
# "\u2191", # 上
# "\u2197", # 上右
# "\u2192", # 右
# "\u2198", # 下右
# "\u2193", # 下
# "\u2199", # 下左
# "-",
# ][x]


def DIRECTIONS(x):
return [
"\u2190", # 左
"\u2196", # 上左
"\u2191", # 上
"\u2197", # 上右
"\u2192", # 右
"\u2198", # 下右
"\u2193", # 下
"\u2199", # 下左
"-",
][x]


# INSTRUCTIONS = lambda x: ["跑动", "传球", "射门", "铲球"][x]


def INSTRUCTIONS(x):
return ["跑动", "传球", "射门", "铲球"][x]


# USE_NEW_INSTRUCTIONS = lambda x: ["旧指令", "新指令"][x]


def USE_NEW_INSTRUCTIONS(x):
return ["旧指令", "新指令"][x]
Loading

0 comments on commit 233e420

Please sign in to comment.