This repository has been archived by the owner on May 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webapp.py
187 lines (162 loc) · 5.75 KB
/
webapp.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#import of the needed libraries
from flask import Flask, request, render_template, url_for, redirect
import csv
import lib
app = Flask(__name__)
winnumber = 0
simwinnumber = 0
win = 'Verloren'
prize = 0
simprize = 0
@app.route('/')
def start():
return render_template('startscreen.html')
@app.route('/willkommen')
def welcome():
return render_template('screen1.html')
@app.route('/kooperation')
def kooperation():
return render_template('screen2a.html')
@app.route('/nichtkooperation')
def nichtkooperation():
return render_template('screen2b.html')
@app.route('/result')
def result():
global win
showwin = win
win = 'Verloren'
global prize
showprize = prize
prize = 0
return render_template('screen3.html', winnumber=str(winnumber), win=str(showwin), prize=str(round(showprize)))
@app.route('/simulation')
def simulation():
return render_template('simulation1.html')
@app.route('/end')
def ending():
return render_template('simulation2.html')
@app.route('/', methods=['POST'])
def startpost():
if request.form['submit'] == 'Experiment':
return redirect(url_for("welcome"))
elif request.form['submit'] == 'Simulation':
return redirect(url_for("simulation"))
else:
return redirect(url_for('welcome'))
@app.route('/willkommen', methods=['POST'])
def welcomepost():
if request.form['submit'] == 'Kooperieren':
return redirect(url_for("kooperation"))
elif request.form['submit'] == 'Nicht Kooperieren':
return redirect(url_for("nichtkooperation"))
else:
return redirect(url_for('result'))
@app.route('/kooperation', methods=['POST'])
def kooperationpost():
amount = int(request.form['text'])
print('Kooperierende:' + str(amount))
guesslist = lib.addownguess(lib.playersguess(9 - amount), 0)
for i in range(amount):
guesslist[len(guesslist):] = [0]
print('Rateliste')
print(guesslist)
global winnumber
winnumber = lib.findwinnumber(guesslist)
print(winnumber)
closeguess = lib.closestguess(guesses=guesslist, winnumber=winnumber)
print(closeguess)
if 9 in closeguess or len(closeguess) == 10:
global win
win = 'Gewonnen'
print('Du hast ' + win)
global prize
prize = lib.calculateprize(closeguess)
return redirect(url_for('result'))
@app.route('/nichtkooperation', methods=['POST'])
def nichtkooperationpost():
guess = int(request.form['text'])
print('Eingabe: ' + str(guess))
guesslist = lib.addownguess(lib.playersguess(9), guess)
print('Ratelist: ')
print(guesslist)
global winnumber
winnumber = lib.findwinnumber(guesslist)
print('Gewinnzahl:' + str(winnumber))
if 10 in lib.closestguess(guesses=guesslist, winnumber=winnumber):
global win
win = 'Gewonnen'
print(win)
global prize
prize = lib.calculateprize(lib.closestguess(guesses=guess, winnumber=winnumber))
return redirect(url_for('result'))
@app.route('/result', methods=['POST'])
def resultpost():
name = request.form['name']
geschlecht = request.form['sex']
alter = request.form['age']
kursnummer = request.form['classnumber']
kenntnis = request.form['knowledge']
kooperiert = request.form['cooperation']
anzahl = request.form['amount']
zahl = request.form['number']
grund = request.form['reason']
print('Name: ' + str(name))
print('Geschecht: ' + str(geschlecht))
print('Alter: ' + str(alter))
print('Kursnummer: ' + str(kursnummer))
print('Kenntnis: ' + str(kenntnis))
print('Kooperiert: ' + str(kooperiert))
print('Anzahl: ' + str(anzahl))
print('Zahl: ' + str(zahl))
print('Grund: ' + str(grund))
return redirect(url_for('start'))
@app.route('/simulation', methods=['POST'])
def end():
repitition = int(request.form["repitition"])
playeramount = int(request.form["playeramount"])
knowingplayeramount = int(request.form["knowingplayeramount"])
prizelist = []
amount = knowingplayeramount - 1
for i in range(repitition):
print('Kooperierende:' + str(amount))
guesslist = lib.addownguess(lib.playersguess(9 - amount), 0)
for i in range(amount):
guesslist[len(guesslist):] = [0]
print('Rateliste')
print(guesslist)
global simwinnumber
simwinnumber = lib.findwinnumber(guesslist)
print(simwinnumber)
closeguess = lib.closestguess(guesses=guesslist, winnumber=simwinnumber)
print(closeguess)
global simprize
if 9 in closeguess or len(closeguess) == 10:
simprize = lib.calculateprize(closeguess)
else:
simprize = 0
print(simprize)
prizelist[len(prizelist):] = [simprize]
summe = sum(prizelist)
averagewin = summe / repitition
print(averagewin)
# distribution = lib.playersguess(playeramount - knowingplayeramount)
# for i in range(knowingplayeramount):
# distribution = lib.addownguess(distribution, 0)
# print(distribution)
# winnernumber = lib.findwinnumber(distribution)
# prize = lib.calculateprize(lib.closestguess(distribution,winnernumber))
# print(prize)
#with open('.csv', 'a', newline='') as csvfile:
# writer = csv.writer(csvfile)
# writer.writerow(distribution)
#with open('winningnumber.csv', 'a', newline='') as csvfile:
# writer = csv.writer(csvfile)
# writer.writerow(csvfile)
#print('Der zu erwartende Gewinn bei ' + str(knowingplayeramount) + 'Spielern ist:')
#print(sum(prizelist)/len(prizelist))
return redirect(url_for('ending'))
@app.route('/end', methods=['POST'])
def again():
return redirect('simulation')
if __name__ == "__main__":
app.run(use_reloader=True,host='0.0.0.0')