Commit f89ac8fe authored by sbl1996@126.com's avatar sbl1996@126.com

Support more decks

parent 04efda84
#created by ...
#main
27204311
46565218
46565218
91800273
91800273
33854624
91810826
91810826
91810826
39931513
39931513
39931513
65326118
65326118
14558127
14558127
14558127
23434538
23434538
23434538
18144506
14532163
14532163
12580477
12580477
35269904
91880660
73628505
24299458
24299458
66730191
66730191
66730191
47355498
30336082
30336082
30336082
10045474
10045474
10045474
#extra
84815190
39402797
73218989
18969888
50954680
9012916
73580471
25862681
82570174
82570174
1686814
93039339
29301450
24361622
73539069
!side
36668118
27204312
#created by ...
#main
27204311
53804307
91810826
91810826
91810826
39931513
39931513
39931513
65326118
65326118
14558127
14558127
14558127
59438930
59438930
23434538
23434538
23434538
14532163
14532163
25311006
73628505
75500286
24224830
24224830
24299458
24299458
18144506
66730191
66730191
66730191
30336082
30336082
30336082
47355498
91880660
10045474
10045474
10045474
23002292
#extra
73218989
40139997
18969888
39402797
84815190
50954680
9012916
82570174
82570174
33698022
25862681
68431965
1686814
24361622
!side
73580471
27204312
#created by ...
#main
27204311
55063751
78661338
33854624
46565218
46565218
46565218
91800273
91800273
91810826
91810826
91810826
97682931
39931513
39931513
39931513
65326118
65326118
14558127
14558127
14558127
23434538
23434538
23434538
94145021
4031928
4031928
25311006
73628505
8267140
48130397
66730191
66730191
66730191
73468603
30336082
30336082
30336082
56111151
10045474
10045474
10045474
#extra
11765832
54757758
27572350
18969888
18969888
39402797
84815190
33698022
82570174
82570174
25862681
74997493
29301450
58699500
24361622
!side
27204312
......@@ -63,18 +63,4 @@
38811586
53971455
!side
27204311
82385847
34267821
73642296
27572350
93039339
18144506
08267140
08267140
08267140
15693423
15693423
15693423
51452091
23002292
\ No newline at end of file
27204312
\ No newline at end of file
#created by ...
#main
27204311
55204071
69680031
25451383
25451383
32731036
33854624
60242223
60242223
19096726
82489470
62962630
62962630
60303688
55273560
95515789
95515789
45883110
45484331
68468459
68468459
68468459
14558127
14558127
14558127
23434538
23434538
23434538
36577931
94145021
94145021
35269904
75500286
81439173
6498706
6498706
6498706
1984618
1984618
1984618
11110587
11110587
34995106
44362883
24224830
24224830
27204311
36637374
29948294
29948294
82738008
18973184
10045474
81767888
6763530
1041278
19271881
32756828
17751597
17751597
#extra
11321089
92892239
41373230
51409648
1906812
24915933
24915933
70534340
3410461
38811586
44146295
44146295
87746184
87746184
53971455
!side
27204312
81767889
#created by ...
#main
27204311
32731036
78888899
97698279
6637331
33854624
15005145
15005145
15005145
42493140
42493140
42493140
14558127
14558127
14558127
77202120
23434538
23434538
23434538
94145021
94145021
97268402
97268402
97268402
25311006
4160316
24224830
24224830
77765207
77765207
77765207
34090915
41371602
41371602
41371602
10045474
10045474
10045474
40155014
77543769
#extra
21123811
26268488
99585850
15982593
71858682
71858682
63436931
27572350
22850702
84815190
72444406
30983281
93039339
93854893
29301450
!side
27204312
#created by wxapp_ygo
#main
42493140
42493140
42493140
15005145
15005145
15005145
97698279
23434538
23434538
23434538
14558127
14558127
14558127
97268402
97268402
27204311
27204311
41371602
41371602
41371602
77765207
77765207
77765207
92907248
81674782
81674782
81674782
35059553
35059553
35059553
24224830
24224830
84211599
73628505
40155014
40155014
10045474
10045474
10045474
82732705
#extra
72444406
63436931
63436931
71858682
71858682
71858682
15982593
15982593
21123811
21123811
93039339
34755994
65741786
29301450
02857636
!side
27204312
#created by ...
#main
27204311
27204311
27204311
58143852
58143852
58143852
55461744
55461744
28954097
28954097
28954097
23076639
23076639
23076639
61173621
61173621
84478195
92565383
92565383
92565383
34541543
14558127
14558127
14558127
23434538
23434538
23434538
94145021
94145021
97268402
97268402
24094653
24094653
25311006
25311006
34773082
34773082
34773082
24224830
24224830
63136489
63136489
63136489
53329234
#extra
11321089
11321089
38264974
43227
69946549
69601012
69601012
1769875
1769875
11765832
22850702
93039339
27552504
29301450
71607202
!side
5818798
77207191
4796100
27204312
File mode changed from 100644 to 100755
#created by ...
#main
24508238
54334420
54334420
54334420
18940725
18940725
18940725
80433039
17827173
17827173
23434538
23434538
23434538
14558127
14558127
14558127
91800273
91800273
29587993
69327790
80611581
53212882
75500286
98645731
49238328
51697825
51697825
51697825
84211599
28126717
55521751
24224830
24224830
25311006
69087397
69087397
69087397
87639778
87639778
41215808
#extra
35809262
35809262
81003500
81003500
81003500
76913983
76913983
76913983
48608796
48608796
48608796
90448279
94259633
4280258
98127546
!side
21844576
58932615
86188410
89252153
#created by wxapp_ygo
#main
53212882
80611581
69327790
29587993
91800273
91800273
14558127
14558127
14558127
18940725
18940725
18940725
54334420
54334420
54334420
80433039
80433039
17827173
24508238
84211599
75500286
98645731
49238328
51697825
69087397
69087397
69087397
25311006
24224830
24224830
81674782
55521751
28126717
41215808
15693423
15693423
15693423
10045474
10045474
10045474
#extra
90448279
72167543
72971064
48608796
98127546
86066372
04280258
21887175
38342335
08264361
48815792
65741786
02857636
75452921
94259633
!side
\ No newline at end of file
#created by wxapp_ygo
#created by ...
#main
18094166
18094166
......@@ -9,8 +9,8 @@
27780618
40044918
40044918
09411399
09411399
9411399
9411399
89943723
16605586
50720316
......@@ -25,9 +25,9 @@
14558127
94145021
94145021
08949584
08949584
08949584
8949584
8949584
8949584
21143940
21143940
21143940
......@@ -55,20 +55,5 @@
90590303
58004362
19324993
01948619
1948619
!side
94145021
34267821
34267821
35269904
35269904
35269904
14532163
14532163
05758500
18144506
08267140
08267140
08267140
43262273
23002292
\ No newline at end of file
#created by ...
#main
2347656
81497285
81497285
75730490
1225009
1225009
1225009
73642296
62015408
62015408
14558127
14558127
14558127
37629703
37629703
23434538
23434538
23434538
74018812
74018812
97268402
2511
2511
84211599
24224830
24224830
33407125
4931121
83326048
6351147
30748475
10045474
10045474
10045474
5380979
5380979
92714517
92714517
92714517
82732705
#extra
87746184
84815190
22850702
22850702
90590303
54498517
98127546
4280258
2772337
65741786
8264361
27381364
71607202
71607202
94259633
!side
68468459
File mode changed from 100644 to 100755
......@@ -57,4 +57,4 @@
90590303
08728498
!side
70902743
\ No newline at end of file
70902743
#created by ...
#main
27204311
27204311
32909498
68304193
68304193
68304193
91800273
91800273
60303688
47961808
10963799
10963799
10963799
42009836
42009836
42009836
14558127
14558127
23434538
23434538
23434538
1984618
1984618
35261759
84211599
49238328
84797028
84797028
69540484
71832012
82956214
82956214
36975314
36975314
36975314
41420027
41420027
41420027
84749824
84749824
#extra
11765832
11765832
80532587
80532587
96633955
84815190
98506199
90448279
48626373
48626373
80117527
80117527
10019086
34755994
34755994
!side
73542331
27204311
File mode changed from 100644 to 100755
#created by wxapp_ygo
#main
97268402
97268402
97268402
09742784
09674034
09674034
09674034
45663742
90241276
90241276
90241276
23434538
23434538
23434538
14558127
14558127
14558127
52038441
52038441
52038441
06637331
33854624
72270339
72270339
72270339
48452496
48452496
27204311
27204311
27204311
89023486
89023486
02295440
53639887
80845034
80845034
80845034
10045474
10045474
10045474
#extra
27548199
02772337
41999284
02857636
48815792
87871125
65741786
08264361
38342335
61245672
20665527
04280258
86066372
45112597
98127546
!side
27204312
#created by ...
#main
97268402
97268402
9674034
9674034
9674034
45663742
90241276
90241276
90241276
23434538
23434538
23434538
14558127
14558127
14558127
6637331
32909498
68304193
68304193
72270339
72270339
72270339
48452496
48452496
27204311
89023486
89023486
25311006
24081957
53639887
69540484
80845034
80845034
80845034
24224830
24224830
24299458
10045474
10045474
10045474
#extra
2772337
41999284
94259633
2857636
48815792
87871125
65741786
8264361
38342335
45819647
20665527
4280258
86066372
45112597
98127546
!side
27204312
File mode changed from 100644 to 100755
#created by ...
#main
48452496
72270339
53143898
27132400
27132400
42790071
14558127
14558127
14558127
89538537
23434538
23434538
23434538
9674034
90241276
25533642
25533642
25533642
54126514
59185998
59185998
24508238
2295440
51405049
84211599
89023486
24224830
24224830
26700718
52340444
80845034
80845034
80845034
10045474
10045474
10045474
22024279
35146019
53329234
27541563
#extra
93039339
61470213
20665527
86066372
4280258
2772337
93503294
45819647
48815792
29301450
1508649
1508649
63013339
41999284
94259633
!side
52340445
#created by ...
#main
66431519
66431519
66431519
2526224
2526224
2526224
72270339
18621798
18621798
18621798
14558127
14558127
14558127
23434538
23434538
23434538
9674034
9674034
90241276
90241276
90681088
90681088
90681088
12058741
12058741
22993208
22993208
73628505
85106525
85106525
85106525
89023486
89023486
59388357
59388357
91703676
65305978
65305978
57554544
57554544
57554544
38798785
38798785
#extra
63767246
63767246
64182380
64182380
93854893
98127546
86066372
86066372
4280258
2772337
2772337
2772337
38342335
48815792
48815792
!side
#created by ...
#main
27204311
48452496
72270339
72270339
32909498
4928565
5560911
572850
572850
73956664
73956664
73956664
42009836
37961969
97682931
14558127
14558127
14558127
23434538
23434538
23434538
45663742
9674034
9674034
90241276
90241276
24081957
33878367
89023486
24224830
24224830
60362066
80845034
80845034
80845034
6767771
53639887
71832012
77103950
7436169
38436986
74920585
#extra
28226490
84330567
92731385
84815190
27548199
63533837
73082255
20665527
4280258
2772337
98095162
84271823
65741786
50277355
41999284
!side
56099748
27204312
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -58,18 +58,4 @@
24094258
22125101
!side
27204311
94145021
94145021
94145021
14532163
25311006
25311006
08267140
08267140
08267140
10045474
10045474
15693423
15693423
15693423
27204312
......@@ -656,3 +656,187 @@
86310763
84211599
10804018
15982593
56111151
98095162
27541563
84330567
11765832
22024279
34773082
68431965
72167543
38436986
82489470
63436931
38264974
33407125
51697825
69087397
32909498
11110587
21887175
19271881
66730191
43227
55204071
37961969
84478195
51405049
80611581
10019086
35146019
6351147
1225009
89252153
22993208
60303688
77543769
53143898
33878367
86188410
54757758
1769875
5818798
59388357
71832012
2511
55521751
97698279
27132400
72444406
71858682
25862681
29587993
81674782
65681983
5560911
77765207
21844576
69540484
2347656
74920585
24361622
73542331
73468603
48626373
77202120
84271823
91800273
36975314
36668118
21123811
63136489
27552504
63533837
52038441
18940725
72971064
4160316
26268488
77103950
59185998
10963799
73628505
5380979
69680031
71607202
34995106
56099748
73218989
69327790
28226490
82570174
54334420
50277355
81003500
91810826
6763530
65326118
4928565
30336082
32756828
58143852
30983281
6767771
33854624
93854893
69946549
42790071
81497285
55063751
25533642
91880660
54498517
42493140
40139997
42009836
41420027
53804307
1686814
18969888
1508649
39402797
73956664
68304193
60362066
53329234
17827173
58932615
34755994
572850
38798785
81767888
98506199
15005145
28954097
97682931
28126717
73539069
61470213
92714517
48608796
4931121
75730490
47355498
39931513
77207191
9012916
4796100
47961808
53212882
78661338
87639778
98645731
58699500
92907248
69601012
45819647
37629703
6637331
80117527
23076639
99585850
30748475
93503294
41215808
24508238
35059553
46565218
55461744
61173621
40155014
92565383
7436169
80433039
34090915
62015408
54126514
82956214
78888899
41371602
34541543
89538537
35809262
92731385
74018812
......@@ -3,6 +3,7 @@ import time
from dataclasses import dataclass
from typing import Optional
import pickle
import numpy as np
import voyageai
......@@ -12,14 +13,15 @@ import tyro
from ygoai.embed import read_cards
from ygoai.utils import load_deck
@dataclass
class Args:
deck_dir: str = "../assets/deck"
"""the directory of ydk files"""
code_list_file: str = "code_list.txt"
"""the file containing the list of card codes"""
embeddings_file: Optional[str] = "embeddings.npy"
"""the npz file containing the embeddings of the cards"""
embeddings_file: Optional[str] = None
"""the pickle file containing the embeddings of the cards"""
cards_db: str = "../assets/locale/en/cards.cdb"
"""the cards database file"""
batch_size: int = 64
......@@ -76,18 +78,7 @@ if __name__ == "__main__":
with open(code_list_file, "r") as f:
code_list = f.readlines()
code_list = [int(code.strip()) for code in code_list]
print(f"The database contains {len(code_list)} cards.")
if embeddings_file is not None:
# read embeddings
if not os.path.exists(embeddings_file):
sample_embedding = get_embeddings(["test"])[0]
all_embeddings = np.zeros((0, len(sample_embedding)), dtype=np.float32)
else:
all_embeddings = np.load(embeddings_file)
print("Embedding dim:", all_embeddings.shape[1])
assert len(all_embeddings) == len(code_list), f"The number of embeddings({len(all_embeddings)}) does not match the number of cards."
print(f"The code list contains {len(code_list)} cards.")
all_codes = set(code_list)
......@@ -97,20 +88,32 @@ if __name__ == "__main__":
new_codes.append(code)
if new_codes == []:
print("No new cards have been added to the database.")
exit()
new_texts = read_texts(cards_db, new_codes)
print(new_texts)
if embeddings_file is not None:
embeddings = get_embeddings(new_texts, args.batch_size, args.wait_time, verbose=True)
all_embeddings = np.concatenate([all_embeddings, np.array(embeddings)], axis=0)
np.save(embeddings_file, all_embeddings)
print("No new cards have been added to the code list.")
else:
# update code_list
code_list += new_codes
# update code_list
code_list += new_codes
with open(code_list_file, "w") as f:
f.write("\n".join(map(str, code_list)) + "\n")
with open(code_list_file, "w") as f:
f.write("\n".join(map(str, code_list)) + "\n")
print(f"{len(new_codes)} new cards have been added to the code list.")
print(f"{len(new_codes)} new cards have been added to the database.")
\ No newline at end of file
if embeddings_file is not None:
if not os.path.exists(embeddings_file):
all_embeddings = {}
else:
all_embeddings = pickle.load(open(embeddings_file, "rb"))
codes_not_in_embeddings = [code for code in code_list if code not in all_embeddings]
if codes_not_in_embeddings == []:
print("All cards have embeddings.")
exit()
print(f"{len(codes_not_in_embeddings)} cards do not have embeddings.")
new_texts = read_texts(cards_db, codes_not_in_embeddings)
print(new_texts)
embeddings = get_embeddings(new_texts, args.batch_size, args.wait_time, verbose=True)
embeddings = np.array(embeddings, dtype=np.float32)
for code, embedding in zip(codes_not_in_embeddings, embeddings):
all_embeddings[code] = embedding
print(f"Embeddings of {len(codes_not_in_embeddings)} cards have been added.")
pickle.dump(all_embeddings, open(embeddings_file, "wb"))
\ No newline at end of file
......@@ -4,7 +4,7 @@ import time
from collections import deque
from dataclasses import dataclass
from typing import Literal, Optional
import pickle
import ygoenv
import numpy as np
......@@ -18,7 +18,7 @@ import torch.distributed as dist
from torch.cuda.amp import GradScaler, autocast
from ygoai.utils import init_ygopro
from ygoai.rl.utils import RecordEpisodeStatistics, to_tensor
from ygoai.rl.utils import RecordEpisodeStatistics, to_tensor, load_embeddings
from ygoai.rl.agent import PPOAgent as Agent
from ygoai.rl.dist import reduce_gradidents, torchrun_setup, fprint
from ygoai.rl.buffer import create_obs
......@@ -238,7 +238,7 @@ def main():
eval_envs = RecordEpisodeStatistics(eval_envs)
if args.embedding_file:
embeddings = np.load(args.embedding_file)
embeddings = load_embeddings(args.embedding_file, args.code_list_file)
embedding_shape = embeddings.shape
else:
embedding_shape = None
......
......@@ -19,7 +19,7 @@ import torch.distributed as dist
from torch.cuda.amp import GradScaler, autocast
from ygoai.utils import init_ygopro
from ygoai.rl.utils import RecordEpisodeStatistics
from ygoai.rl.utils import RecordEpisodeStatistics, load_embeddings
from ygoai.rl.agent2 import PPOAgent as Agent
from ygoai.rl.dist import reduce_gradidents, torchrun_setup, fprint
from ygoai.rl.buffer import create_obs
......@@ -238,7 +238,7 @@ def main():
eval_envs = RecordEpisodeStatistics(eval_envs)
if args.embedding_file:
embeddings = np.load(args.embedding_file)
embeddings = load_embeddings(args.embedding_file, args.code_list_file)
embedding_shape = embeddings.shape
else:
embedding_shape = None
......
......@@ -18,7 +18,7 @@ import torch.distributed as dist
from torch.cuda.amp import GradScaler, autocast
from ygoai.utils import init_ygopro
from ygoai.rl.utils import RecordEpisodeStatistics, to_tensor
from ygoai.rl.utils import RecordEpisodeStatistics, to_tensor, load_embeddings
from ygoai.rl.agent import PPOAgent as Agent
from ygoai.rl.dist import reduce_gradidents, torchrun_setup, fprint
from ygoai.rl.buffer import create_obs
......@@ -243,7 +243,7 @@ def main():
eval_envs = RecordEpisodeStatistics(eval_envs)
if args.embedding_file:
embeddings = np.load(args.embedding_file)
embeddings = load_embeddings(args.embedding_file, args.code_list_file)
embedding_shape = embeddings.shape
else:
embedding_shape = None
......
......@@ -18,7 +18,7 @@ import torch.distributed as dist
from torch.cuda.amp import GradScaler, autocast
from ygoai.utils import init_ygopro
from ygoai.rl.utils import RecordEpisodeStatistics, to_tensor
from ygoai.rl.utils import RecordEpisodeStatistics, to_tensor, load_embeddings
from ygoai.rl.agent import PPOAgent as Agent
from ygoai.rl.dist import reduce_gradidents, torchrun_setup, fprint
from ygoai.rl.buffer import create_obs
......@@ -243,7 +243,7 @@ def main():
eval_envs = RecordEpisodeStatistics(eval_envs)
if args.embedding_file:
embeddings = np.load(args.embedding_file)
embeddings = load_embeddings(args.embedding_file, args.code_list_file)
embedding_shape = embeddings.shape
else:
embedding_shape = None
......
......@@ -108,6 +108,7 @@ def bootstrap_value_self(values, rewards, dones, learns, nextvalues, next_done,
def bootstrap_value_selfplay(values, rewards, dones, learns, nextvalues1, nextvalues2, next_done, gamma, gae_lambda):
# TODO: drop epsilon steps for estimated nextvalues
num_steps = rewards.size(0)
advantages = torch.zeros_like(rewards)
# TODO: optimize this
......
import re
import numpy as np
import gymnasium as gym
import pickle
import optree
import torch
......@@ -104,3 +105,14 @@ def masked_normalize(x, valid, eps=1e-8):
def to_tensor(x, device, dtype=torch.float32):
return optree.tree_map(lambda x: torch.from_numpy(x).to(device=device, dtype=dtype, non_blocking=True), x)
def load_embeddings(embedding_file, code_list_file):
with open(embedding_file, "rb") as f:
embeddings = pickle.load(f)
with open(code_list_file, "r") as f:
code_list = f.readlines()
code_list = [int(code.strip()) for code in code_list]
assert len(embeddings) == len(code_list), f"len(embeddings)={len(embeddings)}, len(code_list)={len(code_list)}"
embeddings = np.array([embeddings[code] for code in code_list], dtype=np.float32)
return embeddings
......@@ -459,6 +459,11 @@ static std::tuple<std::vector<uint32>, std::vector<uint32>, std::vector<uint32>>
}
}
if (main_deck.size() < 40) {
std::string err = fmt::format("Main deck must contain at least 40 cards, found: {}, file: {}", main_deck.size(), fp);
throw std::runtime_error(err);
}
// Read the extra deck
if (found_extra) {
while (std::getline(file, line)) {
......@@ -801,6 +806,7 @@ protected:
uint32_t data_ = 0;
uint32_t status_ = 0;
PlayerId controler_ = 0;
uint32_t location_ = 0;
uint32_t sequence_ = 0;
......@@ -1236,7 +1242,7 @@ public:
static decltype(auto) StateSpec(const Config &conf) {
int n_action_feats = 10 + conf["max_multi_select"_] * 2;
return MakeDict(
"obs:cards_"_.Bind(Spec<uint8_t>({conf["max_cards"_] * 2, 40})),
"obs:cards_"_.Bind(Spec<uint8_t>({conf["max_cards"_] * 2, 41})),
"obs:global_"_.Bind(Spec<uint8_t>({23})),
"obs:actions_"_.Bind(
Spec<uint8_t>({conf["max_options"_], n_action_feats})),
......@@ -1803,17 +1809,18 @@ private:
f_cards(offset, 8) = race2id.at(c.race_);
f_cards(offset, 9) = c.level_;
f_cards(offset, 10) = std::min(c.counter_, static_cast<uint32_t>(15));
f_cards(offset, 11) = static_cast<uint8_t>((c.status_ & (STATUS_DISABLED | STATUS_FORBIDDEN)) != 0);
auto [atk1, atk2] = float_transform(c.attack_);
f_cards(offset, 11) = atk1;
f_cards(offset, 12) = atk2;
f_cards(offset, 12) = atk1;
f_cards(offset, 13) = atk2;
auto [def1, def2] = float_transform(c.defense_);
f_cards(offset, 13) = def1;
f_cards(offset, 14) = def2;
f_cards(offset, 14) = def1;
f_cards(offset, 15) = def2;
auto type_ids = type_to_ids(c.type_);
for (int j = 0; j < type_ids.size(); ++j) {
f_cards(offset, 15 + j) = type_ids[j];
f_cards(offset, 16 + j) = type_ids[j];
}
}
}
......@@ -2402,8 +2409,8 @@ private:
std::vector<Card> get_cards_in_location(PlayerId player, uint8_t loc) {
int32_t flags = QUERY_CODE | QUERY_POSITION | QUERY_LEVEL | QUERY_RANK |
QUERY_ATTACK | QUERY_DEFENSE | QUERY_EQUIP_CARD |
QUERY_OVERLAY_CARD | QUERY_COUNTERS | QUERY_LSCALE |
QUERY_RSCALE | QUERY_LINK;
QUERY_OVERLAY_CARD | QUERY_COUNTERS | QUERY_STATUS |
QUERY_LSCALE | QUERY_RSCALE | QUERY_LINK;
int32_t bl = YGO_QueryFieldCard(pduel_, player, loc, flags, query_buf_);
qdp_ = 0;
std::vector<Card> cards;
......@@ -2467,6 +2474,7 @@ private:
}
}
c.status_ = q_read_u32();
c.lscale_ = q_read_u32();
c.rscale_ = q_read_u32();
......@@ -2931,7 +2939,43 @@ private:
p->notify(fmt::format("{}: {}", cards[i].get_spec(pl), cards[i].name_));
}
}
} else if (msg_ == MSG_PLAYER_HINT) {
if (!verbose_) {
dp_ = dl_;
return;
}
dp_ += 6;
// TODO: implement output
} else if (msg_ == MSG_CARD_TARGET) {
if (!verbose_) {
dp_ = dl_;
return;
}
auto c1 = read_u8();
auto l1 = read_u8();
auto s1 = read_u8();
read_u8();
auto c2 = read_u8();
auto l2 = read_u8();
auto s2 = read_u8();
read_u8();
Card card1 = get_card(c1, l1, s1);
Card card2 = get_card(c2, l2, s2);
for (PlayerId pl = 0; pl < 2; pl++) {
auto p = players_[pl];
auto spec1 = card1.get_spec(pl);
auto spec2 = card2.get_spec(pl);
auto c1name = card1.name_;
auto c2name = card2.name_;
if ((card1.controler_ != pl) && (card1.position_ & POS_FACEDOWN)) {
c1name = position_to_string(card1.position_) + " card";
}
if ((card2.controler_ != pl) && (card2.position_ & POS_FACEDOWN)) {
c2name = position_to_string(card2.position_) + " card";
}
p->notify(fmt::format(" {} ({}) targets {} ({})", spec1, c1name, spec2, c2name));
}
} else if (msg_ == MSG_CONFIRM_CARDS) {
auto player = read_u8();
auto size = read_u8();
......@@ -3686,7 +3730,7 @@ private:
auto must_select_size = read_u8();
if (mode == 0) {
if (must_select_size != 1) {
if (must_select_size > 2) {
throw std::runtime_error(
" must select size: " + std::to_string(must_select_size) +
" not implemented for MSG_SELECT_SUM");
......@@ -3704,7 +3748,7 @@ private:
must_select_params.reserve(must_select_size);
must_select_specs.reserve(must_select_size);
int expected;
int expected = val;
if (verbose_) {
std::vector<Card> must_select;
must_select.reserve(must_select_size);
......@@ -3717,8 +3761,8 @@ private:
Card card = get_card(controller, loc, seq);
must_select.push_back(card);
must_select_params.push_back(param);
expected -= (param & 0xff);
}
expected = int(val) - (must_select_params[0] & 0xff);
auto pl = players_[player];
pl->notify("Select cards with a total value of " +
std::to_string(expected) + ", seperated by spaces.");
......@@ -3739,8 +3783,8 @@ private:
auto spec = ls_to_spec(loc, seq, 0, controller != player);
must_select_specs.push_back(spec);
must_select_params.push_back(param);
expected -= (param & 0xff);
}
expected = int(val) - (must_select_params[0] & 0xff);
}
uint8_t select_size = read_u8();
......
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