-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase_client_2.py
92 lines (75 loc) · 4.03 KB
/
base_client_2.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import random
from game.client.user_client import UserClient
from game.common.enums import *
from game.utils.vector import Vector
class State(Enum):
MINING = auto()
SELLING = auto()
class Client(UserClient):
# Variables and info you want to save between turns go here
def __init__(self):
super().__init__()
def team_name(self):
"""
Allows the team to set a team name.
:return: Your team name
"""
return 'Unpaid Intern'
def first_turn_init(self, world, mobbot):
"""
This is where you can put setup for things that should happen at the beginning of the first turn
"""
self.company = mobbot.company
self.my_station_type = ObjectType.TURING_STATION if self.company == Company.TURING else ObjectType.CHURCH_STATION
self.current_state = State.MINING
self.base_position = world.get_objects(self.my_station_type)[0][0]
# This is where your AI will decide what to do
def take_turn(self, turn, actions, world, mobbot):
"""
This is where your AI will decide what to do.
:param turn: The current turn of the game.
:param actions: This is the actions object that you will add effort allocations or decrees to.
:param world: Generic world information
"""
if turn == 1:
self.first_turn_init(world, mobbot)
current_tile = world.game_map[mobbot.position.y][mobbot.position.x] # set current tile to the tile that I'm standing on
# If I start the turn on my station, I should...
if current_tile.occupied_by.object_type == self.my_station_type:
# buy Improved Mining tech if I can...
if mobbot.science_points >= mobbot.get_tech_info('Improved Drivetrain').cost and not mobbot.is_researched('Improved Drivetrain'):
return [ActionType.BUY_IMPROVED_DRIVETRAIN]
# otherwise set my state to mining
self.current_state = State.MINING
# If I have at least 5 items in my inventory, set my state to selling
if len([item for item in self.get_my_inventory(world) if item is not None]) >= 5:
self.current_state = State.SELLING
# Make action decision for this turn
if self.current_state == State.SELLING:
# actions = [ActionType.MOVE_LEFT if self.company == Company.TURING else ActionType.MOVE_RIGHT] # If I'm selling, move towards my base
actions = self.generate_moves(mobbot.position, self.base_position, turn % 2 == 0)
else:
if current_tile.occupied_by.object_type == ObjectType.ORE_OCCUPIABLE_STATION:
# If I'm mining and I'm standing on an ore, mine it
actions = [ActionType.MINE]
else:
# If I'm mining and I'm not standing on an ore, move randomly
actions = [random.choice(
[ActionType.MOVE_LEFT, ActionType.MOVE_RIGHT, ActionType.MOVE_UP, ActionType.MOVE_DOWN])]
return actions
def generate_moves(self, start_position, end_position, vertical_first):
"""
This function will generate a path between the start and end position. It does not consider walls and will
try to walk directly to the end position.
:param start_position: Position to start at
:param end_position: Position to get to
:param vertical_first: True if the path should be vertical first, False if the path should be horizontal first
:return: Path represented as a list of ActionType
"""
dx = end_position.x - start_position.x
dy = end_position.y - start_position.y
horizontal = [ActionType.MOVE_LEFT] * -dx if dx < 0 else [ActionType.MOVE_RIGHT] * dx
vertical = [ActionType.MOVE_UP] * -dy if dy < 0 else [ActionType.MOVE_DOWN] * dy
return vertical + horizontal if vertical_first else horizontal + vertical
def get_my_inventory(self, world):
return world.inventory_manager.get_inventory(self.company)