Skip to content

Commit 23c899d

Browse files
authoredDec 2, 2020
Add files via upload
1 parent e25942a commit 23c899d

12 files changed

+404
-0
lines changed
 

‎Readme.pdf

2.6 MB
Binary file not shown.

‎ans_time.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import sys, select
2+
#Chosing a default buzzer or answer if answer is not provided within 10 sec
3+
def buzzer(inte):
4+
if(inte == 0):
5+
print "You have ten seconds to press!"
6+
7+
i, o, e = select.select( [sys.stdin], [], [], 10 )
8+
9+
if (i):
10+
return sys.stdin.readline().strip()
11+
else:
12+
return "b"
13+
else:
14+
print "You have ten seconds to answer!"
15+
16+
i, o, e = select.select( [sys.stdin], [], [], 10 )
17+
18+
if (i):
19+
return sys.stdin.readline().strip()
20+
else:
21+
return "5000"

‎answer_check.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#checking if the entered answer is correct
2+
def Ans_check(string,num):
3+
file = open("answers.txt",'r',0)
4+
answer = str(num)+"."+string+"\n"
5+
for s in file:
6+
if num<10:
7+
if(s[0] == str(num)):
8+
if(answer == str(s)):
9+
return 1
10+
else:
11+
return -0.5
12+
13+
else:
14+
if(s[0] == str((num/10)) and s[1] == str((num%10))):
15+
if(answer == str(s)):
16+
return 1
17+
else:
18+
return -0.5

‎answers.txt

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
1.63
2+
2.18
3+
3.12
4+
4.106
5+
5.30
6+
6.20
7+
7.7
8+
8.21
9+
9.12
10+
10.7
11+
11.12
12+
12.13
13+
13.4
14+
14.10
15+
15.8
16+
16.10
17+
17.4
18+
18.28
19+
19.13
20+
20.3
21+
21.1000
22+
22.14
23+
23.13
24+
24.5
25+
25.4
26+
26.11
27+
27.7
28+
28.7
29+
29.2
30+
30.18
31+
31.14
32+
32.1
33+
33.100
34+
34.33
35+
35.10

‎buz_first.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from datetime import datetime
2+
3+
#Finding the time taken to press buzzer
4+
def buz_first(before_time,imp):
5+
#If buzzer is pressed
6+
if(imp == 'a'):
7+
now = datetime.now()
8+
after_time = now.strftime("%S")
9+
bt = int(before_time)
10+
at = int(after_time)
11+
ans = at-bt
12+
if(bt>50 and at<10):
13+
bt = 60-bt
14+
ans = bt+at
15+
if(ans<0):
16+
ans = -ans
17+
return ans
18+
#If buzzer id not pressed returning 30sec as default
19+
else:
20+
return 30

‎client.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import socket
2+
from buz_first import *
3+
from datetime import datetime
4+
from ans_time import *
5+
6+
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
7+
client.connect(('0.0.0.0', 8080))
8+
9+
while True:
10+
from_server = client.recv(4096)
11+
12+
#Game termination when "U Lost" or "U Won" is received
13+
if(from_server[0]=="U"):
14+
break
15+
16+
print from_server
17+
#To calculate the time taken by client to press the buzzer
18+
#Sending the time taken to server
19+
#Server receives time taken from three clients
20+
#and decides upon whom to chose for answering
21+
now = datetime.now()
22+
before_time = now.strftime("%S")
23+
if (type(from_server) == str):
24+
buzz = buzzer(0)
25+
ans_in = buz_first(before_time,buzz)
26+
client.send(str(ans_in))
27+
28+
#Command to type/wait forothers to type in the answer
29+
from_server = client.recv(4096)
30+
print from_server
31+
32+
#If the command is to "Type the answer"
33+
#Then sending the answer
34+
if (from_server[0]=='T'):
35+
answer = buzzer(1)
36+
client.send(answer)
37+
38+
client.close()
39+
print from_server

‎client2.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import socket
2+
from buz_first import *
3+
from datetime import datetime
4+
from ans_time import *
5+
6+
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
7+
client.connect(('0.0.0.0', 8080))
8+
9+
while True:
10+
from_server = client.recv(4096)
11+
12+
#Game termination when "U Lost" or "U Won" is received
13+
if(from_server[0] == "U"):
14+
break
15+
16+
print from_server
17+
#To calculate the time taken by client to press the buzzer
18+
#Sending the time taken to server
19+
#Server receives time taken from three clients
20+
#and decides upon whom to chose for answering
21+
now = datetime.now()
22+
before_time = now.strftime("%S")
23+
if (type(from_server) == str):
24+
buzz = buzzer(0)
25+
ans_in = buz_first(before_time,buzz)
26+
client.send(str(ans_in))
27+
28+
#Command to type/wait forothers to type in the answer
29+
from_server = client.recv(4096)
30+
print from_server
31+
32+
#If the command is to "Type the answer"
33+
#Then sending the answer
34+
if (from_server[0]=='T'):
35+
answer = buzzer(1)
36+
client.send(answer)
37+
38+
client.close()
39+
print from_server
40+

