-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
64 lines (61 loc) · 2.33 KB
/
test.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
import json, prismataengine as p, random
from pprint import pprint
import numpy
import timeit, time
class PythonRandomPlayer(object):
def getAction(self, gamestate):
state = gamestate.toVector()
actions = gamestate.getAbstractActions()
# print(gamestate.getAbstractActionsVector())
# print(actions)
# print([action.json() for action in gamestate._actions])
# print([str(p.ConcreteAction(gamestate, action)) for action in gamestate._actions])
action = random.choice(actions)
return action
def runGame():
if __debug__:
print('----------------NO GAME NO LIFE-------------')
gamestate = p.GameState('''{
"whiteMana":"0HH",
"blackMana":"0HH",
"phase":"action",
"table":
[
{"cardName":"Drone", "color":0, "amount":6},
{"cardName":"Engineer", "color":0, "amount":2},
{"cardName":"Drone", "color":1, "amount":7},
{"cardName":"Engineer", "color":1, "amount":2}
],
"cards":["Drone","Engineer","Blastforge","Steelsplitter"]
}''', cards=4, player1=PythonRandomPlayer(), player2="EasyAI")
if __debug__:
print('----------------NEW GAME NEW LIFE-------------')
lastPlayer = 0
i = 0
while not gamestate.isGameOver():
print(type(gamestate))
print([(card.type, card.name) for card in gamestate.getLiveCards(gamestate.activePlayer)])
state = gamestate.toVector()
print(state)
print(gamestate.annotate(state))
if gamestate.activePlayer != lastPlayer:
lastPlayer = gamestate.activePlayer
pprint(gamestate.annotate(state))
print(numpy.array_str(state, max_line_width=120))
print(gamestate.json())
time.sleep(0.1)
gamestate.step()
i += 1
if i > 10000:
break
print(f"Winner: {gamestate.winner()}")
# state = gamestate.toVector()
if __debug__:
pprint(gamestate.annotate(state))
# pprint(gamestate.json())
# print(numpy.array_str(state, max_line_width=120))
n = 100
# for n in range(n):
# runGame()
time = timeit.timeit(runGame, setup='gc.enable()', number=n)
print(f"n = {n}, wall time = {time} ({1/time*n} Hz)")