-
Notifications
You must be signed in to change notification settings - Fork 4
/
bot.py
executable file
·82 lines (61 loc) · 1.94 KB
/
bot.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from sys import argv, exit as sys_exit, path
from os import _exit as os_exit
path.append('lib')
from clientside.gameclient import GameClient
from share.mathlib import *
from share.ask_hostname import ask_hostname
from config import *
from time import sleep, time
from threading import Thread
from multiprocessing import Process, Event
from engine.mathlib import chance
from random import randrange
class Bot(GameClient, Process):
def __init__(self, hostname, running):
GameClient.__init__(self, self, hostname)
Process.__init__(self)
self.running = running
self.shift = Point(0,0)
self.antilag_init = lambda *args: args
def run(self):
d = 1
t = time()
while not self.running.is_set():
if not self.accepted:
self.accept()
else:
sleep(ROUND_TIMER)
self.update()
self.in_messages = []
if time()-t>1:
d*=-1
x = randrange(-500, 500)
y = randrange(-500, 500)
if d>0:
self.send_move(Point(x,y))
else:
self.send_ball(Point(x,y))
if chance(10):
self.send_skill()
if chance(10):
self.send_apply_item(randrange(8))
t = time()
def on_close(self, a=''):
self.running.set()
print 'close'
sys_exit()
os_exit()
def main():
if len(argv)==2:
n = int(argv[1])
else:
n = int(argv[2])
hostname = ask_hostname(HOSTNAME)
running = Event()
bots = [Bot(hostname, running = running) for i in range(n)]
[bot.start() for bot in bots]
[bot.join() for bot in bots]
if __name__=='__main__':
main()