Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
Neos
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
Neos
Commits
437233f8
Commit
437233f8
authored
Jul 04, 2024
by
biluo.shen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix deck cards; intercept for test
parent
3a8c96b5
Pipeline
#28112
failed with stages
in 31 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
101 additions
and
57 deletions
+101
-57
src/service/duel/agent.ts
src/service/duel/agent.ts
+42
-10
src/service/duel/gameMsg.ts
src/service/duel/gameMsg.ts
+42
-31
src/service/duel/start.ts
src/service/duel/start.ts
+7
-4
src/stores/matStore/store.ts
src/stores/matStore/store.ts
+6
-3
src/stores/matStore/types.ts
src/stores/matStore/types.ts
+2
-1
src/ui/Duel/PlayMat/Menu/index.tsx
src/ui/Duel/PlayMat/Menu/index.tsx
+2
-8
No files found.
src/service/duel/agent.ts
View file @
437233f8
...
...
@@ -15,11 +15,38 @@ import { cardStore, matStore } from "@/stores";
import
{
ActionMsgName
,
Global
,
convertPhase
,
convertCard
,
convertDeckCard
,
parsePlayerFromMsg
,
convertActionMsg
,
Input
}
from
"
@/api/ygoAgent/schema
"
;
import
{
predictDuel
}
from
"
@/api/ygoAgent/predict
"
;
function
computeSetDifference
(
a1
:
number
[],
a2
:
number
[]):
number
[]
{
const
freq1
=
new
Map
<
number
,
number
>
();
const
freq2
=
new
Map
<
number
,
number
>
();
for
(
const
num
of
a1
)
{
freq1
.
set
(
num
,
(
freq1
.
get
(
num
)
||
0
)
+
1
);
}
for
(
const
num
of
a2
)
{
freq2
.
set
(
num
,
(
freq2
.
get
(
num
)
||
0
)
+
1
);
}
for
(
const
[
num
,
count
]
of
freq2
)
{
if
(
freq1
.
has
(
num
))
{
freq1
.
set
(
num
,
freq1
.
get
(
num
)
!
-
count
);
}
}
const
difference
:
number
[]
=
[];
for
(
const
[
num
,
count
]
of
freq1
)
{
if
(
count
>
0
)
{
difference
.
push
(...
Array
(
count
).
fill
(
num
));
}
}
return
difference
;
}
export
function
genPredictReq
(
msg
:
ygopro
.
StocGameMessage
):
PredictReq
{
// 全局信息可以从 `matStore` 里面拿
const
mat
=
matStore
;
// 卡片信息可以从 `cardStore` 里面拿
// TODO (ygo-agent): TZONE
const
zones
=
[
ygopro
.
CardZone
.
DECK
,
ygopro
.
CardZone
.
HAND
,
...
...
@@ -45,16 +72,15 @@ export function genPredictReq(msg: ygopro.StocGameMessage): PredictReq {
)
.
map
((
card
)
=>
convertCard
(
card
,
player
));
const
card_codes_me
=
new
Set
(
cardStore
.
inner
const
card_codes_me
=
cardStore
.
inner
.
filter
((
card
)
=>
zones
.
includes
(
card
.
location
.
zone
)
&&
card
.
location
.
controller
===
player
)
.
map
((
card
)
=>
card
.
code
)
)
;
const
deck_cards_me
=
matStore
.
main_deck_cards
.
filter
((
meta
)
=>
card_codes_me
.
has
(
meta
.
id
))
.
map
(
convertDeckCard
);
.
map
((
card
)
=>
card
.
code
);
const
card_codes_me_deck
=
computeSetDifference
(
mat
.
main_deck
,
card_codes_me
);
const
main_deck_card_meta
=
mat
.
main_deck_card_meta
;
// TODO (ygo-agent): 临时方案,有很多边界情况未考虑
const
deck_cards_me
=
card_codes_me_deck
.
map
((
code
)
=>
convertDeckCard
(
main_deck_card_meta
.
get
(
code
)
!
)
);
const
turnPlayer
=
mat
.
currentPlayer
;
const
global
:
Global
=
{
...
...
@@ -79,23 +105,29 @@ export function genPredictReq(msg: ygopro.StocGameMessage): PredictReq {
index
:
mat
.
agentIndex
,
input
:
input
,
// TODO (ygo-agent): use real value
prev_action_idx
:
0
,
prev_action_idx
:
mat
.
prevActionIndex
,
}
}
export
async
function
sendAIPredictAsResponse
(
msg
:
ygopro
.
StocGameMessage
)
{
export
async
function
sendAIPredictAsResponse
()
{
const
msg
=
matStore
.
actionMsg
;
const
req
=
genPredictReq
(
msg
);
console
.
log
(
"
Sending predict request:
"
,
req
);
const
duelId
=
matStore
.
duelId
;
const
resp
=
await
predictDuel
(
duelId
,
req
);
if
(
!
resp
)
{
console
.
log
(
"
Got predict response:
"
,
resp
);
if
(
resp
!==
undefined
)
{
matStore
.
agentIndex
=
resp
.
index
;
}
else
{
console
.
error
(
"
Failed to get predict response
"
);
return
;
}
const
preds
=
resp
.
predict_results
.
action_preds
;
const
action_idx
=
argmax
(
preds
,
(
r
)
=>
r
.
prob
);
matStore
.
prevActionIndex
=
action_idx
;
const
response
=
preds
[
action_idx
].
response
;
const
msg_name
=
req
.
input
.
action_msg
.
name
;
switch
(
msg_name
)
{
...
...
src/service/duel/gameMsg.ts
View file @
437233f8
...
...
@@ -100,58 +100,69 @@ export default async function handleGameMsg(
if
(
replayStore
.
isReplay
&&
ReplayIgnoreMsg
.
includes
(
msg
.
gameMsg
))
return
;
console
.
log
(
"
Got
"
+
msg
.
gameMsg
);
switch
(
msg
.
gameMsg
)
{
case
"
select_card
"
:
{
matStore
.
actionMsg
=
msg
.
select_card
;
break
;
}
case
"
select_tribute
"
:
{
matStore
.
actionMsg
=
msg
.
select_tribute
;
break
;
}
case
"
select_sum
"
:
{
matStore
.
actionMsg
=
msg
.
select_sum
;
break
;
case
"
announce
"
:
{
matStore
.
actionMsg
=
msg
.
announce
;
console
.
log
(
"
intercept announce
"
);
return
;
}
case
"
select_idle_cmd
"
:
{
matStore
.
actionMsg
=
msg
.
select_idle_cmd
;
break
;
case
"
select_battle_cmd
"
:
{
matStore
.
actionMsg
=
msg
.
select_battle_cmd
;
console
.
log
(
"
intercept select_battle_cmd
"
);
return
;
}
case
"
select_chain
"
:
{
matStore
.
actionMsg
=
msg
.
select_chain
;
break
;
console
.
log
(
"
intercept select_chain
"
);
return
;
}
case
"
select_position
"
:
{
matStore
.
actionMsg
=
msg
.
select_position
;
break
;
case
"
select_yes_no
"
:
{
matStore
.
actionMsg
=
msg
.
select_yes_no
;
console
.
log
(
"
intercept select_yes_no
"
);
return
;
}
case
"
select_effect_yn
"
:
{
matStore
.
actionMsg
=
msg
.
select_effect_yn
;
break
;
console
.
log
(
"
intercept select_effect_yn
"
);
return
;
}
case
"
select_yes_no
"
:
{
matStore
.
actionMsg
=
msg
.
select_yes_no
;
break
;
case
"
select_idle_cmd
"
:
{
matStore
.
actionMsg
=
msg
.
select_idle_cmd
;
console
.
log
(
"
intercept select_idle_cmd
"
);
return
;
}
case
"
select_battle_cmd
"
:
{
matStore
.
actionMsg
=
msg
.
select_battle_cmd
;
break
;
case
"
select_option
"
:
{
matStore
.
actionMsg
=
msg
.
select_option
;
console
.
log
(
"
intercept select_option
"
);
return
;
}
case
"
select_position
"
:
{
matStore
.
actionMsg
=
msg
.
select_position
;
console
.
log
(
"
intercept select_position
"
);
return
;
}
case
"
select_unselect_card
"
:
{
matStore
.
actionMsg
=
msg
.
select_unselect_card
;
break
;
}
case
"
select_option
"
:
{
matStore
.
actionMsg
=
msg
.
select_option
;
break
;
}
case
"
select_place
"
:
{
matStore
.
actionMsg
=
msg
.
select_place
;
break
;
}
case
"
announce
"
:
matStore
.
actionMsg
=
msg
.
announce
;
case
"
select_card
"
:
{
matStore
.
actionMsg
=
msg
.
select_card
;
break
;
}
case
"
select_sum
"
:
{
matStore
.
actionMsg
=
msg
.
select_sum
;
break
;
}
case
"
select_tribute
"
:
{
matStore
.
actionMsg
=
msg
.
select_tribute
;
break
;
}
default
:
{
break
;
}
...
...
src/service/duel/start.ts
View file @
437233f8
...
...
@@ -92,10 +92,13 @@ export default async (start: ygopro.StocGameMessage.MsgStart) => {
const
{
duelId
,
index
}
=
(
await
createDuel
())
!
;
matStore
.
duelId
=
duelId
;
matStore
.
agentIndex
=
index
;
const
main_deck_cards
=
matStore
.
main_deck
.
map
((
code
)
=>
{
return
fetchCard
(
code
);
});
matStore
.
main_deck_cards
=
main_deck_cards
;
matStore
.
main_deck_card_meta
=
matStore
.
main_deck
.
reduce
((
map
,
item
)
=>
{
if
(
!
map
.
has
(
item
))
{
map
.
set
(
item
,
fetchCard
(
item
));
}
return
map
;
},
new
Map
());
if
(
replayStore
.
isReplay
)
{
replayStart
();
...
...
src/stores/matStore/store.ts
View file @
437233f8
...
...
@@ -95,9 +95,10 @@ const initialState: Omit<MatState, "reset"> = {
isMe
,
duelId
:
""
,
agentIndex
:
0
,
prevActionIndex
:
0
,
actionMsg
:
undefined
,
main_deck
:
[],
main_deck_card
s
:
[]
,
main_deck_card
_meta
:
new
Map
()
,
};
class
MatStore
implements
MatState
,
NeosStore
{
...
...
@@ -116,9 +117,10 @@ class MatStore implements MatState, NeosStore {
duelEnd
=
initialState
.
duelEnd
;
duelId
=
initialState
.
duelId
;
agentIndex
=
initialState
.
agentIndex
;
prevActionIndex
=
initialState
.
prevActionIndex
;
actionMsg
=
initialState
.
actionMsg
;
main_deck
=
initialState
.
main_deck
;
main_deck_card
s
=
initialState
.
main_deck_cards
;
main_deck_card
_meta
=
initialState
.
main_deck_card_meta
;
// methods
isMe
=
initialState
.
isMe
;
...
...
@@ -150,9 +152,10 @@ class MatStore implements MatState, NeosStore {
this
.
duelEnd
=
false
;
this
.
duelId
=
""
;
this
.
agentIndex
=
0
;
this
.
prevActionIndex
=
0
;
this
.
actionMsg
=
undefined
;
this
.
main_deck
=
[];
this
.
main_deck_card
s
=
[]
;
this
.
main_deck_card
_meta
=
new
Map
()
;
}
}
...
...
src/stores/matStore/types.ts
View file @
437233f8
...
...
@@ -52,9 +52,10 @@ export interface MatState {
duelId
:
string
;
agentIndex
:
number
;
prevActionIndex
:
number
;
actionMsg
?:
any
;
main_deck
:
number
[];
main_deck_card
s
:
CardMeta
[]
;
main_deck_card
_meta
:
Map
<
number
,
CardMeta
>
;
}
export
interface
InitInfo
{
...
...
src/ui/Duel/PlayMat/Menu/index.tsx
View file @
437233f8
...
...
@@ -29,8 +29,7 @@ import {
}
from
"
@/api
"
;
import
{
ChainSetting
,
matStore
}
from
"
@/stores
"
;
import
{
IconFont
}
from
"
@/ui/Shared
"
;
import
{
predictDuel
}
from
"
@/api/ygoAgent/predict
"
;
import
{
genPredictReq
}
from
"
@/service/duel/agent
"
;
import
{
sendAIPredictAsResponse
}
from
"
@/service/duel/agent
"
;
import
styles
from
"
./index.module.scss
"
;
import
PhaseType
=
ygopro
.
StocGameMessage
.
MsgNewPhase
.
PhaseType
;
...
...
@@ -301,12 +300,7 @@ export const Menu = () => {
const
globalDisable
=
!
matStore
.
isMe
(
currentPlayer
);
const
aiPredict
=
async
()
=>
{
console
.
log
(
"
AI Predict
"
);
const
req
=
genPredictReq
(
matStore
.
actionMsg
);
console
.
log
(
req
);
const
duelId
=
matStore
.
duelId
;
const
predictRes
=
await
predictDuel
(
duelId
,
req
);
console
.
log
(
predictRes
);
await
sendAIPredictAsResponse
();
};
return
(
...
...
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