Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Research Football Integration #188

Draft
wants to merge 32 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5220337
feat(gfootball): init third_party
Benjamin-eecs Jun 17, 2022
69d1417
Merge branch 'sail-sg:main' into feature/gfootball
Benjamin-eecs Jul 22, 2022
8c5d04f
Add files via upload
kfq2002 Jul 22, 2022
46d1081
Add files via upload
kfq2002 Jul 26, 2022
50a94a0
Merge branch 'sail-sg:main' into feature/gfootball
Benjamin-eecs Aug 1, 2022
61e50a1
Add files via upload
kfq2002 Aug 3, 2022
7b38975
Add files via upload
kfq2002 Aug 3, 2022
50040c3
Update workspace0.bzl
kfq2002 Aug 3, 2022
2bb4690
Update entry.py
kfq2002 Aug 3, 2022
a7d81be
Merge remote-tracking branch 'upstream/main' into feature/gfootball
Benjamin-eecs Aug 10, 2022
d6f5c78
Update BUILD
kfq2002 Aug 10, 2022
9970368
Delete football_observation_processor.py
kfq2002 Aug 10, 2022
8eeeb62
Update football_env.h
kfq2002 Aug 10, 2022
e63a8fa
Update config.h
kfq2002 Aug 10, 2022
cfa09ef
Update football_env_test.cc
kfq2002 Aug 10, 2022
1e3941d
Create football_envpool_test.py
kfq2002 Aug 10, 2022
ba87f41
Update registration.py
kfq2002 Aug 10, 2022
8e957e4
Update registration.py
kfq2002 Aug 10, 2022
7592e91
Update BUILD
kfq2002 Aug 10, 2022
05191ff
Update entry.py
kfq2002 Aug 10, 2022
54ada45
Update workspace0.bzl
kfq2002 Aug 10, 2022
95bf9f9
Merge branch 'sail-sg:main' into feature/gfootball
Benjamin-eecs Aug 18, 2022
c3e1e0f
Update BUILD
kfq2002 Aug 19, 2022
3d7b359
Update config.h
kfq2002 Aug 19, 2022
4fdd1cd
Update football_action_set.h
kfq2002 Aug 19, 2022
a9ced8d
Update football_env.h
kfq2002 Aug 19, 2022
1a357cb
Update football_env_test.cc
kfq2002 Aug 19, 2022
bc36475
Update config.h
kfq2002 Aug 19, 2022
a9b72a1
Update football_env.h
kfq2002 Aug 19, 2022
8d78de3
0901
kfq2002 Sep 1, 2022
f3c7c7c
2022/09/01
kfq2002 Sep 1, 2022
8a81a94
0902
kfq2002 Sep 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions envpool/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ py_library(
"//envpool/mujoco:mujoco_gym_registration",
"//envpool/toy_text:toy_text_registration",
"//envpool/vizdoom:vizdoom_registration",
"//envpool/football:football_registration",
],
)

