@@ -8,12 +8,15 @@ 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
+
11
12
var cycleCount = 0 ;
12
13
var cycleCountLimit = 6 ;
13
14
var masterCycleCount = 0 ;
14
15
var masterCycleCountLimit = 15 ;
16
+
15
17
var arrayDepot = [ ] ;
16
18
var arrayDepotIndex = 0 ;
19
+
17
20
var iterateControl = [ ' ' ] ;
18
21
19
22
var doneArray ; //to pass from findOptions to logSingleton
@@ -33,10 +36,9 @@ function findOptions(fullArray){
33
36
34
37
return }
35
38
for ( row = 0 ; row < 9 ; row ++ ) {
36
- for ( col = 0 ; col < 9 ; col ++ ) {
37
-
39
+ for ( col = 0 ; col < 9 ; col ++ ) {
38
40
if ( fullArray [ row ] [ col ] . value === null ) {
39
- solvedSquares = 1 ;
41
+ solvedSquares = 1 ;
40
42
checkRow ( row , col , fullArray ) ; //assemble and return possible values
41
43
checkCol ( row , col , fullArray ) ; //assemble and return possible values
42
44
temprow = row + 1 ;
@@ -54,10 +56,54 @@ function findOptions(fullArray){
54
56
console . log ( 'cycle count: ' + cycleCount ) ;
55
57
console . log ( 'array depot index: ' + arrayDepotIndex ) ;
56
58
console . log ( 'array depot length ' + arrayDepot . length )
57
- insertSingletonValues ( fullArray ) ;
58
-
59
+ //insertSingletonValues(fullArray);
60
+ insertSingletonValue ( fullArray ) ; //insert ONLY ONE value
61
+
59
62
} ;
60
63
64
+ //Inserts only one singleton value prior to recalculation
65
+ function insertSingletonValue ( fullArray ) {
66
+ var possibleLengths = 0 ;
67
+ var row , col ;
68
+ cycleCount = cycleCount + 1 ;
69
+
70
+ if ( cycleCount === cycleCountLimit ) {
71
+ cycleCount = 0 ;
72
+ console . log ( 'calling findOptions from arrayDepot' )
73
+
74
+ arrayDepotIndex = arrayDepotIndex + 1 ;
75
+ var arrayToPass = arrayDepotIndex - 1 ;
76
+ buildPrinterString ( arrayDepot [ arrayToPass ] ) ;
77
+ findOptions ( arrayDepot [ arrayToPass ] ) ;
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
+
94
+ findOptions ( fullArray ) ;
95
+
96
+
97
+ }
98
+ }
99
+ }
100
+ if ( possibleLengths === 0 ) {
101
+ console . log ( 'NO NEW POSSIBLES ARRAYS WITH A LENGTH OF 1' ) ;
102
+ buildPrinterString ( fullArray ) ;
103
+ insertDupleValues ( fullArray ) ;
104
+ }
105
+ } ;
106
+ //inserts all singleton values prior to recalculation?
61
107
function insertSingletonValues ( fullArray ) {
62
108
var possibleLengths = 0 ;
63
109
var row , col ;
@@ -78,6 +124,8 @@ function insertSingletonValues(fullArray){
78
124
possibleLengths = 1 ;
79
125
fullArray [ row ] [ col ] . value = fullArray [ row ] [ col ] . possibles [ 0 ] ;
80
126
console . log ( 'Singleton assigned at: ' + ( col + 1 ) + ', ' + ( 9 - row ) ) ;
127
+ console . log ( 'Block is: ' + fullArray [ row ] [ col ] . block ) ;
128
+ console . log ( 'Possibles Array for location is ' + fullArray [ row ] [ col ] . possibles [ 0 ] ) ;
81
129
buildPrinterString ( fullArray ) ;
82
130
}
83
131
}
@@ -90,6 +138,10 @@ function insertSingletonValues(fullArray){
90
138
findOptions ( fullArray ) ;
91
139
} ;
92
140
141
+
142
+
143
+
144
+
93
145
function insertDupleValues ( fullArray ) {
94
146
for ( row = 0 ; row < 9 ; row ++ ) {
95
147
for ( col = 0 ; col < 9 ; col ++ ) {
0 commit comments