Gitlab CSE Unil

games.html 21 KB
Newer Older
M. Chardon's avatar
M. Chardon committed
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
<!DOCTYPE html>
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>@lea</title>
        <meta name="author" content="Marion CHARDON for ESC/RISET - University of Lausanne" />
        <meta name="description" content="Free Web tool for guess data" />
        <meta name="keywords" content="Cipher, Bigdata, Guess" />
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="js/bootstrap/bootstrap.min.css" />
        <link rel="stylesheet" href="js/bootstrap/dashboard.css" />
        <link rel="stylesheet" href="js/bootstrap/font-awesome.min.css" />
        <link rel="stylesheet" href="js/bootstrap/logo_unil.css" />
        <link rel="stylesheet" href="../css/main.css" />
        <script src="js/jquery/jquery-3.2.1.min.js"></script>
        <script src="js/bootstrap/bootstrap.min.js"></script>
        <script src="js/crypto/asmcrypto.js"></script>
        <script src="js/controleur.js"></script>
        <script src="js/entities/global.js"></script>
        <script src="js/entities/modeleTwo.js"></script>
        <script src="js/entities/modeleThree.js"></script>
        <script src="js/entities/modeleFour.js"></script>
        <script src="js/entities/modeleMaskEight.js"></script>
        <script src="js/entities/resultat.js"></script>
        <script src="js/graph/d3.v4.min.js"></script>
        <script src="js/graph/gauge.js"></script>
        <script src="js/graph.js"></script>
    </head>
    <body>
        <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="../index.html"><img src="../img/g3761.png" alt="" style="height:28px;display: inline;"/>Cryptex - @lea</a>
                </div>
                <div id="navbar" class="navbar-collapse collapse">
                    <ul class="nav navbar-nav navbar-right">
                        <li><a href="help.html">Help</a></li>
                    </ul>
                </div>
            </div>
        </nav>    
        <div class="container" style="margin-bottom: 70px; margin-top: 20px;">
            <div class="row">
                <div class="col-sm-3">
                    <ul class="nav nav-pills nav-stacked">
                        <li><a href="index.html">Step 1: test your sequence</a></li>
                        <li><a href="pasapas.html">Step 2: test the computeur</a></li>
                        <li><a href="understand.html">Step 3: understand</a></li>
                        <li class="active"><a href="games.html">Game</a></li>
                    </ul>
                </div>
                <div class="col-sm-9" style="padding-left: 20px;">

                    <div class="row">
                        <div class="col-sm-12">
                            <div class="alert alert-info alert-dismissable">
                                <strong>Info!</strong>
                                <p>
                                    Here is a game: you against the machine. Will you be
                                    able to deceive it? Or are you predictable? 
                                </p>
                            </div>

                            <div class="panel panel-default" id='playerdiv'>
                                <div class="panel-heading">Game configuration</div>
                                <div class="panel-body">
                                    <div class="row" >
                                        <div class="col-sm-4">
                                            <b>Play against:</b><br/>
                                            <input class='vs' type="radio" name="vs" value="computer" checked='checked' /> the computer<br/>
                                            <input class='vs' type="radio" name="vs" value="player"/> an other player   
                                        </div>
                                        <div class="col-sm-4">
                                            <b>Name:</b><br/>
                                            <input type="text" id="nameplayerA" placeholder="Player A" class='form-control' />
                                            <input type="text" id="nameplayerB" placeholder="Player B" class='form-control' style='display: none;'/>
                                        </div>
                                        <div class="col-sm-offset-1 col-sm-3">
                                            <button class="btn btn-default" onclick="startGame();"><i class="fa fa-play" aria-hidden="true"></i> Let's go!</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="row" id='gamediv' style='display: none;'>
                        <div class="row">

                            <div class="col-sm-offset-9 col-sm-1">
                                <button class="btn btn-default" onclick="reset();">Restart game</button>
                            </div>
                        </div>
                        <div class="row" style='margin-top: 10px;'>

                            <div class="col-sm-6">

                                <div class="panel panel-warning">
                                    <div class="panel-heading">Player A</div>
                                    <div class="panel-body">
                                        <div class="row" style="padding-bottom: 10px;padding-top: 10px;">
                                            <div class="col-sm-10">
                                                <button class="btn btn-info btn-lg btnbre" onclick="insertVal(0, 'A');">0 [s]</button>
                                                <button class="btn btn-primary btn-lg btnbre" onclick="insertVal(1, 'A');">1 [d]</button>
                                            </div>
                                        </div>
                                        <div class="row" style="padding: 10px;">
                                            <div class="col-sm-12">
                                                <textarea class="form-control" readonly="readonly" id="userinputA" style="font-size: large;height: 150px;background-color: papayawhip;"></textarea>
                                                <div id="userinputdivA" style="display: none;"></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div style="text-align: center;">
                                    <span id="playerAGaugeContainer"></span>
                                </div>
                                <div class="row" id='propositionPanelA' style="display:none;">
                                    <div class="col-sm-12">
                                        <div class="panel panel-primary">
                                            <div class="panel-heading">Percent correct answers</div>
                                            <div class="panel-body">
                                                <div class="row">
                                                    <ul>
                                                        <li><span style="color:orange;">Orange: wrong guess</span></li>
                                                        <li><span style="color:blue;">Blue: right guess</span></li>
                                                    </ul>
                                                    <div class="col-sm-6">
                                                        Total of right guesses:
                                                        <input class="form-control" readonly="readonly" id="guessValueCorrectA" />
                                                    </div>
                                                    <div class="col-sm-6">
                                                        About the last 10 results:
                                                        <input class="form-control" readonly="readonly" id="guessValueCorrect10A" />
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                            </div>

                            <div class="col-sm-6">

                                <div class="panel panel-success">
                                    <div class="panel-heading">Player B</div>
                                    <div class="panel-body">
                                        <div class="row" style="padding-bottom: 10px;padding-top: 10px;">
                                            <div class="col-sm-10">
                                                <button class="btn btn-info btn-lg btnbre" onclick="insertVal(0, 'B');">0 [k]</button>
                                                <button class="btn btn-primary btn-lg btnbre" onclick="insertVal(1, 'B');">1 [l]</button>
                                            </div>
                                        </div>
                                        <div class="row" style="padding-bottom: 42px;display: none;" id="computerplayer"></div>
                                        <div class="row" style="padding: 10px;">
                                            <div class="col-sm-12">
                                                <textarea class="form-control" readonly="readonly" id="userinputB" style="font-size: large;height: 150px;background-color: mintcream;"></textarea>
                                                <div id="userinputdivB" style="display: none;"></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div style="text-align: center;">
                                    <span id="playerBGaugeContainer"></span>
                                </div>
                                <div class="row" id='propositionPanelB' style="display:none;">
                                    <div class="col-sm-12">
                                        <div class="panel panel-primary">
                                            <div class="panel-heading">Percent correct answers</div>
                                            <div class="panel-body">
                                                <div class="row">
                                                    <ul>
                                                        <li><span style="color:orange;">Orange: wrong guess</span></li>
                                                        <li><span style="color:blue;">Blue: right guess</span></li>
                                                    </ul>
                                                    <div class="col-sm-6">
                                                        Total of right guesses:
                                                        <input class="form-control" readonly="readonly" id="guessValueCorrectB" />
                                                    </div>
                                                    <div class="col-sm-6">
                                                        About the last 10 results:
                                                        <input class="form-control" readonly="readonly" id="guessValueCorrect10B" />
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>
                </div>

                <!--div class="col-sm-6">
                    <svg id="graphic" width="960" height="500"></svg>
                </div-->
            </div>
        </div>


        <div id="contacts" class="modal fade" role="dialog"></div>
        <div id="credits" class="modal fade" role="dialog"></div>
        <div id="legalInformation" class="modal fade" role="dialog"></div>
        <footer class="footer"></footer>

        <script>

            var controleurA = new Controleur("game");
            var controleurB = new Controleur("game");
            var limitGame = 200;

            var gauges = [];

            function createGauge(name, label, min, max)
            {
                var config =
                        {
                            size: 180,
                            label: label,
                            min: undefined !== min ? min : 0,
                            max: undefined !== max ? max : 100,
                            minorTicks: 5
                        };

                var range = config.max - config.min;
                config.yellowZones = [{from: config.min + range * 0.70, to: config.min + range * 0.9}];
                config.redZones = [{from: config.min + range * 0.9, to: config.max}];

                gauges[name] = new Gauge(name + "GaugeContainer", config);
                gauges[name].render();
            }

            function createGauges()
            {
                createGauge("playerA", "Divination");
                createGauge("playerB", "Divination");
                //createGauge("test", "Test", -50, 50 );
            }

            function updateGaugesVal(key, value)
            {
                gauges[key].redraw(value);
            }

            function initialize()
            {
                createGauges();
                updateGaugesVal('playerA', 0);
                updateGaugesVal('playerB', 0);
                //setInterval(updateGauges, 5000);
            }


            $(document).ready(function () {
                $("input[name='vs']").on('change', function () {
                    var vs = $('input[name=vs]:checked').val();
                    if (vs === "computer") {
                        $("#nameplayerB").hide();
                    } else {
                        $("#nameplayerB").show();
                    }
                });
                initialize();
            });

            function trigKeyDownInit(event) {
                //event.preventDefault();
                if (event.which === 83) {
                    insertVal(0, 'A');
                } else if (event.which === 68) {
                    insertVal(1, 'A');
                }
                var vs = $('input[name=vs]:checked').val();
                if (vs !== "computer") {
                    if (event.which === 75) {
                        insertVal(0, 'B');
                    } else if (event.which === 76) {
                        insertVal(1, 'B');
                    }
                }
            }

            function insertVal(val, player) {
                var nbreSaisis = -1;
                if (player === "A") {
                    nbreSaisis = controleurA.suite.length;
                } else {
                    nbreSaisis = controleurB.suite.length;
                }
                if (nbreSaisis < limitGame) {
                    $("#userinput" + player).val($("#userinput" + player).val() + val);
                    nbreSaisis++;
                    var res = null;
                    if (player === "A") {
                        controleurA.registerVal(val);
                        res = controleurA.guestNextValue();
                    } else {
                        controleurB.registerVal(val);
                        res = controleurB.guestNextValue();
                    }
                    if (res) {
                        $("#guessValue" + player).val(res.valeur);
                        var controlelastValue = null;
                        if (player === "A") {
                            controlelastValue = controleurA.getControlelastValue();
                        } else {
                            controlelastValue = controleurB.getControlelastValue();
                        }
                        if (controlelastValue !== null) {
                            if (controlelastValue > 0)
                                $('#userinputdiv' + player).append('<span style="color:blue;">' + val + '</span> ');
                            else
                                $('#userinputdiv' + player).append('<span style="color:orange;">' + val + '</span> ');
                        } else {
                            $('#userinputdiv' + player).append(val + ' ');
                        }
                    } else {
                        $('#userinputdiv' + player).append(val + ' ');
                    }
                    if (player === "A") {
                        controleurA.majIndices('A');
                        if (res && controleurA.global.reponses.length > 0) {
                            updateGaugesVal('playerA', getNbreBonnesReponses(controleurA.global.reponses) * 100 / (controleurA.global.reponses.length));
                        }
                    } else {
                        controleurB.majIndices('B');
                        if (res && controleurB.global.reponses.length > 0) {
                            updateGaugesVal('playerB', getNbreBonnesReponses(controleurB.global.reponses) * 100 / (controleurB.global.reponses.length));
                        }
                    }
                    if (nbreSaisis === limitGame) {
                        $("#propositionPanel" + player).show();
                        $(".btnbre").hide();
                        $("#userinput" + player).hide();
                        $('#userinputdiv' + player).show();
                        $("#computerplayer").hide();
                        //$('body').off('keydown');
                    }

                    if (player === "A" && playerB === "computer") {
                        insertVal(getCharAleatoire(), 'B');
                    }
                }
            }

            function reset() {
                controleurA.resetApi();
                controleurB.resetApi();
                $("input[name!=vs]").each(function () {
                    $(this).val("");
                });
                $("textarea").each(function () {
                    $(this).val("");
                });
                $("#propositionPanelA").hide();
                $("#propositionPanelB").hide();
                $(".btnbre").show();
                $("#userinputA").show();
                $("#userinputdivA").html("");
                $("#userinputdivA").hide();
                $("#userinputB").show();
                $("#userinputdivB").html("");
                $("#userinputdivB").hide();

                $('body').off('keydown');
                //$('body').on('keydown', trigKeyDownInit);

                $("#gamediv").hide();
                $("#playerdiv").show();
                $("#nameplayerB").hide();
                $("input[name=vs][value=computer]").prop('checked', true);
                $("#computerplayer").hide();

                updateGaugesVal('playerA', 0);
                updateGaugesVal('playerB', 0);
            }

            function startGame() {
                if ($("#nameplayerA").val() && $("#nameplayerA").val().length > 0) {
                    $(".panel-warning > .panel-heading").html($("#nameplayerA").val());
                } else
                    $(".panel-warning > .panel-heading").html("Player A");
                var vs = $('input[name=vs]:checked').val();
                if (vs === "computer") {
                    $(".panel-success > .panel-heading").html("Computer");
                    $(".panel-success button").hide();
                    playerB = "computer";
                    $("#computerplayer").show();
                } else {
                    playerB = "player";
                    if ($("#nameplayerB").val() && $("#nameplayerB").val().length > 0) {
                        $(".panel-success > .panel-heading").html($("#nameplayerB").val());
                    } else {
                        $(".panel-success > .panel-heading").html("Player B");
                    }
                    $(".panel-success button").show();
                    $("#computerplayer").hide();
                }

                $("#gamediv").show();
                $("#playerdiv").hide();
                $('body').on('keydown', trigKeyDownInit);
            }
        </script>

        <script src="../js/main.js"></script>

    </body>
</html>