Expand All @@ -35,6 +36,7 @@ py_library(
"//envpool/atari",
"//envpool/box2d",
"//envpool/classic_control",
"//envpool/football",
"//envpool/mujoco:mujoco_dmc",
"//envpool/mujoco:mujoco_gym",
"//envpool/python",
Expand Down
1 change: 1 addition & 0 deletions envpool/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
import envpool.mujoco.gym.registration # noqa: F401
import envpool.toy_text.registration # noqa: F401
import envpool.vizdoom.registration # noqa: F401
import envpool.football.registration
81 changes: 81 additions & 0 deletions envpool/football/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
load("@pip_requirements//:requirements.bzl", "requirement")
load("@pybind11_bazel//:build_defs.bzl", "pybind_extension")

package(default_visibility = ["//visibility:public"])

cc_library(
name = "football_env",
hdrs = ["football_env.h"],
deps = [
"//envpool/core:async_envpool",
"@gfootball_engine//:game_env",
"//envpool/football:config",
"//envpool/football:football_action_set",
],
)

cc_library(
name = "config",
hdrs = ["config.h"],
deps = [
"@gfootball_engine//:game_env",
],
)

cc_library(
name = "football_action_set",
hdrs = ["football_action_set.h"],
deps = [
"//envpool/football:config",
"@gfootball_engine//:game_env",
],
)

pybind_extension(
name = "football_envpool",
srcs = [
"football_envpool.cc",
],
deps = [
"//envpool/football:football_env",
"//envpool/core:py_envpool",
],
)

py_library(
name = "football",
srcs = ["__init__.py"],
data = [":football_envpool.so"],
deps = ["//envpool/python:api"],
)

py_library(
name = "football_registration",
srcs = ["registration.py"],
deps = [
"//envpool:registration",
],
)

py_test(
name = "football_envpool_test",
size = "enormous",
srcs = ["football_envpool_test.py"],
deps = [
":football",
requirement("numpy"),
requirement("jax"),
requirement("absl-py"),
],
)

cc_test(
name = "football_env_test",
size = "enormous",
srcs = ["football_env_test.cc"],
deps = [
":football_env",
"@com_google_googletest//:gtest_main",
],
)

29 changes: 29 additions & 0 deletions envpool/football/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python3
# Copyright 2021 Garena Online Private Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Football env in EnvPool."""

from envpool.python.api import py_env

from .football_envpool import _FootballEnvPool, _FootballEnvSpec

FootballEnvSpec, FootballDMEnvPool, FootballGymEnvPool = py_env(
_FootballEnvSpec, _FootballEnvPool
)

__all__ = [
"FootballEnvSpec",
"FootballDMEnvPool",
"FootballGymEnvPool",
]
48 changes: 48 additions & 0 deletions envpool/football/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef ENVPOOL_FOOTBALL_CONFIG_H_
#define ENVPOOL_FOOTBALL_CONFIG_H_

#include <string>
#include <vector>
#include <stdio.h>
#include <unistd.h>
#include "game_env.hpp"

class Config_football{
public:
std::string action_set = "default";
std::string custom_display_stats = "";
bool display_game_stats = true;
bool dump_full_episodes = false;
bool dump_scores = false;
std::vector<std::string>players = {"agent:left_players=1"};
std::string level = "11_vs_11_stochastic";
int physics_steps_per_frame = 10;
float render_resolution_x = 1280;
float render_resolution_y = 0.5625 * render_resolution_x;
bool real_time = false;
char* tracesdir_pre_char = getcwd(NULL, 0);
std::string tracesdir_pre = tracesdir_pre_char;
std::string tracesdir = tracesdir_pre + "/dump";
std::string video_format = "avi";
int video_quality_level = 0;
bool write_video = false;
int episode_number = 0;
Config_football(){ };
void NewScenario(int inc = 1){
this->episode_number += inc;
auto scenario_config = ScenarioConfig::make();
};
int number_of_left_players = players[0];
int number_of_right_players = players[1];
int number_of_players_agent_controls();
};

int Config_football::number_of_players_agent_controls(){
int sum = 0;
for(int i = 0; i < this->players.size(); i++){
sum += players[i];
}
return sum;
}

#endif // ENVPOOL_FOOTBALL_CONFIG_H_
119 changes: 119 additions & 0 deletions envpool/football/football_action_set.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#ifndef ENVPOOL_FOOTBALL_ACTION_SET_H_
#define ENVPOOL_FOOTBALL_ACTION_SET_H_

#include <string>
#include "config.h"
#include "game_env.hpp"

class CoreAction{
public:
CoreAction(Action action, std::string name, bool sticky = false, bool directional = false){
_backend_action = backend_action;
_name = name;
_sticky = sticky;
_directional = directional;
}
bool is_in_actionset(Config_football config){
};
Action _backend_action;
std::string _name;
bool _sticky;
bool _directional;
};

bool T = true;
bool F = false;

CoreAction action_idle(Action::game_idle, "idle");
CoreAction action_builtin_ai(Action::game_builtin_ai, "builtin_ai");
CoreAction action_left(Action::game_left, "left", T, T);
CoreAction action_top_left(Action::game_top_left, "top_left", T, T);
CoreAction action_top(Action::game_top, "top", T, T);
CoreAction action_top_right(Action::game_top_right, "top_right", T, T);
CoreAction action_right(Action::game_right, "right", T, T);
CoreAction action_bottom_right(Action::game_bottom_right, "bottom_right", T, T);
CoreAction action_bottom(Action::game_bottom, "bottom", T, T);
CoreAction action_bottom_left(Action::game_bottom_left, "bottom_left", T, T);
CoreAction action_long_pass(Action::game_long_pass, "long_pass");
CoreAction action_high_pass(Action::game_high_pass, "high_pass");
CoreAction action_short_pass(Action::game_short_pass, "short_pass");
CoreAction action_shot(Action::game_shot, "shot");
CoreAction action_keeper_rush(Action::game_keeper_rush, "keeper_rush", T);
CoreAction action_sliding(Action::game_sliding, "sliding");
CoreAction action_pressure(Action::game_pressure, "pressure", T);
CoreAction action_team_pressure(Action::game_team_pressure, "team_pressure", T);
CoreAction action_switch(Action::game_switch, "switch");
CoreAction action_sprint(Action::game_sprint, "sprint", T);
CoreAction action_dribble(Action::game_dribble, "dribble", T);
CoreAction action_release_direction(Action::game_release_direction, "release_direction", F, T);
CoreAction action_release_long_pass(Action::game_release_long_pass, "release_long_pass");
CoreAction action_release_high_pass(Action::game_release_high_pass, "release_high_pass");
CoreAction action_release_short_pass(Action::game_release_short_pass, "release_short_pass");
CoreAction action_release_shot(Action::game_release_shot, "release_shot");
CoreAction action_release_keeper_rush(Action::game_release_keeper_rush, "release_keeper_rush");
CoreAction action_release_sliding(Action::game_release_sliding, "release_sliding");
CoreAction action_release_pressure(Action::game_release_pressure, "release_pressure");
CoreAction action_release_team_pressure(Action::game_release_team_pressure, "release_team_pressure");
CoreAction action_release_switch(Action::game_release_switch, "release_switch");
CoreAction action_release_sprint(Action::game_release_sprint, "release_sprint");
CoreAction action_release_dribble(Action::game_release_dribble, "release_dribble");

std::vector<CoreAction> get_action_set(Config_football cfg){
std::vector<CoreAction> action_set;
if(cfg.action_set == "default"){
action_set = {
action_idle, action_left, action_top_left, action_top,
action_top_right, action_right, action_bottom_right,
action_bottom, action_bottom_left, action_long_pass,
action_high_pass, action_short_pass, action_shot,
action_sprint, action_release_direction, action_release_sprint,
action_sliding, action_dribble, action_release_dribble
};
}
else if(cfg.action_set == "v2"){
action_set = {
action_idle, action_left, action_top_left, action_top,
action_top_right, action_right, action_bottom_right,
action_bottom, action_bottom_left, action_long_pass,
action_high_pass, action_short_pass, action_shot,
action_sprint, action_release_direction, action_release_sprint,
action_sliding, action_dribble, action_release_dribble, action_builtin_ai
};
}
else if(cfg.action_set == "full"){
action_set = {
action_idle, action_left, action_top_left, action_top,
action_top_right, action_right, action_bottom_right,
action_bottom, action_bottom_left, action_long_pass,
action_high_pass, action_short_pass, action_shot,
action_sprint, action_release_direction, action_release_sprint,
action_sliding, action_dribble, action_release_dribble, action_builtin_ai,
action_keeper_rush, action_pressure,
action_team_pressure, action_switch,
action_release_long_pass, action_release_high_pass,
action_release_short_pass, action_release_shot,
action_release_keeper_rush, action_release_sliding,
action_release_pressure, action_release_team_pressure,
action_release_switch
};
}
return action_set;
}

std::vector<CoreAction> get_sticky_actions(Config_football cfg){
std::vector<CoreAction> sticky_actions;
std::vector<CoreAction> action_set;
action_set = get_action_set(cfg);
for(int i = 0; i < action_set.size(); i++){
if(action_set[i]._sticky){
sticky_actions.push_back(action_set[i]);
}
}
return sticky_actions;
}

CoreAction named_action_from_action_set(std::vector<CoreAction> action_set, int action){
return action_set[action];
}

#endif //ENVPOOL_FOOTBALL_ACTION_SET_H_