forked from aishowdown/chickenAttack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
randomplayer.py
65 lines (47 loc) · 2.36 KB
/
randomplayer.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
import actions
import random
class Player:
#Get passed all the board information that never changes throughout the game.
#It is recommended that you store these in member variables since you will probably need to look at them later.
# PARAMS:
# money_payout_rates:
# This is a 50x50 2D array of floats between 0.0 and 1.0 that tell your bot how money per turn this spot produces
# Food production is the inverse of money production and follow the formula food_payout_rate = 1.0 - money_payout_rate
# This means areas that produce a lot of money, produce less food
# my_spawn_point:
# An (x, y) tuple of where your new chickens will hatch each turn
# their_spawn_point:
# An (x, y) tuple of where your opponent's chickens will hatch each turn
def __init__(self, money_payout_rates, my_spawn_point, their_spawn_point):
self.money_payout_rates = money_payout_rates,
self.my_spawn_point = my_spawn_point
self.their_spawn_point = their_spawn_point
# Gets called each turn and where you decide where your chickens will go
# PARAMS:
# guys:
# A 50x50 2D matrix showing where all the guys are on the board.
# An entry of 'None' indicates an unoccupied spot.
# A space with chickens will be an object with "num_guys" and "is_mine" properties.
#
# my_food:
# A float showing how much food you have left over from last turn.
# their_food:
# A float showing how much food your opponent has left over from last run.
# my_money:
# A float showing how much money you will earn at market so far
# their_money:
# A float showing how much money your opponent will earn at market so far
# RETURN:
# a python dict that takes a tuple ((x_pos, y_pos), direction) as a key and the number of guys to move as the value.
# direction is defined in action.py
def take_turn(self, guys, my_food, their_food, my_money, their_money):
width = len(guys)
height = len(guys[0])
orders = {}
for x in range(width):
for y in range(height):
if not guys[x][y]: continue
num_guys, is_mine = guys[x][y]
if not is_mine: continue
orders[((x, y), random.choice(actions.ALL_ACTIONS))] = num_guys - 1
return orders