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
1=== modified file 'components/SudokuBlocksGrid.qml'
2--- components/SudokuBlocksGrid.qml 2013-07-03 05:51:44 +0000
3+++ components/SudokuBlocksGrid.qml 2013-07-03 17:17:28 +0000
4@@ -145,7 +145,7 @@
5 print("Theme updated " + String(newColorScheme));
6 }
7
8- function createNewGame(difficulty) {
9+ function createNewGame(difficulty) {
10 for (var i = 0; i < 9; i++) {
11 for (var j = 0; j < 9; j++) {
12 /*if (i % 3 == 0 && i != 0 && !alreadyCreated)
13@@ -307,6 +307,7 @@
14 grid.setValue(column,row, 0);
15 buttonsGrid.itemAt(currentX).buttonColor = defaultColor;
16 buttonsGrid.itemAt(currentX).boldText = false;
17+ buttonsGrid.redrawGrid()
18 PopupUtils.close(dialogue)
19 }
20 }
21@@ -338,6 +339,7 @@
22
23 //print (row, column)
24 grid.setValue(column, row, index+1);
25+ /*
26 //print(grid)
27 var testField = grid.cellConflicts(column,row)
28 //print (testField)
29@@ -347,6 +349,8 @@
30 buttonsGrid.itemAt(currentX).buttonColor = defaultColor;
31 buttonsGrid.itemAt(currentX).boldText = false;
32 }
33+ */
34+ buttonsGrid.redrawGrid()
35
36 PopupUtils.close(dialogue)
37
38@@ -365,7 +369,8 @@
39 size: units.gu(5)
40 anchors.left: parent.left;
41 onTriggered: {
42- PopupUtils.close(dialogue)
43+ buttonsGrid.redrawGrid()
44+ PopupUtils.close(dialogue)
45 }
46 }
47
48
49=== modified file 'components/SudokuButtonsGrid.qml'
50--- components/SudokuButtonsGrid.qml 2013-07-01 11:02:52 +0000
51+++ components/SudokuButtonsGrid.qml 2013-07-03 17:17:28 +0000
52@@ -10,6 +10,33 @@
53 model: 81
54 objectName: "buttonsGrid";
55
56+ function redrawGrid()
57+ {
58+ console.log("on redraw grid")
59+ for(var i=0; i < model; i++)
60+ {
61+ var row = Math.floor(i/9);
62+ var column = i%9;
63+
64+
65+ if(buttonsGrid.itemAt(i).enabled)
66+ {
67+ var testField = grid.cellConflicts(column,row)
68+ //print (testField)
69+
70+ if (testField == true)
71+ {
72+ console.log("index "+i+" row/col "+row+"/"+column)
73+ buttonsGrid.itemAt(i).buttonColor = defaultNotAllowedColor;
74+ }
75+ else {
76+ buttonsGrid.itemAt(i).buttonColor = defaultColor;
77+ buttonsGrid.itemAt(currentX).boldText = false;
78+ }
79+ }
80+ }
81+ }
82+
83 SudokuButton {
84 id: gridButton;
85 buttonText: "0";
86
87=== modified file 'js/SudokuCU.js'
88--- js/SudokuCU.js 2013-07-01 11:02:52 +0000
89+++ js/SudokuCU.js 2013-07-03 17:17:28 +0000
90@@ -159,21 +159,26 @@
91 if(value == 0)
92 return false;
93
94+ console.log("test for "+value)
95 for(var i = 0; i < 9; i++)
96 {
97+ console.log("test with col"+this.rows[i][column])
98 if(i != row && this.rows[i][column] == value)
99 {
100+ console.log("find row")
101 return true;
102 }
103
104+ // console.log("test with row"+this.rows[row][i])
105 if(i != column && this.rows[row][i] == value)
106 {
107+ console.log("find col")
108 return true;
109 }
110 }
111-
112+ console.log("ok cellconflicts")
113 //At this point, everything else is checked as valid except the 3x3 grid
114- return !this._miniGridValid(column, row);
115+ return !this._miniGridValidFor(column, row, value);
116 },
117
118 /**
119@@ -204,9 +209,54 @@
120 if(value == 0)
121 continue;
122
123- //if(App.Utils.arrayContains(numbers, value))
124- // return false;
125- if (numbers.indexOf(value) != -1)
126+ console.log("test minigrid "+value)
127+
128+ //if(App.Utils.arrayContains(numbers, value))
129+ // return false;
130+ if (numbers.indexOf(value) != -1 )
131+ return false;
132+
133+ numbers.push(value);
134+ }
135+ }
136+
137+ return true;
138+ },
139+
140+ /**
141+ * Checks if the inner 3x3 grid a cell resides in is valid for a specific value
142+ * @method
143+ * @private
144+ * @param {Number} column
145+ * @param {Number} row
146+ * @param {Number} value to test
147+ * @return {Boolean}
148+ */
149+ _miniGridValidFor: function(column, row, val) {
150+ //Determine 3x3 grid position
151+ var mgX = Math.floor(column / 3);
152+ var mgY = Math.floor(row / 3);
153+
154+ var startCol = mgX * 3;
155+ var startRow = mgY * 3;
156+
157+ var endCol = (mgX + 1) * 3;
158+ var endRow = (mgY + 1) * 3;
159+
160+ var numbers = [];
161+ for(var r = startRow; r < endRow; r++)
162+ {
163+ for(var c = startCol; c < endCol; c++)
164+ {
165+ var value = this.rows[r][c];
166+ if(value == 0)
167+ continue;
168+
169+ console.log("test minigrid "+value)
170+
171+ //if(App.Utils.arrayContains(numbers, value))
172+ // return false;
173+ if (numbers.indexOf(value) != -1 && value == val)
174 return false;
175
176 numbers.push(value);

Subscribers

People subscribed via source and target branches