-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
86 lines (55 loc) · 1.75 KB
/
bot.py
File metadata and controls
86 lines (55 loc) · 1.75 KB
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
from client import Client
from server import Server
#dummy_server = Server()
#dummy_server.start()
client = Client()
username = 'admin'
pass_hash = 'admin'
sid = client.login(username, pass_hash)
def get_player_position():
game_map = client.show_map()
for i, row in enumerate(game_map):
for j, col in enumerate(row):
if game_map[i][j] == str(client._sid):
return [j, i] # j is x-pos, i is y-pos
def print_map(game_map):
print '\n'
print '\n'.join([str(row) for row in game_map])
print '\n'
def collect_all_items():
game_map = client.show_map()
for i, row in enumerate(game_map):
for j, col in enumerate(row):
if col != ' ' and col != 'x':
x, y = get_player_position()
move_vect = [j - x, i - y]
client.move(move_vect)
game_map = client.show_map()
print_map(game_map)
def attack_players():
# TODO hardcoded this for now, need to search through
# players's items and find the one with biggest damage
client.equip('staff')
game_map = client.show_map()
for i, row in enumerate(game_map):
for j, col in enumerate(row):
try:
enemy_id = int(col)
except ValueError: # if cast fails
continue
if enemy_id == client._sid:
continue
client.attack(enemy_id)
game_map = client.show_map()
print_map(game_map)
def play_game():
collect_all_resources()
attack_players()
collect_all_items()
print 'BOT: collect all items done'
player_str = client.show_player()
print 'BOT: player ', player_str
attack_players()
print 'BOT: DONE'
#dummy_server.stop()
quit()