Commit 04e61b91 authored by sbl1996@126.com's avatar sbl1996@126.com

Add YGOPro-v1

parent f6139c17
# Action
## Types
- Set + card
- Reposition + card
- Special summon + card
- Summon Face-up Attack + card
- Summon Face-down Defense + card
- Attack + card
- DirectAttack + card
- Activate + card + effect
- Cancel
- Switch + phase
- SelectPosition + card + position
- AnnounceNumber + card + effect + number
- SelectPlace + card + place
- AnnounceAttrib + card + effect + attrib
## Effect
### MSG_SELECT_BATTLECMD | MSG_SELECT_IDLECMD | MSG_SELECT_CHAIN | MSG_SELECT_EFFECTYN
- desc == 0: default effect of card
- desc < LIMIT: system string
- desc > LIMIT: card + effect
### MSG_SELECT_OPTION | MSG_SELECT_YESNO
- desc == 0: error
- desc < LIMIT: system string
- desc > LIMIT: card + effect
......@@ -49,50 +49,42 @@ The card id is the index of the card code in `code_list.txt`.
## Legal Actions
- 0,1: spec index, uint16 -> 2 uint8
- 2: msg, discrete, 0: N/A, 1+: same as msg2str (15)
- 3: act, discrete (11)
- 0: spec index
- 1,2: code, uint16 -> 2 uint8
- 3: msg, discrete, 0: N/A, 1+: same as msg2str (15)
- 4: act, discrete (11)
- N/A
- t: Set
- r: Reposition
- c: Special Summon
- s: Summon Face-up Attack
- m: Summon Face-down Defense
- a: Attack
- v: Activate
- v2: Activate the second effect
- v3: Activate the third effect
- v4: Activate the fourth effect
- 4: yes/no, discrete (3)
- Set
- Reposition
- Special Summon
- Summon Face-up Attack
- Summon Face-down Defense
- Attack
- DirectAttack
- Activate
- Cancel
- 5: finish, discrete (2)
- N/A
- Yes
- No
- 5: phase, discrete (4)
- Finish
- 6: effect, discrete, 0: N/A
- 7: phase, discrete (4)
- N/A
- Battle (b)
- Main Phase 2 (m)
- End Phase (e)
- 6: cancel, discrete (2)
- N/A
- Cancel
- 7: finish, discrete (2)
- N/A
- Finish
- 8: position, discrete, 0: N/A, same as position2str
- 9: option, discrete, 0: N/A
- 10: number, discrete, 0: N/A
- 11: place, discrete
- 9: number, discrete, 0: N/A
- 10: place, discrete
- 0: N/A
- 1-7: m
- 8-15: s
- 16-22: om
- 23-30: os
- 12: attribute, discrete, 0: N/A, same as attribute2id
- 11: attribute, discrete, 0: N/A, same as attribute2id
## History Actions
- 0,1: card id, uint16 -> 2 uint8
- 2-12 same as legal actions
- 13: player, discrete, 0: me, 1: oppo
- 14: turn, discrete, trunc to 3
- 2-11 same as legal actions
- 12: turn, discrete, trunc to 3
- 13: phase, discrete (10)
......@@ -18,7 +18,7 @@ import flax
from ygoai.utils import init_ygopro
from ygoai.rl.utils import RecordEpisodeStatistics
from ygoai.rl.jax.agent2 import RNNAgent, ModelArgs
from ygoai.rl.jax.agent import RNNAgent, ModelArgs
@dataclass
......
......@@ -135,7 +135,7 @@ if __name__ == "__main__":
import jax
import jax.numpy as jnp
import flax
from ygoai.rl.jax.agent2 import RNNAgent
from ygoai.rl.jax.agent import RNNAgent
from jax.experimental.compilation_cache import compilation_cache as cc
cc.set_cache_dir(os.path.expanduser("~/.cache/jax"))
......@@ -168,7 +168,6 @@ if __name__ == "__main__":
obs, infos = envs.reset()
print(obs)
next_to_play = infos['to_play']
dones = np.zeros(num_envs, dtype=np.bool_)
......
......@@ -8,6 +8,24 @@ add_requires(
"sqlitecpp 3.2.1")
target("ygopro0_ygoenv")
add_rules("python.library")
add_files("ygoenv/ygoenv/ygopro0/*.cpp")
add_packages("pybind11", "fmt", "glog", "concurrentqueue", "sqlitecpp", "unordered_dense", "ygopro-core")
set_languages("c++17")
if is_mode("release") then
set_policy("build.optimization.lto", true)
add_cxxflags("-march=native")
end
add_includedirs("ygoenv")
after_build(function (target)
local install_target = "$(projectdir)/ygoenv/ygoenv/ygopro0"
os.cp(target:targetfile(), install_target)
print("Copy target to " .. install_target)
end)
target("ygopro_ygoenv")
add_rules("python.library")
add_files("ygoenv/ygoenv/ygopro/*.cpp")
......@@ -25,7 +43,6 @@ target("ygopro_ygoenv")
print("Copy target to " .. install_target)
end)
target("edopro_ygoenv")
add_rules("python.library")
add_files("ygoenv/ygoenv/edopro/*.cpp")
......
This diff is collapsed.
This diff is collapsed.
......@@ -41,7 +41,12 @@ def init_ygopro(env_id, lang, deck, code_list_file, preload_tokens=False):
raise FileNotFoundError(f"Token deck not found: {token_deck}")
decks["_tokens"] = str(token_deck)
if 'YGOPro' in env_id:
from ygoenv.ygopro import init_module
if env_id == 'YGOPro-v1':
from ygoenv.ygopro import init_module
elif env_id == 'YGOPro-v0':
from ygoenv.ygopro0 import init_module
else:
raise ValueError(f"Unknown YGOPro environment: {env_id}")
elif 'EDOPro' in env_id:
from ygoenv.edopro import init_module
init_module(str(db_path), code_list_file, decks)
......
......@@ -18,13 +18,16 @@ try:
except ImportError:
pass
try:
import ygoenv.ygopro0.registration # noqa: F401
except ImportError:
pass
try:
import ygoenv.edopro.registration # noqa: F401
except ImportError:
pass
try:
import ygoenv.dummy.registration # noqa: F401
except ImportError:
......
from ygoenv.registration import register
register(
task_id="YGOPro-v0",
task_id="YGOPro-v1",
import_path="ygoenv.ygopro",
spec_cls="YGOProEnvSpec",
dm_cls="YGOProDMEnvPool",
......
This diff is collapsed.
from ygoenv.python.api import py_env
from .ygopro0_ygoenv import (
_YGOPro0EnvPool,
_YGOPro0EnvSpec,
init_module,
)
(
YGOPro0EnvSpec,
YGOPro0DMEnvPool,
YGOPro0GymEnvPool,
YGOPro0GymnasiumEnvPool,
) = py_env(_YGOPro0EnvSpec, _YGOPro0EnvPool)
__all__ = [
"YGOPro0EnvSpec",
"YGOPro0DMEnvPool",
"YGOPro0GymEnvPool",
"YGOPro0GymnasiumEnvPool",
]
from ygoenv.registration import register
register(
task_id="YGOPro-v0",
import_path="ygoenv.ygopro0",
spec_cls="YGOPro0EnvSpec",
dm_cls="YGOPro0DMEnvPool",
gym_cls="YGOPro0GymEnvPool",
gymnasium_cls="YGOPro0GymnasiumEnvPool",
)
#include "ygoenv/ygopro0/ygopro.h"
#include "ygoenv/core/py_envpool.h"
using YGOPro0EnvSpec = PyEnvSpec<ygopro0::YGOProEnvSpec>;
using YGOPro0EnvPool = PyEnvPool<ygopro0::YGOProEnvPool>;
PYBIND11_MODULE(ygopro0_ygoenv, m) {
REGISTER(m, YGOPro0EnvSpec, YGOPro0EnvPool)
m.def("init_module", &ygopro0::init_module);
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment