-
Notifications
You must be signed in to change notification settings - Fork 2
/
bot1.py
63 lines (55 loc) · 1.71 KB
/
bot1.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
from MINER_STATE import State
import numpy as np
class PlayerInfo:
def __init__(self, id):
self.playerId = id
self.score = 0
self.energy = 0
self.posx = 0
self.posy = 0
self.lastAction = -1
self.status = 0
self.freeCount = 0
class Bot1:
ACTION_GO_LEFT = 0
ACTION_GO_RIGHT = 1
ACTION_GO_UP = 2
ACTION_GO_DOWN = 3
ACTION_FREE = 4
ACTION_CRAFT = 5
def __init__(self, id):
self.state = State()
self.info = PlayerInfo(id)
def next_action(self):
if self.state.mapInfo.gold_amount(self.info.posx, self.info.posy) > 0:
if self.info.energy >= 6:
return self.ACTION_CRAFT
else:
return self.ACTION_FREE
if self.info.energy < 5:
return self.ACTION_FREE
else:
action = self.ACTION_GO_UP
if self.info.posy % 2 == 0:
if self.info.posx < self.state.mapInfo.max_x:
action = self.ACTION_GO_RIGHT
else:
if self.info.posx > 0:
action = self.ACTION_GO_LEFT
else:
action = self.ACTION_GO_DOWN
return action
def new_game(self, data):
try:
self.state.init_state(data)
except Exception as e:
import traceback
traceback.print_exc()
def new_state(self, data):
# action = self.next_action();
# self.socket.send(action)
try:
self.state.update_state(data)
except Exception as e:
import traceback
traceback.print_exc()