Merge lp:~fredoust/sudoku-app/fix-bug-1196468 into lp:sudoku-app

Proposed by Frédéric Delgado
Status: Merged
Approved by: Dinko Osmankovic
Approved revision: 58
Merged at revision: 57
Proposed branch: lp:~fredoust/sudoku-app/fix-bug-1196468
Merge into: lp:sudoku-app
Diff against target: 176 lines (+89/-7)
3 files modified
components/SudokuBlocksGrid.qml (+7/-2)
components/SudokuButtonsGrid.qml (+27/-0)
js/SudokuCU.js (+55/-5)
To merge this branch: bzr merge lp:~fredoust/sudoku-app/fix-bug-1196468
Reviewer Review Type Date Requested Status
Dinko Osmankovic Approve
Review via email: mp+172862@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Dinko Osmankovic (dinko-metalac) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'components/SudokuBlocksGrid.qml'
--- components/SudokuBlocksGrid.qml 2013-07-03 05:51:44 +0000
+++ components/SudokuBlocksGrid.qml 2013-07-03 17:17:28 +0000
@@ -145,7 +145,7 @@
145 print("Theme updated " + String(newColorScheme));145 print("Theme updated " + String(newColorScheme));
146 }146 }
147147
148 function createNewGame(difficulty) { 148 function createNewGame(difficulty) {
149 for (var i = 0; i < 9; i++) {149 for (var i = 0; i < 9; i++) {
150 for (var j = 0; j < 9; j++) {150 for (var j = 0; j < 9; j++) {
151 /*if (i % 3 == 0 && i != 0 && !alreadyCreated)151 /*if (i % 3 == 0 && i != 0 && !alreadyCreated)
@@ -307,6 +307,7 @@
307 grid.setValue(column,row, 0);307 grid.setValue(column,row, 0);
308 buttonsGrid.itemAt(currentX).buttonColor = defaultColor;308 buttonsGrid.itemAt(currentX).buttonColor = defaultColor;
309 buttonsGrid.itemAt(currentX).boldText = false;309 buttonsGrid.itemAt(currentX).boldText = false;
310 buttonsGrid.redrawGrid()
310 PopupUtils.close(dialogue)311 PopupUtils.close(dialogue)
311 }312 }
312 }313 }
@@ -338,6 +339,7 @@
338339
339 //print (row, column)340 //print (row, column)
340 grid.setValue(column, row, index+1);341 grid.setValue(column, row, index+1);
342 /*
341 //print(grid)343 //print(grid)
342 var testField = grid.cellConflicts(column,row)344 var testField = grid.cellConflicts(column,row)
343 //print (testField)345 //print (testField)
@@ -347,6 +349,8 @@
347 buttonsGrid.itemAt(currentX).buttonColor = defaultColor;349 buttonsGrid.itemAt(currentX).buttonColor = defaultColor;
348 buttonsGrid.itemAt(currentX).boldText = false;350 buttonsGrid.itemAt(currentX).boldText = false;
349 }351 }
352 */
353 buttonsGrid.redrawGrid()
350354
351 PopupUtils.close(dialogue)355 PopupUtils.close(dialogue)
352356
@@ -365,7 +369,8 @@
365 size: units.gu(5)369 size: units.gu(5)
366 anchors.left: parent.left;370 anchors.left: parent.left;
367 onTriggered: {371 onTriggered: {
368 PopupUtils.close(dialogue)372 buttonsGrid.redrawGrid()
373 PopupUtils.close(dialogue)
369 }374 }
370 }375 }
371376
372377
=== modified file 'components/SudokuButtonsGrid.qml'
--- components/SudokuButtonsGrid.qml 2013-07-01 11:02:52 +0000
+++ components/SudokuButtonsGrid.qml 2013-07-03 17:17:28 +0000
@@ -10,6 +10,33 @@
10 model: 8110 model: 81
11 objectName: "buttonsGrid";11 objectName: "buttonsGrid";
1212
13 function redrawGrid()
14 {
15 console.log("on redraw grid")
16 for(var i=0; i < model; i++)
17 {
18 var row = Math.floor(i/9);
19 var column = i%9;
20
21
22 if(buttonsGrid.itemAt(i).enabled)
23 {
24 var testField = grid.cellConflicts(column,row)
25 //print (testField)
26
27 if (testField == true)
28 {
29 console.log("index "+i+" row/col "+row+"/"+column)
30 buttonsGrid.itemAt(i).buttonColor = defaultNotAllowedColor;
31 }
32 else {
33 buttonsGrid.itemAt(i).buttonColor = defaultColor;
34 buttonsGrid.itemAt(currentX).boldText = false;
35 }
36 }
37 }
38 }
39
13 SudokuButton {40 SudokuButton {
14 id: gridButton;41 id: gridButton;
15 buttonText: "0";42 buttonText: "0";
1643
=== modified file 'js/SudokuCU.js'
--- js/SudokuCU.js 2013-07-01 11:02:52 +0000
+++ js/SudokuCU.js 2013-07-03 17:17:28 +0000
@@ -159,21 +159,26 @@
159 if(value == 0)159 if(value == 0)
160 return false;160 return false;
161161
162 console.log("test for "+value)
162 for(var i = 0; i < 9; i++)163 for(var i = 0; i < 9; i++)
163 {164 {
165 console.log("test with col"+this.rows[i][column])
164 if(i != row && this.rows[i][column] == value)166 if(i != row && this.rows[i][column] == value)
165 {167 {
168 console.log("find row")
166 return true;169 return true;
167 }170 }
168171
172 // console.log("test with row"+this.rows[row][i])
169 if(i != column && this.rows[row][i] == value)173 if(i != column && this.rows[row][i] == value)
170 {174 {
175 console.log("find col")
171 return true;176 return true;
172 }177 }
173 }178 }
174179 console.log("ok cellconflicts")
175 //At this point, everything else is checked as valid except the 3x3 grid180 //At this point, everything else is checked as valid except the 3x3 grid
176 return !this._miniGridValid(column, row);181 return !this._miniGridValidFor(column, row, value);
177 },182 },
178183
179 /**184 /**
@@ -204,9 +209,54 @@
204 if(value == 0)209 if(value == 0)
205 continue;210 continue;
206211
207 //if(App.Utils.arrayContains(numbers, value))212 console.log("test minigrid "+value)
208 // return false;213
209 if (numbers.indexOf(value) != -1)214 //if(App.Utils.arrayContains(numbers, value))
215 // return false;
216 if (numbers.indexOf(value) != -1 )
217 return false;
218
219 numbers.push(value);
220 }
221 }
222
223 return true;
224 },
225
226 /**
227 * Checks if the inner 3x3 grid a cell resides in is valid for a specific value
228 * @method
229 * @private
230 * @param {Number} column
231 * @param {Number} row
232 * @param {Number} value to test
233 * @return {Boolean}
234 */
235 _miniGridValidFor: function(column, row, val) {
236 //Determine 3x3 grid position
237 var mgX = Math.floor(column / 3);
238 var mgY = Math.floor(row / 3);
239
240 var startCol = mgX * 3;
241 var startRow = mgY * 3;
242
243 var endCol = (mgX + 1) * 3;
244 var endRow = (mgY + 1) * 3;
245
246 var numbers = [];
247 for(var r = startRow; r < endRow; r++)
248 {
249 for(var c = startCol; c < endCol; c++)
250 {
251 var value = this.rows[r][c];
252 if(value == 0)
253 continue;
254
255 console.log("test minigrid "+value)
256
257 //if(App.Utils.arrayContains(numbers, value))
258 // return false;
259 if (numbers.indexOf(value) != -1 && value == val)
210 return false;260 return false;
211261
212 numbers.push(value);262 numbers.push(value);

Subscribers

People subscribed via source and target branches