-
Notifications
You must be signed in to change notification settings - Fork 0
/
trainer2.py
executable file
·66 lines (51 loc) · 1.74 KB
/
trainer2.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
#!/usr/bin/env python
# imports
from __future__ import print_function
import urllib2
import json
import sys
# global vars/constants
site = "https://umbelmania.umbel.com/"
endpoint = "training/"
site = site + endpoint
initial_payload = {}
initial_payload["opponent"] = sys.argv[2]
initial_payload["player_name"] = "Bodds by Dodds"
initial_payload["email"] = "[email protected]"
print("### START ###")
print("site:", site)
print("initial_payload: ", json.dumps(initial_payload, indent = 4))
def getTheMotherLoad(json_payload, site):
post = urllib2.Request(site)
post.add_header('Content-Type', 'application/json')
return_payload = urllib2.urlopen(post, json.dumps(json_payload))
if return_payload.msg != "OK":
print("error retrieving motherload using site [%s] json [%s]") % (site, json)
quit(1)
payload_string = ""
for line in return_payload.readlines():
payload_string = payload_string + line
motherload = json.loads(payload_string)
return motherload
def calculateMove(json_payload):
json_payload["move"] = sys.argv[1]
return json_payload
def main():
# initialize game
json_payload = getTheMotherLoad(initial_payload, site)
print("game initialized, json:", json.dumps(json_payload, indent=4))
"""
# make the first move
json_payload = calculateMove(json_payload)
json_payload = getTheMotherLoad(json_payload, site)
print("first move made, json:", json.dumps(json_payload, indent = 4))
"""
# make 1000 moves
for i in range(1, 1001):
json_payload = calculateMove(json_payload)
json_payload = getTheMotherLoad(json_payload, site)
print("move", i, "made, payload:", json_payload)
# exit
quit()
if __name__ == "__main__":
main()