-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewtonwars
executable file
·150 lines (139 loc) · 2.96 KB
/
newtonwars
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
#! /bin/python
import socket
import time
import thread
import sys
import random
try:
import readline
except:
pass #readline not available
angle = 0
velocity = 15
clientRandom = False
def connect(HOST = 'localhost', PORT = 3490):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#bind the socket to a public host,
# and a well-known port
s.connect((HOST, PORT))
return s
def name():
s.sendall('n memo \n')
send()
time.sleep( 1 )
s.sendall('n memo \n')
send()
time.sleep( 1 )
s.sendall('n memo\n')
send()
time.sleep( 1 )
s.sendall('n mem\n')
send()
time.sleep( 1 )
s.sendall('n me\n')
send()
time.sleep( 1 )
s.sendall('n m\n')
send()
time.sleep( 1 )
s.sendall('n \n')
send()
time.sleep( 1 )
s.sendall('n o \n')
send()
time.sleep( 1 )
s.sendall('n mo \n')
send()
time.sleep( 1 )
s.sendall('n emo \n')
send()
time.sleep( 1 )
def send():
s.sendall('v ' + str(velocity)+'\n')
s.sendall(str(angle) + '\n')
def ninput(s):
while True:
ninput = raw_input("> ")
if('v' in ninput):
global velocity
velocity = ninput.split().pop()
elif('c' in ninput):
s.sendall('c\n')
elif('r' in ninput):
global clientRandom
clientRandom = True
print "Random Mode - randomly shooting +-10 around the set angle"
elif('q' in ninput):
global clientRandom
clientRandom = False
print "Random Mode disabled"
elif ninput:
try:
global angle
angle = float(ninput)
except ValueError:
print "not a valid angle"
print angle
def plusOneBot(s, startangle):
s.sendall('n memoBot\n')
print "sending..."
if startangle:
angle = float(startangle)
while True:
angle = angle + 1
s.sendall('v ' + str(velocity) + '\n')
s.sendall(str(angle) + '\n')
time.sleep(5)
def randomBot(s):
s.sendall('n memoBot\n')
print "sending..."
random.seed()
while True:
angle = random.random() * 360
s.sendall('v ' + str(velocity) + '\n')
s.sendall(str(angle) + '\n')
time.sleep(5)
def client(s):
s.sendall('n memo\n')
thread.start_new_thread(ninput,(s,))
while True:
global clientRandom
global angle
if clientRandom == True:
angle = random.random() * 20 - 10 + angle
print "Angle: " + str(angle) + " - Random mode - press q to exit"
send()
name()
if len(sys.argv) == 5:
s = connect(sys.argv[1], int(sys.argv[2]))
if('b' in sys.argv[3]):
plusOneBot(s, sys.argv[4])
elif len(sys.argv) == 4:
if 'b' in sys.argv[2]:
s = connect(sys.argv[1])
plusOneBot(s, sys.argv[3])
elif 'r' in sys.argv[3]:
s = connect(sys.argv[1], int(sys.argv[2]))
randomBot(s)
elif len(sys.argv) == 3:
if 'r' in sys.argv[2]:
s = connect(sys.argv[1])
randomBot(s)
elif 'b' in sys.argv[1]:
s = connect()
plusOneBot(s, sys.argv[2])
else:
s = connect(sys.argv[1], int(sys.argv[2]))
client(s)
elif len(sys.argv) == 2:
if 'r' in sys.argv[1]:
s = connect()
randomBot(s)
else:
s = connect(sys.argv[1])
client(s)
elif len(sys.argv) == 1:
s = connect()
client(s)
else:
print "wrong number of arguments"