Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
puzzleplayer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Floris
puzzleplayer
Commits
8360f26f
Commit
8360f26f
authored
3 months ago
by
DamianKomdeur
Browse files
Options
Downloads
Patches
Plain Diff
Sudoku Solver
parent
7b9672e4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
PuzzlePlayer/Sudoku.cs
+26
-5
26 additions, 5 deletions
PuzzlePlayer/Sudoku.cs
with
26 additions
and
5 deletions
PuzzlePlayer/Sudoku.cs
+
26
−
5
View file @
8360f26f
...
@@ -14,7 +14,7 @@ namespace PuzzlePlayer_Namespace
...
@@ -14,7 +14,7 @@ namespace PuzzlePlayer_Namespace
{
{
private
static
int
boardLength
;
private
static
int
boardLength
;
private
static
int
rootBoardLength
;
private
static
int
rootBoardLength
;
public
Sudoku
(
int
boardSize
=
16
)
public
Sudoku
(
int
boardSize
=
9
)
{
{
boardState
=
GetClearBoard
(
boardSize
,
boardSize
);
boardState
=
GetClearBoard
(
boardSize
,
boardSize
);
lastGeneratedBoard
=
GetClearBoard
(
boardSize
,
boardSize
);
lastGeneratedBoard
=
GetClearBoard
(
boardSize
,
boardSize
);
...
@@ -75,6 +75,15 @@ namespace PuzzlePlayer_Namespace
...
@@ -75,6 +75,15 @@ namespace PuzzlePlayer_Namespace
}
}
FillSudoku
(
0
,
rootBoardLength
);
FillSudoku
(
0
,
rootBoardLength
);
RemoveSpaces
(
54
);
}
public
override
SOLUTIONS
Solve
(
bool
j
)
{
FillSudoku
(
0
,
rootBoardLength
);
return
SOLUTIONS
.
UNIQUE
;
}
}
private
int
RandomNumber
(
int
number
)
private
int
RandomNumber
(
int
number
)
...
@@ -169,8 +178,9 @@ namespace PuzzlePlayer_Namespace
...
@@ -169,8 +178,9 @@ namespace PuzzlePlayer_Namespace
boardState
[
row
,
col
]
=
num
;
boardState
[
row
,
col
]
=
num
;
if
(
FillSudoku
(
row
,
col
+
1
))
if
(
FillSudoku
(
row
,
col
+
1
))
{
return
true
;
return
true
;
}
boardState
[
row
,
col
]
=
-
1
;
boardState
[
row
,
col
]
=
-
1
;
}
}
}
}
...
@@ -219,7 +229,7 @@ namespace PuzzlePlayer_Namespace
...
@@ -219,7 +229,7 @@ namespace PuzzlePlayer_Namespace
{
{
if
(
p
==
null
)
return
;
if
(
p
==
null
)
return
;
int
num
=
(
int
)
k
-
48
;
int
num
=
(
int
)
k
-
48
;
if
(
num
>=
1
&&
num
<=
9
)
boardState
[((
Point
)
p
).
X
,
((
Point
)
p
).
Y
]
=
num
;
if
(
num
>=
1
&&
num
<=
boardLength
)
boardState
[((
Point
)
p
).
X
,
((
Point
)
p
).
Y
]
=
num
;
}
}
public
override
void
TileClick
(
Point
p
,
int
x
)
public
override
void
TileClick
(
Point
p
,
int
x
)
...
@@ -242,11 +252,11 @@ namespace PuzzlePlayer_Namespace
...
@@ -242,11 +252,11 @@ namespace PuzzlePlayer_Namespace
}
}
else
else
{
{
boardState
[
p
.
X
,
p
.
Y
]
=
9
;
boardState
[
p
.
X
,
p
.
Y
]
=
boardLength
;
return
;
return
;
}
}
}
}
else
if
(
boardState
[
p
.
X
,
p
.
Y
]
==
9
)
else
if
(
boardState
[
p
.
X
,
p
.
Y
]
==
boardLength
)
{
{
if
(
x
==
1
)
if
(
x
==
1
)
{
{
...
@@ -279,6 +289,17 @@ namespace PuzzlePlayer_Namespace
...
@@ -279,6 +289,17 @@ namespace PuzzlePlayer_Namespace
}
}
}
}
private
void
RemoveSpaces
(
int
k
)
{
for
(
int
i
=
0
;
i
<
k
;
i
++)
{
int
row
=
RandomNumber
(
boardLength
)
-
1
;
int
col
=
RandomNumber
(
boardLength
)
-
1
;
boardState
[
row
,
col
]
=
emptySpace
;
}
}
protected
override
List
<
Move
>
GetSolveList
(
int
[,]
boardToSolve
)
protected
override
List
<
Move
>
GetSolveList
(
int
[,]
boardToSolve
)
{
{
List
<
Move
>
result
=
new
List
<
Move
>();
List
<
Move
>
result
=
new
List
<
Move
>();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment