This repository has been archived by the owner on May 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathirctest.py
97 lines (78 loc) · 2.16 KB
/
irctest.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
import miniirc_extras
import miniirc
import random
import time
from typing import List, Tuple
irc = None
code = ""
actions: List[int] = [0]
prevsend = 0
start_poss = None
fruit = None
def init(codee: int = None):
nick = str(random.randint(100000, 100000000))
if codee is None:
codee = "#" + str(random.randint(1000000, 100000000))
else:
codee = "#" + str(codee)
global code, irc
code = codee
irc = miniirc.IRC(
"a.linode.servers.malhotra.cc", 29615, nick, [code], auto_connect=False
)
irc.require("users")
irc.connect()
return irc
def twoppl() -> bool:
return len(irc.users._users) == 2
def senddir(i: int):
global prevsend
if i != prevsend:
irc.msg(code, "dir " + str(i))
prevsend = i
def start_pos() -> Tuple[int,int,int,int]:
global start_poss
if start_poss is None:
irc.msg(code, "getstart")
while start_poss is None:
time.sleep(0.01)
return tuple(start_poss[2:] + start_poss[:2])
def set_start_pos(a:int, b:int, c:int, d:int):
print("HI")
global start_poss
start_poss = (a, b, c, d)
def send_start_pos():
irc.msg(code, "start " + " ".join([str(i) for i in start_poss + spawn_fruit()]))
def spawn_fruit():
global fruit
while fruit is None:
time.sleep(0.01)
print("WAITING FOR FRUIT")
print("GOTFRUIT")
return fruit
def set_fruit(a,b):
global fruit
irc.msg(code, "fruit " + str(a) + " " + str(b))
fruit = (a,b)
if __name__ == "__main__":
init(123)
while not twoppl():
time.sleep(0.1)
print("other person joined")
while True:
print(actions[-1])
@miniirc.Handler("PRIVMSG", colon=False)
def handler(irc: miniirc.IRC, hostmask: tuple, args):
global fruit, start_poss
args = args[1].split(" ")
if args[0] == "fruit":
fruit = (int(args[1]), int(args[2]))
elif args[0] == "getstart":
send_start_pos()
elif args[0] == "start":
start_poss = tuple([int(args[i]) for i in (1, 2, 3, 4)])
fruit = (int(args[5]), int(args[6]))
elif args[0] == "dir":
actions.append(int(args[1]))
else:
print("unknown action")