-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathghost_vs_ghost.py
89 lines (65 loc) · 2.4 KB
/
ghost_vs_ghost.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
from absl import app
import numpy as np
from Ghost1 import Ghost as Ghost1
from Ghost import Ghost as Ghost2
from Referee import Referee
import random
def main(argv):
# 记录两方胜局数
num_vs = int(argv[1])
num_g1win = 0
num_g2win = 0
for vsIdx in range(num_vs):
referee = Referee()
colorList = [-1, 1]
ghost1_color = colorList[random.randint(0, 1)]
ghost1 = Ghost1(ghost1_color)
ghost2 = Ghost2(-ghost1_color)
print('Ghost1 color:', ghost1_color)
print('Ghost2 color:', -ghost1_color)
num_move = 0
while True:
print('g1win:', num_g1win, ' ', 'g2win:', num_g2win)
print(referee.go)
winner = 0
if -(num_move%2-0.5)*2 == ghost1.color:
print("Ghost1's turn")
action = ghost1.action()
is_legal, takes, winner = referee.action(action)
while not is_legal:
print('Ghost1 try:',action)
action = ghost1.on_legalInfo(is_legal)
is_legal, takes, winner = referee.action(action)
print('action:', action)
if len(takes):
print('Ghost1 takes:\n', takes)
ghost1.on_legalInfo(True)
# 告知双方提子信息
ghost1.on_takeInfo(takes)
ghost2.on_takeInfo(takes)
else:
print("Ghost2's turn")
action = ghost2.action()
is_legal, takes, winner = referee.action(action)
while not is_legal:
print('Ghost2 try:', action)
action = ghost2.on_legalInfo(is_legal)
is_legal, takes, winner = referee.action(action)
print('action:', action)
if len(takes):
print('Ghost2 takes:\n', takes)
ghost2.on_legalInfo(True)
# 告知双方提子信息
ghost2.on_takeInfo(takes)
ghost1.on_takeInfo(takes)
if winner == ghost1_color:
print('Ghost1 wins!')
num_g1win += 1
break
if winner == -ghost1_color:
print('Ghost2 wins!')
num_g2win += 1
break
num_move += 1
if __name__ == '__main__':
app.run(main)