-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtcg.py
130 lines (119 loc) · 3.5 KB
/
tcg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from gitcg import (
Deck, Player, Game, CreateParam, GameStatus
)
from ai import HeuristicPlayer, LLMPlayer, LMPlayer, LMTrainer
# 星柚
# AZFy20EQAUHC9UUQFVFB94QQCWJhBo8RClJxB5gRFGICCTEUDLLxi8AZDaJRDMYRDcEB
example_deck = {
"characters": [
1107,
1507,
1204
],
"cards": [
215071,
215071,
311206,
311303,
311406,
312004,
312004,
312018,
312018,
321013,
321013,
322004,
322004,
322008,
330001,
332004,
332004,
332005,
332006,
332006,
332021,
332021,
332022,
332022,
332024,
332025,
332032,
332032,
333003,
333004
]
}
DECK0 = Deck(characters=example_deck["characters"], cards=example_deck["cards"])
DECK1 = Deck(characters=example_deck["characters"], cards=example_deck["cards"])
LMTRAINER = LMTrainer()
def play_game_heuristic_train():
game = Game(create_param=CreateParam(deck0=DECK0, deck1=DECK1))
heuristic_id = 0
llm_id = 1
game.set_player(heuristic_id, HeuristicPlayer(heuristic_id))
game.set_player(llm_id, LMPlayer(llm_id, LMTRAINER))
game.start()
while game.is_running():
game.step()
if game.status() == GameStatus.FINISHED:
print("game over")
print("winner is player", game.winner(), "LLMPlayer" if game.winner() == llm_id else "HeuristicPlayer" if game.winner() == heuristic_id else "draw")
return game.winner()
else:
print("game aborted")
print("game status:", game.status())
print("error message:", game.error())
return -1
def play_game_eval():
LMTRAINER.train = False
game = Game(create_param=CreateParam(deck0=DECK0, deck1=DECK1))
heuristic_id = 0
llm_id = 1
game.set_player(heuristic_id, HeuristicPlayer(heuristic_id))
game.set_player(llm_id, LMPlayer(llm_id, LMTRAINER))
game.start()
while game.is_running():
game.step()
if game.status() == GameStatus.FINISHED:
print("game over")
print("winner is player", game.winner(), "LLMPlayer" if game.winner() == llm_id else "HeuristicPlayer" if game.winner() == heuristic_id else "draw")
LMTRAINER.train = True
return game.winner()
else:
print("game aborted")
print("game status:", game.status())
print("error message:", game.error())
LMTRAINER.train = True
return -1
def play_game():
game = Game(create_param=CreateParam(deck0=DECK0, deck1=DECK1))
heuristic_id = 0
llm_id = 1
# game.set_player(heuristic_id, HeuristicPlayer(heuristic_id))
game.set_player(heuristic_id, LMPlayer(heuristic_id, LMTRAINER))
game.set_player(llm_id, LMPlayer(llm_id, LMTRAINER))
game.start()
while game.is_running():
game.step()
if game.status() == GameStatus.FINISHED:
print("game over")
print("LLMPlayer winner is player", game.winner())
return game.winner()
else:
print("game aborted")
print("game status:", game.status())
print("error message:", game.error())
return -1
if __name__ == "__main__":
play_result = []
eval_result = []
LMTRAINER.start()
for k in range(5):
for _ in range(5):
if LMTRAINER.want_to_stop():
break
play_result.append(play_game())
eval_result.append(play_game_eval())
LMTRAINER.stop()
print(play_result)
print(eval_result)