sudoku breaker-.net edition
Deducer class:
puzzleCS.aspx.cs:
puzzleCS.aspx
puzzleVB.aspx.vb:
puzzleVB.aspx:
1using System;
2using System.Data;
3using System.Configuration;
4using System.Web;
5using System.Web.Security;
6using System.Web.UI;
7using System.Web.UI.WebControls;
8using System.Web.UI.WebControls.WebParts;
9using System.Web.UI.HtmlControls;
10
11/// <summary>
12/// Summary description for Deducer
13/// </summary>
14public class Deducer
15{
16 private int[,] _array;
17 public Deducer(int[,] array)
18 {
19 this.Array = new int[9, 9];
20 for (int row = 0; row < 9; row++)
21 {
22 for (int column = 0; column < 9; column++)
23 {
24 this.Array[row, column] = array[row, column];
25 }
26 }
27 }
28 private bool IsFinished()
29 {
30 for (int row = 0; row < 9; row++)
31 {
32 for (int column = 0; column < 9; column++)
33 {
34 if (this.Array[row, column] == 0)
35 {
36 return false;
37 }
38 }
39 }
40 return true;
41 }
42 public void DeduceAll()
43 {
44 if (IsFinished())
45 {
46 return;
47 }
48 for (int row = 0; row < 7; row = row + 3)
49 {
50 for (int column = 0; column < 7; column = column + 3)
51 {
52 if (ReduceFromOneZone(this.Array, row, column))
53 {
54 DeduceAll();
55 return;
56 }
57 }
58 }
59 for (int row = 0; row < 9; row++)
60 {
61 if (ReduceFromOneRow(this.Array, row))
62 {
63 DeduceAll();
64 return;
65 }
66 }
67 for (int column = 0; column < 9; column++)
68 {
69 if (ReduceFromOneColumn(this.Array, column))
70 {
71 DeduceAll();
72 return;
73 }
74 }
75 for (int row = 0; row < 7; row = row + 3)
76 {
77 if (ReduceFromThreeRows(this.Array, row, row + 2))
78 {
79 DeduceAll();
80 return;
81 }
82 }
83 for (int column = 0; column < 7; column = column + 3)
84 {
85 if (ReduceFromThreeColumns(this.Array, column, column + 2))
86 {
87 DeduceAll();
88 return;
89 }
90 }
91 }
92 public void DeduceOnce()
93 {
94 for (int row = 0; row < 7; row = row + 3)
95 {
96 for (int column = 0; column < 7; column = column + 3)
97 {
98 if (ReduceFromOneZone(this.Array, row, column))
99 {
100 return;
101 }
102 }
103 }
104 for (int row = 0; row < 9; row++)
105 {
106 if (ReduceFromOneRow(this.Array, row))
107 {
108 return;
109 }
110 }
111 for (int column = 0; column < 9; column++)
112 {
113 if (ReduceFromOneColumn(this.Array, column))
114 {
115 return;
116 }
117 }
118 for (int row = 0; row < 7; row = row + 3)
119 {
120 if (ReduceFromThreeRows(this.Array, row, row + 2))
121 {
122 return;
123 }
124 }
125 for (int column = 0; column < 7; column = column + 3)
126 {
127 if (ReduceFromThreeColumns(this.Array, column, column + 2))
128 {
129 return;
130 }
131 }
132 }
133 private bool ReduceFromOneZone(int[,] array, int row, int column)
134 {
135 int startRow = (row / 3) * 3;
136 int startColumn = (column / 3) * 3;
137 int[] unknown = new int[9];
138 for (int pointer = 0; pointer < 9; pointer++)
139 {
140 unknown[pointer] = pointer + 1;
141 }
142 for (int rowPointer = startRow; rowPointer < startRow + 3; rowPointer++)
143 {
144 for (int columnPointer = startColumn; columnPointer < startColumn + 3; columnPointer++)
145 {
146 if (array[rowPointer, columnPointer] != 0)
147 {
148 unknown[array[rowPointer, columnPointer] - 1] = 0;
149 }
150 }
151 }
152 for (int digit = 0; digit < 9; digit++)
153 {
154 if (unknown[digit] != 0)
155 {
156 int number = unknown[digit];
157 int posibilities = 0;
158 int rowPosition = -1;
159 int columnPosition = -1;
160 for (int rowPointer = startRow; rowPointer < startRow + 3; rowPointer++)
161 {
162 for (int columnPointer = startColumn; columnPointer < startColumn + 3; columnPointer++)
163 {
164 if (array[rowPointer, columnPointer] == 0)
165 {
166 if (IsPossibleInThatCellCheckByColumn(array, number,
167 rowPointer, columnPointer)
168 && IsPossibleInThatCellCheckByRow(array,
169 number, rowPointer, columnPointer))
170 {
171 rowPosition = rowPointer;
172 columnPosition = columnPointer;
173 posibilities++;
174 }
175 }
176 }
177 }
178 if (posibilities == 1)
179 {
180 array[rowPosition, columnPosition] = number;
181 return true;
182 }
183 }
184 }
185 return false;
186 }
187 private bool ReduceFromOneRow(int[,] array, int row)
188 {
189 int[] unknown = new int[9];
190 for (int column = 0; column < 9; column++)
191 {
192 unknown[column] = column + 1;
193 }
194 for (int column = 0; column < 9; column++)
195 {
196 if (array[row, column] != 0)
197 {
198 unknown[array[row, column] - 1] = 0;
199 }
200 }
201 for (int column = 0; column < 9; column++)
202 {
203 if (unknown[column] != 0)
204 {
205 int number = unknown[column];
206 int posibilities = 0;
207 int position = -1;
208 for (int pointer = 0; pointer < 9; pointer++)
209 {
210 if (array[row, pointer] == 0)
211 {
212 if (IsPossibleInThatCellCheckByColumnAndZone(array,
213 number, row, pointer))
214 {
215 position = pointer;
216 posibilities++;
217 }
218 }
219 }
220 if (posibilities == 1)
221 {
222 array[row, position] = number;
223 return true;
224 }
225 }
226 }
227 return false;
228 }
229 private bool ReduceFromOneColumn(int[,] array, int column)
230 {
231 int[] unknown = new int[9];
232 for (int row = 0; row < 9; row++)
233 {
234 unknown[row] = row + 1;
235 }
236 for (int row = 0; row < 9; row++)
237 {
238 if (array[row, column] != 0)
239 {
240 unknown[array[row, column] - 1] = 0;
241 }
242 }
243 for (int row = 0; row < 9; row++)
244 {
245 if (unknown[row] != 0)
246 {
247 int number = unknown[row];
248 int posibilities = 0;
249 int position = -1;
250 for (int pointer = 0; pointer < 9; pointer++)
251 {
252 if (array[pointer, column] == 0)
253 {
254 if (IsPossibleInThatCellCheckByRowAndZone(array, number,
255 pointer, column))
256 {
257 position = pointer;
258 posibilities++;
259 }
260 }
261 }
262 if (posibilities == 1)
263 {
264 array[position, column] = number;
265 return true;
266 }
267 }
268 }
269 return false;
270 }
271 private bool IsPossibleInThatCellCheckByRowAndZone(int[,] array,
272 int number, int row, int column)
273 {
274 if (!IsPossibleInThatCellCheckByRow(array, number, row, column))
275 {
276 return false;
277 }
278 else if (!IsPossibleInThatCellCheckByZone(array, number, row, column))
279 {
280 return false;
281 }
282 else if (!CanBeInThatZoneCheckByColumn(array, number, row, column))
283 {
284 return false;
285 }
286 else
287 {
288 return true;
289 }
290 }
291 private bool IsPossibleInThatCellCheckByColumnAndZone(int[,] array,
292 int number, int row, int column)
293 {
294 if (!IsPossibleInThatCellCheckByColumn(array, number, row, column))
295 {
296 return false;
297 }
298 else if (!IsPossibleInThatCellCheckByZone(array, number, row, column))
299 {
300 return false;
301 }
302 else if (!CanBeInThatZoneCheckByRow(array, number, row, column))
303 {
304 return false;
305 }
306 else
307 {
308 return true;
309 }
310 }
311 private bool CanBeInThatZoneCheckByRow(int[,] array, int number,
312 int row, int column)
313 {
314 int startRow = (row / 3) * 3;
315 int startColumn = (column / 3) * 3;
316 for (int rowPointer = startRow; rowPointer < startRow + 3; rowPointer++)
317 {
318 if (rowPointer != row)
319 {
320 if (!IsPossibleInThatCellCheckByRow(array, number, rowPointer,
321 column))
322 {
323 continue;
324 }
325 bool canItBe = true;
326 for (int columnPointer = 0; columnPointer < 9; columnPointer++)
327 {
328 if (columnPointer < startColumn
329 || columnPointer > startColumn + 2)
330 {
331 if (array[rowPointer, columnPointer] == 0)
332 {
333 if (IsPossibleInThatCellCheckByColumn(array, number,
334 rowPointer, columnPointer)
335 && IsPossibleInThatCellCheckByZone(array,
336 number, rowPointer, columnPointer))
337 {
338 canItBe = false;
339 }
340 }
341 }
342 }
343 if (canItBe)
344 {
345 return false;
346 }
347 }
348 }
349 return true;
350 }
351 private bool CanBeInThatZoneCheckByColumn(int[,] array, int number,
352 int row, int column)
353 {
354 int startRow = (row / 3) * 3;
355 int startColumn = (column / 3) * 3;
356 for (int columnPointer = startColumn; columnPointer < startColumn + 3; columnPointer++)
357 {
358 if (columnPointer != column)
359 {
360 if (!IsPossibleInThatCellCheckByColumn(array, number, row,
361 columnPointer))
362 {
363 continue;
364 }
365 bool canItBe = true;
366 for (int rowPointer = 0; rowPointer < 9; rowPointer++)
367 {
368 if (rowPointer < startRow || rowPointer > startRow + 2)
369 {
370 if (array[rowPointer, columnPointer] == 0)
371 {
372 if (IsPossibleInThatCellCheckByRow(array, number,
373 rowPointer, columnPointer)
374 && IsPossibleInThatCellCheckByZone(array,
375 number, rowPointer, columnPointer))
376 {
377 canItBe = false;
378 }
379 }
380 }
381 }
382 if (canItBe)
383 {
384 return false;
385 }
386 }
387 }
388 return true;
389 }
390 private bool IsPossibleInThatCellCheckByZone(int[,] array, int number,
391 int row, int column)
392 {
393 int startRow = (row / 3) * 3;
394 int startColumn = (column / 3) * 3;
395 for (int rowPointer = startRow; rowPointer < startRow + 3; rowPointer++)
396 {
397 for (int columnPointer = startColumn; columnPointer < startColumn + 3; columnPointer++)
398 {
399 if (array[rowPointer, columnPointer] == number)
400 {
401 return false;
402 }
403 }
404 }
405 return true;
406 }
407 private bool ReduceFromThreeColumns(int[,] array, int firstColumn,
408 int lastColumn)
409 {
410 int[,] numberAndCount = new int[9, 2];
411 int[,] numberAndPosition = new int[27, 3];
412 for (int row = 0; row < 9; row++)
413 {
414 numberAndCount[row, 0] = row + 1;
415 numberAndCount[row, 1] = 0;
416 }
417 for (int row = 0; row < 27; row++)
418 {
419 for (int column = 0; column < 3; column++)
420 {
421 numberAndPosition[row, column] = 0;
422 }
423 }
424 for (int column = firstColumn; column <= lastColumn; column++)
425 {
426 for (int row = 0; row < 9; row++)
427 {
428 if (array[row, column] != 0)
429 {
430 numberAndCount[array[row, column] - 1, 1]++;
431 numberAndPosition[9 * (column % 3) + row, 0] = array[row, column];
432 numberAndPosition[9 * (column % 3) + row, 1] = row;
433 numberAndPosition[9 * (column % 3) + row, 2] = column;
434 }
435 }
436 }
437 for (int row = 0; row < 9; row++)
438 {
439 if (numberAndCount[row, 1] == 2)
440 {
441 int number = numberAndCount[row, 0];
442 int pointer = 0;
443 int firstAppearanceRowPosition = -1;
444 int firstAppearanceColumnPosition = -1;
445 int secondAppearanceRowPosition = -1;
446 int secondAppearanceColumnPosition = -1;
447 while (pointer < 27)
448 {
449 if (numberAndPosition[pointer, 0] == number)
450 {
451 firstAppearanceRowPosition = numberAndPosition[pointer, 1];
452 firstAppearanceColumnPosition = numberAndPosition[pointer, 2];
453 pointer++;
454 break;
455 }
456 else
457 {
458 pointer++;
459 }
460 }
461 while (pointer < 27)
462 {
463 if (numberAndPosition[pointer, 0] == number)
464 {
465 secondAppearanceRowPosition = numberAndPosition[pointer, 1];
466 secondAppearanceColumnPosition = numberAndPosition[pointer, 2];
467 break;
468 }
469 else
470 {
471 pointer++;
472 }
473 }
474 int thirdAppearanceColumnPosition = 3
475 * (firstAppearanceColumnPosition / 3) + 3
476 - firstAppearanceColumnPosition % 3
477 - secondAppearanceColumnPosition % 3;
478 int thirdAppearanceRowStartPosition = (3 - firstAppearanceRowPosition / 3 - secondAppearanceRowPosition / 3) * 3;
479 int posibilities = 0;
480 int thirdAppearanceRowPosition = -1;
481 for (int indicator = thirdAppearanceRowStartPosition; indicator < thirdAppearanceRowStartPosition + 3; indicator++)
482 {
483 if (array[indicator, thirdAppearanceColumnPosition] == 0)
484 {
485 if (IsPossibleInThatCellCheckByRow(array, number,
486 indicator, thirdAppearanceColumnPosition))
487 {
488 thirdAppearanceRowPosition = indicator;
489 posibilities++;
490 }
491 }
492 }
493 if (posibilities == 1)
494 {
495 array[thirdAppearanceRowPosition, thirdAppearanceColumnPosition] = number;
496 return true;
497 }
498 }
499 }
500 return false;
501 }
502 private bool ReduceFromThreeRows(int[,] array, int firstRow, int lastRow)
503 {
504 int[,] numberAndCount = new int[2, 9];
505 int[,] numberAndPosition = new int[3, 27];
506 for (int column = 0; column < 9; column++)
507 {
508 numberAndCount[0, column] = column + 1;
509 numberAndCount[1, column] = 0;
510 }
511 for (int row = 0; row < 3; row++)
512 {
513 for (int column = 0; column < 27; column++)
514 {
515 numberAndPosition[row, column] = 0;
516 }
517 }
518 for (int row = firstRow; row <= lastRow; row++)
519 {
520 for (int column = 0; column < 9; column++)
521 {
522 if (array[row, column] != 0)
523 {
524 numberAndCount[1, array[row, column] - 1]++;
525 numberAndPosition[0, 9 * (row % 3) + column] = array[row, column];
526 numberAndPosition[1, 9 * (row % 3) + column] = row;
527 numberAndPosition[2, 9 * (row % 3) + column] = column;
528 }
529 }
530 }
531 for (int column = 0; column < 9; column++)
532 {
533 if (numberAndCount[1, column] == 2)
534 {
535 int number = numberAndCount[0, column];
536 int pointer = 0;
537 int firstAppearanceRowPosition = -1;
538 int firstAppearanceColumnPosition = -1;
539 int secondAppearanceRowPosition = -1;
540 int secondAppearanceColumnPosition = -1;
541 while (pointer < 27)
542 {
543 if (numberAndPosition[0, pointer] == number)
544 {
545 firstAppearanceRowPosition = numberAndPosition[1, pointer];
546 firstAppearanceColumnPosition = numberAndPosition[2, pointer];
547 pointer++;
548 break;
549 }
550 else
551 {
552 pointer++;
553 }
554 }
555 while (pointer < 27)
556 {
557 if (numberAndPosition[0, pointer] == number)
558 {
559 secondAppearanceRowPosition = numberAndPosition[1, pointer];
560 secondAppearanceColumnPosition = numberAndPosition[2, pointer];
561 break;
562 }
563 else
564 {
565 pointer++;
566 }
567 }
568 int thirdAppearanceRowPosition = 3
569 * (firstAppearanceRowPosition / 3) + 3
570 - firstAppearanceRowPosition % 3
571 - secondAppearanceRowPosition % 3;
572 int thirdAppearanceColumnStartPosition = (3 - firstAppearanceColumnPosition / 3 - secondAppearanceColumnPosition / 3) * 3;
573 int posibilities = 0;
574 int thirdAppearanceColumnPosition = -1;
575 for (int indicator = thirdAppearanceColumnStartPosition; indicator < thirdAppearanceColumnStartPosition + 3; indicator++)
576 {
577 if (array[thirdAppearanceRowPosition, indicator] == 0)
578 {
579 if (IsPossibleInThatCellCheckByColumn(array, number,
580 thirdAppearanceRowPosition, indicator))
581 {
582 thirdAppearanceColumnPosition = indicator;
583 posibilities++;
584 }
585 }
586 }
587 if (posibilities == 1)
588 {
589 array[thirdAppearanceRowPosition, thirdAppearanceColumnPosition] = number;
590 return true;
591 }
592 }
593 }
594 return false;
595 }
596 private bool IsPossibleInThatCellCheckByColumn(int[,] array,
597 int number, int row, int column)
598 {
599 for (int pointer = 0; pointer < 9; pointer++)
600 {
601 if (pointer != row)
602 {
603 if (array[pointer, column] == number)
604 {
605 return false;
606 }
607 }
608 }
609 return true;
610 }
611 private bool IsPossibleInThatCellCheckByRow(int[,] array, int number,
612 int row, int column)
613 {
614 for (int pointer = 0; pointer < 9; pointer++)
615 {
616 if (pointer != column)
617 {
618 if (array[row, pointer] == number)
619 {
620 return false;
621 }
622 }
623 }
624 return true;
625 }
626 public int[,] Array
627 {
628 set
629 {
630 this._array = value;
631 }
632 get
633 {
634 return _array;
635 }
636 }
637}
638
2using System.Data;
3using System.Configuration;
4using System.Web;
5using System.Web.Security;
6using System.Web.UI;
7using System.Web.UI.WebControls;
8using System.Web.UI.WebControls.WebParts;
9using System.Web.UI.HtmlControls;
10
11/// <summary>
12/// Summary description for Deducer
13/// </summary>
14public class Deducer
15{
16 private int[,] _array;
17 public Deducer(int[,] array)
18 {
19 this.Array = new int[9, 9];
20 for (int row = 0; row < 9; row++)
21 {
22 for (int column = 0; column < 9; column++)
23 {
24 this.Array[row, column] = array[row, column];
25 }
26 }
27 }
28 private bool IsFinished()
29 {
30 for (int row = 0; row < 9; row++)
31 {
32 for (int column = 0; column < 9; column++)
33 {
34 if (this.Array[row, column] == 0)
35 {
36 return false;
37 }
38 }
39 }
40 return true;
41 }
42 public void DeduceAll()
43 {
44 if (IsFinished())
45 {
46 return;
47 }
48 for (int row = 0; row < 7; row = row + 3)
49 {
50 for (int column = 0; column < 7; column = column + 3)
51 {
52 if (ReduceFromOneZone(this.Array, row, column))
53 {
54 DeduceAll();
55 return;
56 }
57 }
58 }
59 for (int row = 0; row < 9; row++)
60 {
61 if (ReduceFromOneRow(this.Array, row))
62 {
63 DeduceAll();
64 return;
65 }
66 }
67 for (int column = 0; column < 9; column++)
68 {
69 if (ReduceFromOneColumn(this.Array, column))
70 {
71 DeduceAll();
72 return;
73 }
74 }
75 for (int row = 0; row < 7; row = row + 3)
76 {
77 if (ReduceFromThreeRows(this.Array, row, row + 2))
78 {
79 DeduceAll();
80 return;
81 }
82 }
83 for (int column = 0; column < 7; column = column + 3)
84 {
85 if (ReduceFromThreeColumns(this.Array, column, column + 2))
86 {
87 DeduceAll();
88 return;
89 }
90 }
91 }
92 public void DeduceOnce()
93 {
94 for (int row = 0; row < 7; row = row + 3)
95 {
96 for (int column = 0; column < 7; column = column + 3)
97 {
98 if (ReduceFromOneZone(this.Array, row, column))
99 {
100 return;
101 }
102 }
103 }
104 for (int row = 0; row < 9; row++)
105 {
106 if (ReduceFromOneRow(this.Array, row))
107 {
108 return;
109 }
110 }
111 for (int column = 0; column < 9; column++)
112 {
113 if (ReduceFromOneColumn(this.Array, column))
114 {
115 return;
116 }
117 }
118 for (int row = 0; row < 7; row = row + 3)
119 {
120 if (ReduceFromThreeRows(this.Array, row, row + 2))
121 {
122 return;
123 }
124 }
125 for (int column = 0; column < 7; column = column + 3)
126 {
127 if (ReduceFromThreeColumns(this.Array, column, column + 2))
128 {
129 return;
130 }
131 }
132 }
133 private bool ReduceFromOneZone(int[,] array, int row, int column)
134 {
135 int startRow = (row / 3) * 3;
136 int startColumn = (column / 3) * 3;
137 int[] unknown = new int[9];
138 for (int pointer = 0; pointer < 9; pointer++)
139 {
140 unknown[pointer] = pointer + 1;
141 }
142 for (int rowPointer = startRow; rowPointer < startRow + 3; rowPointer++)
143 {
144 for (int columnPointer = startColumn; columnPointer < startColumn + 3; columnPointer++)
145 {
146 if (array[rowPointer, columnPointer] != 0)
147 {
148 unknown[array[rowPointer, columnPointer] - 1] = 0;
149 }
150 }
151 }
152 for (int digit = 0; digit < 9; digit++)
153 {
154 if (unknown[digit] != 0)
155 {
156 int number = unknown[digit];
157 int posibilities = 0;
158 int rowPosition = -1;
159 int columnPosition = -1;
160 for (int rowPointer = startRow; rowPointer < startRow + 3; rowPointer++)
161 {
162 for (int columnPointer = startColumn; columnPointer < startColumn + 3; columnPointer++)
163 {
164 if (array[rowPointer, columnPointer] == 0)
165 {
166 if (IsPossibleInThatCellCheckByColumn(array, number,
167 rowPointer, columnPointer)
168 && IsPossibleInThatCellCheckByRow(array,
169 number, rowPointer, columnPointer))
170 {
171 rowPosition = rowPointer;
172 columnPosition = columnPointer;
173 posibilities++;
174 }
175 }
176 }
177 }
178 if (posibilities == 1)
179 {
180 array[rowPosition, columnPosition] = number;
181 return true;
182 }
183 }
184 }
185 return false;
186 }
187 private bool ReduceFromOneRow(int[,] array, int row)
188 {
189 int[] unknown = new int[9];
190 for (int column = 0; column < 9; column++)
191 {
192 unknown[column] = column + 1;
193 }
194 for (int column = 0; column < 9; column++)
195 {
196 if (array[row, column] != 0)
197 {
198 unknown[array[row, column] - 1] = 0;
199 }
200 }
201 for (int column = 0; column < 9; column++)
202 {
203 if (unknown[column] != 0)
204 {
205 int number = unknown[column];
206 int posibilities = 0;
207 int position = -1;
208 for (int pointer = 0; pointer < 9; pointer++)
209 {
210 if (array[row, pointer] == 0)
211 {
212 if (IsPossibleInThatCellCheckByColumnAndZone(array,
213 number, row, pointer))
214 {
215 position = pointer;
216 posibilities++;
217 }
218 }
219 }
220 if (posibilities == 1)
221 {
222 array[row, position] = number;
223 return true;
224 }
225 }
226 }
227 return false;
228 }
229 private bool ReduceFromOneColumn(int[,] array, int column)
230 {
231 int[] unknown = new int[9];
232 for (int row = 0; row < 9; row++)
233 {
234 unknown[row] = row + 1;
235 }
236 for (int row = 0; row < 9; row++)
237 {
238 if (array[row, column] != 0)
239 {
240 unknown[array[row, column] - 1] = 0;
241 }
242 }
243 for (int row = 0; row < 9; row++)
244 {
245 if (unknown[row] != 0)
246 {
247 int number = unknown[row];
248 int posibilities = 0;
249 int position = -1;
250 for (int pointer = 0; pointer < 9; pointer++)
251 {
252 if (array[pointer, column] == 0)
253 {
254 if (IsPossibleInThatCellCheckByRowAndZone(array, number,
255 pointer, column))
256 {
257 position = pointer;
258 posibilities++;
259 }
260 }
261 }
262 if (posibilities == 1)
263 {
264 array[position, column] = number;
265 return true;
266 }
267 }
268 }
269 return false;
270 }
271 private bool IsPossibleInThatCellCheckByRowAndZone(int[,] array,
272 int number, int row, int column)
273 {
274 if (!IsPossibleInThatCellCheckByRow(array, number, row, column))
275 {
276 return false;
277 }
278 else if (!IsPossibleInThatCellCheckByZone(array, number, row, column))
279 {
280 return false;
281 }
282 else if (!CanBeInThatZoneCheckByColumn(array, number, row, column))
283 {
284 return false;
285 }
286 else
287 {
288 return true;
289 }
290 }
291 private bool IsPossibleInThatCellCheckByColumnAndZone(int[,] array,
292 int number, int row, int column)
293 {
294 if (!IsPossibleInThatCellCheckByColumn(array, number, row, column))
295 {
296 return false;
297 }
298 else if (!IsPossibleInThatCellCheckByZone(array, number, row, column))
299 {
300 return false;
301 }
302 else if (!CanBeInThatZoneCheckByRow(array, number, row, column))
303 {
304 return false;
305 }
306 else
307 {
308 return true;
309 }
310 }
311 private bool CanBeInThatZoneCheckByRow(int[,] array, int number,
312 int row, int column)
313 {
314 int startRow = (row / 3) * 3;
315 int startColumn = (column / 3) * 3;
316 for (int rowPointer = startRow; rowPointer < startRow + 3; rowPointer++)
317 {
318 if (rowPointer != row)
319 {
320 if (!IsPossibleInThatCellCheckByRow(array, number, rowPointer,
321 column))
322 {
323 continue;
324 }
325 bool canItBe = true;
326 for (int columnPointer = 0; columnPointer < 9; columnPointer++)
327 {
328 if (columnPointer < startColumn
329 || columnPointer > startColumn + 2)
330 {
331 if (array[rowPointer, columnPointer] == 0)
332 {
333 if (IsPossibleInThatCellCheckByColumn(array, number,
334 rowPointer, columnPointer)
335 && IsPossibleInThatCellCheckByZone(array,
336 number, rowPointer, columnPointer))
337 {
338 canItBe = false;
339 }
340 }
341 }
342 }
343 if (canItBe)
344 {
345 return false;
346 }
347 }
348 }
349 return true;
350 }
351 private bool CanBeInThatZoneCheckByColumn(int[,] array, int number,
352 int row, int column)
353 {
354 int startRow = (row / 3) * 3;
355 int startColumn = (column / 3) * 3;
356 for (int columnPointer = startColumn; columnPointer < startColumn + 3; columnPointer++)
357 {
358 if (columnPointer != column)
359 {
360 if (!IsPossibleInThatCellCheckByColumn(array, number, row,
361 columnPointer))
362 {
363 continue;
364 }
365 bool canItBe = true;
366 for (int rowPointer = 0; rowPointer < 9; rowPointer++)
367 {
368 if (rowPointer < startRow || rowPointer > startRow + 2)
369 {
370 if (array[rowPointer, columnPointer] == 0)
371 {
372 if (IsPossibleInThatCellCheckByRow(array, number,
373 rowPointer, columnPointer)
374 && IsPossibleInThatCellCheckByZone(array,
375 number, rowPointer, columnPointer))
376 {
377 canItBe = false;
378 }
379 }
380 }
381 }
382 if (canItBe)
383 {
384 return false;
385 }
386 }
387 }
388 return true;
389 }
390 private bool IsPossibleInThatCellCheckByZone(int[,] array, int number,
391 int row, int column)
392 {
393 int startRow = (row / 3) * 3;
394 int startColumn = (column / 3) * 3;
395 for (int rowPointer = startRow; rowPointer < startRow + 3; rowPointer++)
396 {
397 for (int columnPointer = startColumn; columnPointer < startColumn + 3; columnPointer++)
398 {
399 if (array[rowPointer, columnPointer] == number)
400 {
401 return false;
402 }
403 }
404 }
405 return true;
406 }
407 private bool ReduceFromThreeColumns(int[,] array, int firstColumn,
408 int lastColumn)
409 {
410 int[,] numberAndCount = new int[9, 2];
411 int[,] numberAndPosition = new int[27, 3];
412 for (int row = 0; row < 9; row++)
413 {
414 numberAndCount[row, 0] = row + 1;
415 numberAndCount[row, 1] = 0;
416 }
417 for (int row = 0; row < 27; row++)
418 {
419 for (int column = 0; column < 3; column++)
420 {
421 numberAndPosition[row, column] = 0;
422 }
423 }
424 for (int column = firstColumn; column <= lastColumn; column++)
425 {
426 for (int row = 0; row < 9; row++)
427 {
428 if (array[row, column] != 0)
429 {
430 numberAndCount[array[row, column] - 1, 1]++;
431 numberAndPosition[9 * (column % 3) + row, 0] = array[row, column];
432 numberAndPosition[9 * (column % 3) + row, 1] = row;
433 numberAndPosition[9 * (column % 3) + row, 2] = column;
434 }
435 }
436 }
437 for (int row = 0; row < 9; row++)
438 {
439 if (numberAndCount[row, 1] == 2)
440 {
441 int number = numberAndCount[row, 0];
442 int pointer = 0;
443 int firstAppearanceRowPosition = -1;
444 int firstAppearanceColumnPosition = -1;
445 int secondAppearanceRowPosition = -1;
446 int secondAppearanceColumnPosition = -1;
447 while (pointer < 27)
448 {
449 if (numberAndPosition[pointer, 0] == number)
450 {
451 firstAppearanceRowPosition = numberAndPosition[pointer, 1];
452 firstAppearanceColumnPosition = numberAndPosition[pointer, 2];
453 pointer++;
454 break;
455 }
456 else
457 {
458 pointer++;
459 }
460 }
461 while (pointer < 27)
462 {
463 if (numberAndPosition[pointer, 0] == number)
464 {
465 secondAppearanceRowPosition = numberAndPosition[pointer, 1];
466 secondAppearanceColumnPosition = numberAndPosition[pointer, 2];
467 break;
468 }
469 else
470 {
471 pointer++;
472 }
473 }
474 int thirdAppearanceColumnPosition = 3
475 * (firstAppearanceColumnPosition / 3) + 3
476 - firstAppearanceColumnPosition % 3
477 - secondAppearanceColumnPosition % 3;
478 int thirdAppearanceRowStartPosition = (3 - firstAppearanceRowPosition / 3 - secondAppearanceRowPosition / 3) * 3;
479 int posibilities = 0;
480 int thirdAppearanceRowPosition = -1;
481 for (int indicator = thirdAppearanceRowStartPosition; indicator < thirdAppearanceRowStartPosition + 3; indicator++)
482 {
483 if (array[indicator, thirdAppearanceColumnPosition] == 0)
484 {
485 if (IsPossibleInThatCellCheckByRow(array, number,
486 indicator, thirdAppearanceColumnPosition))
487 {
488 thirdAppearanceRowPosition = indicator;
489 posibilities++;
490 }
491 }
492 }
493 if (posibilities == 1)
494 {
495 array[thirdAppearanceRowPosition, thirdAppearanceColumnPosition] = number;
496 return true;
497 }
498 }
499 }
500 return false;
501 }
502 private bool ReduceFromThreeRows(int[,] array, int firstRow, int lastRow)
503 {
504 int[,] numberAndCount = new int[2, 9];
505 int[,] numberAndPosition = new int[3, 27];
506 for (int column = 0; column < 9; column++)
507 {
508 numberAndCount[0, column] = column + 1;
509 numberAndCount[1, column] = 0;
510 }
511 for (int row = 0; row < 3; row++)
512 {
513 for (int column = 0; column < 27; column++)
514 {
515 numberAndPosition[row, column] = 0;
516 }
517 }
518 for (int row = firstRow; row <= lastRow; row++)
519 {
520 for (int column = 0; column < 9; column++)
521 {
522 if (array[row, column] != 0)
523 {
524 numberAndCount[1, array[row, column] - 1]++;
525 numberAndPosition[0, 9 * (row % 3) + column] = array[row, column];
526 numberAndPosition[1, 9 * (row % 3) + column] = row;
527 numberAndPosition[2, 9 * (row % 3) + column] = column;
528 }
529 }
530 }
531 for (int column = 0; column < 9; column++)
532 {
533 if (numberAndCount[1, column] == 2)
534 {
535 int number = numberAndCount[0, column];
536 int pointer = 0;
537 int firstAppearanceRowPosition = -1;
538 int firstAppearanceColumnPosition = -1;
539 int secondAppearanceRowPosition = -1;
540 int secondAppearanceColumnPosition = -1;
541 while (pointer < 27)
542 {
543 if (numberAndPosition[0, pointer] == number)
544 {
545 firstAppearanceRowPosition = numberAndPosition[1, pointer];
546 firstAppearanceColumnPosition = numberAndPosition[2, pointer];
547 pointer++;
548 break;
549 }
550 else
551 {
552 pointer++;
553 }
554 }
555 while (pointer < 27)
556 {
557 if (numberAndPosition[0, pointer] == number)
558 {
559 secondAppearanceRowPosition = numberAndPosition[1, pointer];
560 secondAppearanceColumnPosition = numberAndPosition[2, pointer];
561 break;
562 }
563 else
564 {
565 pointer++;
566 }
567 }
568 int thirdAppearanceRowPosition = 3
569 * (firstAppearanceRowPosition / 3) + 3
570 - firstAppearanceRowPosition % 3
571 - secondAppearanceRowPosition % 3;
572 int thirdAppearanceColumnStartPosition = (3 - firstAppearanceColumnPosition / 3 - secondAppearanceColumnPosition / 3) * 3;
573 int posibilities = 0;
574 int thirdAppearanceColumnPosition = -1;
575 for (int indicator = thirdAppearanceColumnStartPosition; indicator < thirdAppearanceColumnStartPosition + 3; indicator++)
576 {
577 if (array[thirdAppearanceRowPosition, indicator] == 0)
578 {
579 if (IsPossibleInThatCellCheckByColumn(array, number,
580 thirdAppearanceRowPosition, indicator))
581 {
582 thirdAppearanceColumnPosition = indicator;
583 posibilities++;
584 }
585 }
586 }
587 if (posibilities == 1)
588 {
589 array[thirdAppearanceRowPosition, thirdAppearanceColumnPosition] = number;
590 return true;
591 }
592 }
593 }
594 return false;
595 }
596 private bool IsPossibleInThatCellCheckByColumn(int[,] array,
597 int number, int row, int column)
598 {
599 for (int pointer = 0; pointer < 9; pointer++)
600 {
601 if (pointer != row)
602 {
603 if (array[pointer, column] == number)
604 {
605 return false;
606 }
607 }
608 }
609 return true;
610 }
611 private bool IsPossibleInThatCellCheckByRow(int[,] array, int number,
612 int row, int column)
613 {
614 for (int pointer = 0; pointer < 9; pointer++)
615 {
616 if (pointer != column)
617 {
618 if (array[row, pointer] == number)
619 {
620 return false;
621 }
622 }
623 }
624 return true;
625 }
626 public int[,] Array
627 {
628 set
629 {
630 this._array = value;
631 }
632 get
633 {
634 return _array;
635 }
636 }
637}
638
puzzleCS.aspx.cs:
1using System;
2using System.Data;
3using System.Configuration;
4using System.Collections;
5using System.Web;
6using System.Web.Security;
7using System.Web.UI;
8using System.Web.UI.WebControls;
9using System.Web.UI.WebControls.WebParts;
10using System.Web.UI.HtmlControls;
11using System.Text;
12
13public partial class puzzleCS : System.Web.UI.Page
14{
15 protected void Page_Load(object sender, EventArgs e)
16 {
17 if (this.Request.Form.Get("type") != null)
18 {
19 try
20 {
21 String array = this.Request.Form.Get("array");
22 String[] numbers = array.Split(',');
23 int[,] dealingArray = new int[9, 9];
24 for (int row = 0; row < 9; row++)
25 {
26 for (int column = 0; column < 9; column++)
27 {
28 dealingArray[row, column] = Convert.ToInt32(numbers[row * 9 + column]);
29 }
30 }
31 Deducer deducer = new Deducer(dealingArray);
32 if (this.Request.Form.Get("type") == "OneStep")
33 {
34 deducer.DeduceOnce();
35 }
36 else if (this.Request.Form.Get("type") == "AllSteps")
37 {
38 deducer.DeduceAll();
39 }
40 StringBuilder sb = new StringBuilder();
41 for (int row = 0; row < 9; row++)
42 {
43 for (int column = 0; column < 9; column++)
44 {
45 if (sb.ToString() == "")
46 {
47 sb.Append(deducer.Array[row, column]);
48 }
49 else
50 {
51 sb.Append("," + deducer.Array[row, column]);
52 }
53 }
54 }
55 this.Response.Write(sb);
56 }
57 catch
58 {
59 this.Response.Write("ri");
60 }
61 this.Response.End();
62 }
63 }
64}
65
2using System.Data;
3using System.Configuration;
4using System.Collections;
5using System.Web;
6using System.Web.Security;
7using System.Web.UI;
8using System.Web.UI.WebControls;
9using System.Web.UI.WebControls.WebParts;
10using System.Web.UI.HtmlControls;
11using System.Text;
12
13public partial class puzzleCS : System.Web.UI.Page
14{
15 protected void Page_Load(object sender, EventArgs e)
16 {
17 if (this.Request.Form.Get("type") != null)
18 {
19 try
20 {
21 String array = this.Request.Form.Get("array");
22 String[] numbers = array.Split(',');
23 int[,] dealingArray = new int[9, 9];
24 for (int row = 0; row < 9; row++)
25 {
26 for (int column = 0; column < 9; column++)
27 {
28 dealingArray[row, column] = Convert.ToInt32(numbers[row * 9 + column]);
29 }
30 }
31 Deducer deducer = new Deducer(dealingArray);
32 if (this.Request.Form.Get("type") == "OneStep")
33 {
34 deducer.DeduceOnce();
35 }
36 else if (this.Request.Form.Get("type") == "AllSteps")
37 {
38 deducer.DeduceAll();
39 }
40 StringBuilder sb = new StringBuilder();
41 for (int row = 0; row < 9; row++)
42 {
43 for (int column = 0; column < 9; column++)
44 {
45 if (sb.ToString() == "")
46 {
47 sb.Append(deducer.Array[row, column]);
48 }
49 else
50 {
51 sb.Append("," + deducer.Array[row, column]);
52 }
53 }
54 }
55 this.Response.Write(sb);
56 }
57 catch
58 {
59 this.Response.Write("ri");
60 }
61 this.Response.End();
62 }
63 }
64}
65
puzzleCS.aspx
1<%@ Page Language="C#" AutoEventWireup="true" CodeFile="puzzleCS.aspx.cs" Inherits="puzzleCS" %>
2
3<html>
4<body>
5<script>
6var request=false;
7try
8{
9 request = new XMLHttpRequest();//Firefox
10}
11catch(trymicrosoft)
12{
13 try
14 {
15 request = new ActiveXObject("Msxml2.XMLHTTP.5.0");//New IE
16 }
17 catch(othermicrosoft)
18 {
19 try
20 {
21 request = new ActiveXObject("Microsoft.XMLHTTP");//Old IE
22 }
23 catch(failed)
24 {
25 request = false;//Unknown browser
26 }
27 }
28}
29if(!request)
30{
31 alert("Please use Internet Explorer");
32}
33function dealNullInput(input)
34{
35 if(input=="")
36 {
37 return "0";
38 }
39 else
40 {
41 return input;
42 }
43}
44function dealZeroOutput(input)
45{
46 if(input==0)
47 {
48 return "";
49 }
50 else
51 {
52 return input;
53 }
54}
55function sendOneStepRequest()
56{
57 url=escape("puzzleCS.aspx")+"?random=" + Math.random();//use a random number to avoid cache
58 request.open("POST",url,true);//connection method
59 request.onreadystatechange=showProcess;//show Process method
60 request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
61 var array="";
62 for(var i=0;i<81;i++)
63 {
64 if(array=="")
65 {
66 array=array+dealNullInput(document.getElementsByName("TextBox")[i].value);
67 }
68 else
69 {
70 array=array+","+dealNullInput(document.getElementsByName("TextBox")[i].value);
71 }
72 }
73 request.send("type=OneStep"+"&array="+escape(array));
74}
75function sendAllStepsRequest()
76{
77 url=escape("puzzleCS.aspx")+"?random=" + Math.random();
78 request.open("POST",url,true);//connection method
79 request.onreadystatechange=showProcess;//show Process method
80 request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
81 var array="";
82 for(var i=0;i<81;i++)
83 {
84 if(array=="")
85 {
86 array=array+dealNullInput(document.getElementsByName("TextBox")[i].value);
87 }
88 else
89 {
90 array=array+","+dealNullInput(document.getElementsByName("TextBox")[i].value.replace(/ /g, ""));
91 }
92 }
93 request.send("type=AllSteps"+"&array="+escape(array));
94}
95function showProcess()
96{
97 if(request.readyState == 4)//finished
98 {
99 if(request.status == 200)//normal
100 {
101 var splitResult=request.responseText.split(",");
102 for(var i=0;i<81;i++)
103 {
104 document.getElementsByName("TextBox")[i].value=dealZeroOutput(splitResult[i]);
105 }
106 }
107 }
108 else if(request.readyState == 1)
109 {
110 //"finished step1";
111 }
112 else if(request.readyState == 2)
113 {
114 //"finished step2";
115 }
116 else if(request.readyState == 3)
117 {
118 //"finished step3";
119 }
120}
121</script>
122<table>
123<tr>
124<td>
125<input name="TextBox" type="text" style="width: 25px"/>
126</td>
127<td>
128<input name="TextBox" type="text" style="width: 25px"/>
129</td>
130<td>
131<input name="TextBox" type="text" style="width: 25px"/>
132</td>
133<td>
134<input name="TextBox" type="text" style="width: 25px"/>
135</td>
136<td>
137<input name="TextBox" type="text" style="width: 25px"/>
138</td>
139<td>
140<input name="TextBox" type="text" style="width: 25px"/>
141</td>
142<td>
143<input name="TextBox" type="text" style="width: 25px"/>
144</td>
145<td>
146<input name="TextBox" type="text" style="width: 25px"/>
147</td>
148<td>
149<input name="TextBox" type="text" style="width: 25px"/>
150</td>
151</tr>
152<tr>
153<td>
154<input name="TextBox" type="text" style="width: 25px"/>
155</td>
156<td>
157<input name="TextBox" type="text" style="width: 25px"/>
158</td>
159<td>
160<input name="TextBox" type="text" style="width: 25px"/>
161</td>
162<td>
163<input name="TextBox" type="text" style="width: 25px"/>
164</td>
165<td>
166<input name="TextBox" type="text" style="width: 25px"/>
167</td>
168<td>
169<input name="TextBox" type="text" style="width: 25px"/>
170</td>
171<td>
172<input name="TextBox" type="text" style="width: 25px"/>
173</td>
174<td>
175<input name="TextBox" type="text" style="width: 25px"/>
176</td>
177<td>
178<input name="TextBox" type="text" style="width: 25px"/>
179</td>
180</tr>
181<tr>
182<td>
183<input name="TextBox" type="text" style="width: 25px"/>
184</td>
185<td>
186<input name="TextBox" type="text" style="width: 25px"/>
187</td>
188<td>
189<input name="TextBox" type="text" style="width: 25px"/>
190</td>
191<td>
192<input name="TextBox" type="text" style="width: 25px"/>
193</td>
194<td>
195<input name="TextBox" type="text" style="width: 25px"/>
196</td>
197<td>
198<input name="TextBox" type="text" style="width: 25px"/>
199</td>
200<td>
201<input name="TextBox" type="text" style="width: 25px"/>
202</td>
203<td>
204<input name="TextBox" type="text" style="width: 25px"/>
205</td>
206<td>
207<input name="TextBox" type="text" style="width: 25px"/>
208</td>
209</tr>
210<tr>
211<td>
212<input name="TextBox" type="text" style="width: 25px"/>
213</td>
214<td>
215<input name="TextBox" type="text" style="width: 25px"/>
216</td>
217<td>
218<input name="TextBox" type="text" style="width: 25px"/>
219</td>
220<td>
221<input name="TextBox" type="text" style="width: 25px"/>
222</td>
223<td>
224<input name="TextBox" type="text" style="width: 25px"/>
225</td>
226<td>
227<input name="TextBox" type="text" style="width: 25px"/>
228</td>
229<td>
230<input name="TextBox" type="text" style="width: 25px"/>
231</td>
232<td>
233<input name="TextBox" type="text" style="width: 25px"/>
234</td>
235<td>
236<input name="TextBox" type="text" style="width: 25px"/>
237</td>
238</tr>
239<tr>
240<td>
241<input name="TextBox" type="text" style="width: 25px"/>
242</td>
243<td>
244<input name="TextBox" type="text" style="width: 25px"/>
245</td>
246<td>
247<input name="TextBox" type="text" style="width: 25px"/>
248</td>
249<td>
250<input name="TextBox" type="text" style="width: 25px"/>
251</td>
252<td>
253<input name="TextBox" type="text" style="width: 25px"/>
254</td>
255<td>
256<input name="TextBox" type="text" style="width: 25px"/>
257</td>
258<td>
259<input name="TextBox" type="text" style="width: 25px"/>
260</td>
261<td>
262<input name="TextBox" type="text" style="width: 25px"/>
263</td>
264<td>
265<input name="TextBox" type="text" style="width: 25px"/>
266</td>
267</tr>
268<tr>
269<td>
270<input name="TextBox" type="text" style="width: 25px"/>
271</td>
272<td>
273<input name="TextBox" type="text" style="width: 25px"/>
274</td>
275<td>
276<input name="TextBox" type="text" style="width: 25px"/>
277</td>
278<td>
279<input name="TextBox" type="text" style="width: 25px"/>
280</td>
281<td>
282<input name="TextBox" type="text" style="width: 25px"/>
283</td>
284<td>
285<input name="TextBox" type="text" style="width: 25px"/>
286</td>
287<td>
288<input name="TextBox" type="text" style="width: 25px"/>
289</td>
290<td>
291<input name="TextBox" type="text" style="width: 25px"/>
292</td>
293<td>
294<input name="TextBox" type="text" style="width: 25px"/>
295</td>
296</tr>
297<tr>
298<td>
299<input name="TextBox" type="text" style="width: 25px"/>
300</td>
301<td>
302<input name="TextBox" type="text" style="width: 25px"/>
303</td>
304<td>
305<input name="TextBox" type="text" style="width: 25px"/>
306</td>
307<td>
308<input name="TextBox" type="text" style="width: 25px"/>
309</td>
310<td>
311<input name="TextBox" type="text" style="width: 25px"/>
312</td>
313<td>
314<input name="TextBox" type="text" style="width: 25px"/>
315</td>
316<td>
317<input name="TextBox" type="text" style="width: 25px"/>
318</td>
319<td>
320<input name="TextBox" type="text" style="width: 25px"/>
321</td>
322<td>
323<input name="TextBox" type="text" style="width: 25px"/>
324</td>
325</tr>
326<tr>
327<td>
328<input name="TextBox" type="text" style="width: 25px"/>
329</td>
330<td>
331<input name="TextBox" type="text" style="width: 25px"/>
332</td>
333<td>
334<input name="TextBox" type="text" style="width: 25px"/>
335</td>
336<td>
337<input name="TextBox" type="text" style="width: 25px"/>
338</td>
339<td>
340<input name="TextBox" type="text" style="width: 25px"/>
341</td>
342<td>
343<input name="TextBox" type="text" style="width: 25px"/>
344</td>
345<td>
346<input name="TextBox" type="text" style="width: 25px"/>
347</td>
348<td>
349<input name="TextBox" type="text" style="width: 25px"/>
350</td>
351<td>
352<input name="TextBox" type="text" style="width: 25px"/>
353</td>
354</tr>
355<tr>
356<td>
357<input name="TextBox" type="text" style="width: 25px"/>
358</td>
359<td>
360<input name="TextBox" type="text" style="width: 25px"/>
361</td>
362<td>
363<input name="TextBox" type="text" style="width: 25px"/>
364</td>
365<td>
366<input name="TextBox" type="text" style="width: 25px"/>
367</td>
368<td>
369<input name="TextBox" type="text" style="width: 25px"/>
370</td>
371<td>
372<input name="TextBox" type="text" style="width: 25px"/>
373</td>
374<td>
375<input name="TextBox" type="text" style="width: 25px"/>
376</td>
377<td>
378<input name="TextBox" type="text" style="width: 25px"/>
379</td>
380<td>
381<input name="TextBox" type="text" style="width: 25px"/>
382</td>
383</tr>
384</table>
385<input type="button" name="OneStep" value="OneStep" id="OneStep" onclick="sendOneStepRequest()" />
386<input type="button" name="AllSteps" value="AllSteps" id="AllSteps" onclick="sendAllStepsRequest()" />
387</body>
388</html>
2
3<html>
4<body>
5<script>
6var request=false;
7try
8{
9 request = new XMLHttpRequest();//Firefox
10}
11catch(trymicrosoft)
12{
13 try
14 {
15 request = new ActiveXObject("Msxml2.XMLHTTP.5.0");//New IE
16 }
17 catch(othermicrosoft)
18 {
19 try
20 {
21 request = new ActiveXObject("Microsoft.XMLHTTP");//Old IE
22 }
23 catch(failed)
24 {
25 request = false;//Unknown browser
26 }
27 }
28}
29if(!request)
30{
31 alert("Please use Internet Explorer");
32}
33function dealNullInput(input)
34{
35 if(input=="")
36 {
37 return "0";
38 }
39 else
40 {
41 return input;
42 }
43}
44function dealZeroOutput(input)
45{
46 if(input==0)
47 {
48 return "";
49 }
50 else
51 {
52 return input;
53 }
54}
55function sendOneStepRequest()
56{
57 url=escape("puzzleCS.aspx")+"?random=" + Math.random();//use a random number to avoid cache
58 request.open("POST",url,true);//connection method
59 request.onreadystatechange=showProcess;//show Process method
60 request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
61 var array="";
62 for(var i=0;i<81;i++)
63 {
64 if(array=="")
65 {
66 array=array+dealNullInput(document.getElementsByName("TextBox")[i].value);
67 }
68 else
69 {
70 array=array+","+dealNullInput(document.getElementsByName("TextBox")[i].value);
71 }
72 }
73 request.send("type=OneStep"+"&array="+escape(array));
74}
75function sendAllStepsRequest()
76{
77 url=escape("puzzleCS.aspx")+"?random=" + Math.random();
78 request.open("POST",url,true);//connection method
79 request.onreadystatechange=showProcess;//show Process method
80 request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
81 var array="";
82 for(var i=0;i<81;i++)
83 {
84 if(array=="")
85 {
86 array=array+dealNullInput(document.getElementsByName("TextBox")[i].value);
87 }
88 else
89 {
90 array=array+","+dealNullInput(document.getElementsByName("TextBox")[i].value.replace(/ /g, ""));
91 }
92 }
93 request.send("type=AllSteps"+"&array="+escape(array));
94}
95function showProcess()
96{
97 if(request.readyState == 4)//finished
98 {
99 if(request.status == 200)//normal
100 {
101 var splitResult=request.responseText.split(",");
102 for(var i=0;i<81;i++)
103 {
104 document.getElementsByName("TextBox")[i].value=dealZeroOutput(splitResult[i]);
105 }
106 }
107 }
108 else if(request.readyState == 1)
109 {
110 //"finished step1";
111 }
112 else if(request.readyState == 2)
113 {
114 //"finished step2";
115 }
116 else if(request.readyState == 3)
117 {
118 //"finished step3";
119 }
120}
121</script>
122<table>
123<tr>
124<td>
125<input name="TextBox" type="text" style="width: 25px"/>
126</td>
127<td>
128<input name="TextBox" type="text" style="width: 25px"/>
129</td>
130<td>
131<input name="TextBox" type="text" style="width: 25px"/>
132</td>
133<td>
134<input name="TextBox" type="text" style="width: 25px"/>
135</td>
136<td>
137<input name="TextBox" type="text" style="width: 25px"/>
138</td>
139<td>
140<input name="TextBox" type="text" style="width: 25px"/>
141</td>
142<td>
143<input name="TextBox" type="text" style="width: 25px"/>
144</td>
145<td>
146<input name="TextBox" type="text" style="width: 25px"/>
147</td>
148<td>
149<input name="TextBox" type="text" style="width: 25px"/>
150</td>
151</tr>
152<tr>
153<td>
154<input name="TextBox" type="text" style="width: 25px"/>
155</td>
156<td>
157<input name="TextBox" type="text" style="width: 25px"/>
158</td>
159<td>
160<input name="TextBox" type="text" style="width: 25px"/>
161</td>
162<td>
163<input name="TextBox" type="text" style="width: 25px"/>
164</td>
165<td>
166<input name="TextBox" type="text" style="width: 25px"/>
167</td>
168<td>
169<input name="TextBox" type="text" style="width: 25px"/>
170</td>
171<td>
172<input name="TextBox" type="text" style="width: 25px"/>
173</td>
174<td>
175<input name="TextBox" type="text" style="width: 25px"/>
176</td>
177<td>
178<input name="TextBox" type="text" style="width: 25px"/>
179</td>
180</tr>
181<tr>
182<td>
183<input name="TextBox" type="text" style="width: 25px"/>
184</td>
185<td>
186<input name="TextBox" type="text" style="width: 25px"/>
187</td>
188<td>
189<input name="TextBox" type="text" style="width: 25px"/>
190</td>
191<td>
192<input name="TextBox" type="text" style="width: 25px"/>
193</td>
194<td>
195<input name="TextBox" type="text" style="width: 25px"/>
196</td>
197<td>
198<input name="TextBox" type="text" style="width: 25px"/>
199</td>
200<td>
201<input name="TextBox" type="text" style="width: 25px"/>
202</td>
203<td>
204<input name="TextBox" type="text" style="width: 25px"/>
205</td>
206<td>
207<input name="TextBox" type="text" style="width: 25px"/>
208</td>
209</tr>
210<tr>
211<td>
212<input name="TextBox" type="text" style="width: 25px"/>
213</td>
214<td>
215<input name="TextBox" type="text" style="width: 25px"/>
216</td>
217<td>
218<input name="TextBox" type="text" style="width: 25px"/>
219</td>
220<td>
221<input name="TextBox" type="text" style="width: 25px"/>
222</td>
223<td>
224<input name="TextBox" type="text" style="width: 25px"/>
225</td>
226<td>
227<input name="TextBox" type="text" style="width: 25px"/>
228</td>
229<td>
230<input name="TextBox" type="text" style="width: 25px"/>
231</td>
232<td>
233<input name="TextBox" type="text" style="width: 25px"/>
234</td>
235<td>
236<input name="TextBox" type="text" style="width: 25px"/>
237</td>
238</tr>
239<tr>
240<td>
241<input name="TextBox" type="text" style="width: 25px"/>
242</td>
243<td>
244<input name="TextBox" type="text" style="width: 25px"/>
245</td>
246<td>
247<input name="TextBox" type="text" style="width: 25px"/>
248</td>
249<td>
250<input name="TextBox" type="text" style="width: 25px"/>
251</td>
252<td>
253<input name="TextBox" type="text" style="width: 25px"/>
254</td>
255<td>
256<input name="TextBox" type="text" style="width: 25px"/>
257</td>
258<td>
259<input name="TextBox" type="text" style="width: 25px"/>
260</td>
261<td>
262<input name="TextBox" type="text" style="width: 25px"/>
263</td>
264<td>
265<input name="TextBox" type="text" style="width: 25px"/>
266</td>
267</tr>
268<tr>
269<td>
270<input name="TextBox" type="text" style="width: 25px"/>
271</td>
272<td>
273<input name="TextBox" type="text" style="width: 25px"/>
274</td>
275<td>
276<input name="TextBox" type="text" style="width: 25px"/>
277</td>
278<td>
279<input name="TextBox" type="text" style="width: 25px"/>
280</td>
281<td>
282<input name="TextBox" type="text" style="width: 25px"/>
283</td>
284<td>
285<input name="TextBox" type="text" style="width: 25px"/>
286</td>
287<td>
288<input name="TextBox" type="text" style="width: 25px"/>
289</td>
290<td>
291<input name="TextBox" type="text" style="width: 25px"/>
292</td>
293<td>
294<input name="TextBox" type="text" style="width: 25px"/>
295</td>
296</tr>
297<tr>
298<td>
299<input name="TextBox" type="text" style="width: 25px"/>
300</td>
301<td>
302<input name="TextBox" type="text" style="width: 25px"/>
303</td>
304<td>
305<input name="TextBox" type="text" style="width: 25px"/>
306</td>
307<td>
308<input name="TextBox" type="text" style="width: 25px"/>
309</td>
310<td>
311<input name="TextBox" type="text" style="width: 25px"/>
312</td>
313<td>
314<input name="TextBox" type="text" style="width: 25px"/>
315</td>
316<td>
317<input name="TextBox" type="text" style="width: 25px"/>
318</td>
319<td>
320<input name="TextBox" type="text" style="width: 25px"/>
321</td>
322<td>
323<input name="TextBox" type="text" style="width: 25px"/>
324</td>
325</tr>
326<tr>
327<td>
328<input name="TextBox" type="text" style="width: 25px"/>
329</td>
330<td>
331<input name="TextBox" type="text" style="width: 25px"/>
332</td>
333<td>
334<input name="TextBox" type="text" style="width: 25px"/>
335</td>
336<td>
337<input name="TextBox" type="text" style="width: 25px"/>
338</td>
339<td>
340<input name="TextBox" type="text" style="width: 25px"/>
341</td>
342<td>
343<input name="TextBox" type="text" style="width: 25px"/>
344</td>
345<td>
346<input name="TextBox" type="text" style="width: 25px"/>
347</td>
348<td>
349<input name="TextBox" type="text" style="width: 25px"/>
350</td>
351<td>
352<input name="TextBox" type="text" style="width: 25px"/>
353</td>
354</tr>
355<tr>
356<td>
357<input name="TextBox" type="text" style="width: 25px"/>
358</td>
359<td>
360<input name="TextBox" type="text" style="width: 25px"/>
361</td>
362<td>
363<input name="TextBox" type="text" style="width: 25px"/>
364</td>
365<td>
366<input name="TextBox" type="text" style="width: 25px"/>
367</td>
368<td>
369<input name="TextBox" type="text" style="width: 25px"/>
370</td>
371<td>
372<input name="TextBox" type="text" style="width: 25px"/>
373</td>
374<td>
375<input name="TextBox" type="text" style="width: 25px"/>
376</td>
377<td>
378<input name="TextBox" type="text" style="width: 25px"/>
379</td>
380<td>
381<input name="TextBox" type="text" style="width: 25px"/>
382</td>
383</tr>
384</table>
385<input type="button" name="OneStep" value="OneStep" id="OneStep" onclick="sendOneStepRequest()" />
386<input type="button" name="AllSteps" value="AllSteps" id="AllSteps" onclick="sendAllStepsRequest()" />
387</body>
388</html>
puzzleVB.aspx.vb:
1
2Partial Class puzzleVB
3 Inherits System.Web.UI.Page
4
5 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
6 If Me.Request.Form.Get("type") <> Nothing Then
7 Try
8 Dim array As String = Me.Request.Form.Get("array")
9 Dim numbers As String() = array.Split(","c)
10 Dim dealingArray(8, 8) As Integer
11 For row As Integer = 0 To 8
12 For column As Integer = 0 To 8
13 dealingArray(row, column) = Convert.ToInt32(numbers(row * 9 + column))
14 Next
15 Next
16 Dim deducer As Deducer = New Deducer(dealingArray)
17 If Me.Request.Form.Get("type") = "OneStep" Then
18 deducer.DeduceOnce()
19 ElseIf Me.Request.Form.Get("type") = "AllSteps" Then
20 deducer.DeduceAll()
21 End If
22 Dim sb As StringBuilder = New StringBuilder()
23 For row As Integer = 0 To 8
24 For column As Integer = 0 To 8
25 If sb.ToString() = "" Then
26 sb.Append(deducer.Array(row, column))
27 Else
28 sb.Append("," & deducer.Array(row, column))
29 End If
30 Next
31 Next
32 Me.Response.Write(sb)
33 Catch ex As Exception
34 Me.Response.Write("ri")
35 End Try
36 Me.Response.End()
37 End If
38 End Sub
39End Class
40
2Partial Class puzzleVB
3 Inherits System.Web.UI.Page
4
5 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
6 If Me.Request.Form.Get("type") <> Nothing Then
7 Try
8 Dim array As String = Me.Request.Form.Get("array")
9 Dim numbers As String() = array.Split(","c)
10 Dim dealingArray(8, 8) As Integer
11 For row As Integer = 0 To 8
12 For column As Integer = 0 To 8
13 dealingArray(row, column) = Convert.ToInt32(numbers(row * 9 + column))
14 Next
15 Next
16 Dim deducer As Deducer = New Deducer(dealingArray)
17 If Me.Request.Form.Get("type") = "OneStep" Then
18 deducer.DeduceOnce()
19 ElseIf Me.Request.Form.Get("type") = "AllSteps" Then
20 deducer.DeduceAll()
21 End If
22 Dim sb As StringBuilder = New StringBuilder()
23 For row As Integer = 0 To 8
24 For column As Integer = 0 To 8
25 If sb.ToString() = "" Then
26 sb.Append(deducer.Array(row, column))
27 Else
28 sb.Append("," & deducer.Array(row, column))
29 End If
30 Next
31 Next
32 Me.Response.Write(sb)
33 Catch ex As Exception
34 Me.Response.Write("ri")
35 End Try
36 Me.Response.End()
37 End If
38 End Sub
39End Class
40
puzzleVB.aspx:
1<%@ Page Language="VB" AutoEventWireup="false" CodeFile="puzzleVB.aspx.vb" Inherits="puzzleVB" %>
2
3<html>
4<body>
5<script>
6var request=false;
7try
8{
9 request = new XMLHttpRequest();//Firefox
10}
11catch(trymicrosoft)
12{
13 try
14 {
15 request = new ActiveXObject("Msxml2.XMLHTTP.5.0");//New IE
16 }
17 catch(othermicrosoft)
18 {
19 try
20 {
21 request = new ActiveXObject("Microsoft.XMLHTTP");//Old IE
22 }
23 catch(failed)
24 {
25 request = false;//Unknown browser
26 }
27 }
28}
29if(!request)
30{
31 alert("Please use Internet Explorer");
32}
33function dealNullInput(input)
34{
35 if(input=="")
36 {
37 return "0";
38 }
39 else
40 {
41 return input;
42 }
43}
44function dealZeroOutput(input)
45{
46 if(input==0)
47 {
48 return "";
49 }
50 else
51 {
52 return input;
53 }
54}
55function sendOneStepRequest()
56{
57 url=escape("puzzleVB.aspx")+"?random=" + Math.random();//use a random number to avoid cache
58 request.open("POST",url,true);//connection method
59 request.onreadystatechange=showProcess;//show Process method
60 request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
61 var array="";
62 for(var i=0;i<81;i++)
63 {
64 if(array=="")
65 {
66 array=array+dealNullInput(document.getElementsByName("TextBox")[i].value);
67 }
68 else
69 {
70 array=array+","+dealNullInput(document.getElementsByName("TextBox")[i].value);
71 }
72 }
73 request.send("type=OneStep"+"&array="+escape(array));
74}
75function sendAllStepsRequest()
76{
77 url=escape("puzzleCS.aspx")+"?random=" + Math.random();
78 request.open("POST",url,true);//connection method
79 request.onreadystatechange=showProcess;//show Process method
80 request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
81 var array="";
82 for(var i=0;i<81;i++)
83 {
84 if(array=="")
85 {
86 array=array+dealNullInput(document.getElementsByName("TextBox")[i].value);
87 }
88 else
89 {
90 array=array+","+dealNullInput(document.getElementsByName("TextBox")[i].value.replace(/ /g, ""));
91 }
92 }
93 request.send("type=AllSteps"+"&array="+escape(array));
94}
95function showProcess()
96{
97 if(request.readyState == 4)//finished
98 {
99 if(request.status == 200)//normal
100 {
101 var splitResult=request.responseText.split(",");
102 for(var i=0;i<81;i++)
103 {
104 document.getElementsByName("TextBox")[i].value=dealZeroOutput(splitResult[i]);
105 }
106 }
107 }
108 else if(request.readyState == 1)
109 {
110 //"finished step1";
111 }
112 else if(request.readyState == 2)
113 {
114 //"finished step2";
115 }
116 else if(request.readyState == 3)
117 {
118 //"finished step3";
119 }
120}
121</script>
122<table>
123<tr>
124<td>
125<input name="TextBox" type="text" style="width: 25px"/>
126</td>
127<td>
128<input name="TextBox" type="text" style="width: 25px"/>
129</td>
130<td>
131<input name="TextBox" type="text" style="width: 25px"/>
132</td>
133<td>
134<input name="TextBox" type="text" style="width: 25px"/>
135</td>
136<td>
137<input name="TextBox" type="text" style="width: 25px"/>
138</td>
139<td>
140<input name="TextBox" type="text" style="width: 25px"/>
141</td>
142<td>
143<input name="TextBox" type="text" style="width: 25px"/>
144</td>
145<td>
146<input name="TextBox" type="text" style="width: 25px"/>
147</td>
148<td>
149<input name="TextBox" type="text" style="width: 25px"/>
150</td>
151</tr>
152<tr>
153<td>
154<input name="TextBox" type="text" style="width: 25px"/>
155</td>
156<td>
157<input name="TextBox" type="text" style="width: 25px"/>
158</td>
159<td>
160<input name="TextBox" type="text" style="width: 25px"/>
161</td>
162<td>
163<input name="TextBox" type="text" style="width: 25px"/>
164</td>
165<td>
166<input name="TextBox" type="text" style="width: 25px"/>
167</td>
168<td>
169<input name="TextBox" type="text" style="width: 25px"/>
170</td>
171<td>
172<input name="TextBox" type="text" style="width: 25px"/>
173</td>
174<td>
175<input name="TextBox" type="text" style="width: 25px"/>
176</td>
177<td>
178<input name="TextBox" type="text" style="width: 25px"/>
179</td>
180</tr>
181<tr>
182<td>
183<input name="TextBox" type="text" style="width: 25px"/>
184</td>
185<td>
186<input name="TextBox" type="text" style="width: 25px"/>
187</td>
188<td>
189<input name="TextBox" type="text" style="width: 25px"/>
190</td>
191<td>
192<input name="TextBox" type="text" style="width: 25px"/>
193</td>
194<td>
195<input name="TextBox" type="text" style="width: 25px"/>
196</td>
197<td>
198<input name="TextBox" type="text" style="width: 25px"/>
199</td>
200<td>
201<input name="TextBox" type="text" style="width: 25px"/>
202</td>
203<td>
204<input name="TextBox" type="text" style="width: 25px"/>
205</td>
206<td>
207<input name="TextBox" type="text" style="width: 25px"/>
208</td>
209</tr>
210<tr>
211<td>
212<input name="TextBox" type="text" style="width: 25px"/>
213</td>
214<td>
215<input name="TextBox" type="text" style="width: 25px"/>
216</td>
217<td>
218<input name="TextBox" type="text" style="width: 25px"/>
219</td>
220<td>
221<input name="TextBox" type="text" style="width: 25px"/>
222</td>
223<td>
224<input name="TextBox" type="text" style="width: 25px"/>
225</td>
226<td>
227<input name="TextBox" type="text" style="width: 25px"/>
228</td>
229<td>
230<input name="TextBox" type="text" style="width: 25px"/>
231</td>
232<td>
233<input name="TextBox" type="text" style="width: 25px"/>
234</td>
235<td>
236<input name="TextBox" type="text" style="width: 25px"/>
237</td>
238</tr>
239<tr>
240<td>
241<input name="TextBox" type="text" style="width: 25px"/>
242</td>
243<td>
244<input name="TextBox" type="text" style="width: 25px"/>
245</td>
246<td>
247<input name="TextBox" type="text" style="width: 25px"/>
248</td>
249<td>
250<input name="TextBox" type="text" style="width: 25px"/>
251</td>
252<td>
253<input name="TextBox" type="text" style="width: 25px"/>
254</td>
255<td>
256<input name="TextBox" type="text" style="width: 25px"/>
257</td>
258<td>
259<input name="TextBox" type="text" style="width: 25px"/>
260</td>
261<td>
262<input name="TextBox" type="text" style="width: 25px"/>
263</td>
264<td>
265<input name="TextBox" type="text" style="width: 25px"/>
266</td>
267</tr>
268<tr>
269<td>
270<input name="TextBox" type="text" style="width: 25px"/>
271</td>
272<td>
273<input name="TextBox" type="text" style="width: 25px"/>
274</td>
275<td>
276<input name="TextBox" type="text" style="width: 25px"/>
277</td>
278<td>
279<input name="TextBox" type="text" style="width: 25px"/>
280</td>
281<td>
282<input name="TextBox" type="text" style="width: 25px"/>
283</td>
284<td>
285<input name="TextBox" type="text" style="width: 25px"/>
286</td>
287<td>
288<input name="TextBox" type="text" style="width: 25px"/>
289</td>
290<td>
291<input name="TextBox" type="text" style="width: 25px"/>
292</td>
293<td>
294<input name="TextBox" type="text" style="width: 25px"/>
295</td>
296</tr>
297<tr>
298<td>
299<input name="TextBox" type="text" style="width: 25px"/>
300</td>
301<td>
302<input name="TextBox" type="text" style="width: 25px"/>
303</td>
304<td>
305<input name="TextBox" type="text" style="width: 25px"/>
306</td>
307<td>
308<input name="TextBox" type="text" style="width: 25px"/>
309</td>
310<td>
311<input name="TextBox" type="text" style="width: 25px"/>
312</td>
313<td>
314<input name="TextBox" type="text" style="width: 25px"/>
315</td>
316<td>
317<input name="TextBox" type="text" style="width: 25px"/>
318</td>
319<td>
320<input name="TextBox" type="text" style="width: 25px"/>
321</td>
322<td>
323<input name="TextBox" type="text" style="width: 25px"/>
324</td>
325</tr>
326<tr>
327<td>
328<input name="TextBox" type="text" style="width: 25px"/>
329</td>
330<td>
331<input name="TextBox" type="text" style="width: 25px"/>
332</td>
333<td>
334<input name="TextBox" type="text" style="width: 25px"/>
335</td>
336<td>
337<input name="TextBox" type="text" style="width: 25px"/>
338</td>
339<td>
340<input name="TextBox" type="text" style="width: 25px"/>
341</td>
342<td>
343<input name="TextBox" type="text" style="width: 25px"/>
344</td>
345<td>
346<input name="TextBox" type="text" style="width: 25px"/>
347</td>
348<td>
349<input name="TextBox" type="text" style="width: 25px"/>
350</td>
351<td>
352<input name="TextBox" type="text" style="width: 25px"/>
353</td>
354</tr>
355<tr>
356<td>
357<input name="TextBox" type="text" style="width: 25px"/>
358</td>
359<td>
360<input name="TextBox" type="text" style="width: 25px"/>
361</td>
362<td>
363<input name="TextBox" type="text" style="width: 25px"/>
364</td>
365<td>
366<input name="TextBox" type="text" style="width: 25px"/>
367</td>
368<td>
369<input name="TextBox" type="text" style="width: 25px"/>
370</td>
371<td>
372<input name="TextBox" type="text" style="width: 25px"/>
373</td>
374<td>
375<input name="TextBox" type="text" style="width: 25px"/>
376</td>
377<td>
378<input name="TextBox" type="text" style="width: 25px"/>
379</td>
380<td>
381<input name="TextBox" type="text" style="width: 25px"/>
382</td>
383</tr>
384</table>
385<input type="button" name="OneStep" value="OneStep" id="OneStep" onclick="sendOneStepRequest()" />
386<input type="button" name="AllSteps" value="AllSteps" id="AllSteps" onclick="sendAllStepsRequest()" />
387</body>
388</html>
2
3<html>
4<body>
5<script>
6var request=false;
7try
8{
9 request = new XMLHttpRequest();//Firefox
10}
11catch(trymicrosoft)
12{
13 try
14 {
15 request = new ActiveXObject("Msxml2.XMLHTTP.5.0");//New IE
16 }
17 catch(othermicrosoft)
18 {
19 try
20 {
21 request = new ActiveXObject("Microsoft.XMLHTTP");//Old IE
22 }
23 catch(failed)
24 {
25 request = false;//Unknown browser
26 }
27 }
28}
29if(!request)
30{
31 alert("Please use Internet Explorer");
32}
33function dealNullInput(input)
34{
35 if(input=="")
36 {
37 return "0";
38 }
39 else
40 {
41 return input;
42 }
43}
44function dealZeroOutput(input)
45{
46 if(input==0)
47 {
48 return "";
49 }
50 else
51 {
52 return input;
53 }
54}
55function sendOneStepRequest()
56{
57 url=escape("puzzleVB.aspx")+"?random=" + Math.random();//use a random number to avoid cache
58 request.open("POST",url,true);//connection method
59 request.onreadystatechange=showProcess;//show Process method
60 request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
61 var array="";
62 for(var i=0;i<81;i++)
63 {
64 if(array=="")
65 {
66 array=array+dealNullInput(document.getElementsByName("TextBox")[i].value);
67 }
68 else
69 {
70 array=array+","+dealNullInput(document.getElementsByName("TextBox")[i].value);
71 }
72 }
73 request.send("type=OneStep"+"&array="+escape(array));
74}
75function sendAllStepsRequest()
76{
77 url=escape("puzzleCS.aspx")+"?random=" + Math.random();
78 request.open("POST",url,true);//connection method
79 request.onreadystatechange=showProcess;//show Process method
80 request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
81 var array="";
82 for(var i=0;i<81;i++)
83 {
84 if(array=="")
85 {
86 array=array+dealNullInput(document.getElementsByName("TextBox")[i].value);
87 }
88 else
89 {
90 array=array+","+dealNullInput(document.getElementsByName("TextBox")[i].value.replace(/ /g, ""));
91 }
92 }
93 request.send("type=AllSteps"+"&array="+escape(array));
94}
95function showProcess()
96{
97 if(request.readyState == 4)//finished
98 {
99 if(request.status == 200)//normal
100 {
101 var splitResult=request.responseText.split(",");
102 for(var i=0;i<81;i++)
103 {
104 document.getElementsByName("TextBox")[i].value=dealZeroOutput(splitResult[i]);
105 }
106 }
107 }
108 else if(request.readyState == 1)
109 {
110 //"finished step1";
111 }
112 else if(request.readyState == 2)
113 {
114 //"finished step2";
115 }
116 else if(request.readyState == 3)
117 {
118 //"finished step3";
119 }
120}
121</script>
122<table>
123<tr>
124<td>
125<input name="TextBox" type="text" style="width: 25px"/>
126</td>
127<td>
128<input name="TextBox" type="text" style="width: 25px"/>
129</td>
130<td>
131<input name="TextBox" type="text" style="width: 25px"/>
132</td>
133<td>
134<input name="TextBox" type="text" style="width: 25px"/>
135</td>
136<td>
137<input name="TextBox" type="text" style="width: 25px"/>
138</td>
139<td>
140<input name="TextBox" type="text" style="width: 25px"/>
141</td>
142<td>
143<input name="TextBox" type="text" style="width: 25px"/>
144</td>
145<td>
146<input name="TextBox" type="text" style="width: 25px"/>
147</td>
148<td>
149<input name="TextBox" type="text" style="width: 25px"/>
150</td>
151</tr>
152<tr>
153<td>
154<input name="TextBox" type="text" style="width: 25px"/>
155</td>
156<td>
157<input name="TextBox" type="text" style="width: 25px"/>
158</td>
159<td>
160<input name="TextBox" type="text" style="width: 25px"/>
161</td>
162<td>
163<input name="TextBox" type="text" style="width: 25px"/>
164</td>
165<td>
166<input name="TextBox" type="text" style="width: 25px"/>
167</td>
168<td>
169<input name="TextBox" type="text" style="width: 25px"/>
170</td>
171<td>
172<input name="TextBox" type="text" style="width: 25px"/>
173</td>
174<td>
175<input name="TextBox" type="text" style="width: 25px"/>
176</td>
177<td>
178<input name="TextBox" type="text" style="width: 25px"/>
179</td>
180</tr>
181<tr>
182<td>
183<input name="TextBox" type="text" style="width: 25px"/>
184</td>
185<td>
186<input name="TextBox" type="text" style="width: 25px"/>
187</td>
188<td>
189<input name="TextBox" type="text" style="width: 25px"/>
190</td>
191<td>
192<input name="TextBox" type="text" style="width: 25px"/>
193</td>
194<td>
195<input name="TextBox" type="text" style="width: 25px"/>
196</td>
197<td>
198<input name="TextBox" type="text" style="width: 25px"/>
199</td>
200<td>
201<input name="TextBox" type="text" style="width: 25px"/>
202</td>
203<td>
204<input name="TextBox" type="text" style="width: 25px"/>
205</td>
206<td>
207<input name="TextBox" type="text" style="width: 25px"/>
208</td>
209</tr>
210<tr>
211<td>
212<input name="TextBox" type="text" style="width: 25px"/>
213</td>
214<td>
215<input name="TextBox" type="text" style="width: 25px"/>
216</td>
217<td>
218<input name="TextBox" type="text" style="width: 25px"/>
219</td>
220<td>
221<input name="TextBox" type="text" style="width: 25px"/>
222</td>
223<td>
224<input name="TextBox" type="text" style="width: 25px"/>
225</td>
226<td>
227<input name="TextBox" type="text" style="width: 25px"/>
228</td>
229<td>
230<input name="TextBox" type="text" style="width: 25px"/>
231</td>
232<td>
233<input name="TextBox" type="text" style="width: 25px"/>
234</td>
235<td>
236<input name="TextBox" type="text" style="width: 25px"/>
237</td>
238</tr>
239<tr>
240<td>
241<input name="TextBox" type="text" style="width: 25px"/>
242</td>
243<td>
244<input name="TextBox" type="text" style="width: 25px"/>
245</td>
246<td>
247<input name="TextBox" type="text" style="width: 25px"/>
248</td>
249<td>
250<input name="TextBox" type="text" style="width: 25px"/>
251</td>
252<td>
253<input name="TextBox" type="text" style="width: 25px"/>
254</td>
255<td>
256<input name="TextBox" type="text" style="width: 25px"/>
257</td>
258<td>
259<input name="TextBox" type="text" style="width: 25px"/>
260</td>
261<td>
262<input name="TextBox" type="text" style="width: 25px"/>
263</td>
264<td>
265<input name="TextBox" type="text" style="width: 25px"/>
266</td>
267</tr>
268<tr>
269<td>
270<input name="TextBox" type="text" style="width: 25px"/>
271</td>
272<td>
273<input name="TextBox" type="text" style="width: 25px"/>
274</td>
275<td>
276<input name="TextBox" type="text" style="width: 25px"/>
277</td>
278<td>
279<input name="TextBox" type="text" style="width: 25px"/>
280</td>
281<td>
282<input name="TextBox" type="text" style="width: 25px"/>
283</td>
284<td>
285<input name="TextBox" type="text" style="width: 25px"/>
286</td>
287<td>
288<input name="TextBox" type="text" style="width: 25px"/>
289</td>
290<td>
291<input name="TextBox" type="text" style="width: 25px"/>
292</td>
293<td>
294<input name="TextBox" type="text" style="width: 25px"/>
295</td>
296</tr>
297<tr>
298<td>
299<input name="TextBox" type="text" style="width: 25px"/>
300</td>
301<td>
302<input name="TextBox" type="text" style="width: 25px"/>
303</td>
304<td>
305<input name="TextBox" type="text" style="width: 25px"/>
306</td>
307<td>
308<input name="TextBox" type="text" style="width: 25px"/>
309</td>
310<td>
311<input name="TextBox" type="text" style="width: 25px"/>
312</td>
313<td>
314<input name="TextBox" type="text" style="width: 25px"/>
315</td>
316<td>
317<input name="TextBox" type="text" style="width: 25px"/>
318</td>
319<td>
320<input name="TextBox" type="text" style="width: 25px"/>
321</td>
322<td>
323<input name="TextBox" type="text" style="width: 25px"/>
324</td>
325</tr>
326<tr>
327<td>
328<input name="TextBox" type="text" style="width: 25px"/>
329</td>
330<td>
331<input name="TextBox" type="text" style="width: 25px"/>
332</td>
333<td>
334<input name="TextBox" type="text" style="width: 25px"/>
335</td>
336<td>
337<input name="TextBox" type="text" style="width: 25px"/>
338</td>
339<td>
340<input name="TextBox" type="text" style="width: 25px"/>
341</td>
342<td>
343<input name="TextBox" type="text" style="width: 25px"/>
344</td>
345<td>
346<input name="TextBox" type="text" style="width: 25px"/>
347</td>
348<td>
349<input name="TextBox" type="text" style="width: 25px"/>
350</td>
351<td>
352<input name="TextBox" type="text" style="width: 25px"/>
353</td>
354</tr>
355<tr>
356<td>
357<input name="TextBox" type="text" style="width: 25px"/>
358</td>
359<td>
360<input name="TextBox" type="text" style="width: 25px"/>
361</td>
362<td>
363<input name="TextBox" type="text" style="width: 25px"/>
364</td>
365<td>
366<input name="TextBox" type="text" style="width: 25px"/>
367</td>
368<td>
369<input name="TextBox" type="text" style="width: 25px"/>
370</td>
371<td>
372<input name="TextBox" type="text" style="width: 25px"/>
373</td>
374<td>
375<input name="TextBox" type="text" style="width: 25px"/>
376</td>
377<td>
378<input name="TextBox" type="text" style="width: 25px"/>
379</td>
380<td>
381<input name="TextBox" type="text" style="width: 25px"/>
382</td>
383</tr>
384</table>
385<input type="button" name="OneStep" value="OneStep" id="OneStep" onclick="sendOneStepRequest()" />
386<input type="button" name="AllSteps" value="AllSteps" id="AllSteps" onclick="sendAllStepsRequest()" />
387</body>
388</html>