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
58379501
Commit
58379501
authored
Mar 11, 2024
by
biluo.shen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extend max_cards to 80 (75 cards and tokens)
parent
389fcd9c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
37 deletions
+35
-37
mcts/mcts/alphazero/alphazero_mcts.pyi
mcts/mcts/alphazero/alphazero_mcts.pyi
+1
-4
ygoenv/ygoenv/ygopro/ygopro.h
ygoenv/ygoenv/ygopro/ygopro.h
+34
-33
No files found.
mcts/mcts/alphazero/alphazero_mcts.pyi
View file @
58379501
...
@@ -30,7 +30,4 @@ def batch_expand(arg0: int, arg1: numpy.ndarray[bool], arg2: numpy.ndarray[numpy
...
@@ -30,7 +30,4 @@ def batch_expand(arg0: int, arg1: numpy.ndarray[bool], arg2: numpy.ndarray[numpy
def batch_traverse(arg0: Roots, arg1: int, arg2: float, arg3: float, arg4: MinMaxStatsList, arg5: SearchResults) -> tuple:
def batch_traverse(arg0: Roots, arg1: int, arg2: float, arg3: float, arg4: MinMaxStatsList, arg5: SearchResults) -> tuple:
...
...
def init_module(seed: int) -> None:
def init_module(seed: int) -> None:
"""
...
(asd
,)
"""
ygoenv/ygoenv/ygopro/ygopro.h
View file @
58379501
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
#include <SQLiteCpp/SQLiteCpp.h>
#include <SQLiteCpp/SQLiteCpp.h>
#include <SQLiteCpp/VariadicBind.h>
#include <SQLiteCpp/VariadicBind.h>
#include <ankerl/unordered_dense.h>
#include <ankerl/unordered_dense.h>
#include <unordered_
map
>
#include <unordered_
set
>
#include "ygoenv/core/async_envpool.h"
#include "ygoenv/core/async_envpool.h"
#include "ygoenv/core/env.h"
#include "ygoenv/core/env.h"
...
@@ -1234,7 +1234,7 @@ public:
...
@@ -1234,7 +1234,7 @@ public:
"deck2"
_
.
Bind
(
std
::
string
(
"OldSchool"
)),
"player"
_
.
Bind
(
-
1
),
"deck2"
_
.
Bind
(
std
::
string
(
"OldSchool"
)),
"player"
_
.
Bind
(
-
1
),
"play_mode"
_
.
Bind
(
std
::
string
(
"bot"
)),
"play_mode"
_
.
Bind
(
std
::
string
(
"bot"
)),
"verbose"
_
.
Bind
(
false
),
"max_options"
_
.
Bind
(
16
),
"verbose"
_
.
Bind
(
false
),
"max_options"
_
.
Bind
(
16
),
"max_cards"
_
.
Bind
(
75
),
"n_history_actions"
_
.
Bind
(
16
),
"max_cards"
_
.
Bind
(
80
),
"n_history_actions"
_
.
Bind
(
16
),
"max_multi_select"
_
.
Bind
(
5
),
"record"
_
.
Bind
(
false
));
"max_multi_select"
_
.
Bind
(
5
),
"record"
_
.
Bind
(
false
));
}
}
template
<
typename
Config
>
template
<
typename
Config
>
...
@@ -1377,18 +1377,19 @@ protected:
...
@@ -1377,18 +1377,19 @@ protected:
int
ha_p_1_
=
0
;
int
ha_p_1_
=
0
;
std
::
vector
<
std
::
vector
<
CardId
>>
h_card_ids_1_
;
std
::
vector
<
std
::
vector
<
CardId
>>
h_card_ids_1_
;
std
::
vector
<
std
::
string
>
revealed_
;
std
::
unordered_set
<
std
::
string
>
revealed_
;
// discard hand cards
// discard hand cards
bool
discard_hand_
=
false
;
bool
discard_hand_
=
false
;
// replay
// replay
bool
record_
=
false
;
bool
record_
=
false
;
// uint8_t *replay_data_;
// uint8_t *rdata_;
FILE
*
fp_
=
nullptr
;
FILE
*
fp_
=
nullptr
;
bool
is_recording
=
false
;
bool
is_recording
=
false
;
// MSG_SELECT_COUNTER
int
n_counters_
=
0
;
public:
public:
YGOProEnv
(
const
Spec
&
spec
,
int
env_id
)
YGOProEnv
(
const
Spec
&
spec
,
int
env_id
)
:
Env
<
YGOProEnvSpec
>
(
spec
,
env_id
),
:
Env
<
YGOProEnvSpec
>
(
spec
,
env_id
),
...
@@ -1641,12 +1642,10 @@ public:
...
@@ -1641,12 +1642,10 @@ public:
void
Step
(
const
Action
&
action
)
override
{
void
Step
(
const
Action
&
action
)
override
{
// clock_t start = clock();
// clock_t start = clock();
// fmt::println("Step");
int
idx
=
action
[
"action"
_
];
int
idx
=
action
[
"action"
_
];
callback_
(
idx
);
callback_
(
idx
);
// update_history_actions(to_play_, idx);
update_history_actions
(
to_play_
,
idx
);
// fmt::println("update_history_actions");
PlayerId
player
=
to_play_
;
PlayerId
player
=
to_play_
;
...
@@ -1737,8 +1736,7 @@ private:
...
@@ -1737,8 +1736,7 @@ private:
};
};
for
(
auto
&
[
location
,
hidden_for_opponent
]
:
configs
)
{
for
(
auto
&
[
location
,
hidden_for_opponent
]
:
configs
)
{
// check this
// check this
if
(
opponent
&&
(
location
==
LOCATION_HAND
)
&&
if
(
opponent
&&
(
revealed_
.
size
()
!=
0
))
{
(
revealed_
.
size
()
!=
0
))
{
hidden_for_opponent
=
false
;
hidden_for_opponent
=
false
;
}
}
if
(
opponent
&&
hidden_for_opponent
)
{
if
(
opponent
&&
hidden_for_opponent
)
{
...
@@ -1759,9 +1757,7 @@ private:
...
@@ -1759,9 +1757,7 @@ private:
bool
hide
=
false
;
bool
hide
=
false
;
if
(
opponent
)
{
if
(
opponent
)
{
hide
=
c
.
position_
&
POS_FACEDOWN
;
hide
=
c
.
position_
&
POS_FACEDOWN
;
if
((
location
==
LOCATION_HAND
)
&&
if
(
revealed_
.
find
(
spec
)
!=
revealed_
.
end
())
{
(
std
::
find
(
revealed_
.
begin
(),
revealed_
.
end
(),
spec
)
!=
revealed_
.
end
()))
{
hide
=
false
;
hide
=
false
;
}
}
}
}
...
@@ -1777,6 +1773,7 @@ private:
...
@@ -1777,6 +1773,7 @@ private:
void
_set_obs_card_
(
TArray
<
uint8_t
>
&
f_cards
,
int
offset
,
const
Card
&
c
,
void
_set_obs_card_
(
TArray
<
uint8_t
>
&
f_cards
,
int
offset
,
const
Card
&
c
,
bool
hide
)
{
bool
hide
)
{
// check offset exceeds max_cards
uint8_t
location
=
c
.
location_
;
uint8_t
location
=
c
.
location_
;
bool
overlay
=
location
&
LOCATION_OVERLAY
;
bool
overlay
=
location
&
LOCATION_OVERLAY
;
if
(
overlay
)
{
if
(
overlay
)
{
...
@@ -2156,8 +2153,8 @@ private:
...
@@ -2156,8 +2153,8 @@ private:
fwrite
(
buf
,
1
,
1
,
fp_
);
fwrite
(
buf
,
1
,
1
,
fp_
);
break
;
break
;
case
MSG_SELECT_COUNTER
:
case
MSG_SELECT_COUNTER
:
ReplayWriteInt8
(
2
);
ReplayWriteInt8
(
2
*
n_counters_
);
fwrite
(
buf
,
2
,
1
,
fp_
);
fwrite
(
buf
,
2
*
n_counters_
,
1
,
fp_
);
break
;
break
;
case
MSG_SELECT_PLACE
:
case
MSG_SELECT_PLACE
:
case
MSG_SELECT_DISFIELD
:
case
MSG_SELECT_DISFIELD
:
...
@@ -2189,13 +2186,10 @@ private:
...
@@ -2189,13 +2186,10 @@ private:
state
[
"obs:global_"
_
][
22
]
=
uint8_t
(
1
);
state
[
"obs:global_"
_
][
22
]
=
uint8_t
(
1
);
return
;
return
;
}
}
// fmt::println("writestate");
auto
[
spec2index
,
loc_n_cards
]
=
_set_obs_cards
(
state
[
"obs:cards_"
_
],
to_play_
);
auto
[
spec2index
,
loc_n_cards
]
=
_set_obs_cards
(
state
[
"obs:cards_"
_
],
to_play_
);
// fmt::println("_set_obs_cards");
// _set_obs_global(state["obs:global_"_], to_play_, loc_n_cards);
_set_obs_global
(
state
[
"obs:global_"
_
],
to_play_
,
loc_n_cards
);
// fmt::println("_set_obs_global");
// we can't shuffle because idx must be stable in callback
// we can't shuffle because idx must be stable in callback
if
(
n_options
>
max_options
())
{
if
(
n_options
>
max_options
())
{
...
@@ -2207,12 +2201,10 @@ private:
...
@@ -2207,12 +2201,10 @@ private:
// fmt::println("{} {}", key, val);
// fmt::println("{} {}", key, val);
// }
// }
// _set_obs_actions(state["obs:actions_"_], spec2index, msg_, options_);
_set_obs_actions
(
state
[
"obs:actions_"
_
],
spec2index
,
msg_
,
options_
);
// fmt::println("_set_obs_actions");
n_options
=
options_
.
size
();
n_options
=
options_
.
size
();
state
[
"info:num_options"
_
]
=
n_options
;
state
[
"info:num_options"
_
]
=
n_options
;
return
;
// update h_card_ids from state
// update h_card_ids from state
auto
&
h_card_ids
=
to_play_
==
0
?
h_card_ids_0_
:
h_card_ids_1_
;
auto
&
h_card_ids
=
to_play_
==
0
?
h_card_ids_0_
:
h_card_ids_1_
;
...
@@ -2233,7 +2225,6 @@ private:
...
@@ -2233,7 +2225,6 @@ private:
}
}
h_card_ids
[
i
]
=
card_ids
;
h_card_ids
[
i
]
=
card_ids
;
}
}
// fmt::println("update h_card_ids");
// write history actions
// write history actions
...
@@ -2247,7 +2238,6 @@ private:
...
@@ -2247,7 +2238,6 @@ private:
n_action_feats
*
n1
);
n_action_feats
*
n1
);
state
[
"obs:h_actions_"
_
][
n1
].
Assign
((
uint8_t
*
)
history_actions
.
Data
(),
state
[
"obs:h_actions_"
_
][
n1
].
Assign
((
uint8_t
*
)
history_actions
.
Data
(),
n_action_feats
*
ha_p
);
n_action_feats
*
ha_p
);
// fmt::println("write history actions");
}
}
void
show_decision
(
int
idx
)
{
void
show_decision
(
int
idx
)
{
...
@@ -2320,8 +2310,8 @@ private:
...
@@ -2320,8 +2310,8 @@ private:
if
((
play_mode_
==
kSelfPlay
)
||
(
to_play_
==
ai_player_
))
{
if
((
play_mode_
==
kSelfPlay
)
||
(
to_play_
==
ai_player_
))
{
if
(
options_
.
size
()
==
1
)
{
if
(
options_
.
size
()
==
1
)
{
callback_
(
0
);
callback_
(
0
);
//
update_h_card_ids(to_play_, 0);
update_h_card_ids
(
to_play_
,
0
);
//
update_history_actions(to_play_, 0);
update_history_actions
(
to_play_
,
0
);
if
(
verbose_
)
{
if
(
verbose_
)
{
show_decision
(
0
);
show_decision
(
0
);
}
}
...
@@ -2501,7 +2491,6 @@ private:
...
@@ -2501,7 +2491,6 @@ private:
}
}
cards
.
push_back
(
c
);
cards
.
push_back
(
c
);
}
}
fmt
::
println
(
"qdp: {}, bl: {}, n: {}"
,
qdp_
,
bl
,
cards
.
size
());
return
cards
;
return
cards
;
}
}
...
@@ -3001,8 +2990,7 @@ private:
...
@@ -3001,8 +2990,7 @@ private:
if
(
verbose_
)
{
if
(
verbose_
)
{
cards
.
push_back
(
get_card
(
c
,
loc
,
seq
));
cards
.
push_back
(
get_card
(
c
,
loc
,
seq
));
}
}
// TODO: check if this is correct
revealed_
.
insert
(
ls_to_spec
(
loc
,
seq
,
0
,
c
==
player
));
revealed_
.
push_back
(
ls_to_spec
(
loc
,
seq
,
0
,
c
==
player
));
}
}
if
(
!
verbose_
)
{
if
(
!
verbose_
)
{
return
;
return
;
...
@@ -4349,9 +4337,9 @@ private:
...
@@ -4349,9 +4337,9 @@ private:
}
else
if
(
msg_
==
MSG_SELECT_COUNTER
)
{
}
else
if
(
msg_
==
MSG_SELECT_COUNTER
)
{
auto
player
=
read_u8
();
auto
player
=
read_u8
();
auto
counter_type
=
read_u16
();
auto
counter_type
=
read_u16
();
auto
counter_count
=
read_u16
();
int
counter_count
=
read_u16
();
int
count
=
read_u8
();
int
count
=
read_u8
();
if
(
count
!=
1
)
{
if
(
count
>
2
)
{
throw
std
::
runtime_error
(
"Select counter count "
+
throw
std
::
runtime_error
(
"Select counter count "
+
std
::
to_string
(
count
)
+
" not implemented"
);
std
::
to_string
(
count
)
+
" not implemented"
);
}
}
...
@@ -4359,12 +4347,16 @@ private:
...
@@ -4359,12 +4347,16 @@ private:
if
(
verbose_
)
{
if
(
verbose_
)
{
pl
->
notify
(
fmt
::
format
(
"Type new {} for {} card(s), separated by spaces."
,
"UNKNOWN_COUNTER"
,
count
));
pl
->
notify
(
fmt
::
format
(
"Type new {} for {} card(s), separated by spaces."
,
"UNKNOWN_COUNTER"
,
count
));
}
}
std
::
vector
<
int
>
counters
;
counters
.
reserve
(
count
);
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
auto
code
=
read_u32
();
auto
code
=
read_u32
();
auto
controller
=
read_u8
();
auto
controller
=
read_u8
();
auto
loc
=
read_u8
();
auto
loc
=
read_u8
();
auto
seq
=
read_u8
();
auto
seq
=
read_u8
();
auto
counter
=
read_u16
();
auto
counter
=
read_u16
();
counters
.
push_back
(
counter
&
0xffff
);
if
(
verbose_
)
{
if
(
verbose_
)
{
pl
->
notify
(
c_get_card
(
code
).
name_
+
": "
+
std
::
to_string
(
counter
));
pl
->
notify
(
c_get_card
(
code
).
name_
+
": "
+
std
::
to_string
(
counter
));
}
}
...
@@ -4372,8 +4364,17 @@ private:
...
@@ -4372,8 +4364,17 @@ private:
// options_.push_back(spec);
// options_.push_back(spec);
}
}
// TODO: implement action
// TODO: implement action
uint16_t
resp
=
counter_count
&
0xffff
;
n_counters_
=
count
;
memcpy
(
resp_buf_
,
&
resp
,
2
);
uint16_t
resp1
=
static_cast
<
uint16_t
>
(
std
::
min
(
counter_count
,
counters
[
0
]));
memcpy
(
resp_buf_
,
&
resp1
,
2
);
counter_count
-=
counters
[
0
];
if
(
count
==
2
)
{
uint16_t
resp2
=
0
;
if
(
counter_count
>
0
)
{
resp2
=
static_cast
<
uint16_t
>
(
counter_count
);
}
memcpy
(
resp_buf_
+
2
,
&
resp2
,
2
);
}
YGO_SetResponseb
(
pduel_
,
resp_buf_
);
YGO_SetResponseb
(
pduel_
,
resp_buf_
);
}
else
if
(
msg_
==
MSG_ANNOUNCE_NUMBER
)
{
}
else
if
(
msg_
==
MSG_ANNOUNCE_NUMBER
)
{
auto
player
=
read_u8
();
auto
player
=
read_u8
();
...
...
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