-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSudoku.cs
1171 lines (765 loc) · 28.9 KB
/
Sudoku.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Media;
namespace Sudoku
{
class Sudoku
{
#region Class Decelerations
public int[,] s; // sudoku numbers
private int[,] a; // aids
private int[,] f; // facts
private int[,] e; // errors
private Random R;
private float realx;
private float realy;
private float realw;
private int hitx = -1;
private int hity;
public int sw = 0;
private DateTime starttime;
private string duration;
private string msg_text1;
private string msg_text2;
private bool DisplayMessage = false;
private bool PriorityMessage = false;
public enum SudokuSound
{
Stop = 0,
Square = 1,
No = 2,
Fine = 3,
Delete = 4,
Solved = 5,
NewPuzzle = 6,
};
public delegate void SudokuEvent(SudokuSound S);
public delegate void SudokuEvent2();
public event SudokuEvent PlaySound;
public event SudokuEvent2 RequestRepaint;
public bool ShowErrors = false;
public enum SolveMethods
{
All = 65535,
NakedSingles = 1,
HiddenSingles = 2,
BlockHiddenSingles = 4,
}
public class SolutionStep
{
public int x;
public int y;
public int num;
public SolutionStep()
{
x = 0; y = 0; num = 0;
}
public SolutionStep(int x, int y, int num)
{
this.x = x;
this.y = y;
this.num = num;
}
};
public class SolutionStepList
{
private List<SolutionStep> L;
public SolutionStepList()
{
L = new List<SolutionStep>();
}
private bool Search(SolutionStep ss)
{
for (int i = 0; i < L.Count; i++)
{
SolutionStep present = L[i];
if (ss.x == present.x && ss.y == present.y && ss.num == present.num) return true;
}
return false;
}
public void Add(SolutionStep ss)
{
// if (!Search(ss)) L.Add(ss);
L.Add(ss);
}
public int Count()
{
return L.Count;
}
public SolutionStep getItem(int index)
{
return L[index];
}
}
#endregion
public Sudoku()
{
s = new int[9, 9];
f = new int[9, 9];
a = new int[9, 9];
e = new int[9, 9];
R = new Random();
EnumeratePossibilities();
return;
}
public void SetLocation(Point Location)
{
if (DisplayMessage & !PriorityMessage)
{
DisplayMessage = false;
return;
}
int new_hitx = (int)Math.Floor((Location.X - realx) / realw * 9.0);
int new_hity = (int)Math.Floor((Location.Y - realy) / realw * 9.0);
if (new_hitx < 0 || new_hitx > 8 || new_hity < 0 || new_hity > 8)
{
hitx = -1;
return;
}
if (new_hitx == hitx && new_hity == hity)
{
hitx = -1;
}
else
{
if (f[new_hity, new_hitx] == 0)
{
hitx = new_hitx;
hity = new_hity;
}
}
}
public void Deselect()
{
hitx = -1;
}
public void DeleteCurrentSquare()
{
if (hitx != -1)
{
s[hity, hitx] = 0;
e[hity, hitx] = 0;
}
hitx = -1;
EnumeratePossibilities();
}
public void KeyPress(char KeyCode)
{
if (DisplayMessage & !PriorityMessage)
{
DisplayMessage = false;
return;
}
if (KeyCode < '1' || KeyCode > '9') return;
if (hitx == -1) return;
s[hity, hitx] = KeyCode - '0';
e[hity, hitx] = 0;
hitx = -1;
EnumeratePossibilities();
// ComputeErrors();
if (PlaySound != null) PlaySound(SudokuSound.Square);
if (isSolved())
{
while (hitx != -1) Application.DoEvents();
Timer T = new Timer();
T.Tick += new EventHandler(DisplayPuzzleSolved);
T.Interval = 1500;
T.Start();
TimeSpan d = (DateTime.Now - starttime);
duration = "";
if (d.Minutes > 0) duration = d.Minutes.ToString() + " minute";
if (d.Minutes > 1) duration += "s";
if (d.Minutes > 0 && d.Seconds > 0) duration += " and ";
if (d.Seconds > 0) duration += d.Seconds.ToString() + " second";
if (d.Seconds > 1) duration += "s";
}
}
public void UseTemplate()
{
string game1 = "X6X1X4X5XXX83X56XX2XXXXXXX18XX4X7XX6XX6XXX3XX7XX9X1XX45XXXXXXX2XX72X69XXX4X5X8X7X"; // easy 1
game1 = "XXXX7XX6X6XXXXXX42XXX89XX15XXXXX54XX769XXX521XX19XXXXX91XX42XXX28XXXXXX3X7XX8XXXX"; // easy 2
// game1 = "XXXXXXXX547XXXXXXX85XX42XXX64X58XXXXXX79X41XXXXXX73X96XXX85XX34XXXXXXX673XXXXXXXX"; // hard 1
game1 = "829173456713645298645298173381726945976514832452839617297381564168457329534962781"; //complete game
SetGameString(game1);
}
public void GenerateGame()
{
if (PlaySound != null) PlaySound(SudokuSound.Stop);
UseTemplate();
int trials_counter = 0;
int trials_max = 100;
SolveMethods M = SolveMethods.All;
// Generating a list of filled squares
List<Point> L = new List<Point>();
for (int i = 0; i < 9; i++)
for (int j = 0; j < 9; j++)
{
if (s[j, i] > 0) L.Add(new Point(i, j));
}
int n;
for (n = 0; n < 55; )
{
int index = R.Next(L.Count);
int x = L[index].X;
int y = L[index].Y;
int temp = s[x, y];
if (temp != 0)
{
s[x, y] = 0;
Sudoku S2 = CreateCopy();
int solutionStepsCount = S2.ComputePossibleSteps(M).Count();
bool range0Ok = ((n > 35) && (solutionStepsCount > 25));
bool range1Ok = ((n > 15) && (solutionStepsCount > 25));
bool range2Ok = n < 16;
bool solutionStepsCountOk = range0Ok || range1Ok || range2Ok;
if (solutionStepsCountOk)
{
bool isSolvable = S2.SolvePuzzle(M);
if (isSolvable)
{
L.RemoveAt(index);
n++;
trials_counter = 0;
}
else
{
s[x, y] = temp;
}
}
else
{
s[x, y] = temp;
}
trials_counter++;
}
if (trials_counter > trials_max) break;
}
ScrambleGame();
for (int i = 0; i < 9; i++)
for (int j = 0; j < 9; j++)
{
if (s[i, j] == 0) f[i, j] = 0; else f[i, j] = 1;
}
// SetGameString("XX7XXX5XXXXXX4XX3XXXX832X9X8XXXXX4XXX294X586XXX6XXXXX7X5X364XXXX7XX5XXXXXX3XXX2XX");
EnumeratePossibilities();
starttime = DateTime.Now;
DisplayMessage = false;
if (PlaySound != null) PlaySound(SudokuSound.NewPuzzle);
if (RequestRepaint != null) RequestRepaint();
}
public void RenderMessage(string line1, string line2, bool priority)
{
if (!priority && DisplayMessage) return;
msg_text1 = line1;
msg_text2 = line2;
PriorityMessage = priority;
DisplayMessage = true;
if (RequestRepaint != null) RequestRepaint();
}
public void ScrambleGame()
{
//0 1, 1 2, 3 4, 4 5, 6 7 7 8
int[] scramble_array = { 0, 1, 3, 4, 6, 7 };
int scrambles = 10;
for (int n = 0; n < scrambles; n++)
{
int index = R.Next(6);
int val = scramble_array[index];
SwapRows(val, val + 1);
}
for (int n = 0; n < scrambles; n++)
{
int index = R.Next(6);
int val = scramble_array[index];
SwapCols(val, val + 1);
}
ChangeSymbols();
EnumeratePossibilities();
}
public string GetGameString()
{
string result = "";
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
result += s[i, j].ToString();
}
}
result = result.Replace("0", "X");
return result;
}
public bool SetGameString(string game)
{
if (game.Length != 81) return false;
for (int n = 0; n < 81; n++)
{
char c = game[n];
if ((c < '1' || c > '9') && c != 'X') return false;
}
for (int n = 0; n < 81; n++)
{
string c = game.Substring(n, 1);
int i = n / 9;
int j = n % 9;
if (c == "X")
{
s[i, j] = 0;
f[i, j] = 0;
}
else
{
s[i, j] = Convert.ToInt32(c);
f[i, j] = 1;
}
}
EnumeratePossibilities();
DisplayMessage = false;
return true;
}
public void Draw(Graphics G, float angle)
{
Color Background = Color.DarkKhaki;
Brush BG1 = new Pen(Color.Khaki).Brush;
Brush BG2 = new Pen(Color.LightGoldenrodYellow).Brush;
Brush BG;
Brush Selected = new Pen(Color.BurlyWood).Brush;
Selected = new SolidBrush(Color.FromArgb(64, Color.RoyalBlue));
Brush FontColor1 = Brushes.Black;
Brush FontColor2 = Brushes.RoyalBlue;
Brush FontColor3 = Brushes.Crimson;
Brush FontColor = FontColor1;
Pen Error = new Pen(Color.Red, 3);
SolidBrush SmallFontColor = new SolidBrush(Color.FromArgb(200, Color.Black));
G.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
G.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
G.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
G.Clear(Background);
Pen Border1 = new Pen(Color.Black, 3);
Pen Border2 = new Pen(Color.Black, 1);
float w = G.VisibleClipBounds.Width;
float h = G.VisibleClipBounds.Height;
float min = Math.Min(w, h);
float centre_x = w / 2;
float centre_y = h / 2;
float startx = centre_x - min / 2;
float starty = centre_y - min / 2;
float m = 50;
realx = startx + m;
realy = starty + m;
realw = min - 2 * m;
if (realw <= 0) return;
float error_circle_m = realw / 9 * 0.95f;
Font F = new Font("Arial", realw / 20);
Font Fsmall = new Font("Arial", realw / 72);
G.TranslateTransform(centre_x, centre_y);
G.RotateTransform(angle);
G.TranslateTransform(-centre_x, -centre_y);
G.FillRectangle(Brushes.White, realx, realy, realw, realw);
G.DrawRectangle(Border1, realx, realy, realw, realw);
if (sw == 5)
{
FontColor2 = FontColor1;
FontColor3 = FontColor1;
}
string num = "";
for (float i = 0; i < 3; i++)
{
for (float j = 0; j < 3; j++)
{
G.DrawRectangle(Border1, realx + realw * i / 3, realy + realw * j / 3, realw / 3, realw / 3);
if ((i + j) % 2 == 0) BG = BG1; else BG = BG2;
G.FillRectangle(BG, realx + realw * i / 3, realy + realw * j / 3, realw / 3, realw / 3);
for (float i2 = 0; i2 < 3; i2++)
{
for (float j2 = 0; j2 < 3; j2++)
{
if (i * 3 + i2 == hitx && j * 3 + j2 == hity) G.FillRectangle(Selected, realx + realw * (i / 3 + i2 / 9), realy + realw * (j / 3 + j2 / 9), realw / 9, realw / 9);
G.DrawRectangle(Border2, realx + realw * (i / 3 + i2 / 9), realy + realw * (j / 3 + j2 / 9), realw / 9, realw / 9);
int index_i = Convert.ToInt32(i * 3 + i2);
int index_j = Convert.ToInt32(j * 3 + j2);
num = s[index_j, index_i].ToString();
if (num == "0") num = "";
if (f[index_j, index_i] == 1) FontColor = FontColor1;
if (f[index_j, index_i] == 0) FontColor = FontColor2;
SizeF size_num = G.MeasureString(num, F);
float num_x = realx + realw * (i / 3 + i2 / 9) + (realw / 9 - size_num.Width) / 2;
float num_y = realy + realw * (j / 3 + j2 / 9) + (realw / 9 - size_num.Height) / 2;
// Rectangles: x for number, y for hints and z for error circle
RectangleF x = new RectangleF(num_x, num_y, size_num.Width, size_num.Height);
RectangleF y = new RectangleF(realx + realw * (i / 3 + i2 / 9), realy + realw * (j / 3 + j2 / 9), realw / 9, realw / 9);
RectangleF z = new RectangleF(realx + realw * (i / 3 + i2 / 9) + error_circle_m, realy + realw * (j / 3 + j2 / 9) + error_circle_m, realw / 9 - 2 * error_circle_m, realw / 9 - 2 * error_circle_m);
float num_centre_x = num_x + size_num.Width / 2;
float num_centre_y = num_y + size_num.Height / 2;
G.TranslateTransform(num_centre_x, num_centre_y);
G.RotateTransform(-angle);
G.TranslateTransform(-num_centre_x, -num_centre_y);
G.DrawString(num, F, FontColor, x);
G.TranslateTransform(num_centre_x, num_centre_y);
G.RotateTransform(+angle);
G.TranslateTransform(-num_centre_x, -num_centre_y);
if (e[index_j, index_i] == 1 && ShowErrors) G.DrawEllipse(Error, z);
string hints = "";
for (int b = 0; b < 9; b++)
{
if (((a[index_j, index_i] >> b) & 1) == 1)
{
hints = hints + (b + 1).ToString();
}
}
//G.DrawString(hints, Fsmall, SmallFontColor, y);
}
}
}
}
//if (solved == 1) ;
if (DisplayMessage)
{
RenderMessageBox(G, msg_text1, msg_text2, realw / 22, realw / 36, w, h, realx, realy, realw);
}
//RenderMessageBox(G, "14 Possible Deductions", "Press any key to continue", realw / 22, realw / 36, w, h, realx, realy, realw);
//RenderMessageBox(G, "Everything's cool dude!", "Press any key to continue", realw / 22, realw / 36, w, h, realx, realy, realw);
}
private void RenderMessageBox(Graphics G, string txt1, string txt2, float emSize1, float emSize2, float w, float h, float realx, float realy, float realw)
{
Brush Overlay = new SolidBrush(Color.FromArgb(150, Color.White));
Brush MsgBoxBG = new SolidBrush(Color.LightSlateGray);
RectangleF msgbox = new RectangleF(realx + realw / 12, realy + realw / 4, realw * 10 / 12, realw / 3);
Font F1 = new Font("Arial", emSize1);
Font F2 = new Font("Arial", emSize2);
SizeF txt1size = G.MeasureString(txt1, F1);
SizeF txt2size = G.MeasureString(txt2, F2);
G.FillRectangle(Overlay, new RectangleF(0, 0, w, h));
G.FillRectangle(MsgBoxBG, msgbox);
G.DrawRectangle(Pens.Black, realx + realw / 12, realy + realw / 4, realw * 10 / 12, realw / 3);
PointF txt1pos = new PointF(msgbox.Left + (msgbox.Width - txt1size.Width) / 2, msgbox.Top + (msgbox.Height - txt1size.Height) / 2 - msgbox.Height / 5);
PointF txt2pos = new PointF(msgbox.Left + (msgbox.Width - txt2size.Width) / 2, msgbox.Top + (msgbox.Height - txt2size.Height) / 2 + msgbox.Height / 5);
G.DrawString(txt1, F1, Brushes.White, txt1pos);
G.DrawString(txt2, F2, Brushes.White, txt2pos);
}
public bool CheckGame()
{
List<int> L = new List<int>();
for (int i = 0; i < 9; i++)
{
// Checking rows:
L.Clear();
for (int j = 0; j < 9; j++) L.Add(s[i, j]);
if (CheckOneToNine(L) == false) return false;
// Checking rolumns:
L.Clear();
for (int j = 0; j < 9; j++) L.Add(s[j, i]);
if (CheckOneToNine(L) == false) return false;
// Checking blocks:
for (int x = 0; x < 9; x += 3)
{
for (int y = 0; y < 9; y += 3)
{
L.Clear();
for (int j = 0; j < 3; j++)
{
for (int k = 0; k < 3; k++)
{
L.Add(s[x + j, y + k]);
}
}
if (CheckOneToNine(L) == false) return false;
}
}
}
return true;
}
public bool checkSolvable(SolveMethods M)
{
Sudoku copy = CreateCopy();
return copy.SolvePuzzle(M);
}
public SolutionStepList ComputePossibleSteps(SolveMethods M)
{
EnumeratePossibilities();
SolutionStepList L = new SolutionStepList();
// Looking for naked singles
if ((M & SolveMethods.NakedSingles) > 0)
{
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
double index = Math.Log(a[j, i], 2) + 1;
if (index == Math.Floor(index) && a[j, i] > 0 && s[j, i] == 0)
{
L.Add(new SolutionStep(i, j, Convert.ToInt32(index)));
}
}
}
}
// Looking for hidden singles
if ((M & SolveMethods.HiddenSingles) > 0)
{
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
int mask = 0;
for (int m = 0; m < 9; m++)
{
if (m != j) mask |= a[m, i];
}
int match = a[j, i] & (511 - mask);
if (s[j, i] == 0 && match > 0)
{
// Bingo
double index = Math.Log(match, 2) + 1;
L.Add(new SolutionStep(i, j, Convert.ToInt32(index)));
}
}
}
}
// Looking for block-hidden singles
if ((M & SolveMethods.BlockHiddenSingles) > 0)
{
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
int blockx = i / 3;
int blocky = j / 3;
int mask = 0;
for (int m = 0; m < 3; m++)
{
for (int n = 0; n < 3; n++)
{
int xindex = blockx * 3 + m;
int yindex = blocky * 3 + n;
if (yindex != j || xindex != i) mask |= a[yindex, xindex];
}
}
int match = a[j, i] & (511 - mask);
if (s[j, i] == 0 && match > 0)
{
// Bingo
double index = Math.Log(match, 2) + 1;
L.Add(new SolutionStep(i, j, Convert.ToInt32(index)));
}
}
}
}
return L;
}
public bool SolveStep(SolveMethods M)
{
SolutionStepList L = ComputePossibleSteps(M);
if (L.Count() == 0) return false;
ApplySolutionStep(L.getItem(0));
return true;
}
public bool SolvePuzzle(SolveMethods M)
{
while (SolveStep(M)) ;
return (isFull());
}
public bool LoadFile(string file)
{
StreamReader R = new StreamReader(file);
string content = R.ReadLine();
R.Close();
if (content.Length != 81) return false;
return SetGameString(content);
}
public bool SaveFile(string file)
{
StreamWriter W = new StreamWriter(file);
W.WriteLine(GetGameString());
W.Close();
return true;
}
public int ComputeErrors()
{
Sudoku S2 = this.CreateCopy();
int errors_count = 0;
for (int i = 0; i < 9; i++)
for (int j = 0; j < 9; j++)
{
if (f[j, i] == 0) S2.s[j, i] = 0;
}
S2.SolvePuzzle(SolveMethods.All);
for (int i = 0; i < 9; i++)
for (int j = 0; j < 9; j++)
{
if (S2.s[j, i] == s[j, i] || s[j, i] == 0)
{
e[j, i] = 0;
}
else
{
e[j, i] = 1;
errors_count++;
}
}
return errors_count;
}
public bool isSolved()
{
return (isFull() && checkSolvable(SolveMethods.All));
}
#region Private Functions
private bool isFull()
{
for (int i = 0; i < 9; i++)
for (int j = 0; j < 9; j++)
{
if (s[i, j] == 0) return false;
}
return true;
}
private List<int> GenerateRandomList()
{
Random R = new Random();
List<int> L1 = new List<int>();
List<int> L2 = new List<int>();
for (int i = 1; i < 10; i++) L1.Add(i);
while (L1.Count > 0)
{
int index = R.Next(L1.Count);
L2.Add(L1[index]);
L1.RemoveAt(index);
}
return L2;
}
private bool CheckOneToNine(List<int> L)
{
if (L.Count != 9) MessageBox.Show("Problem here!");
int[] vals = new int[10];
for (int i = 0; i < 9; i++)
{
int item = L[i];
if (item > 0)
{
vals[item]++;
if (vals[L[i]] > 1) return false;
}
}
return true;
}
private void EnumeratePossibilities()
{
for (int i = 0; i < 9; i++)