‎client3.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import socket
2+
from buz_first import *
3+
from datetime import datetime
4+
from ans_time import *
5+
6+
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
7+
client.connect(('0.0.0.0', 8080))
8+
9+
while True:
10+
from_server = client.recv(4096)
11+
12+
#Game termination when "U Lost" or "U Won" is received
13+
if(from_server[0]=="U"):
14+
break
15+
16+
print from_server
17+
#To calculate the time taken by client to press the buzzer
18+
#Sending the time taken to server
19+
#Server receives time taken from three clients
20+
#and decides upon whom to chose for answering
21+
now = datetime.now()
22+
before_time = now.strftime("%S")
23+
if (type(from_server) == str):
24+
buzz = buzzer(0)
25+
ans_in = buz_first(before_time,buzz)
26+
client.send(str(ans_in))
27+
28+
#Command to type/wait forothers to type in the answer
29+
from_server = client.recv(4096)#to keep the connection alive
30+
print from_server
31+
32+
#If the command is to "Type the answer"
33+
#Then sending the answer
34+
if (from_server[0]=='T'):
35+
answer = buzzer(1)
36+
client.send(answer)
37+
38+
client.close()
39+
print from_server
40+
41+

‎over.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#Game termination and Winner declearation
2+
def win(score1,score2,score3):
3+
if score1 >= 5:
4+
return 1
5+
elif score2 >= 5:
6+
return 2
7+
elif score3 >= 5:
8+
return 3
9+
elif score1 <= -5 and score2 <= -5 and score3<= -5:
10+
return -1
11+
else:
12+
return 0

‎question.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import socket
2+
import random
3+
4+
#Chosing a random question from "questions.txt" and sending it to clients
5+
questions = 0
6+
max = 35
7+
l = []
8+
Asked = []
9+
for i in range (max):
10+
l.append(i+1)
11+
12+
def question():
13+
file = open("questions.txt",'r',0)
14+
global questions
15+
global l
16+
global Asked
17+
k = random.choice(l)
18+
Asked.append(k)
19+
l.remove(k)#to avoid repetition for questions
20+
for s in file:
21+
if k<10:
22+
if(s[0] == str(k)):
23+
questions += 1
24+
return str(s)
25+
26+
else:
27+
if(s[0] == str((k/10)) and s[1] == str((k%10))):
28+
questions += 1
29+
return str(s)
30+

‎questions.txt

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
1. How many Nayanars existed according to Shaivism?
2+
2. For how many days was the battle Kurukshetra fought?
3+
3. How many Alvars existed as per Vaishnavism?
4+
4. How many Divya desams exist on earth as per to Vaishnavism?
5+
5. How many pasurams are there in Thiruppavai?
6+
6. How many pasurams are there in Thiruvempavai?
7+
7. How many horses are there in Lord Surya's chariot?
8+
8. How many times did Parashurama go around the world to defeat king?
9+
9. How many jyotirlingas are there?
10+
10. How many oceans are there according to Hindu Mythology?
11+
11. For how many years did Janamejaya’s Sarpa-satra last?
12+
12. How many wives did sage Kashyapa have?
13+
13. How many times is Navarathri celebrated in an year?
14+
14. How many Heads did Ravana have?
15+
15. How many immortals in hinduism?
16+
16. How many major avatars of Vishnu?
17+
17. How many vedas in hinduism?
18+
18. For how many days did Shri Krishna and Jambavan fight?
19+
19. For how long did Rama and Ravana fight?
20+
20. How many heads does Dattatreya have?
21+
21. How many hands does Karthaveeryarjuna have?
22+
22. How many years did rama's vanvas last?
23+
23. For how many days did Abhimanyu fight in Kurukshetra?
24+
24. How many sons did Draupadi have?
25+
25. How many yugas, according to Indian Mythology?
26+
26. How many Akshauhinis did the Kauravas have before the battle of Kurukshetra?
27+
27. For how many days did Krishna uphold Mount Govardhan on his finger?
28+
28. How old was Krishna when he held aloft the Govardhan Mountain?
29+
29. How many children did Nala and Damayanthi have?
30+
30. How many Puranas are there according to Hindu Mythology?
31+
31. How many worlds are there according to Hindu Mythology?
32+
32. How many chakras are there in Lord Surya's chariot?
33+
33. A Mahakalpa consists of ___ years of Brahma?
34+
34. How many crores of deities exist in hinduism?
35+
35. How many daivika apsaras are there?

