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
4ef751bf
Commit
4ef751bf
authored
May 23, 2024
by
sbl1996@126.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Accurate evaluate (battle)
parent
b55996bf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
17 deletions
+20
-17
ygoai/rl/jax/eval.py
ygoai/rl/jax/eval.py
+4
-1
ygoenv/ygoenv/ygopro/ygopro.h
ygoenv/ygoenv/ygopro/ygopro.h
+16
-16
No files found.
ygoai/rl/jax/eval.py
View file @
4ef751bf
...
...
@@ -37,6 +37,7 @@ def evaluate(envs, num_episodes, predict_fn, rnn_state=None):
def
battle
(
envs
,
num_episodes
,
predict_fn
,
rstate1
=
None
,
rstate2
=
None
):
assert
num_episodes
==
envs
.
num_envs
num_envs
=
envs
.
num_envs
episode_rewards
=
[]
episode_lengths
=
[]
...
...
@@ -45,6 +46,7 @@ def battle(envs, num_episodes, predict_fn, rstate1=None, rstate2=None):
obs
,
infos
=
envs
.
reset
()
next_to_play
=
infos
[
'to_play'
]
dones
=
np
.
zeros
(
num_envs
,
dtype
=
np
.
bool_
)
collected
=
np
.
zeros
((
num_episodes
,),
dtype
=
np
.
bool_
)
main_player
=
np
.
concatenate
([
np
.
zeros
(
num_envs
//
2
,
dtype
=
np
.
int64
),
...
...
@@ -60,8 +62,9 @@ def battle(envs, num_episodes, predict_fn, rstate1=None, rstate2=None):
next_to_play
=
infos
[
'to_play'
]
for
idx
,
d
in
enumerate
(
dones
):
if
not
d
:
if
not
d
or
collected
[
idx
]
:
continue
collected
[
idx
]
=
True
episode_length
=
infos
[
'l'
][
idx
]
episode_reward
=
infos
[
'r'
][
idx
]
*
(
1
if
main
[
idx
]
else
-
1
)
win
=
1
if
episode_reward
>
0
else
0
...
...
ygoenv/ygoenv/ygopro/ygopro.h
View file @
4ef751bf
...
...
@@ -2230,7 +2230,7 @@ public:
if
(
play_mode_
==
kSelfPlay
)
{
// to_play_ is the previous player
reward
=
winner_
==
to_play_
?
base_reward
:
-
base_reward
;
reward
=
winner_
==
player
?
base_reward
:
-
base_reward
;
}
else
{
reward
=
winner_
==
ai_player_
?
base_reward
:
-
base_reward
;
}
...
...
@@ -2403,21 +2403,21 @@ private:
const
SpecInfo
&
find_spec_info
(
SpecInfos
&
spec_infos
,
const
std
::
string
&
spec
)
{
auto
it
=
spec_infos
.
find
(
spec
);
if
(
it
==
spec_infos
.
end
())
{
// TODO(2): find the root cause
// print spec2index
show_deck
(
0
);
show_deck
(
1
);
show_buffer
();
show_turn
();
fmt
::
println
(
"MS: idx: {}, mode: {}, min: {}, max: {}, must: {}, specs: {}, combs: {}"
,
ms_idx_
,
ms_mode_
,
ms_min_
,
ms_max_
,
ms_must_
,
ms_specs_
,
ms_combs_
);
fmt
::
println
(
"Spec: {}, Spec2index:"
,
spec
);
for
(
auto
&
[
k
,
v
]
:
spec_infos
)
{
fmt
::
print
(
"{}: {} {}, "
,
k
,
v
.
index
,
v
.
cid
);
}
fmt
::
print
(
"
\n
"
);
// throw std::runtime_error("Spec not found: " + spec);
spec_infos
[
spec
]
=
{
1
,
1
};
return
spec_infos
[
spec
];
// TODO(2): find the root cause
// print spec2index
show_deck
(
0
);
show_deck
(
1
);
show_buffer
();
show_turn
();
fmt
::
println
(
"MS: idx: {}, mode: {}, min: {}, max: {}, must: {}, specs: {}, combs: {}"
,
ms_idx_
,
ms_mode_
,
ms_min_
,
ms_max_
,
ms_must_
,
ms_specs_
,
ms_combs_
);
fmt
::
println
(
"Spec: {}, Spec2index:"
,
spec
);
for
(
auto
&
[
k
,
v
]
:
spec_infos
)
{
fmt
::
print
(
"{}: {} {}, "
,
k
,
v
.
index
,
v
.
cid
);
}
fmt
::
print
(
"
\n
"
);
// throw std::runtime_error("Spec not found: " + spec);
spec_infos
[
spec
]
=
{
0
,
0
};
return
spec_infos
[
spec
];
}
return
it
->
second
;
}
...
...
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