1
1
#!/bin/sh
2
2
# -*- coding: utf-8 -*-
3
+ from __future__ import print_function
3
4
''''which python2 >/dev/null && exec python2 "$0" "$@" # '''
4
5
''''which python >/dev/null && exec python "$0" "$@" # '''
5
6
@@ -95,15 +96,13 @@ def is_area_circle(points, diff_ratio = 0.05):
95
96
top_bottom_diff = corner_points [3 ][1 ] - corner_points [2 ][1 ]
96
97
return abs (top_bottom_diff - left_right_diff ) < (left_right_diff + top_bottom_diff ) * 0.5 * diff_ratio
97
98
98
- iteration = 0
99
99
auto_mode = True
100
100
restart_game_after_fail = False
101
101
show_screen_when_jump = False
102
- train_iterations = 3
103
- iteration_sleep_time = 1.3
102
+ iteration_sleep_time = 2
104
103
step_one_distance = - 1
105
104
step_one_time = - 1
106
- DEBUG = 0
105
+ DEBUG = False
107
106
108
107
if len (sys .argv ) > 1 :
109
108
try :
@@ -114,16 +113,20 @@ def is_area_circle(points, diff_ratio = 0.05):
114
113
115
114
if len (sys .argv ) > 2 :
116
115
try :
117
- restart_game_after_fail = bool (sys .argv [2 ])
116
+ restart_game_after_fail = int (sys .argv [2 ])
118
117
print ("[INFO] Set restart_game_after_fail to " , restart_game_after_fail )
119
118
except :
120
119
pass
121
120
122
121
if cv2 :
123
122
cv2 .namedWindow ("img" )
124
123
124
+ iteration = 0
125
+ bullseye_cnt = 0
126
+ previous_state = ((0 , 0 ), (0 , 0 ))
125
127
def main ():
126
- global iteration , auto_mode , train_iterations , iteration_sleep_time , step_one_distance , step_one_time , DEBUG
128
+ global auto_mode , iteration_sleep_time , step_one_distance , step_one_time , DEBUG , iteration , bullseye_cnt
129
+ global previous_state
127
130
img_filename = "screen.png"
128
131
if not DEBUG :
129
132
jump .screen_capture (img_filename )
@@ -223,7 +226,7 @@ def main():
223
226
first_color = colors [x ][y ]
224
227
break
225
228
else :
226
- if first_color == - 1 and colors [x ][y ] != colors [x ][initial_height ] and sum_of_tuple (arr [x , y ], arr [current_position ]) > 300 and color_sum [colors [x ][y ]] > 100 :
229
+ if first_color == - 1 and colors [x ][y ] != colors [x ][initial_height ] and sum_of_tuple (arr [x , y ], arr [current_position ]) > 60 and color_sum [colors [x ][y ]] > 100 :
227
230
first_color = colors [x ][y ]
228
231
break
229
232
@@ -302,6 +305,11 @@ def main():
302
305
303
306
print ("distance" , distance )
304
307
308
+ if bullseye_color != - 1 :
309
+ bullseye_cnt += 1
310
+ else :
311
+ bullseye_cnt = 0
312
+
305
313
suggestion_time = 0
306
314
307
315
if step_one_distance == - 1 :
@@ -312,10 +320,18 @@ def main():
312
320
#step_one_time = 7.2
313
321
suggestion_time = step_one_time * 1.0 / step_one_distance * distance
314
322
315
- if color_sum [first_color ] > 3000 :
316
- random_diff = (random .random () - 0.5 ) * 1.2
317
- print ("[VERBOSE] random_diff: " , random_diff )
318
- suggestion_time += random_diff
323
+ random_diff = 0
324
+ target_area_size = color_sum [first_color ]
325
+ if target_area_size > 3000 :
326
+ random_diff = (random .random () - 0.5 ) * 0.9
327
+ elif target_area_size <= 3000 and target_area_size > 2000 :
328
+ random_diff = (random .random () - 0.5 ) * 0.3
329
+
330
+ if bullseye_cnt > 4 and target_area_size > 1000 :
331
+ random_diff = random_diff if random_diff > 0.444444 else 0.4444444
332
+
333
+ print ("[VERBOSE] random_diff: " , random_diff )
334
+ suggestion_time += random_diff
319
335
320
336
### : if the direction is right-top, this suggestion time will be a little larger than actually correct value
321
337
if target_position [0 ] > current_position [0 ]: #and suggestion_time > 9:
@@ -338,10 +354,21 @@ def main():
338
354
if not DEBUG :
339
355
#sys_time.sleep(iteration_sleep_time)
340
356
time = jump .jump (time )
341
- sys_time .sleep (iteration_sleep_time )
357
+ sys_time .sleep (iteration_sleep_time + random .random ())
358
+
359
+ if previous_state [0 ] == current_position and previous_state [1 ] == target_position :
360
+ raise Exception ("Same state!" )
361
+ else :
362
+ previous_state = (current_position , target_position )
342
363
343
364
print ("current iteration: " , iteration )
344
365
iteration += 1
366
+ if iteration % 20 == 0 :
367
+ sys_time .sleep (random .random () * 10 )
368
+ if iteration % 50 == 0 :
369
+ sys_time .sleep (random .random () * 100 )
370
+ if iteration % 100 == 0 :
371
+ sys_time .sleep (random .random () * 200 )
345
372
346
373
game_count = 0
347
374
#if __name__ == "__main__":
@@ -351,17 +378,18 @@ def main():
351
378
if DEBUG :
352
379
break
353
380
except Exception as e :
381
+ previous_state = ((0 , 0 ), (0 , 0 ))
354
382
print ("Exception occured in main function: " , e )
355
383
if restart_game_after_fail :
356
384
print ("restaring game" )
357
- sys_time .sleep (7 )
385
+ #sys_time.sleep(7)
386
+ if 2 ** game_count < 60 * 10 :
387
+ sys_time .sleep (2 ** game_count )
388
+ else :
389
+ sys_time .sleep (60 * 10 )
358
390
jump .restart_game ()
359
- sys_time .sleep (7 )
391
+ sys_time .sleep (iteration_sleep_time * 2 )
360
392
game_count += 1
361
393
print ("restared game, game_count: " , game_count )
362
- if 2 ** game_count < 60 :
363
- sys_time .sleep (60 * (2 ** game_count ))
364
- else :
365
- sys_time .sleep (60 * 60 )
366
394
else :
367
395
raise
0 commit comments