forked from maxdougherty/snap_autograder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hw3_2048.html
374 lines (317 loc) · 17.7 KB
/
hw3_2048.html
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Snap! Build Your Own Blocks. Beta</title>
<link rel="shortcut icon" href="favicon.ico">
<script src="jschannel.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript" src="underscore-min.js"></script>
<!--<script type="text/javascript" src='gradingLog.js'></script>-->
<script type="text/javascript" src='spriteEventLog.js'></script>
<script type="text/javascript" src='scriptAnalysis.js'></script>
<meta charset="utf-8">
<!-- Moved down to the bottom to have var id. -->
<script type="text/javascript" src="morphic.js"></script>
<script type="text/javascript" src="widgets.js"></script>
<script type="text/javascript" src="blocks.js"></script>
<script type="text/javascript" src="threads.js"></script>
<script type="text/javascript" src="objects.js"></script>
<script type="text/javascript" src="gui.js"></script>
<script type="text/javascript" src="paint.js"></script>
<script type="text/javascript" src="lists.js"></script>
<script type="text/javascript" src="byob.js"></script>
<script type="text/javascript" src="xml.js"></script>
<script type="text/javascript" src="store.js"></script>
<script type="text/javascript" src="locale.js"></script>
<script type="text/javascript" src="cloud.js"></script>
<script type="text/javascript" src="sha512.js"></script>
<script type="text/javascript" src="snap-edx-overrides.js"></script>
<link rel="stylesheet" type="text/css" href="AG_status_bar.css" />
<link rel="stylesheet" type="text/css" href="hintstyle.css" />
<script type="text/javascript" src="AGAgent.js"></script>
<script type="text/javascript" src='feedbackLog.js'></script>
<script type='text/javascript'>
var starter_path = null;
// The id is to act as a course identifier.
// NOTE: FOR NOW YOU ALSO HAVE TO ADD THE ID TO THE BOTTOM OF THE PAGE.
var courseID = "CS10"; // e.g. "BJCx"
// Specify a prerequisite task id, should be null if no such requirement.
var preReqTaskID = null;
var preReqID = courseID + preReqTaskID;
// taskID uniquely identifies the task for saving in browser sessionStorage.
var taskID = "_hw3_2048";
var id = courseID + taskID;
var isEDX = isEDXurl();
// if this question is not meant to be graded, change this flag to false
var graded = true;
// to hide feedback for this problem, change this flag to false
var showFeedback = true;
// to allow for the ability to regrade certain tests, change this flag to true
var regradeOn = false;
// Add tests to the outputLog. Function is called by runAGTest(id, outputLog)
// var testLog;
function AGTest(outputLog) {
//NOTES FOR CS10 Readers:
// If there are comments in the scripting area, some tests will fail. Delete comments before clicking "Get Feedback."
// Make sure all of the blocks being tested are present in the scripting area for the first (original) sprite.
var mergeUpExists = function() {
return spriteContainsBlock("merge up %", 0);
}
var noMovesExists = function() {
return spriteContainsBlock("no moves left for % ?", 0);
}
var rotateExists = function() {
return spriteContainsBlock("rotate % clockwise", 0);
}
var scoreExists = function() {
return spriteContainsBlock("score of %", 0);
}
// var usesScoreTile = function() {
// return customBlockContains("score of %", "score of tile value %");
// }
// var add2or4Exists = function() {
// return spriteContainsBlock("add 2 or 4 to %", 0);
// }
var mergeColumnExists = function() {
return spriteContainsBlock("merge column % of % up", 0);
}
var fb = new FeedbackLog(null, id, 'this is a feedback log test', 0);
fb.snapWorld = world;
// Create a first test chunk
var second_chunk = fb.newChunk('Make the "rotate % clockwise" block.');
// Add a first tip to that first test chunk
var first_tip2 = second_chunk.newTip('Make sure to name your block exactly "rotate % clockwise", and place it in the scripting area.',
'Great job!');
var ass_test2 = first_tip2.newAssertTest(
rotateExists,
"Testing to see if a 'rotate % clockwise' block is in the scripting area.",
"There is a 'rotate % clockwise' block in the scripting area.",
"Make sure there is a 'rotate % clockwise' block in the scripting area.",
1);
var second_tip2 = second_chunk.newTip("The block works fully (+5 points); Minor error (-1 point); rotates counterclockwise instead (+2 points).",
'Great job! The block works fully. (+5)');
second_tip2.newIOTest('r', //testClass
"rotate % clockwise", //blockSpec
[[0, 0, 0, 0, 2, 0, 0, 0, 4, 0, 0, 16, 0, 0, 0, 2]], //input
[0, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 16, 0, 0], //output
5000000, //timeout
true, //isolated
1); //points
second_tip2.newIOTest('r', //testClass
"rotate % clockwise", //blockSpec
[[0, 4, 0, 0, 2, 32, 0, 0, 4, 0, 4, 16, 0, 0, 0, 0]], //input
[0, 4, 2, 0, 0, 0, 32, 4, 0, 4, 0, 0, 0, 16, 0, 0], //output
5000000, //timeout
true, //isolated
1); //points
//_______________________________________________________________________
// Create a first test chunk
var first_chunk = fb.newChunk('Make the "merge up %" block.');
// Add a first tip to that first test chunk
var first_tip = first_chunk.newTip('Make sure to name your block exactly "merge up %", and place it in the scripting area.',
'Great job!');
var ass_test1 = first_tip.newAssertTest(
mergeUpExists,
"Testing to see if a 'merge up %' block is in the scripting area.",
"There is a 'merge up %' block in the scripting area.",
"Make sure there is a 'merge up %' block in the scripting area.",
1);
var second_tip = first_chunk.newTip("Merge up works when a tile hits the edge of the board. (+2 points)",
'Great job! Merge up works when a tile hits the edge of the board. (+2)');
second_tip.newIOTest('r', //testClass
"merge up %", //blockSpec
[[0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], //input
[2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], //output
5000000, //timeout
true, //isolated
1); //points
var third_tip = first_chunk.newTip("Merge up works when a tile hits a tile with no merge. (+2 points)",
'Great job! Merge up works when a tile hits a tile with no merge. (+2)');
third_tip.newIOTest('r', //testClass
"merge up %", //blockSpec
[[4, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0]], //input
[4, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], //output
5000000, //timeout
true, //isolated
1); //points
var fourth_tip = first_chunk.newTip("Merge up works when a tile hits a tile with a merge. (+2 points)",
'Great job! Merge up works when a tile hits a tile with a merge. (+2)');
fourth_tip.newIOTest('r', //testClass
"merge up %", //blockSpec
[[2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0]], //input
[4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], //output
5000000, //timeout
true, //isolated
1); //points
var fifth_tip = first_chunk.newTip("Merge up works when a tile hits a tile of the same value but with no merge. (+3 points)",
'Great job! Merge up works when a tile hits a tile of the same value but with no merge. (+3)');
fifth_tip.newIOTest('r', //testClass
"merge up %", //blockSpec
[[4, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0]], //input
[4, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], //output
5000000, //timeout
true, //isolated
1); //points
//_______________________________________________________________________
// Create a first test chunk
var third_chunk = fb.newChunk('Make the "no moves left for % ?" block.');
// Add a first tip to that first test chunk
var first_tip3 = third_chunk.newTip('Make sure to name your block exactly "no moves left for % ?", and place it in the scripting area.',
'Great job!');
var ass_test3 = first_tip3.newAssertTest(
noMovesExists,
"Testing to see if a 'no moves left for % ?' block is in the scripting area.",
"There is a 'no moves left for % ?' block in the scripting area.",
"Make sure there is a 'no moves left for % ?' block in the scripting area.",
1);
var second_tip3 = third_chunk.newTip("No moves left block works fully (+5 points); -1 For each bug; -1 Doesn’t check the corner OR only merged in 2 directions.",
'Great job! No moves left block works fully (+5)');
second_tip3.newIOTest('r', //testClass
"no moves left for % ?", //blockSpec
[[0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], //input
false, //output
5000000, //timeout
true, //isolated
1); //points
second_tip3.newIOTest('r', //testClass
"no moves left for % ?", //blockSpec
[[2, 4, 2, 4, 16, 16, 2, 4, 2, 4, 2, 4, 4, 2, 4, 2]], //input
false, //output
5000000, //timeout
true, //isolated
1); //points
second_tip3.newIOTest('r', //testClass
"no moves left for % ?", //blockSpec
[[2, 4, 2, 4, 4, 2, 4, 2, 2, 4, 2, 4, 4, 2, 4, 2]], //input
true, //output
5000000, //timeout
true, //isolated
1); //points
//_______________________________________________________________________
// Create a first test chunk
var fourth_chunk = fb.newChunk('Make the "score of %" block.');
// Add a first tip to that first test chunk
var first_tip4 = fourth_chunk.newTip('Make sure to name your block exactly "score of %", and place it in the scripting area.',
'Great job!');
var ass_test4 = first_tip4.newAssertTest(
scoreExists,
"Testing to see if a 'score of %' block is in the scripting area.",
"There is a 'score of %' block in the scripting area.",
"Make sure there is a 'score of %' block in the scripting area.",
1);
var second_tip4 = fourth_chunk.newTip("Score of Board: Sums all tiles. (+1)",
'Great job! Score of Board: Sums all tiles. (+1)');
second_tip4.newIOTest('r', //testClass
"score of %", //blockSpec
[[0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], //input
4, //output
5000000, //timeout
true, //isolated
1); //points
second_tip4.newIOTest('r', //testClass
"score of %", //blockSpec
[[2, 4, 2, 4, 4, 2, 4, 2, 2, 4, 2, 4, 4, 2, 4, 2]], //input
160, //output
5000000, //timeout
true, //isolated
1); //points
second_tip4.newIOTest('r', //testClass
"score of %", //blockSpec
[[0, 4, 0, 0, 2, 32, 0, 0, 4, 0, 4, 16, 0, 0, 0, 0]], //input
1332, //output
5000000, //timeout
true, //isolated
1); //points
// var third_tip4 = fourth_chunk.newTip('Make sure to use the "score of tile value %" block in the body of your "score of %" block. (+1 point)',
// 'Great job! You use "score of tile value %" in the body of your "score of %" block. (+1)');
// var ass_test4_1 = third_tip4.newAssertTest(
// usesScoreTile,
// "Testing to see if you use the 'score of tile value %' block in the body of your 'score of %' block.",
// "You use the 'score of tile value %' block in the body of your 'score of %' block.",
// "Make sure you use the 'score of tile value %' block in the body of your 'score of %' block.",
// 1);
return fb;
}
</script>
<script type="text/javascript" src='feedbackLog.js'></script>
<script type="text/javascript" src="AGFormatting.js"></script>
<script type="text/javascript">
var world;
window.onload = function () {
//INITIALIZE UP SNAP
world = new WorldMorph(document.getElementById('world'));
new IDE_Morph().openIn(world);
var ide = world.children[0];
//Reduce Stage Size on initialization
ide.toggleStageSize(true);
initializeSnapAdditions(world, id);
//AUTOGRADER ADDITION -
//Forced to use setTimeout() to let the world load before... Maybe not.
//Create a gradingLog and initialize the AG status bar (AGSB).
//Initialize AGSB button.
var grade_button = document.getElementById("autograding_button");
grade_button.addEventListener('click', button_listener);
var world_canvas = document.getElementById('world');
world_canvas.addEventListener("mouseup", update_listener);
// Start Snap Environment Loop
setInterval(loop, 1);
};
function loop() {
world.doOneCycle();
}
</script>
<script type="text/javascript" src='feedbackLog.js'></script>
<script type="text/javascript" src="AG_EDX.js"></script>
</head>
<body style="margin: 0;">
<canvas id="world" tabindex="1" style="position: absolute;" ></canvas>
<!-- Snap Autograding Button -->
<div id="autograding_bar">
<div tabindex="0" class="onclick-menu" id='onclick-menu' style="display:inline-block">
<span title="Menu">☰</span>
<div class='hover_darken'></div>
<nav id="navigation" class="site-navigation" role="navigation">
<ul id="dropdown-closed" class="bubble">
<!--<li class="menu-item-sub-menu" id="enabled-button"><a id="feedback-button">View Feedback</a></li>
<li class="menu-divider-sub-menu" id='menu-divider'></li>-->
<li class="menu-item-sub-menu" id="enabled-button"><a id="undo-button">Revert To Last Attempt</a></li>
<li class="menu-item-sub-menu" id="enabled-button"><a id="revert-button">Revert To Best Attempt</a></li>
<!--<li class="menu-item-sub-menu" id="enabled-button"><a id="last-submit">Revert To Last edX Submission</a></li>-->
<li class="menu-item-sub-menu" id="enabled-button"><a id="reset-button">Reset</a></li>
<li class="menu-divider-sub-menu" id='menu-divider'></li>
<li class="menu-item-sub-menu" id='enabled-button' onclick="openPopup();"><a id="help-button">Help</a></li>
</ul>
</nav>
</div>
<div id="autograding_button" style="display:inline-block;">
<span></span>
<div class='hover_darken'></div>
</div>
<div id="numtips" style="display:inline-block"></div>
</div>
<!-- Snap Autograding Menu -->
<!-- Autograding Menu Help Button -->
<div class="overlay is-hidden" id="overlay">
<p class="help-text" id="full-screen-arrow">↘</p>
<p class="help-text" id="full-screen-help">This full-screen button will pop out the Snap! window.</p>
<p class="help-text" id="menu-item-arrow">↗</p>
<p class="help-text" id="menu-item-help">The first two menu items will revert your current Snap! state to one of your previous attempts, depending on whether you wish to revert to your last graded attempt or to your best attempt.</br></br>The 'Reset' button will revert to a blank Snap! project, or to a provided starter file if one is given for this problem.</p>
<p class="help-text" id="ag-button-arrow">↑</p>
<p class="help-text" id="ag-button-help">Clicking this button will grade your current attempt and send the results to edX.</p>
</div>
<div style="display:inline-block" class="view-results" id="circle" onclick="openResults();">Results
</div>
<div class="overlay is-hidden" id="ag-output">
<div class="popup-content" id="ag-results">
<span class="button-close" onclick="closeResults();" id="popup">X</span>
<!--<p id = "different-feedback"></p>
<p id = "edx-submit-different"></p>-->
<div id="toggle-correct-tests"></div>
<p id="comment"></p>
</div>
</div>
</div>
<script type="text/javascript" src="AG_status_bar.js" />
</body>
</html>