-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
708 lines (685 loc) · 21 KB
/
Main.java
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
/**
* Auto Generated Java Class.
*/
import java.util.*;
public class Main {
public Main() {
/* YOUR CONSTRUCTOR CODE HERE*/
}
public static void main(String[] args) {
//As the game starts, we are sent to the choosedifficulty method for players to choose their difficulty
choosedifficulty();
}
public static void choosedifficulty(){
//The variables needed are declared
int difficulty;
Scanner scan = new Scanner(System.in);
do
{
//Ask the user for their difficulty setting
System.out.println("Welcome to Sudoku! Please choose your difficulty.\n Enter\n 1 for Easy\n 2 for Medium\n 3 for Hard");
difficulty=scan.nextInt();
}while(difficulty>3||difficulty<1);//keep asking for a value difficulty
//we move to the startgame method and send the difficulty variable with us
startgame(difficulty);
}
public static void startgame(int difficulty){
//This is where it gets complicated
//Using a 9x9 2-D array makes it very easy to check the rows and columns for possible duplicates in Sudoku, but checking for duplicates in the 3x3 cells are very hard to do
int [][] grid = new int [9][9];
//But using 9 3x3 2-D array makes it very easy to check the 3x3 cells for duplicates, but very hard to check the rows and columns
int [][] cellA = new int [3][3];
int [][] cellB = new int [3][3];
int [][] cellC = new int [3][3];
int [][] cellD = new int [3][3];
int [][] cellE = new int [3][3];
int [][] cellF = new int [3][3];
int [][] cellG = new int [3][3];
int [][] cellH = new int [3][3];
int [][] cellI = new int [3][3];
//So I decided to use the benefits of both and combine them. There is a 9x9 array and 9 3x3 arrays that are made to be exactly identical.
//When we check for duplictaes in the rows and columns, we search through the 9x9 array
//When we check for duplicates in the 3x3 cells, we search through the 3x3 arrays
//Declaring some variables for the loops
int i=0,j=0;
//Fill the 9x9 array with 0's
for (i=0;i<9;i++)
{
for (j=0;j<9;j++)
{
grid[i][j]=0;
}
}
//Filling all 9 of the 3x3 arrays 0's
for (i=0;i<3;i++)
{
for (j=0;j<3;j++)
{
cellA[i][j]=0;
cellB[i][j]=0;
cellC[i][j]=0;
cellD[i][j]=0;
cellE[i][j]=0;
cellF[i][j]=0;
cellG[i][j]=0;
cellH[i][j]=0;
cellI[i][j]=0;
}
}
//If the user chooses the easy difficulty...
if (difficulty==1)
{
//The easy grid is set up
//Every number is inputted in both the 9x9 array and the corresponding 3x3 array
grid[0][0]=2;
cellA[0][0]=2;
grid[1][2]=6;
cellA[1][2]=6;
grid[2][1]=7;
cellA[2][1]=7;
grid[2][2]=4;
cellA[2][2]=4;
grid[0][3]=8;
cellB[0][0]=8;
grid[0][5]=4;
cellB[0][2]=4;
grid[0][8]=6;
cellC[0][2]=6;
grid[1][6]=5;
cellC[1][0]=5;
grid[2][6]=9;
cellC[2][0]=9;
grid[2][7]=2;
cellC[2][1]=2;
grid[3][0]=3;
cellD[0][0]=3;
grid[5][0]=4;
cellD[2][0]=4;
grid[3][4]=4;
cellE[0][1]=4;
grid[4][3]=3;
cellE[1][0]=3;
grid[4][5]=5;
cellE[1][2]=5;
grid[5][4]=6;
cellE[2][1]=6;
grid[3][8]=7;
cellF[0][2]=7;
grid[5][8]=9;
cellF[2][2]=9;
grid[6][1]=1;
cellG[0][1]=1;
grid[6][2]=9;
cellG[0][2]=9;
grid[7][2]=8;
cellG[1][2]=8;
grid[8][0]=5;
cellG[2][0]=5;
grid[8][3]=6;
cellH[2][0]=6;
grid[8][5]=8;
cellH[2][2]=8;
grid[6][6]=7;
cellI[0][0]=7;
grid[6][7]=4;
cellI[0][1]=4;
grid[7][6]=2;
cellI[1][0]=2;
grid[8][8]=1;
cellI[2][2]=1;
//Here is the answer to the easy grid.
/*
___0__1__2_____3__4__5_____6__7__8___
0 | [2][5][3] | [8][9][4] | [1][7][6] |
1 | [1][9][6] | [2][3][7] | [5][8][4] |
2 | [8][7][4] | [1][5][6] | [9][2][3] |
-------------------------------------
3 | [3][8][1] | [9][4][2] | [6][5][7] |
4 | [9][6][7] | [3][8][5] | [4][1][2] |
5 | [4][2][5] | [7][6][1] | [8][3][9] |
-------------------------------------
6 | [6][1][9] | [5][2][3] | [7][4][8] |
7 | [7][3][8] | [4][1][9] | [2][6][5] |
8 | [5][4][2] | [6][7][8] | [3][9][1] |
------------------------------------- */
}
//We do the same for the medium difficulty...
if(difficulty==2)
{
//And set up the medium grid for the user
grid[0][0]=1;
cellA[0][0]=1;
grid[1][1]=2;
cellA[1][1]=2;
grid[1][2]=3;
cellA[1][2]=3;
grid[0][5]=5;
cellB[0][2]=5;
grid[1][3]=4;
cellB[1][0]=4;
grid[1][5]=6;
cellB[1][2]=6;
grid[0][8]=4;
cellC[0][2]=4;
grid[1][7]=5;
cellC[1][1]=5;
grid[2][7]=6;
cellC[2][1]=7;
grid[3][0]=9;
cellD[0][0]=9;
grid[3][2]=4;
cellD[0][2]=4;
grid[5][1]=5;
cellD[2][1]=5;
grid[4][3]=5;
cellE[1][0]=5;
grid[4][4]=6;
cellE[1][1]=6;
grid[4][5]=7;
cellE[1][2]=7;
grid[3][7]=7;
cellF[0][1]=7;
grid[5][6]=8;
cellF[2][0]=8;
grid[5][8]=3;
cellF[2][2]=3;
grid[6][1]=4;
cellG[0][1]=4;
grid[7][1]=3;
cellG[1][1]=3;
grid[8][0]=2;
cellG[2][0]=2;
grid[7][3]=7;
cellG[1][0]=7;
grid[7][5]=1;
cellG[1][2]=1;
grid[8][3]=8;
cellG[2][0]=8;
grid[7][6]=9;
cellI[1][0]=9;
grid[7][7]=8;
cellI[1][1]=9;
grid[8][8]=7;
cellI[2][2]=7;
}
//Same for the hard difficulty
if(difficulty==3)
{
grid[0][1]=7;
cellA[0][1]=7;
grid[1][0]=9;
cellA[1][0]=9;
grid[0][5]=2;
cellB[0][2]=2;
grid[1][4]=6;
cellB[1][1]=6;
grid[2][3]=1;
cellB[2][0]=1;
grid[1][6]=3;
cellC[1][0]=3;
grid[2][7]=8;
cellC[2][1]=8;
grid[3][2]=8;
cellD[0][2]=8;
grid[4][1]=9;
cellD[1][1]=9;
grid[5][0]=3;
cellD[2][0]=3;
grid[3][4]=3;
cellE[0][1]=3;
grid[4][3]=7;
cellE[1][0]=7;
grid[4][5]=4;
cellE[1][2]=4;
grid[5][4]=5;
cellE[2][1]=5;
grid[3][8]=1;
cellF[0][2]=1;
grid[4][7]=6;
cellF[1][1]=6;
grid[5][6]=9;
cellF[2][0]=9;
grid[6][1]=1;
cellG[0][1]=1;
grid[7][2]=6;
cellG[1][2]=6;
grid[6][5]=7;
cellH[0][2]=7;
grid[7][4]=1;
cellH[1][1]=1;
grid[8][3]=4;
cellH[2][0]=4;
grid[7][8]=5;
cellI[1][2]=5;
grid[8][7]=3;
cellI[2][1]=3;
}
//We send all the relevant variables, such as the difficulty setting and the grids, to the gridstate method, which just shows the grid to the user
gridstate(difficulty, grid,cellA,cellB,cellC,cellD,cellE,cellF,cellG,cellH,cellI);
}
public static void gridstate(int difficulty, int[][]grid,int [][] cellA,int[][] cellB,int[][] cellC,int[][] cellD,int[][] cellE,int[][] cellF,int[][] cellG,int [][] cellH,int [][] cellI){
//We draw the grid to the user
int i,j;
System.out.println(" ___0__1__2_____3__4__5_____6__7__8___");
for (i=0;i<9;i++)
{
System.out.print(i + " | ");
for (j=0;j<9;j++)
{
System.out.print("[" + grid[i][j] + "]");
if (j==2||j==5||j==8)
{
System.out.print(" | ");
}
}
System.out.println("");
if (i==2||i==5||i==8)
{
System.out.println(" -------------------------------------");
}
}
//We send the user and the necessary variables to the guess method for the user to guess
guess(difficulty,grid,cellA,cellB,cellC,cellD,cellE,cellF,cellG,cellH,cellI);
}
public static void guess(int difficulty,int [][]grid,int [][] cellA,int[][] cellB,int[][] cellC,int[][] cellD,int[][] cellE,int[][] cellF,int[][] cellG,int [][] cellH,int [][] cellI){
//We initialize the variablies needed for the guessing. I will explain what the ceck variable does soon
int row, col, number, check=-1;
Scanner scan = new Scanner(System.in);
//Ask the user for the row to access
do
{
System.out.println("What row would you like to access?");
row= scan.nextInt();
}
while(row>8||row<0);//make sure the user doesn't input an invalid row
//Ask user for what column to access
do
{
System.out.println("What col would you like to enter in row " + row + "?");
col = scan.nextInt();
//If the difficulty is easy
if(difficulty==1)
{
//if the user enters any of the coordinates for the preset numbers, the user is told that that is invalid
if((row==0&&col==0)||(row==1&&col==2)||(row==2&&col==1)||(row==2&&col==2)||(row==0&&col==3)||(row==0&&col==5)||(row==0&&col==8)||(row==1&&col==6)||(row==2&&col==6)||(row==3&&col==0)||(row==5&&col==0)||(row==3&&col==4)||(row==4&&col==3)||(row==4&&col==5)||(row==5&&col==4)||(row==3&&col==8)||(row==5&&col==8)||(row==6&&col==1)||(row==6&&col==2)||(row==7&&col==2)||(row==8&&col==0)||(row==8&&col==3)||(row==8&&col==5)||(row==6&&col==6)||(row==6&&col==7)||(row==7&&col==6)||(row==8&&col==8)||(row==2&&col==7))
{
System.out.println("You can't access those boxes, those are preset");
//The are sent back to gridstate
gridstate(difficulty,grid,cellA,cellB,cellC,cellD,cellE,cellF,cellG,cellH,cellI);
}
}
//The same thing is done for medium difficulty, only the coordinates are changed for the medium grid
if(difficulty==2)
{
if((row==0&&col==0)||(row==1&&col==1)||(row==1&&col==2)||(row==0&&col==5)||(row==1&&col==3)||(row==1&&col==5)||(row==0&&col==8)||(row==1&&col==7)||(row==2&&col==7)||(row==3&&col==0)||(row==3&&col==2)||(row==5&&col==1)||(row==4&&col==3)||(row==4&&col==4)||(row==4&&col==5)||(row==3&&col==7)||(row==5&&col==6)||(row==5&&col==8)||(row==6&&col==1)||(row==7&&col==1)||(row==8&&col==0)||(row==7&&col==3)||(row==7&&col==5)||(row==8&&col==3)||(row==7&&col==6)||(row==7&&col==7)||(row==8&&col==8))
{
System.out.println("You can't access those boxes, those are preset");
gridstate(difficulty,grid,cellA,cellB,cellC,cellD,cellE,cellF,cellG,cellH,cellI);
}
}
//Same thing for hard difficulty
if(difficulty==3)
{
if((row==0&&col==1)||(row==1&&col==0)||(row==0&&col==5)||(row==1&&col==4)||(row==2&&col==3)||(row==1&&col==6)||(row==2&&col==7)||(row==3&&col==2)||(row==4&&col==1)||(row==5&&col==0)||(row==3&&col==4)||(row==4&&col==3)||(row==4&&col==5)||(row==5&&col==4)||(row==3&&col==8)||(row==4&&col==7)||(row==5&&col==6)||(row==6&&col==1)||(row==7&&col==2)||(row==6&&col==5)||(row==7&&col==4)||(row==8&&col==3)||(row==7&&col==8)||(row==8&&col==7))
{
System.out.println("You can't access those boxes, those are preset");
gridstate(difficulty,grid,cellA,cellB,cellC,cellD,cellE,cellF,cellG,cellH,cellI);
}
}
}while(col>8||col<0);//make sure the user doesn't enter an invalid column
//Ask user for the number they want to input
do
{
System.out.println("What number would you like to enter in row " + row +", col " + col + "?");
number = scan.nextInt();
}
while(number>9||number<1);// make sure user doesn't input an invalid number
//Here's what the check variable does
//When the row is between 0 and 2 and the column is between 0 and 2, that means that we are in cellA, which is signified by setting check to 0
if(row>-1&&row<3&&col>-1&&col<3)
{
check=0;
}
//We do the same for every grid (cellB is check=1, cellC is check = 2, etc)
if(row>-1&&row<3&&col>2&&col<6)
{
check=1;
}
//cellC
if(row>-1&&row<3&&col>5&&col<9)
{
check=2;
}
//cellD
if(row>2&&row<6&&col>-1&&col<3)
{
check=3;
}
//cellE
if(row>2&&row<6&&col>2&&col<6)
{
check=4;
}
//cellF
if(row>2&&row<6&&col>5&&col<9)
{
check=5;
}
//cellG
if(row>5&&row<9&&col>-1&&col<3)
{
check=6;
}
//cellH
if(row>5&&row<9&&col>2&&col<6)
{
check=7;
}
//cellI
if(row>5&&row<9&&col>5&&col<9)
{
check=8;
}
//Now that we have the user's input, we send all the relevant variables to the valid method, where it checks if the guess is valid.
valid(difficulty,check,grid,cellA,cellB,cellC,cellD,cellE,cellF,cellG,cellH,cellI,row, col, number);
}
public static void valid(int difficulty,int check, int [][] grid,int [][] cellA,int[][] cellB,int[][] cellC,int[][] cellD,int[][] cellE,int[][] cellF,int[][] cellG,int [][] cellH,int [][] cellI, int row, int col, int number){
//This for loop checks the row of the guess to find any duplicates
for(int i=0;i<9;i++)
{
//It skips the inputted box to avoid finding a match there
if (i==col)
{
}
//If it finds a match, it sends the user back to gridstate
else if(grid[row][i]==number)
{
System.out.println("That number is already used in that row, try again");
gridstate(difficulty,grid,cellA,cellB,cellC,cellD,cellE,cellF,cellG,cellH,cellI);
}
}
//We do the same exact thing as before, but now we check the columns
for(int i=0;i<9;i++)
{
if(i==row)
{
}
else if (grid[i][col]==number)
{
System.out.println("That number is already used in that col, try again");
gridstate(difficulty,grid,cellA,cellB,cellC,cellD,cellE,cellF,cellG,cellH,cellI);
}
}
//If we are in cellA
if(check==0)
{
//We check all the boxes in that cell
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
//We skip the inputted box
if (i==row&&j==col)
{
}
//If we find a match in the cell, we send them back to gridstate
if(cellA[i][j]==number)
{
System.out.println("The number " + number +" is already in the cell!");
gridstate(difficulty,grid,cellA,cellB,cellC,cellD,cellE,cellF,cellG,cellH,cellI);
}
}
}
}
//We do the exact same for cellB if we are in cellB
if(check==1)
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if (i==row&&j==col)
{
}
if(cellB[i][j]==number)
{
System.out.println("The number " + number +" is already in the cell!");
gridstate(difficulty,grid,cellA,cellB,cellC,cellD,cellE,cellF,cellG,cellH,cellI);
}
}
}
}
//cellC
if(check==2)
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if (i==row&&j==col)
{
}
if(cellC[i][j]==number)
{
System.out.println("The number " + number +" is already in the cell!");
gridstate(difficulty,grid,cellA,cellB,cellC,cellD,cellE,cellF,cellG,cellH,cellI);
}
}
}
}
//cellD
if(check==3)
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if (i==row&&j==col)
{
}
if(cellD[i][j]==number)
{
System.out.println("The number " + number +" is already in the cell!");
gridstate(difficulty,grid,cellA,cellB,cellC,cellD,cellE,cellF,cellG,cellH,cellI);
}
}
}
}
//cellE
if(check==4)
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if (i==row&&j==col)
{
}
if(cellE[i][j]==number)
{
System.out.println("The number " + number +" is already in the cell!");
gridstate(difficulty,grid,cellA,cellB,cellC,cellD,cellE,cellF,cellG,cellH,cellI);
}
}
}
}
//cellF
if(check==5)
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if (i==row&&j==col)
{
}
if(cellF[i][j]==number)
{
System.out.println("The number " + number +" is already in the cell!");
gridstate(difficulty,grid,cellA,cellB,cellC,cellD,cellE,cellF,cellG,cellH,cellI);
}
}
}
}
//cellG
if(check==6)
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if (i==row&&j==col)
{
}
if(cellG[i][j]==number)
{
System.out.println("The number " + number +" is already in the cell!");
gridstate(difficulty,grid,cellA,cellB,cellC,cellD,cellE,cellF,cellG,cellH,cellI);
}
}
}
}
//cellH
if(check==7)
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if (i==row&&j==col)
{
}
if(cellH[i][j]==number)
{
System.out.println("The number " + number +" is already in the cell!");
gridstate(difficulty,grid,cellA,cellB,cellC,cellD,cellE,cellF,cellG,cellH,cellI);
}
}
}
}
//cellI
if(check==8)
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if (i==row&&j==col)
{
}
if(cellI[i][j]==number)
{
System.out.println("The number " + number +" is already in the cell!");
gridstate(difficulty,grid,cellA,cellB,cellC,cellD,cellE,cellF,cellG,cellH,cellI);
}
}
}
}
//If the program runs to this line, we can assume that the guess is valid(as we haven't been sent back) and we send the relevant variables to gridfill
guessfill(difficulty,row,col,number,grid,cellA,cellB,cellC,cellD,cellE,cellF,cellG,cellH,cellI,check);
}
public static void guessfill(int difficulty,int row, int col, int number, int [][]grid,int [][] cellA,int[][] cellB,int[][] cellC,int[][] cellD,int[][] cellE,int[][] cellF,int[][] cellG,int [][] cellH,int [][] cellI,int check){
//Declare new variables
int newcol=-1, newrow=-1;
//So if col==0 or 3 or 6, we can assume that the number is in the first column of the cell
if (col==0||col==3||col==6)
{
newcol=0;
}
//2nd column
if (col==1||col==4||col==7)
{
newcol=1;
}
//3rd column
if (col==2||col==5||col==8)
{
newcol=2;
}
//1st row
if (row==0||row==3||row==6)
{
newrow=0;
}
//2nd row
if (row==1||row==4||row==7)
{
newrow=1;
}
//3rd row
if (row==2||row==5||row==8)
{
newrow=2;
}
//We then fill the box on the 9x9 grid with the number
grid[row][col]=number;
//if we are in cellA, fill the box in the cell with the guess
if (check==0)
{
cellA[newrow][newcol]=number;
}
//Same with cellB
if (check==1)
{
cellB[newrow][newcol]=number;
}
//cellC
if (check==2)
{
cellC[newrow][newcol]=number;
}
//cellD
if (check==3)
{
cellD[newrow][newcol]=number;
}
//cellE
if (check==4)
{
cellE[newrow][newcol]=number;
}
//cellF
if (check==5)
{
cellF[newrow][newcol]=number;
}
//cellG
if (check==6)
{
cellG[newrow][newcol]=number;
}
//cellH
if (check==7)
{
cellH[newrow][newcol]=number;
}
//cellI
if (check==8)
{
cellI[newrow][newcol]=number;
}
//after we have filled all the grids and cells, we send the relevant variables to gridcheck to check if the user has won
gridcheck(difficulty,grid,cellA,cellB,cellC,cellD,cellE,cellF,cellG,cellH,cellI);
}
public static void gridcheck(int difficulty,int [][]grid,int [][] cellA,int[][] cellB,int[][] cellC,int[][] cellD,int[][] cellE,int[][] cellF,int[][] cellG,int [][] cellH,int [][] cellI){
//Declare variables
int i,j;
//We check to see if there are any boxes with 0's, or are unfilled
for (i=0;i<9;i++)
{
for(j=0;j<9;j++)
{
if(grid[i][j]==0)
{
//if there is a box that is unfilled, we go back to gridstate
gridstate(difficulty,grid,cellA,cellB,cellC,cellD,cellE,cellF,cellG,cellH,cellI);
}
}
}
//if not, the user has beat the game
System.out.println("CONGRATULATIONS! YOU BEAT THE GRID!");
//They are sent back to start
choosedifficulty();
}
/* ADD YOUR CODE HERE */
}