‎server.py

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import socket
2+
from over import *
3+
from question import *
4+
import time
5+
from answer_check import *
6+
7+
serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
8+
serv.bind(('0.0.0.0', 8080))
9+
serv.listen(5)
10+
game_on = True
11+
winner = 0
12+
score1 = score2 = score3 = 0
13+
14+
15+
while game_on:#this while loop keeps the connection alive
16+
if winner!= 0:#Stop the connection when winner is decleared
17+
break
18+
conn1, addr1 = serv.accept()
19+
conn2, addr2 = serv.accept()
20+
conn3, addr3 = serv.accept()
21+
print "All connected"
22+
while game_on:
23+
winner = win(score1,score2,score3)
24+
print len(Asked), " - No.of.questions Asked"
25+
26+
#Game Termination
27+
if winner != 0:#Stop the game when winner is decleared
28+
break
29+
if len(Asked) == 35:#If all the questions are asked stop game
30+
game_on = False
31+
break
32+
33+
q = question()#Taking question
34+
print "Took Question",q
35+
36+
buz = q + "\nTo Answer - Press 'a'\nTo Skip - Press 'b'\n"
37+
conn1.send(buz)
38+
conn2.send(buz)
39+
conn3.send(buz)
40+
41+
#Time taken to press the Buzzer
42+
print ("I am at receiving data1")
43+
data1 = conn1.recv(40)
44+
print ("I am at receiving data2")
45+
data2 = conn2.recv(40)
46+
print ("I am at receiving data3")
47+
data3 = conn3.recv(40)
48+
49+
print int(data1),"Time client1"
50+
print int(data2),"Time client2"
51+
print int(data3),"Time client3"
52+
53+
54+
#Taking answer from client which Pressed the buzzer first
55+
if(int(data1)<int(data2) and int(data1)<int(data3) and int(data1)<=10):
56+
conn1.send("Type in the answer")
57+
conn2.send("Please wait")
58+
conn3.send("Please wait")
59+
print Asked[questions-1],"q"
60+
answer = conn1.recv(40)
61+
print answer
62+
score1 = score1+Ans_check(answer,Asked[questions-1])
63+
print score1,"score1 ",score2,"score2 ",score3,"score3 "
64+
elif(int(data2)<int(data1) and int(data2)<int(data3) and int(data2)<=10):
65+
conn2.send("Type in the answer")
66+
conn1.send("Please wait")
67+
conn3.send("Please wait")
68+
answer = conn2.recv(40)
69+
print Asked[questions-1],"q"
70+
print answer
71+
score2 = score2+Ans_check(answer,Asked[questions-1])
72+
print score1,"score1 ",score2,"score2 ",score3,"socre3 "
73+
elif(int(data3)<int(data2) and int(data1)>int(data3) and int(data3)<=10):
74+
conn3.send("Type in the answer")
75+
conn2.send("Please wait")
76+
conn1.send("Please wait")
77+
answer = conn3.recv(40)
78+
print Asked[questions-1],"q"
79+
print answer
80+
score3 = score3+Ans_check(answer,Asked[questions-1])
81+
print score1,"score1 ",score2,"score2 ",score3,"socre3 "
82+
else:#skip the question if no one presses the buzzer
83+
msg = "Moving to next question"
84+
print(msg)
85+
conn3.send(msg)
86+
conn2.send(msg)
87+
conn1.send(msg)
88+
89+
90+
91+
92+
93+
#Result Declearation
94+
if winner == -1 or len(Asked) == 21:
95+
conn1.send("U lost")
96+
conn2.send("U lost")
97+
conn3.send("U lost")
98+
elif winner == 1:
99+
conn1.send("U Won")
100+
conn2.send("U lost")
101+
conn3.send("U lost")
102+
elif winner == 2:
103+
conn1.send("U lost")
104+
conn2.send("U Won")
105+
conn3.send("U lost")
106+
elif winner == 3:
107+
conn1.send("U lost")
108+
conn2.send("U lost")
109+
conn3.send("U Won")
110+
111+
112+
113+

0 commit comments

Comments
 (0)
Please sign in to comment.