Changeset View
Standalone View
src/activities/sudoku/sudoku.js
Show All 16 Lines | |||||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program; if not, see <https://www.gnu.org/licenses/>. | 18 | along with this program; if not, see <https://www.gnu.org/licenses/>. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | .pragma library | 21 | .pragma library | ||
22 | .import QtQuick 2.6 as Quick | 22 | .import QtQuick 2.6 as Quick | ||
23 | .import "qrc:/gcompris/src/core/core.js" as Core | 23 | .import "qrc:/gcompris/src/core/core.js" as Core | ||
24 | 24 | | |||
25 | | ||||
26 | // Hard coded level definitions | | |||
27 | var levels = [ | | |||
28 | [ // Level 1 | | |||
29 | [ | | |||
30 | ['.','C','B'], | | |||
31 | ['.','B','A'], | | |||
32 | ['.','A','C'] | | |||
33 | ], | | |||
34 | [ | | |||
35 | ['C','A','B'], | | |||
36 | ['.','.','.'], | | |||
37 | ['B','C','A'] | | |||
38 | ], | | |||
39 | [ | | |||
40 | ['C','A','B'], | | |||
41 | ['A','B','C'], | | |||
42 | ['.','.','.'] | | |||
43 | ], | | |||
44 | [ | | |||
45 | ['A','.','C'], | | |||
46 | ['C','.','B'], | | |||
47 | ['B','.','A'] | | |||
48 | ], | | |||
49 | [ | | |||
50 | ['A','.','C'], | | |||
51 | ['B','C','.'], | | |||
52 | ['.','A','B'] | | |||
53 | ], | | |||
54 | [ | | |||
55 | ['A','B','C'], | | |||
56 | ['B','.','A'], | | |||
57 | ['.','A','.'] | | |||
58 | ], | | |||
59 | [ | | |||
60 | ['.','B','A'], | | |||
61 | ['B','.','C'], | | |||
62 | ['A','C','.'] | | |||
63 | ], [ | | |||
64 | ['A','B','C'], | | |||
65 | ['.','C','A'], | | |||
66 | ['.','A','.'] | | |||
67 | ], | | |||
68 | ], | | |||
69 | [ // Level 2 | | |||
70 | [ | | |||
71 | ['A','.','.'], | | |||
72 | ['D','.','.'], | | |||
73 | ['C','A','.'], | | |||
74 | ], | | |||
75 | [ | | |||
76 | ['C','.','D'], | | |||
77 | ['.','.','B'], | | |||
78 | ['.','D','C'], | | |||
79 | ], | | |||
80 | [ | | |||
81 | ['.','B','D'], | | |||
82 | ['D','.','.'], | | |||
83 | ['B','.','C'], | | |||
84 | ], | | |||
85 | [ | | |||
86 | ['A','.','.'], | | |||
87 | ['.','D','A'], | | |||
88 | ['D','.','C'], | | |||
89 | ], | | |||
90 | [ | | |||
91 | ['C','.','D'], | | |||
92 | ['.','C','.'], | | |||
93 | ['B','.','C'], | | |||
94 | ], | | |||
95 | ], | | |||
96 | [ // Level 3 | | |||
97 | [ | | |||
98 | ['.','A','.'], | | |||
99 | ['A','C','.'], | | |||
100 | ['.','B','.'], | | |||
101 | ], | | |||
102 | [ | | |||
103 | ['B','A','.'], | | |||
104 | ['A','C','.'], | | |||
105 | ['.','.','.'], | | |||
106 | ], | | |||
107 | [ | | |||
108 | ['.','A','C'], | | |||
109 | ['.','.','B'], | | |||
110 | ['C','.','.'], | | |||
111 | ], | | |||
112 | [ | | |||
113 | ['.','.','C'], | | |||
114 | ['D','.','A'], | | |||
115 | ['C','.','.'], | | |||
116 | ], | | |||
117 | [ | | |||
118 | ['.','.','C'], | | |||
119 | ['D','.','A'], | | |||
120 | ['.','A','.'], | | |||
121 | ], | | |||
122 | ], | | |||
123 | [ // Level 4 | | |||
124 | [ | | |||
125 | ['.','B','C','D'], | | |||
126 | ['D','C','.','A'], | | |||
127 | ['.','D','A','B'], | | |||
128 | ['B','A','.','C'], | | |||
129 | ], | | |||
130 | [ | | |||
131 | ['A','.','.','D'], | | |||
132 | ['D','C','B','.'], | | |||
133 | ['C','D','A','.'], | | |||
134 | ['.','.','D','C'], | | |||
135 | ], | | |||
136 | [ | | |||
137 | ['.','B','.','.'], | | |||
138 | ['.','C','B','A'], | | |||
139 | ['C','D','A','.'], | | |||
140 | ['.','.','D','.'], | | |||
141 | ], | | |||
142 | | ||||
143 | [ | | |||
144 | ['.','B','A','.'], | | |||
145 | ['D','.','B','C'], | | |||
146 | ['A','C','.','B'], | | |||
147 | ['.','D','C','.'] | | |||
148 | ], | | |||
149 | [ | | |||
150 | ['.','.','.','.'], | | |||
151 | ['D','A','B','C'], | | |||
152 | ['A','C','D','B'], | | |||
153 | ['.','.','.','.'] | | |||
154 | ], | | |||
155 | ], | | |||
156 | [ // Level 5 | | |||
157 | [ | | |||
158 | ['.','.','.','.'], | | |||
159 | ['D','A','B','.'], | | |||
160 | ['C','.','A','B'], | | |||
161 | ['.','.','.','D'] | | |||
162 | ], | | |||
163 | [ | | |||
164 | ['A','B','C','D'], | | |||
165 | ['.','.','.','.'], | | |||
166 | ['.','.','.','.'], | | |||
167 | ['B','C','D','A'] | | |||
168 | ], | | |||
169 | [ | | |||
170 | ['.','.','A','D'], | | |||
171 | ['D','.','.','C'], | | |||
172 | ['A','.','.','B'], | | |||
173 | ['B','D','.','.'] | | |||
174 | ], | | |||
175 | [ | | |||
176 | ['.','.','A','.'], | | |||
177 | ['D','A','B','.'], | | |||
178 | ['.','C','D','B'], | | |||
179 | ['.','D','.','.'] | | |||
180 | ], | | |||
181 | [ | | |||
182 | ['C','B','.','D'], | | |||
183 | ['.','.','.','C'], | | |||
184 | ['A','.','.','.'], | | |||
185 | ['B','.','C','A'] | | |||
186 | ], | | |||
187 | ], | | |||
188 | [ // Level 6 | | |||
189 | [ | | |||
190 | ['C','.','.','D'], | | |||
191 | ['.','.','B','.'], | | |||
192 | ['A','.','.','.'], | | |||
193 | ['.','.','D','.'] | | |||
194 | ], | | |||
195 | [ | | |||
196 | ['.','B','.','A'], | | |||
197 | ['.','.','B','.'], | | |||
198 | ['C','.','D','.'], | | |||
199 | ['.','.','.','C'] | | |||
200 | ], | | |||
201 | [ | | |||
202 | ['A','.','B','.'], | | |||
203 | ['.','C','.','A'], | | |||
204 | ['.','.','.','D'], | | |||
205 | ['D','.','C','.'] | | |||
206 | ], | | |||
207 | [ | | |||
208 | ['.','A','.','.'], | | |||
209 | ['C','.','A','B'], | | |||
210 | ['.','.','C','.'], | | |||
211 | ['D','.','.','A'] | | |||
212 | ], | | |||
213 | [ | | |||
214 | ['C','.','.','D'], | | |||
215 | ['B','.','A','.'], | | |||
216 | ['.','B','.','A'], | | |||
217 | ['.','.','.','.'] | | |||
218 | ], | | |||
219 | [ | | |||
220 | ['.','A','C','.'], | | |||
221 | ['.','.','.','D'], | | |||
222 | ['C','.','.','A'], | | |||
223 | ['.','B','.','.'] | | |||
224 | ], | | |||
225 | [ | | |||
226 | ['.','C','.','D'], | | |||
227 | ['B','.','.','.'], | | |||
228 | ['.','.','.','.'], | | |||
229 | ['C','A','.','B'] | | |||
230 | ], | | |||
231 | [ | | |||
232 | ['B','.','.','C'], | | |||
233 | ['.','A','.','.'], | | |||
234 | ['.','.','D','.'], | | |||
235 | ['.','B','.','.'] | | |||
236 | ], | | |||
237 | ], | | |||
238 | [ // Level 7 | | |||
239 | [ | | |||
240 | ['A','B','C','D','E'], | | |||
241 | ['.','A','B','C','D'], | | |||
242 | ['.','.','A','B','C'], | | |||
243 | ['.','.','.','A','B'], | | |||
244 | ['.','.','.','.','A'] | | |||
245 | ], | | |||
246 | [ | | |||
247 | ['A','B','.','D','.'], | | |||
248 | ['.','.','D','E','A'], | | |||
249 | ['C','.','.','A','.'], | | |||
250 | ['D','E','.','.','C'], | | |||
251 | ['.','A','B','.','D'] | | |||
252 | ], | | |||
253 | [ | | |||
254 | ['.','C','.','A','.'], | | |||
255 | ['A','.','B','.','C'], | | |||
256 | ['.','B','.','C','.'], | | |||
257 | ['D','.','C','.','A'], | | |||
258 | ['.','A','E','.','B'] | | |||
259 | ], | | |||
260 | [ | | |||
261 | ['C','B','.','.','D'], | | |||
262 | ['.','.','D','C','.'], | | |||
263 | ['D','.','B','.','E'], | | |||
264 | ['.','A','.','D','C'], | | |||
265 | ['E','.','.','B','.'] | | |||
266 | ], | | |||
267 | [ | | |||
268 | ['D','.','.','B','E'], | | |||
269 | ['.','E','A','.','.'], | | |||
270 | ['A','C','.','.','B'], | | |||
271 | ['.','.','B','C','.'], | | |||
272 | ['C','B','.','A','.'] | | |||
273 | ], | | |||
274 | [ | | |||
275 | ['.','.','C','D','.'], | | |||
276 | ['B','.','.','.','C'], | | |||
277 | ['.','C','.','B','D'], | | |||
278 | ['C','.','D','A','.'], | | |||
279 | ['D','E','.','.','A'] | | |||
280 | ], | | |||
281 | ], | | |||
282 | [ // Level 8 | | |||
283 | [ | | |||
284 | ['1','2','3','4','5'], | | |||
285 | ['.','1','2','3','4'], | | |||
286 | ['.','.','1','2','3'], | | |||
287 | ['.','.','.','1','2'], | | |||
288 | ['.','.','.','.','1'] | | |||
289 | ], | | |||
290 | [ | | |||
291 | ['1','2','.','4','.'], | | |||
292 | ['.','.','4','5','1'], | | |||
293 | ['3','.','.','1','.'], | | |||
294 | ['4','5','.','.','3'], | | |||
295 | ['.','1','2','.','4'] | | |||
296 | ], | | |||
297 | [ | | |||
298 | ['.','3','.','1','.'], | | |||
299 | ['1','.','2','.','3'], | | |||
300 | ['.','2','.','3','.'], | | |||
301 | ['4','.','3','.','1'], | | |||
302 | ['.','1','5','.','2'] | | |||
303 | ], | | |||
304 | [ | | |||
305 | ['3','2','.','.','4'], | | |||
306 | ['.','.','4','3','.'], | | |||
307 | ['4','.','2','.','5'], | | |||
308 | ['.','1','.','4','3'], | | |||
309 | ['5','.','.','2','.'] | | |||
310 | ], | | |||
311 | [ | | |||
312 | ['4','.','.','2','5'], | | |||
313 | ['.','5','1','.','.'], | | |||
314 | ['1','3','.','.','2'], | | |||
315 | ['.','.','2','3','.'], | | |||
316 | ['3','2','.','1','.'] | | |||
317 | ], | | |||
318 | [ | | |||
319 | ['.','.','3','4','.'], | | |||
320 | ['2','.','.','.','3'], | | |||
321 | ['.','3','.','2','4'], | | |||
322 | ['3','.','4','1','.'], | | |||
323 | ['4','5','.','.','1'] | | |||
324 | ], | | |||
325 | ], | | |||
326 | [ // Level 9 | | |||
327 | [ | | |||
328 | ['8', '9', '3', '4', '5', '2', '6', '7', '1'], | | |||
329 | ['7', '1', '6', '3', '9', '8', '5', '.', '2'], | | |||
330 | ['2', '4', '5', '1', '7', '6', '9', '8', '3'], | | |||
331 | ['5', '2', '1', '8', '4', '9', '3', '6', '7'], | | |||
332 | ['9', '6', '.', '2', '3', '7', '1', '5', '8'], | | |||
333 | ['3', '8', '7', '5', '6', '1', '4', '2', '9'], | | |||
334 | ['4', '7', '.', '9', '1', '5', '8', '.', '6'], | | |||
335 | ['6', '5', '9', '7', '8', '3', '2', '1', '4'], | | |||
336 | ['1', '3', '8', '6', '.', '4', '.', '9', '5'] | | |||
337 | ], | | |||
338 | [ | | |||
339 | ['7', '9', '4', '6', '3', '5', '8', '1', '2'], | | |||
340 | ['8', '3', '2', '4', '9', '1', '5', '7', '6'], | | |||
341 | ['6', '1', '5', '.', '8', '2', '4', '.', '3'], | | |||
342 | ['5', '2', '8', '1', '7', '3', '6', '4', '9'], | | |||
343 | ['4', '7', '3', '2', '6', '9', '1', '5', '8'], | | |||
344 | ['9', '6', '1', '8', '5', '4', '3', '2', '7'], | | |||
345 | ['3', '8', '9', '5', '1', '7', '2', '6', '4'], | | |||
346 | ['2', '5', '6', '.', '4', '.', '7', '3', '1'], | | |||
347 | ['1', '4', '7', '3', '2', '6', '9', '8', '5'], | | |||
348 | ], | | |||
349 | [ | | |||
350 | ['5', '6', '2', '1', '7', '9', '4', '3', '8'], | | |||
351 | ['.', '3', '4', '8', '5', '6', '7', '1', '2'], | | |||
352 | ['1', '8', '7', '4', '3', '2', '5', '9', '6'], | | |||
353 | ['6', '9', '.', '7', '1', '5', '3', '2', '4'], | | |||
354 | ['4', '1', '3', '9', '2', '8', '6', '.', '5'], | | |||
355 | ['7', '2', '5', '3', '6', '4', '9', '8', '1'], | | |||
356 | ['8', '5', '9', '2', '4', '3', '1', '6', '7'], | | |||
357 | ['2', '7', '6', '5', '9', '1', '8', '4', '3'], | | |||
358 | ['3', '4', '1', '.', '8', '7', '2', '5', '9'], | | |||
359 | ], | | |||
360 | [ | | |||
361 | ['2', '1', '6', '4', '7', '8', '9', '5', '3'], | | |||
362 | ['4', '9', '7', '.', '5', '3', '2', '6', '8'], | | |||
363 | ['5', '3', '8', '2', '6', '9', '4', '1', '7'], | | |||
364 | ['8', '.', '4', '9', '3', '6', '1', '7', '5'], | | |||
365 | ['6', '5', '.', '7', '4', '1', '8', '2', '9'], | | |||
366 | ['1', '7', '9', '8', '2', '5', '3', '4', '6'], | | |||
367 | ['3', '4', '1', '6', '9', '7', '5', '8', '2'], | | |||
368 | ['7', '8', '5', '3', '1', '2', '6', '.', '4'], | | |||
369 | ['9', '6', '2', '5', '8', '4', '7', '3', '1'], | | |||
370 | ] | | |||
371 | ], | | |||
372 | [ // Level 10 | | |||
373 | [ | | |||
374 | ['3', '8', '4', '9', '5', '6', '2', '7', '1'], | | |||
375 | ['9', '.', '6', '8', '7', '2', '5', '3', '4'], | | |||
376 | ['2', '5', '7', '1', '4', '.', '6', '9', '8'], | | |||
377 | ['8', '9', '3', '.', '.', '5', '1', '.', '7'], | | |||
378 | ['7', '2', '1', '4', '3', '9', '8', '5', '6'], | | |||
379 | ['6', '4', '5', '7', '1', '8', '9', '2', '.'], | | |||
380 | ['1', '3', '9', '.', '8', '7', '.', '6', '2'], | | |||
381 | ['4', '6', '2', '3', '9', '1', '7', '.', '5'], | | |||
382 | ['5', '7', '8', '2', '6', '4', '.', '1', '.'], | | |||
383 | ], | | |||
384 | [ | | |||
385 | ['1', '2', '8', '4', '9', '3', '.', '6', '5'], | | |||
386 | ['6', '.', '4', '5', '7', '8', '2', '9', '1'], | | |||
387 | ['5', '7', '9', '2', '1', '6', '8', '4', '3'], | | |||
388 | ['2', '6', '1', '3', '8', '5', '4', '7', '9'], | | |||
389 | ['8', '5', '3', '.', '4', '9', '1', '2', '6'], | | |||
390 | ['9', '.', '7', '6', '.', '1', '3', '5', '8'], | | |||
391 | ['.', '.', '6', '1', '5', '.', '9', '3', '2'], | | |||
392 | ['3', '9', '2', '8', '6', '7', '5', '1', '.'], | | |||
393 | ['4', '1', '5', '9', '3', '2', '6', '.', '.'], | | |||
394 | ], | | |||
395 | [ | | |||
396 | ['.', '8', '.', '4', '9', '2', '5', '1', '6'], | | |||
397 | ['5', '.', '.', '7', '1', '6', '8', '.', '3'], | | |||
398 | ['.', '6', '1', '3', '5', '.', '2', '4', '7'], | | |||
399 | ['1', '2', '6', '.', '3', '7', '4', '5', '9'], | | |||
400 | ['.', '9', '5', '2', '6', '1', '3', '7', '8'], | | |||
401 | ['8', '7', '3', '.', '4', '5', '6', '2', '1'], | | |||
402 | ['.', '3', '9', '1', '2', '4', '7', '8', '5'], | | |||
403 | ['7', '1', '4', '5', '8', '3', '9', '6', '2'], | | |||
404 | ['2', '5', '8', '6', '7', '9', '1', '3', '4'], | | |||
405 | ], | | |||
406 | [ | | |||
407 | ['3', '7', '.', '4', '1', '.', '8', '5', '9'], | | |||
408 | ['9', '5', '.', '8', '7', '3', '6', '.', '2'], | | |||
409 | ['6', '1', '8', '2', '9', '5', '3', '4', '7'], | | |||
410 | ['4', '3', '9', '1', '8', '.', '2', '6', '5'], | | |||
411 | ['1', '2', '7', '5', '6', '4', '9', '8', '3'], | | |||
412 | ['.', '8', '6', '3', '2', '9', '4', '7', '1'], | | |||
413 | ['8', '9', '.', '7', '.', '2', '5', '3', '.'], | | |||
414 | ['7', '6', '5', '9', '3', '8', '1', '2', '4'], | | |||
415 | ['2', '4', '3', '6', '5', '.', '7', '9', '.'], | | |||
416 | ] | | |||
417 | ], | | |||
418 | [ // Level 11 | | |||
419 | [ | | |||
420 | ['6', '1', '7', '5', '2', '9', '3', '.', '8'], | | |||
421 | ['.', '4', '.', '.', '8', '6', '9', '2', '7'], | | |||
422 | ['8', '9', '.', '.', '7', '4', '5', '6', '.'], | | |||
423 | ['1', '8', '.', '.', '5', '7', '4', '.', '2'], | | |||
424 | ['.', '2', '6', '9', '3', '1', '7', '.', '5'], | | |||
425 | ['7', '.', '5', '2', '4', '8', '.', '1', '9'], | | |||
426 | ['9', '7', '8', '4', '.', '2', '1', '5', '3'], | | |||
427 | ['3', '.', '1', '8', '.', '.', '.', '7', '4'], | | |||
428 | ['.', '5', '4', '7', '1', '3', '8', '.', '6'], | | |||
429 | ], | | |||
430 | [ | | |||
431 | ['8', '5', '2', '4', '3', '1', '9', '6', '7'], | | |||
432 | ['1', '9', '6', '2', '.', '5', '4', '.', '8'], | | |||
433 | ['.', '.', '.', '6', '8', '9', '5', '2', '1'], | | |||
434 | ['2', '1', '5', '.', '6', '8', '.', '4', '9'], | | |||
435 | ['7', '.', '.', '1', '2', '4', '3', '.', '.'], | | |||
436 | ['6', '.', '3', '9', '5', '7', '1', '8', '.'], | | |||
437 | ['.', '2', '1', '7', '4', '6', '8', '9', '3'], | | |||
438 | ['.', '6', '.', '5', '1', '3', '2', '7', '4'], | | |||
439 | ['3', '.', '4', '.', '.', '.', '6', '.', '5'], | | |||
440 | ], | | |||
441 | [ | | |||
442 | ['.', '3', '2', '8', '5', '1', '6', '.', '.'], | | |||
443 | ['6', '8', '9', '3', '4', '2', '.', '7', '1'], | | |||
444 | ['4', '1', '5', '.', '9', '7', '8', '2', '3'], | | |||
445 | ['2', '4', '.', '.', '.', '9', '7', '3', '.'], | | |||
446 | ['5', '.', '7', '2', '3', '.', '1', '6', '8'], | | |||
447 | ['1', '6', '3', '7', '8', '5', '4', '9', '2'], | | |||
448 | ['9', '7', '.', '4', '.', '8', '3', '5', '.'], | | |||
449 | ['3', '2', '.', '.', '1', '6', '9', '.', '7'], | | |||
450 | ['8', '.', '6', '.', '7', '3', '2', '.', '.'], | | |||
451 | ], | | |||
452 | [ | | |||
453 | ['9', '5', '8', '6', '4', '.', '1', '7', '2'], | | |||
454 | ['2', '6', '4', '.', '5', '1', '.', '8', '3'], | | |||
455 | ['1', '3', '7', '.', '8', '2', '4', '.', '6'], | | |||
456 | ['3', '4', '9', '8', '2', '.', '6', '1', '7'], | | |||
457 | ['6', '1', '2', '4', '9', '7', '8', '3', '.'], | | |||
458 | ['.', '.', '.', '1', '3', '6', '2', '9', '4'], | | |||
459 | ['5', '.', '1', '.', '.', '9', '7', '.', '8'], | | |||
460 | ['7', '8', '6', '.', '.', '.', '3', '.', '9'], | | |||
461 | ['4', '9', '3', '2', '.', '8', '5', '.', '.'], | | |||
462 | ] | | |||
463 | ], | | |||
464 | [ // Level 12 | | |||
465 | [ | | |||
466 | ['.', '1', '7', '3', '.', '8', '.', '.', '2'], | | |||
467 | ['2', '9', '8', '.', '1', '6', '3', '7', '.'], | | |||
468 | ['3', '5', '.', '9', '7', '2', '.', '.', '4'], | | |||
469 | ['6', '3', '9', '5', '4', '.', '7', '.', '8'], | | |||
470 | ['.', '.', '4', '.', '.', '3', '5', '1', '9'], | | |||
471 | ['1', '8', '.', '2', '9', '.', '4', '.', '.'], | | |||
472 | ['5', '.', '3', '.', '.', '9', '2', '.', '7'], | | |||
473 | ['.', '7', '.', '6', '3', '5', '9', '.', '.'], | | |||
474 | ['.', '.', '1', '7', '2', '4', '.', '5', '.'], | | |||
475 | ], | | |||
476 | [ | | |||
477 | ['.', '5', '8', '6', '7', '.', '3', '9', '2'], | | |||
478 | ['2', '.', '.', '4', '5', '.', '.', '7', '6'], | | |||
479 | ['.', '.', '6', '.', '.', '.', '8', '5', '4'], | | |||
480 | ['.', '8', '.', '7', '2', '6', '5', '4', '.'], | | |||
481 | ['5', '.', '2', '9', '.', '4', '.', '3', '.'], | | |||
482 | ['1', '7', '4', '5', '.', '3', '2', '6', '.'], | | |||
483 | ['3', '.', '.', '8', '6', '.', '4', '1', '.'], | | |||
484 | ['8', '9', '5', '.', '4', '.', '6', '.', '.'], | | |||
485 | ['6', '4', '.', '.', '.', '5', '9', '8', '7'], | | |||
486 | ], | | |||
487 | [ | | |||
488 | ['4', '.', '5', '7', '3', '1', '9', '6', '2'], | | |||
489 | ['3', '.', '6', '4', '.', '.', '.', '8', '.'], | | |||
490 | ['9', '1', '7', '.', '.', '2', '4', '5', '3'], | | |||
491 | ['.', '9', '8', '5', '2', '7', '.', '1', '.'], | | |||
492 | ['.', '7', '.', '.', '.', '4', '.', '.', '8'], | | |||
493 | ['.', '.', '1', '3', '6', '8', '.', '7', '.'], | | |||
494 | ['.', '3', '2', '.', '.', '9', '7', '4', '.'], | | |||
495 | ['7', '.', '.', '.', '.', '.', '2', '3', '1'], | | |||
496 | ['1', '6', '.', '2', '7', '3', '8', '9', '5'], | | |||
497 | ], | | |||
498 | [ | | |||
499 | ['6', '5', '1', '8', '4', '7', '3', '.', '9'], | | |||
500 | ['.', '4', '9', '.', '1', '5', '6', '.', '.'], | | |||
501 | ['7', '.', '3', '.', '2', '9', '4', '.', '.'], | | |||
502 | ['.', '2', '.', '7', '9', '6', '8', '4', '1'], | | |||
503 | ['.', '9', '.', '4', '3', '.', '5', '.', '2'], | | |||
504 | ['1', '6', '4', '.', '.', '2', '.', '.', '3'], | | |||
505 | ['4', '1', '.', '9', '.', '.', '7', '5', '.'], | | |||
506 | ['5', '3', '6', '.', '.', '.', '.', '9', '.'], | | |||
507 | ['.', '7', '8', '1', '5', '.', '.', '3', '6'], | | |||
508 | ] | | |||
509 | ], | | |||
510 | [ // Level 13 | | |||
511 | [ | | |||
512 | ['.', '2', '.', '1', '.', '5', '.', '.', '9'], | | |||
513 | ['.', '.', '1', '4', '7', '6', '2', '8', '.'], | | |||
514 | ['3', '7', '4', '.', '8', '2', '.', '.', '6'], | | |||
515 | ['.', '6', '3', '.', '4', '1', '.', '9', '2'], | | |||
516 | ['4', '5', '9', '.', '.', '.', '8', '.', '7'], | | |||
517 | ['.', '.', '2', '7', '5', '.', '6', '3', '.'], | | |||
518 | ['.', '4', '7', '.', '.', '8', '3', '.', '1'], | | |||
519 | ['.', '3', '.', '6', '.', '4', '.', '2', '5'], | | |||
520 | ['6', '.', '.', '3', '.', '.', '.', '.', '8'], | | |||
521 | ], | | |||
522 | [ | | |||
523 | ['4', '.', '5', '.', '2', '.', '7', '.', '1'], | | |||
524 | ['.', '.', '.', '3', '4', '.', '5', '6', '8'], | | |||
525 | ['6', '.', '.', '8', '5', '7', '2', '.', '.'], | | |||
526 | ['.', '.', '4', '.', '.', '5', '.', '7', '.'], | | |||
527 | ['.', '3', '.', '2', '.', '.', '8', '.', '.'], | | |||
528 | ['5', '.', '.', '.', '.', '9', '.', '.', '2'], | | |||
529 | ['.', '7', '1', '.', '.', '.', '4', '2', '.'], | | |||
530 | ['2', '.', '6', '.', '9', '.', '3', '.', '.'], | | |||
531 | ['3', '.', '9', '1', '.', '2', '6', '.', '.'], | | |||
532 | ], | | |||
533 | [ | | |||
534 | ['5', '7', '8', '.', '.', '3', '.', '9', '.'], | | |||
535 | ['.', '6', '.', '4', '.', '9', '7', '.', '8'], | | |||
536 | ['2', '4', '9', '7', '8', '1', '5', '3', '.'], | | |||
537 | ['.', '1', '.', '.', '9', '7', '.', '.', '.'], | | |||
538 | ['.', '.', '.', '5', '.', '.', '4', '.', '3'], | | |||
539 | ['6', '8', '5', '2', '3', '.', '.', '.', '.'], | | |||
540 | ['.', '5', '1', '9', '.', '.', '.', '.', '2'], | | |||
541 | ['4', '.', '6', '3', '.', '2', '.', '5', '1'], | | |||
542 | ['.', '.', '2', '.', '4', '5', '.', '7', '.'], | | |||
543 | ], | | |||
544 | [ | | |||
545 | ['9', '.', '.', '.', '7', '2', '.', '3', '.'], | | |||
546 | ['4', '1', '.', '8', '5', '.', '9', '.', '.'], | | |||
547 | ['2', '7', '3', '9', '.', '.', '.', '.', '.'], | | |||
548 | ['.', '3', '.', '.', '.', '.', '7', '.', '.'], | | |||
549 | ['1', '9', '7', '.', '3', '.', '.', '.', '5'], | | |||
550 | ['6', '5', '2', '1', '.', '.', '4', '8', '3'], | | |||
551 | ['.', '.', '9', '.', '.', '4', '.', '1', '8'], | | |||
552 | ['.', '.', '.', '2', '.', '5', '3', '4', '.'], | | |||
553 | ['5', '.', '8', '.', '.', '.', '.', '6', '7'], | | |||
554 | ] | | |||
555 | ] | | |||
556 | ] | | |||
557 | | ||||
558 | var currentLevel = 0 | 25 | var currentLevel = 0 | ||
559 | var numberOfLevel = levels.length | 26 | var numberOfLevel | ||
560 | var items | 27 | var items | ||
561 | var symbolizeLevelMax = 7 // Last level in which we set symbols | 28 | var symbols | ||
shubhammishra: Previously hardcoded symbolizeLevelMax variable makes the first 7 levels to use symbols… | |||||
562 | | ||||
563 | var url = "qrc:/gcompris/src/activities/sudoku/resource/" | 29 | var url = "qrc:/gcompris/src/activities/sudoku/resource/" | ||
564 | 30 | | |||
565 | var symbols = [ | | |||
566 | {"imgName": "circle", "text": 'A', "extension": ".svg"}, | | |||
567 | {"imgName": "rectangle", "text": 'B', "extension": ".svg"}, | | |||
568 | {"imgName": "rhombus", "text": 'C', "extension": ".svg"}, | | |||
569 | {"imgName": "star", "text": 'D', "extension": ".svg"}, | | |||
570 | {"imgName": "triangle", "text": 'E', "extension": ".svg"} | | |||
571 | ] | | |||
572 | | ||||
573 | function start(items_) { | 31 | function start(items_) { | ||
574 | items = items_ | 32 | items = items_ | ||
575 | currentLevel = 0 | 33 | currentLevel = 0 | ||
576 | items.score.currentSubLevel = 1 | 34 | items.score.currentSubLevel = 1 | ||
577 | 35 | numberOfLevel = items.levels.length | |||
578 | // Shuffle all levels | 36 | // Shuffle all levels | ||
579 | for(var nb = 0 ; nb < levels.length ; ++ nb) { | 37 | for(var nb = 0 ; nb < items.levels.length ; ++ nb) { | ||
580 | Core.shuffle(levels[nb]); | 38 | Core.shuffle(items.levels[nb]["data"]); | ||
581 | } | | |||
582 | | ||||
583 | // Shuffle the symbols | | |||
584 | Core.shuffle(symbols); | | |||
585 | for(var s = 0 ; s < symbols.length ; ++ s) { | | |||
586 | // Change the letter | | |||
587 | symbols[s].text = String.fromCharCode('A'.charCodeAt() +s); | | |||
588 | } | 39 | } | ||
589 | 40 | | |||
590 | initLevel() | 41 | initLevel() | ||
591 | } | 42 | } | ||
592 | 43 | | |||
593 | function stop() { | 44 | function stop() { | ||
594 | } | 45 | } | ||
595 | 46 | | |||
596 | function initLevel() { | 47 | function initLevel() { | ||
597 | items.bar.level = currentLevel + 1; | 48 | items.bar.level = currentLevel + 1; | ||
598 | items.score.numberOfSubLevels = levels[currentLevel].length | 49 | items.score.numberOfSubLevels = items.levels[currentLevel]["data"].length | ||
50 | symbols = items.levels[currentLevel]["symbols"] | ||||
599 | 51 | | |||
600 | for(var i = items.availablePiecesModel.model.count-1 ; i >= 0 ; -- i) { | 52 | for(var i = items.availablePiecesModel.model.count-1 ; i >= 0 ; -- i) { | ||
601 | items.availablePiecesModel.model.remove(i); | 53 | items.availablePiecesModel.model.remove(i); | ||
602 | } | 54 | } | ||
603 | | ||||
604 | items.sudokuModel.clear(); | 55 | items.sudokuModel.clear(); | ||
605 | 56 | | |||
606 | // Copy current sudoku in local variable | 57 | // Copy current sudoku in local variable | ||
607 | var initialSudoku = levels[currentLevel][items.score.currentSubLevel-1]; | 58 | var initialSudoku = items.levels[currentLevel]["data"][items.score.currentSubLevel-1]; | ||
jjazeix: missing space | |||||
608 | 59 | | |||
609 | items.columns = initialSudoku.length | 60 | items.columns = initialSudoku.length | ||
610 | items.rows = items.columns | 61 | items.rows = items.columns | ||
611 | 62 | | |||
is there a preference for not setting it in the dataset directly instead of computing it when we initialize the level? jjazeix: is there a preference for not setting it in the dataset directly instead of computing it when… | |||||
It will cost us an extra variable in datasets for each level and then levels would not be simple arrays anymore but transform into maps and arrays and it's easy to compute it by code too, shubhammishra: It will cost us an extra variable in datasets for each level and then levels would not be… | |||||
We need to think on how we will allow teachers/users to create datasets (and if it makes sense for the activity). Then, for this activity specifically, we probably don't need it... jjazeix: We need to think on how we will allow teachers/users to create datasets (and if it makes sense… | |||||
612 | // Compute number of regions | 63 | // Compute number of regions | ||
613 | var nbLines = Math.floor(Math.sqrt(items.columns)); | 64 | var nbLines = Math.floor(Math.sqrt(items.columns)); | ||
614 | items.background.nbRegions = nbLines*nbLines == items.columns ? nbLines : 1; | 65 | items.background.nbRegions = (nbLines*nbLines == items.columns) ? nbLines : 1; | ||
jjazeix: please add parenthesis here to avoid confusion | |||||
615 | 66 | | |||
616 | // Create grid | 67 | // Create grid | ||
617 | for(var i = 0 ; i < initialSudoku.length ; ++ i) { | 68 | for(var i = 0 ; i < initialSudoku.length ; ++ i) { | ||
618 | var line = []; | 69 | var line = []; | ||
619 | for(var j = 0 ; j < initialSudoku[i].length ; ++ j) { | 70 | for(var j = 0 ; j < initialSudoku[i].length ; ++ j) { | ||
620 | items.sudokuModel.append({ | 71 | items.sudokuModel.append({ | ||
621 | 'textValue': initialSudoku[i][j], | 72 | 'textValue': initialSudoku[i][j], | ||
622 | 'initial': initialSudoku[i][j] != ".", | 73 | 'initial': initialSudoku[i][j] != ".", | ||
623 | 'mState': initialSudoku[i][j] != "." ? "initial" : "default", | 74 | 'mState': initialSudoku[i][j] != "." ? "initial" : "default", | ||
624 | }) | 75 | }) | ||
625 | } | 76 | } | ||
626 | } | 77 | } | ||
627 | 78 | | |||
628 | if(currentLevel < symbolizeLevelMax) { // Play with symbols | | |||
629 | // Randomize symbols | | |||
630 | for(var i = 0 ; i < symbols.length ; ++ i) { | 79 | for(var i = 0 ; i < symbols.length ; ++ i) { | ||
jjazeix: here it is always "undefined" | |||||
631 | for(var line = 0 ; line < items.sudokuModel.count ; ++ line) { | 80 | for(var line = 0 ; line < items.sudokuModel.count ; ++ line) { | ||
632 | if(items.sudokuModel.get(line).textValue == symbols[i].text) { | 81 | if(items.sudokuModel.get(line).textValue == symbols[i].text) { | ||
633 | items.availablePiecesModel.model.append(symbols[i]); | 82 | items.availablePiecesModel.model.append(symbols[i]); | ||
634 | break; // break to pass to the next symbol | 83 | break; // break to pass to the next symbol | ||
635 | } | 84 | } | ||
636 | } | 85 | } | ||
637 | } | 86 | } | ||
638 | } | 87 | | ||
639 | else { // Play with numbers | | |||
640 | for(var i = 1 ; i < items.columns+1 ; ++ i) { | | |||
641 | items.availablePiecesModel.model.append({"imgName": i.toString(), | | |||
642 | "text": i.toString(), | | |||
643 | "extension": ".svg"}); | | |||
644 | } | | |||
645 | } | | |||
646 | } | 88 | } | ||
647 | 89 | | |||
648 | function nextLevel() { | 90 | function nextLevel() { | ||
649 | items.score.currentSubLevel = 1 | 91 | items.score.currentSubLevel = 1 | ||
650 | if(numberOfLevel <= ++currentLevel) { | 92 | if(numberOfLevel <= ++currentLevel) { | ||
651 | currentLevel = 0 | 93 | currentLevel = 0 | ||
652 | } | 94 | } | ||
653 | initLevel(); | 95 | initLevel(); | ||
Here within qtcreator it gives a warning telling that we should use !== which makes more sens because we do no need to convert type. echarruau: Here within qtcreator it gives a warning telling that we should use !== which makes more sens… | |||||
jjazeix: yes, it would be better to have a strong comparison if QtCreator warns on it | |||||
654 | } | 96 | } | ||
jjazeix: missing spaces after = | |||||
655 | 97 | | |||
656 | function previousLevel() { | 98 | function previousLevel() { | ||
657 | items.score.currentSubLevel = 1 | 99 | items.score.currentSubLevel = 1 | ||
658 | if(--currentLevel < 0) { | 100 | if(--currentLevel < 0) { | ||
659 | currentLevel = numberOfLevel - 1 | 101 | currentLevel = numberOfLevel - 1 | ||
660 | } | 102 | } | ||
661 | initLevel(); | 103 | initLevel(); | ||
662 | } | 104 | } | ||
663 | 105 | | |||
664 | /* | 106 | /* | ||
665 | Code that increments the sublevel and level | 107 | Code that increments the sublevel and level | ||
666 | And bail out if no more levels are available | 108 | And bail out if no more levels are available | ||
667 | */ | 109 | */ | ||
668 | function incrementLevel() { | 110 | function incrementLevel() { | ||
669 | 111 | | |||
670 | items.score.currentSubLevel ++ | 112 | items.score.currentSubLevel ++ | ||
671 | 113 | | |||
672 | if(items.score.currentSubLevel > items.score.numberOfSubLevels) { | 114 | if(items.score.currentSubLevel > items.score.numberOfSubLevels) { | ||
673 | // Try the next level | 115 | // Try the next level | ||
674 | items.score.currentSubLevel = 1 | 116 | items.score.currentSubLevel = 1 | ||
675 | currentLevel ++ | 117 | currentLevel ++ | ||
676 | } | 118 | } | ||
677 | if(currentLevel > numberOfLevel) { | 119 | if(currentLevel >= numberOfLevel) { | ||
678 | currentLevel = numberOfLevel | 120 | currentLevel = 0 | ||
679 | } | 121 | } | ||
680 | initLevel(); | 122 | initLevel(); | ||
681 | } | 123 | } | ||
682 | 124 | | |||
683 | function clickOn(caseX, caseY) { | 125 | function clickOn(caseX, caseY) { | ||
684 | var initialSudoku = levels[currentLevel][items.score.currentSubLevel-1]; | 126 | var initialSudoku = items.levels[currentLevel]["data"][items.score.currentSubLevel-1]; | ||
685 | 127 | | |||
686 | var currentCase = caseX + caseY * initialSudoku.length; | 128 | var currentCase = caseX + caseY * initialSudoku.length; | ||
687 | 129 | | |||
688 | if(initialSudoku[caseY][caseX] == '.') { // Don't update fixed cases. | 130 | if(initialSudoku[caseY][caseX] == '.') { // Don't update fixed cases. | ||
689 | var currentSymbol = items.availablePiecesModel.model.get(items.availablePiecesModel.view.currentIndex); | 131 | var currentSymbol = items.availablePiecesModel.model.get(items.availablePiecesModel.view.currentIndex); | ||
690 | var isGood = isLegal(caseX, caseY, currentSymbol.text); | 132 | var isGood = isLegal(caseX, caseY, currentSymbol.text); | ||
691 | /* | 133 | /* | ||
692 | If current case is empty, we look if it is legal and put the symbol. | 134 | If current case is empty, we look if it is legal and put the symbol. | ||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Line(s) | |||||
796 | 238 | | |||
797 | function restoreState(mCase) { | 239 | function restoreState(mCase) { | ||
798 | items.sudokuModel.get(mCase.gridIndex).mState = mCase.isInitial ? "initial" : "default" | 240 | items.sudokuModel.get(mCase.gridIndex).mState = mCase.isInitial ? "initial" : "default" | ||
799 | } | 241 | } | ||
800 | 242 | | |||
801 | function dataToImageSource(data) { | 243 | function dataToImageSource(data) { | ||
802 | var imageName = ""; | 244 | var imageName = ""; | ||
803 | 245 | | |||
804 | if(currentLevel < symbolizeLevelMax) { // Play with symbols | | |||
805 | for(var i = 0 ; i < symbols.length ; ++ i) { | 246 | for(var i = 0 ; i < symbols.length ; ++ i) { | ||
806 | if(symbols[i].text == data) { | 247 | if(symbols[i].text == data) { | ||
807 | imageName = url + symbols[i].imgName+symbols[i].extension; | 248 | imageName = url + symbols[i].imgName; | ||
808 | break; | 249 | break; | ||
809 | } | 250 | } | ||
810 | } | 251 | } | ||
811 | } | | |||
812 | else { // numbers | | |||
813 | if(data != ".") { | | |||
814 | imageName = url+data+".svg"; | | |||
815 | } | | |||
816 | } | | |||
817 | 252 | | |||
818 | return imageName; | 253 | return imageName; | ||
819 | } | 254 | } | ||
820 | 255 | | |||
821 | function onKeyPressed(event) { | 256 | function onKeyPressed(event) { | ||
822 | var keyValue = -1; | 257 | var keyValue = -1; | ||
823 | switch(event.key) | 258 | switch(event.key) | ||
824 | { | 259 | { | ||
Show All 33 Lines |
Previously hardcoded symbolizeLevelMax variable makes the first 7 levels to use symbols, replaced it with symbolizeLevel variable, and added setSymbolizeLevel function which checks sudoku will form with symbols or numbers at each level.