-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuttt.php
More file actions
473 lines (432 loc) · 14 KB
/
uttt.php
File metadata and controls
473 lines (432 loc) · 14 KB
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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
<?php
include('header.php');
$code ="";
printf ( "<script>location.href='index.php'</script>" );
if (!$session->is_logged_in()) {
printf ( "<script>location.href='login.php'</script>" );
}
$id = $session->user_id;
if (isset($_POST['submit'])){
$code = $_POST['code'];
if (strlen($code)==0 || strlen($id)==0){
echo "You have missed some field";
}
file_put_contents('submissions/'.$id.'.py', stripslashes($code));
//shell_exec("bash utic/run.sh ".$id.".py ".$id."");//insert code into python file and executes python command.Generates the output file.
//exec ('python utic/part1.py');
exec('bash run.sh submissions/'.$id.'.py '.$id.'',$output);
//var_dump($output);
//$err=file_get_contents('submissions/error.tmp');
$move1=file_get_contents('submissions/'.$id.'.lost');
if (strlen($move1)==0){
$move1=file_get_contents('submissions/'.$id.'.win');
}
trim($move1);
$score = file_get_contents('submissions/'.$id.'.score');
$con=mysqli_connect("localhost","trystiit_uttt","uttt@vindy2014","trystiit_ultimate");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="update user set score=".$score." where userid=".$id." and score<".$score."";
mysqli_query($con,$sql);
mysqli_close($con);
}
?>
<html>
<link rel="stylesheet" href="codemirror/lib/codemirror.css">
<script src="codemirror/lib/codemirror.js"></script>
<script src="codemirror/addon/edit/matchbrackets.js"></script>
<script src="codemirror/lib/codemirror.js"></script>
<script src="jquery.js"></script>
<script src = "codemirror/mode/python/python.js"></script>
<style>
#instr,#announcement{
margin-top:6%;
padding:1%;
color:white;
font-family: 'Lato', Arial, sans-serif;
line-height: 1.3;
letter-spacing: 1px;
font-weight: 300;
}
.score{
color:lemonchiffon;
margin-left:17%;
}
.myButton{
float: left;
margin-right: 5px;
background: #10689a;
border: none;
color: #fff;
width: auto;
cursor: pointer;
text-transform: uppercase;
display: inline-block;
padding: 10px 15px;
font-size: 1.1em;
border-radius: 2px;
letter-spacing: 1px;
}
.CodeMirror {
width:50%;
height:350px;
border-radius: 5px;
border-right: 2px solid #000000;
border-bottom: 2px solid #000000;
border-top: 2px solid #000000;
}
.container2{
margin-top : 5%;
}
td
{
text-align: center;
}
.main1{
margin-top:5%;
float: left;
margin-left: 5%;
margin-right:5%;
}
td{
}
table {
border-width: 1px;
border-color : black;
border-collapse: collapse;
}
.tables td{
width : 50px;
height : 50px;
border-width: 1px;
border-style: solid;
border-color: black;
}
#table_00,#table_02,#table_11,#table_20,#table_22{
background-color: #e8edff;
}
#table_01,#table_10,#table_12,#table_21{
background-color: #e8edff;
}
.player1{
background-color:#FF9B82 !important;
}
.player2{
background-color:#B8FF70 !important;
}
</style>
<body style="background: #34495e;">
<div class="container2">
<div style="text-align:center;" id="announcement"><b>Please DO NOT submit the sample code itself as your final submission. We will not be considering such entries.<br>Deadline extended by 12 hours!!! Hurry up. New deadline: 1st March 11:55 AM</b></div>
<div class="score"><?php echo "Your score is ".$score.""?></div>
<table class="main1">
<!-- Top row -->
<tr>
<td class="tables" id = "table_00">
<table>
<tr>
<td id = "cell_00" name="cell_00"></td>
<td id = "cell_01"></td>
<td id = "cell_02"></td>
</tr>
<tr>
<td id = "cell_10"></td>
<td id = "cell_11"></td>
<td id = "cell_12"></td>
</tr>
<tr>
<td id = "cell_20"></td>
<td id = "cell_21"></td>
<td id = "cell_22"></td>
</tr>
</table>
</td>
<td class="tables" id = "table_01">
<table >
<tr>
<td id = "cell_00"></td>
<td id = "cell_01"></td>
<td id = "cell_02"></td>
</tr>
<tr>
<td id = "cell_10"></td>
<td id = "cell_11"></td>
<td id = "cell_12"></td>
</tr>
<tr>
<td id = "cell_20"></td>
<td id = "cell_21"></td>
<td id = "cell_22"></td>
</tr>
</table>
</td>
<td class="tables" id = "table_02">
<table >
<tr>
<td id = "cell_00"></td>
<td id = "cell_01"></td>
<td id = "cell_02"></td>
</tr>
<tr>
<td id = "cell_10"></td>
<td id = "cell_11"></td>
<td id = "cell_12"></td>
</tr>
<tr>
<td id = "cell_20"></td>
<td id = "cell_21"></td>
<td id = "cell_22"></td>
</tr>
</table>
</td>
</tr>
<!-- Middle Row -->
<tr>
<td class="tables" id = "table_10">
<table >
<tr>
<td id = "cell_00"></td>
<td id = "cell_01"></td>
<td id = "cell_02"></td>
</tr>
<tr>
<td id = "cell_10"></td>
<td id = "cell_11"></td>
<td id = "cell_12"></td>
</tr>
<tr>
<td id = "cell_20"></td>
<td id = "cell_21"></td>
<td id = "cell_22"></td>
</tr>
</table>
</td>
<td class="tables" id = "table_11">
<table >
<tr>
<td id = "cell_00"></td>
<td id = "cell_01"></td>
<td id = "cell_02"></td>
</tr>
<tr>
<td id = "cell_10"></td>
<td id = "cell_11"></td>
<td id = "cell_12"></td>
</tr>
<tr>
<td id = "cell_20"></td>
<td id = "cell_21"></td>
<td id = "cell_22"></td>
</tr>
</table>
</td>
<td class="tables" id = "table_12">
<table >
<tr>
<td id = "cell_00"></td>
<td id = "cell_01"></td>
<td id = "cell_02"></td>
</tr>
<tr>
<td id = "cell_10"></td>
<td id = "cell_11"></td>
<td id = "cell_12"></td>
</tr>
<tr>
<td id = "cell_20"></td>
<td id = "cell_21"></td>
<td id = "cell_22"></td>
</tr>
</table>
</td>
</tr>
<!-- Bottom row -->
<tr>
<td class="tables" id = "table_20">
<table >
<tr>
<td id = "cell_00"></td>
<td id = "cell_01"></td>
<td id = "cell_02"></td>
</tr>
<tr>
<td id = "cell_10"></td>
<td id = "cell_11"></td>
<td id = "cell_12"></td>
</tr>
<tr>
<td id = "cell_20"></td>
<td id = "cell_21"></td>
<td id = "cell_22"></td>
</tr>
</table>
</td>
<td class="tables" id = "table_21">
<table >
<tr>
<td id = "cell_00"></td>
<td id = "cell_01"></td>
<td id = "cell_02"></td>
</tr>
<tr>
<td id = "cell_10"></td>
<td id = "cell_11"></td>
<td id = "cell_12"></td>
</tr>
<tr>
<td id = "cell_20"></td>
<td id = "cell_21"></td>
<td id = "cell_22"></td>
</tr>
</table>
</td>
<td class="tables" id = "table_22">
<table >
<tr>
<td id = "cell_00"></td>
<td id = "cell_01"></td>
<td id = "cell_02"></td>
</tr>
<tr>
<td id = "cell_10"></td>
<td id = "cell_11"></td>
<td id = "cell_12"></td>
</tr>
<tr>
<td id = "cell_20"></td>
<td id = "cell_21"></td>
<td id = "cell_22"></td>
</tr>
</table>
</td>
</tr>
</table>
<h2 style="color:lemonchiffon;">Write Your code here! </h2>
<form style="margin-top:3%;color:white;" action = "uttt.php" method="post">
<textarea id="code" name="code"></textarea>
<br>
<input class="myButton" type="submit" name="submit" value="Submit Code"></input>
</form>
<input class = "myButton" type="button" value="Sample Code" onclick="window.open('snippet.py')">
<script>
var id = <?php echo $id; ?>;
var link ='submissions/'+id+'.error';
console.log(link);
</script>
<input class = "myButton" type="button" value="Error" onclick="window.open(link);">
<?php
if (isset($_POST['submit'])){
echo '<div id="buttons">
<!--button class="myButton" id="pause">Pause</button--!>
<button class="myButton" id="play">Play</button>
</div>';
}
?>
</div>
<script type="text/javascript">
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
mode: {name: "python",
version: 2,
singleLineStringErrors: false},
lineNumbers: true,
indentUnit: 4,
tabMode: "shift",
matchBrackets: true
});
</script>
<script type="text/javascript">
$(document).ready(function(){
var move1 = <?php echo "'".$move1."'"; ?>;
console.log(id);
var arr = move1.split(',');
var i = 0;
var inc = 0;
function myloop()
{
console.log(i);
var daddymatrix = arr[i].substring(0,2);
var babycell = arr[i].substring(2,4);
if (babycell=="XX"){
$("#table_"+daddymatrix).addClass("player1");
}
else if (babycell=="OO"){
$("#table_"+daddymatrix).addClass("player2");
}
else {
if (inc==0) {inc = 1 ;}
else {inc = 0 ;}
var matrixid = "#table_"+daddymatrix;
var cellid = " #cell_"+babycell;
console.log(matrixid);
console.log(cellid);
var c =$(matrixid+cellid);
var time = 400;
//console.log(c);
if (inc == 1){
c.html("X");
}
else {
c.html("O");
}
}
var Timeout;
Timeout=setTimeout(function () {
i++;
if (i < arr.length)
myloop();
},500);
$("#pause").click(function(){
clearTimeout(Timeout);
});
}
$("#play").click(function(){
if (i < arr.length)
myloop();
else {
$.each($(".tables tr td"), function () {
$(this).html("");
});
$.each($(".main1 tr td"),function(){$(this).removeClass("player2");});
$.each($(".main1 tr td"),function(){$(this).removeClass("player1");});
i=0;
myloop();
}
});
// for (var i=0;i<arr.length;i++){
// console.log(i);
// var daddymatrix = arr[i].substring(0,2);
// var babycell = arr[i].substring(2,4);
// var matrixid = "#table_"+daddymatrix;
// var cellid = " #cell_"+babycell;
// console.log(matrixid);
// console.log(cellid);
// var c =$(matrixid+cellid);
// var time = 200;
// //console.log(c);
// if (i%2==0){
// setInterval(function(){c.html("O");},);
// }
// else {
// setInterval(function(){c.html("X");},time*i);
// }
// }
});
</script>
<div id = "instr">
<p><b>Important Instuctions:</b></p>
<ul>
<li>Your function definition should be - "def getMove(self,State,PlayerList=[]):"
<li>For more details on the various functions available to you along with the input output specifiaction, please read the rules carefully from <a style = "color:white;" href = "rules.php">here</a>.
<li>Please ensure that your code is well indented and there are no syntax errors.
<li>You can also locally test your code before submiiting here. Download the zipfile from <a style = "color:white;" href="code.zip" id="button-download">here</a>.
<li>The output you will be shown is for the case when you lose the game against our AI.
<li>The score genreated is for 10 matches between our AI and your bot.
<li>Click on Error button to view if there was any error during your last execution of code.
<li>Do not press play button more than once when the animation is playing
</ul>
</div>
</body>
</html>