This repository has been archived by the owner on Jun 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathts19tattack.py
130 lines (121 loc) · 3.89 KB
/
ts19tattack.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
import os
import subprocess
import sys
from time import sleep
path=r'./player'
ls=os.listdir(path)
total_num=len(ls)
vs_time=[]
id_score=[]
for i in range(0,total_num):
vs_time.append([])
id_score.append(0)
for j in range(0,total_num):
vs_time[i].append(0)
#print(ls)
l=len(ls)
for i in range(0,l):
for j in range(i+1,l):
echo=' echo foo> /dev/null 2>&1'
ls1='./player/'+ls[i]+echo
ls2='./player/'+ls[j]+echo
cm1='mkdir '+ls[i]+'_'+ls[j]
subprocess.call(cm1,shell=True)
print(ls1,ls2)
for count in range(0,4):
ser=subprocess.Popen('python3 main.py echo foo> /dev/null 2>&1',shell=True)
sleep(2)
if count<2:
pl1=subprocess.Popen(ls1,shell=True)
sleep(1)
while True:
try:
with open('connection','r') as f:
a=f.read()
if a=='1':
with open('connection','w') as f:
f.write('0')
break
else:
sleep(1)
except :
sleep(1)
pl2=subprocess.Popen(ls2,shell=True)
r='player0:'+ls[i]+' player1:'+ls[j]+' winner:'
else :
pl2=subprocess.Popen(ls2,shell=True)
sleep(1)
while True:
try:
with open('connection','r') as f:
a=f.read()
if a=='1':
with open('connection','w') as f:
f.write('0')
break
else:
sleep(1)
except :
sleep(1)
pl1=subprocess.Popen(ls1,shell=True)
r='player0:'+ls[j]+' player1:'+ls[i]+' winner:'
while ser.poll()==None:
sleep(2)
pl1.kill()
pl2.kill()
kl1='kill '+str(pl1.pid)
kl2='kill '+str(pl2.pid)
subprocess.call(kl1,shell=True)
subprocess.call(kl2,shell=True)
with open('this_path','r') as f:
save_path=f.read()
cm="mv "+save_path+" ./"+ls[i]+'_'+ls[j]+'/'+save_path+'_'
if count<2:
cm=cm+ls[i]+'_'+ls[j]+'.zip'
else:
cm=cm+ls[j]+'_'+ls[i]+'.zip'
subprocess.call(cm,shell=True)
sleep(1)
res=None
with open('temp_result','r') as f:
res=f.read()
r=r+res+'\n'
res=int(res)
with open('result','a') as f:
f.write(r)
if count==3:
f.write('\n')
if count<2:
vs_time[i][j]+=1
else:
vs_time[j][i]+=1
if count<2:
if res==0:
id_score[i]+=2
elif res==1:
id_score[j]+=2
else:
id_score[j]+=1
id_score[i]+=1
else :
if res==0:
id_score[j]+=2
elif res==1:
id_score[i]+=2
else:
id_score[i]+=1
id_score[j]+=1
with open('final_socre','w') as f:
for i in range(0,total_num):
tes='team: '+ls[i]+' score:'+str(id_score[i])+'\n'
f.write(tes)
with open('total_com','w') as f:
for i in range(0,total_num):
f.write(ls[i])
f.write(' ')
f.write('\n')
for i in range(0,total_num):
for j in range(0,total_num):
f.write(str(vs_time[i][j]))
f.write(' ')
f.write('\n')