-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathMyBot.py
executable file
·57 lines (45 loc) · 1.88 KB
/
MyBot.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
# keep these three import statements
import game_API
import fileinput
import json
# your import statements here
import random
first_line = True # DO NOT REMOVE
# global variables or other functions can go here
stances = ["Rock", "Paper", "Scissors"]
def get_winning_stance(stance):
if stance == "Rock":
return "Paper"
elif stance == "Paper":
return "Scissors"
elif stance == "Scissors":
return "Rock"
# main player script logic
# DO NOT CHANGE BELOW ----------------------------
for line in fileinput.input():
if first_line:
game = game_API.Game(json.loads(line))
first_line = False
continue
game.update(json.loads(line))
# DO NOT CHANGE ABOVE ---------------------------
# code in this block will be executed each turn of the game
me = game.get_self()
if me.location == me.destination: # check if we have moved this turn
# get all living monsters closest to me
monsters = game.nearest_monsters(me.location, 1)
# choose a monster to move to at random
monster_to_move_to = monsters[random.randint(0, len(monsters)-1)]
# get the set of shortest paths to that monster
paths = game.shortest_paths(me.location, monster_to_move_to.location)
destination_node = paths[random.randint(0, len(paths)-1)][0]
else:
destination_node = me.destination
if game.has_monster(me.location):
# if there's a monster at my location, choose the stance that damages that monster
chosen_stance = get_winning_stance(game.get_monster(me.location).stance)
else:
# otherwise, pick a random stance
chosen_stance = stances[random.randint(0, 2)]
# submit your decision for the turn (This function should be called exactly once per turn)
game.submit_decision(destination_node, chosen_stance)