Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygo-agent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Biluo Shen
ygo-agent
Commits
04e61b91
Commit
04e61b91
authored
May 21, 2024
by
sbl1996@126.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add YGOPro-v1
parent
f6139c17
Changes
16
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
6345 additions
and
1358 deletions
+6345
-1358
docs/action.md
docs/action.md
+29
-0
docs/feature_engineering.md
docs/feature_engineering.md
+23
-31
scripts/battle.py
scripts/battle.py
+1
-1
scripts/eval.py
scripts/eval.py
+1
-2
xmake.lua
xmake.lua
+18
-1
ygoai/rl/jax/agent.py
ygoai/rl/jax/agent.py
+491
-163
ygoai/rl/jax/agent2.py
ygoai/rl/jax/agent2.py
+0
-494
ygoai/utils.py
ygoai/utils.py
+6
-1
ygoenv/ygoenv/core/BS_thread_pool.h
ygoenv/ygoenv/core/BS_thread_pool.h
+0
-0
ygoenv/ygoenv/entry.py
ygoenv/ygoenv/entry.py
+4
-1
ygoenv/ygoenv/ygopro/registration.py
ygoenv/ygoenv/ygopro/registration.py
+1
-1
ygoenv/ygoenv/ygopro/ygopro.h
ygoenv/ygoenv/ygopro/ygopro.h
+931
-663
ygoenv/ygoenv/ygopro0/__init__.py
ygoenv/ygoenv/ygopro0/__init__.py
+22
-0
ygoenv/ygoenv/ygopro0/registration.py
ygoenv/ygoenv/ygopro0/registration.py
+10
-0
ygoenv/ygoenv/ygopro0/ygopro.cpp
ygoenv/ygoenv/ygopro0/ygopro.cpp
+11
-0
ygoenv/ygoenv/ygopro0/ygopro.h
ygoenv/ygoenv/ygopro0/ygopro.h
+4797
-0
No files found.
docs/action.md
0 → 100644
View file @
04e61b91
# 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
docs/feature_engineering.md
View file @
04e61b91
...
...
@@ -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
-
1
2
: attribute, discrete, 0: N/A, same as attribute2id
-
1
1
: 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)
scripts/battle.py
View file @
04e61b91
...
...
@@ -18,7 +18,7 @@ import flax
from
ygoai.utils
import
init_ygopro
from
ygoai.rl.utils
import
RecordEpisodeStatistics
from
ygoai.rl.jax.agent
2
import
RNNAgent
,
ModelArgs
from
ygoai.rl.jax.agent
import
RNNAgent
,
ModelArgs
@
dataclass
...
...
scripts/eval.py
View file @
04e61b91
...
...
@@ -135,7 +135,7 @@ if __name__ == "__main__":
import
jax
import
jax.numpy
as
jnp
import
flax
from
ygoai.rl.jax.agent
2
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_
)
...
...
xmake.lua
View file @
04e61b91
...
...
@@ -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"
)
...
...
ygoai/rl/jax/agent.py
View file @
04e61b91
This diff is collapsed.
Click to expand it.
ygoai/rl/jax/agent2.py
deleted
100644 → 0
View file @
f6139c17
This diff is collapsed.
Click to expand it.
ygoai/utils.py
View file @
04e61b91
...
...
@@ -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
:
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
)
...
...
ygoenv/ygoenv/
ygopro
/BS_thread_pool.h
→
ygoenv/ygoenv/
core
/BS_thread_pool.h
View file @
04e61b91
File moved
ygoenv/ygoenv/entry.py
View file @
04e61b91
...
...
@@ -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
:
...
...
ygoenv/ygoenv/ygopro/registration.py
View file @
04e61b91
from
ygoenv.registration
import
register
register
(
task_id
=
"YGOPro-v
0
"
,
task_id
=
"YGOPro-v
1
"
,
import_path
=
"ygoenv.ygopro"
,
spec_cls
=
"YGOProEnvSpec"
,
dm_cls
=
"YGOProDMEnvPool"
,
...
...
ygoenv/ygoenv/ygopro/ygopro.h
View file @
04e61b91
This diff is collapsed.
Click to expand it.
ygoenv/ygoenv/ygopro0/__init__.py
0 → 100644
View file @
04e61b91
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"
,
]
ygoenv/ygoenv/ygopro0/registration.py
0 → 100644
View file @
04e61b91
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"
,
)
ygoenv/ygoenv/ygopro0/ygopro.cpp
0 → 100644
View file @
04e61b91
#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
);
}
ygoenv/ygoenv/ygopro0/ygopro.h
0 → 100644
View file @
04e61b91
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment