forked from wncc/CodeWars-v1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scriptred.py
224 lines (174 loc) · 12.9 KB
/
scriptred.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# from random import randint,choice
# def ActRobot(robot):
# if (robot.investigate_down() == 'enemy-base' or robot.investigate_up() == 'enemy-base' or robot.investigate_right() == 'enemy-base' or robot.investigate_left() == 'enemy-base' or robot.investigate_ne() == 'enemy-base' or robot.investigate_nw() == 'enemy-base' or robot.investigate_se() == 'enemy-base' or robot.investigate_sw() == 'enemy-base'):
# robot.DeployVirus(robot.GetVirus())
# return 0
# if (robot.investigate_down() == 'enemy' or robot.investigate_up() == 'enemy' or robot.investigate_right() == 'enemy' or robot.investigate_left() == 'enemy' or robot.investigate_ne() == 'enemy' or robot.investigate_nw() == 'enemy' or robot.investigate_se() == 'enemy' or robot.investigate_sw() == 'enemy'):
# robot.DeployVirus(800)
# if robot.GetYourSignal() != 'stay' and robot.GetYourSignal() != 'patrol':
# if robot.investigate_up() == 'enemy' or robot.investigate_up() == 'enemy-base':
# return choice([2, 3, 4])
# elif robot.investigate_right() == 'enemy' or robot.investigate_right() == 'enemy-base':
# return choice([1, 3, 4])
# elif robot.investigate_down() == 'enemy' or robot.investigate_down() == 'enemy-base':
# return choice([2, 1, 4])
# elif robot.investigate_left() == 'enemy' or robot.investigate_left() == 'enemy-base':
# return choice([2, 3, 1])
# if robot.GetInitialSignal() == 'patrol':
# if (robot.investigate_down() == 'friend-base' or robot.investigate_up() == 'friend-base' or robot.investigate_right() == 'friend-base' or robot.investigate_left() == 'friend-base' or robot.investigate_ne() == 'friend-base' or robot.investigate_nw() == 'friend-base' or robot.investigate_se() == 'friend-base' or robot.investigate_sw() == 'friend-base'):
# return 0
# elif robot.investigate_up() == 'blank':
# robot.setSignal('stay')
# return 1
# elif robot.investigate_right() == 'blank':
# robot.setSignal('stay')
# return 2
# elif robot.investigate_down() == 'blank':
# robot.setSignal('stay')
# return 3
# elif robot.investigate_left() == 'blank':
# robot.setSignal('stay')
# return 4
# else:
# robot.setSignal('explore')
# return randint(1,4)
# elif robot.investigate_up() == 'wall':
# return choice([2, 3, 4])
# elif robot.investigate_right() == 'wall':
# return choice([1, 3, 4])
# elif robot.investigate_down() == 'wall':
# return choice([2, 1, 4])
# elif robot.investigate_left() == 'wall':
# return choice([2, 3, 1])
# else:
# return randint(1,4)
# def ActBase(base):
# if (base.investigate_down() == 'enemy' or base.investigate_up() == 'enemy' or base.investigate_right() == 'enemy' or base.investigate_left() == 'enemy' or base.investigate_ne() == 'enemy' or base.investigate_nw() == 'enemy' or base.investigate_se() == 'enemy' or base.investigate_sw() == 'enemy') or (base.investigate_down() == 'enemy-base' or base.investigate_up() == 'enemy-base' or base.investigate_right() == 'enemy-base' or base.investigate_left() == 'enemy-base' or base.investigate_ne() == 'enemy-base' or base.investigate_nw() == 'enemy-base' or base.investigate_se() == 'enemy-base' or base.investigate_sw() == 'enemy-base'):
# base.DeployVirus(2400)
# if base.GetElixir() > 1800:
# base.create_robot('patrol')
# elif base.GetElixir() > 700:
# base.create_robot('explore')
# return
# this is a test message to check git.
#damage = ((base.GetTotalElixir() / 26) * 8 + 400) {26 ko variable kaise banau}
from random import randint,choice
def ActRobot(robot):
if (robot.investigate_down() == 'enemy-base' or robot.investigate_up() == 'enemy-base' or robot.investigate_right() == 'enemy-base' or robot.investigate_left() == 'enemy-base' or robot.investigate_ne() == 'enemy-base' or robot.investigate_nw() == 'enemy-base' or robot.investigate_se() == 'enemy-base' or robot.investigate_sw() == 'enemy-base'):
robot.DeployVirus(robot.GetVirus())
t = robot.GetPosition()
if not robot.GetCurrentBaseSignal():
if robot.investigate_up() == 'enemy-base':
robot.setSignal("E:{},{}".format(t[0], t[1]-1))
return 0
elif robot.investigate_right() == 'enemy-base':
robot.setSignal("E:{},{}".format(t[0]+1, t[1]))
return 0
elif robot.investigate_down() == 'enemy-base':
robot.setSignal("E:{},{}".format(t[0], t[1]+1))
return 0
elif robot.investigate_left() == 'enemy-base':
robot.setSignal("E:{},{}".format(t[0]-1, t[1]))
return 0
elif robot.investigate_ne() == 'enemy-base':
robot.setSignal("E:{},{}".format(t[0]+1, t[1]-1))
return 0
elif robot.investigate_nw() == 'enemy-base':
robot.setSignal("E:{},{}".format(t[0]-1, t[1]-1))
return 0
elif robot.investigate_se() == 'enemy-base':
robot.setSignal("E:{},{}".format(t[0]+1, t[1]+1))
return 0
elif robot.investigate_sw() == 'enemy-base':
robot.setSignal("E:{},{}".format(t[0]-1, t[1]+1))
return 0
# return 0
if (robot.investigate_down() == 'enemy' or robot.investigate_up() == 'enemy' or robot.investigate_right() == 'enemy' or robot.investigate_left() == 'enemy' or robot.investigate_ne() == 'enemy' or robot.investigate_nw() == 'enemy' or robot.investigate_se() == 'enemy' or robot.investigate_sw() == 'enemy'):
if robot.GetYourSignal() == 'patrol_up' or robot.GetYourSignal() == 'patrol_right' or robot.GetYourSignal() == 'patrol_down' or robot.GetYourSignal() == 'patrol_left':
robot.DeployVirus( ((robot.GetTotalElixir() / 26) * 8 + 400) )
return 0
if not robot.GetCurrentBaseSignal():
if robot.GetInitialSignal() == 'explore' or robot.GetYourSignal() == 'explore':
robot.DeployVirus( robot.GetVirus() * 0.1)
if robot.investigate_up() == 'enemy':
return choice([2, 3, 4])
elif robot.investigate_right() == 'enemy':
return choice([1, 3, 4])
elif robot.investigate_down() == 'enemy':
return choice([2, 1, 4])
elif robot.investigate_left() == 'enemy':
return choice([2, 3, 1])
if robot.GetCurrentBaseSignal() and (robot.GetInitialSignal() == 'explore' or robot.GetYourSignal() == 'explore'):
ebase_pos = robot.GetCurrentBaseSignal()
e = ebase_pos.split(":")[1].split(",")
enemy_pos = (int(e[0]), int(e[1]))
bot_pos = robot.GetPosition()
if abs(enemy_pos[0] - bot_pos[0]) >= abs(enemy_pos[1] - bot_pos[1]):
if (enemy_pos[0] - bot_pos[0]) > 0:
return 2
elif (enemy_pos[0] - bot_pos[0]) < 0:
return 4
if abs(enemy_pos[0] - bot_pos[0]) < abs(enemy_pos[1] - bot_pos[1]):
if (enemy_pos[1] - bot_pos[1]) > 0:
return 3
elif (enemy_pos[1] - bot_pos[1]) < 0:
return 1
if robot.GetInitialSignal() == 'patrol':
if (robot.investigate_down() == 'friend-base' or robot.investigate_up() == 'friend-base' or robot.investigate_right() == 'friend-base' or robot.investigate_left() == 'friend-base' or robot.investigate_ne() == 'friend-base' or robot.investigate_nw() == 'friend-base' or robot.investigate_se() == 'friend-base' or robot.investigate_sw() == 'friend-base'):
return 0
elif robot.investigate_up() == 'blank':
robot.setSignal('patrol_up')
return 1
elif robot.investigate_right() == 'blank':
robot.setSignal('patrol_right')
return 2
elif robot.investigate_down() == 'blank':
robot.setSignal('patrol_down')
return 3
elif robot.investigate_left() == 'blank':
robot.setSignal('patrol_left')
return 4
else:
robot.setSignal('explore')
return randint(1,4)
elif robot.GetInitialSignal() == 'patrol_up' and robot.GetYourSignal() == '':
robot.setSignal('patrol_up')
return 1
elif robot.GetInitialSignal() == 'patrol_down' and robot.GetYourSignal() == '':
robot.setSignal('patrol_down')
return 3
elif robot.GetInitialSignal() == 'patrol_right' and robot.GetYourSignal() == '':
robot.setSignal('patrol_right')
return 2
elif robot.GetInitialSignal() == 'patrol_left' and robot.GetYourSignal() == '':
robot.setSignal('patrol_left')
return 4
elif robot.GetYourSignal() == 'patrol_up' or robot.GetYourSignal() == 'patrol_right' or robot.GetYourSignal() == 'patrol_down' or robot.GetYourSignal() == 'patrol_left':
return 0
if robot.investigate_up() == 'wall':
return choice([2, 3, 4])
elif robot.investigate_right() == 'wall':
return choice([1, 3, 4])
elif robot.investigate_down() == 'wall':
return choice([2, 1, 4])
elif robot.investigate_left() == 'wall':
return choice([2, 3, 1])
else:
return randint(1,4)
def ActBase(base):
patrol_spots = ['patrol_up', 'patrol_right', 'patrol_down', 'patrol_left']
for i in base.GetListOfSignals():
if i.startswith('E:'):
base.SetYourSignal(i)
if (base.investigate_down() == 'enemy' or base.investigate_up() == 'enemy' or base.investigate_right() == 'enemy' or base.investigate_left() == 'enemy' or base.investigate_ne() == 'enemy' or base.investigate_nw() == 'enemy' or base.investigate_se() == 'enemy' or base.investigate_sw() == 'enemy') or (base.investigate_down() == 'enemy-base' or base.investigate_up() == 'enemy-base' or base.investigate_right() == 'enemy-base' or base.investigate_left() == 'enemy-base' or base.investigate_ne() == 'enemy-base' or base.investigate_nw() == 'enemy-base' or base.investigate_se() == 'enemy-base' or base.investigate_sw() == 'enemy-base'):
base.DeployVirus( ((base.GetTotalElixir() / 26) * 8 + 400) )
# format is -> ( elixir we will be allocated at start ) - ( num of robots we want ) * ( cost of robot= 50 )
if base.GetElixir() > (2000 - 4*50): # we want 4 patrol robots
base.create_robot('patrol')
elif base.GetElixir() > (2000 - 30*50):
for i in patrol_spots:
if i not in base.GetListOfSignals() and base.GetElixir() > (2000 - 30*50): # we can adjust upto 30 - 26 = 4 extra robots
base.create_robot(i)
if base.GetElixir() > (2000 - 26*50):
base.create_robot('explore')
return