-
Notifications
You must be signed in to change notification settings - Fork 0
/
bare_minimum.py
executable file
·78 lines (67 loc) · 2.62 KB
/
bare_minimum.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
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/python3
"""
Date: 2020-11-15
Author: Boyd Kane: https://github.com/beyarkay
This is the bare-minimum bot for the Genghis Bot Battle System. (https://github.com/beyarkay/genghis_client)
Use this script as a starting point from which to build your own bot.
"""
import json
import pickle
import os
import sys
import random
def main(root_dir, bot_icon, bg_port_icon):
sys.path.append(root_dir)
import util
move_dict = {
"action": "",
"direction": ""
}
# Go through each motion type. If that motion type can't be completed, move on to the next motion type.
# Read in the Game object from game.pickle
with open(root_dir + "/game.pickle", "rb") as gamefile:
game = pickle.load(gamefile)
# Figure out which bot in the Game object represents this script
this_bot = None
for game_bot in game.bots:
if game_bot.bot_icon == bot_icon:
this_bot = game_bot
break
# Figure out which battleground in the Game the bot is on
this_battleground = None
for bg in game.battlegrounds:
if bg.port_icon == bg_port_icon:
this_battleground = bg
break
bot_x, bot_y = this_battleground.find_icon(this_bot.bot_icon)[0]
# TODO: YOUR BOT LOGIC GOES HERE, AND PUTS YOUR MOVE INTO THE DICTIONARY 'move_dict'
with open(root_dir + "/move.json", "w+") as movefile:
json.dump(move_dict, movefile)
def get_dist(here, there):
"""
A helper method to get the distance between two points
here: a 2-element list (or tuple) containing the x,y coordinates of the first location
there: a 2-element list (or tuple) containing the x,y coordinates of the second location
returns: a number that is the distance between here and there
"""
delta_x = abs(there[0] - here[0])
delta_y = abs(there[1] - here[1])
return max(delta_x, delta_y)
def get_direction(here, there):
"""
A helper method to get the Genghis-compatible direction string from one point to the other
here: a 2-element list (or tuple) containing the x,y coordinates of the first location
there: a 2-element list (or tuple) containing the x,y coordinates of the second location
returns: a string that can be passed to the Genghis 'move_dict' in order to walk/attack/etc
in the direction of 'there'
"""
delta_x = min(1, max(-1, there[0] - here[0]))
delta_y = min(1, max(-1, there[1] - here[1]))
move_array = [
['lu', 'u', 'ru'],
['l', '', 'r'],
['ld', 'd', 'rd']
]
return move_array[delta_y + 1][delta_x + 1]
if __name__ == '__main__':
main(sys.argv[1], sys.argv[2], sys.argv[3])