@@ -8,11 +8,12 @@ var checkBlock = require('./checkBlock.js');
8
8
var printer = require ( './boardprinter.js' ) ;
9
9
var boardString = "8 2 5 97 4 25 1 9 2 7 96 3 1 52 6 1 8 4 73 7 65 3 8 9"
10
10
var boardArray = boardString . split ( '' ) ;
11
-
12
- var cycleCount = 0 ;
13
- var cycleCountLimit = 20 ;
11
+
12
+ var cycleCount = 0 ;
13
+ var cycleCountLimit = 50 ;
14
14
var masterCycleCount = 0 ;
15
- var masterCycleCountLimit = 200 ;
15
+ var masterCycleCountLimit = 1000 ;
16
+
16
17
var arrayDepot = [ ] ;
17
18
var arrayDepotIndex = 0 ;
18
19
@@ -31,8 +32,9 @@ function findOptions(fullArray){
31
32
var solvedSquares = 0 ;
32
33
masterCycleCount = masterCycleCount + 1 ;
33
34
if ( masterCycleCount >= masterCycleCountLimit ) {
34
- return console . log ( 'Master Cycle Limit Exceeded' ) ;
35
- }
35
+ console . log ( 'Master Cycle Limit Exceeded' ) ;
36
+
37
+ return }
36
38
for ( row = 0 ; row < 9 ; row ++ ) {
37
39
for ( col = 0 ; col < 9 ; col ++ ) {
38
40
if ( fullArray [ row ] [ col ] . value === null ) {
@@ -68,81 +70,11 @@ function insertSingletonValue(fullArray){
68
70
if ( cycleCount === cycleCountLimit ) {
69
71
cycleCount = 0 ;
70
72
console . log ( 'calling findOptions from arrayDepot' )
71
-
72
73
arrayDepotIndex = arrayDepotIndex + 1 ;
73
- var arrayToPass = arrayDepotIndex - 1 ;
74
- buildPrinterString ( arrayDepot [ arrayToPass ] ) ;
75
- findOptions ( arrayDepot [ arrayToPass ] ) ;
76
- return ;
77
-
78
-
79
- } ;
80
-
81
- for ( row = 0 ; row < 9 ; row ++ ) {
82
- for ( col = 0 ; col < 9 ; col ++ ) {
83
- if ( fullArray [ row ] [ col ] . possibles . length === 1 && fullArray [ row ] [ col ] . value === null ) {
84
- possibleLengths = 1 ;
85
- fullArray [ row ] [ col ] . value = fullArray [ row ] [ col ] . possibles [ 0 ] ;
86
- console . log ( 'Singleton assigned at: ' + ( col + 1 ) + ', ' + ( 9 - row ) ) ;
87
- console . log ( 'Block is: ' + fullArray [ row ] [ col ] . block ) ;
88
- console . log ( 'Possibles Array for location is ' + fullArray [ row ] [ col ] . possibles [ 0 ] ) ;
89
- buildPrinterString ( fullArray ) ;
90
-
91
-
92
- //after finding ONE singleton, display something
93
- if ( possibleLengths === 0 ) {
94
- console . log ( 'NO NEW POSSIBLES ARRAYS WITH A LENGTH OF 1' ) ;
95
- buildPrinterString ( fullArray ) ;
96
- insertDupleValues ( fullArray ) ;
97
- }
98
-
99
- //after finding ONE singleton, find new options
100
- console . log ( "Calling findOptions after one singleton possibles added." )
101
- findOptions ( fullArray ) ;
102
74
75
+ buildPrinterString ( arrayDepot [ 0 ] ) ;
76
+ findOptions ( arrayDepot . shift ( ) ) ;
103
77
104
- }
105
- //solve for possibles array length of 2
106
- else if ( fullArray [ row ] [ col ] . possibles . length === 2 && fullArray [ row ] [ col ] . value === null ) {
107
-
108
- //insert the first value of the 2 possibles
109
- fullArray [ row ] [ col ] . value = fullArray [ row ] [ col ] . possibles [ 0 ] ;
110
- console . log ( 'Possibles=Two - Solving for Position Zero ' ) ;
111
- console . log ( 'Singleton assigned at: ' + ( col + 1 ) + ', ' + ( 9 - row ) ) ;
112
- console . log ( 'Block is: ' + fullArray [ row ] [ col ] . block ) ;
113
- console . log ( 'Possibles Array for location is ' + fullArray [ row ] [ col ] . possibles [ 0 ] +
114
- " and " + fullArray [ row ] [ col ] . possibles [ 1 ] ) ;
115
- buildPrinterString ( fullArray ) ;
116
-
117
- console . log ( "Calling findOptions after one singleton possibles added." )
118
- findOptions ( fullArray ) ;
119
- }
120
-
121
-
122
- }
123
- }
124
-
125
-
126
- } ;
127
-
128
-
129
- //inserts all singleton values prior to recalculation?
130
- function insertSingletonValues ( fullArray ) {
131
- var possibleLengths = 0 ;
132
- var row , col ;
133
- cycleCount = cycleCount + 1 ;
134
-
135
- if ( cycleCount === cycleCountLimit ) {
136
- cycleCount = 0 ;
137
- console . log ( 'calling findOptions from arrayDepot' )
138
-
139
- arrayDepotIndex = arrayDepotIndex + 1 ;
140
- var arrayToPass = arrayDepotIndex - 1 ;
141
- buildPrinterString ( arrayDepot [ arrayToPass ] ) ;
142
- findOptions ( arrayDepot [ arrayToPass ] ) ;
143
- return ;
144
-
145
-
146
78
} ;
147
79
148
80
for ( row = 0 ; row < 9 ; row ++ ) {
@@ -154,6 +86,7 @@ function insertSingletonValues(fullArray){
154
86
console . log ( 'Block is: ' + fullArray [ row ] [ col ] . block ) ;
155
87
console . log ( 'Possibles Array for location is ' + fullArray [ row ] [ col ] . possibles [ 0 ] ) ;
156
88
buildPrinterString ( fullArray ) ;
89
+ findOptions ( fullArray ) ;
157
90
}
158
91
}
159
92
}
@@ -162,25 +95,26 @@ function insertSingletonValues(fullArray){
162
95
buildPrinterString ( fullArray ) ;
163
96
insertDupleValues ( fullArray ) ;
164
97
}
165
- findOptions ( fullArray ) ;
166
98
} ;
167
99
168
-
169
-
170
-
171
-
172
100
function insertDupleValues ( fullArray ) {
173
101
for ( row = 0 ; row < 9 ; row ++ ) {
174
102
for ( col = 0 ; col < 9 ; col ++ ) {
175
103
if ( fullArray [ row ] [ col ] . possibles . length === 2 && fullArray [ row ] [ col ] . value === null ) {
176
- fullArray [ row ] [ col ] . value = fullArray [ row ] [ col ] . possibles [ 1 ] ;
177
- arrayDepot . push ( fullArray ) ;
104
+
105
+ //clone fullArray
106
+ var secondChoice = clone ( fullArray ) ;
107
+ //set secondchoice value to SECOND possibility
108
+ secondChoice [ row ] [ col ] . value = secondChoice [ row ] [ col ] . possibles [ 1 ] ;
109
+ //send full Array clone to arrayDepot
110
+ arrayDepot . push ( secondChoice ) ;
111
+ //set fullArray value to FIRST possibility
178
112
fullArray [ row ] [ col ] . value = fullArray [ row ] [ col ] . possibles [ 0 ] ;
179
113
console . log ( 'duple assigned at ' + ( col + 1 ) + ', ' + ( 9 - row ) ) ;
180
114
buildPrinterString ( fullArray ) ;
115
+ console . log ( 'Other dupel possible ' ) ;
116
+ buildPrinterString ( arrayDepot [ arrayDepot . length - 1 ] ) ;
181
117
findOptions ( fullArray ) ;
182
-
183
- return ;
184
118
}
185
119
}
186
120
}
@@ -242,3 +176,16 @@ function boxDeletePossibles(possiblesList, callback){
242
176
} )
243
177
} ;
244
178
179
+ function clone ( existingArray ) {
180
+ var newObj = ( existingArray instanceof Array ) ? [ ] : { } ;
181
+ for ( i in existingArray ) {
182
+ if ( i == 'clone' ) continue ;
183
+ if ( existingArray [ i ] && typeof existingArray [ i ] == "object" ) {
184
+ newObj [ i ] = clone ( existingArray [ i ] ) ;
185
+ } else {
186
+ newObj [ i ] = existingArray [ i ]
187
+ }
188
+ }
189
+ return newObj ;
190
+ }
191
+
0 commit comments