-
Notifications
You must be signed in to change notification settings - Fork 0
/
player_ai_1.py
executable file
·68 lines (51 loc) · 1.67 KB
/
player_ai_1.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
#!/usr/bin/env python3
import requests
import lib.board as board
email = "[email protected]"
session = requests.session()
request_url_base = "http://rota.praetorian.com/rota/service/play.php"
if __name__ == "__main__":
counter = 0
b = board.GAME_BOARD(email, session, request_url_base)
try:
# place
for turn in range(1, 4, 1):
# show current board
b.printBoard()
# init
location = 0
# choose a valid location to place
els = b.getEmptyLocations()
location = els[0]
# apply action
b.placeAt(location)
# check if game is finished
if b.isFinished():
raise Exception("Game set. Winner is {0}.".format(b.getWinner()))
# move
while True:
# init
src = 0
dst = 0
# choose a piece and a valid location to move
pls = b.getPlayerLocations()
for pl in pls:
# src location
src = pl
# check our neighbors
nls = b.getNeighborLocations(pl)
for nl in nls:
if b.checkLocation(nl) == "-":
dst = nl
break
# if we get both src and dst
if src and dst:
break
# apply action
b.moveFromTo(src, dst)
# check if game is finished
if b.isFinished():
raise Exception("Game set. Winner is {0}.".format(b.getWinner()))
except Exception as e:
b.printBoard()
print(e)