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
dcd14b4e
Commit
dcd14b4e
authored
4 months ago
by
Floris
Browse files
Options
Downloads
Plain Diff
Merge branch 'Binair' of
https://git.science.uu.nl/8783497/puzzleplayer
into Binair
parents
1c9942b0
a0c1c187
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/Board.cs
+29
-5
29 additions, 5 deletions
PuzzlePlayer/Board.cs
with
29 additions
and
5 deletions
PuzzlePlayer/Board.cs
+
29
−
5
View file @
dcd14b4e
...
...
@@ -8,6 +8,13 @@ using System.Windows.Forms;
namespace
PuzzlePlayer_Namespace
{
public
enum
SOLUTIONS
{
NONE
=
0
,
UNIQUE
=
1
,
MULTIPLE
=
2
}
/*
* This abstract class can be used to implement any kind of puzzle
* One thing that is common for all puzzles is that a empty space is equal to -1
...
...
@@ -22,14 +29,28 @@ namespace PuzzlePlayer_Namespace
public
int
[,]
boardState
{
get
{
return
boardState
;
}
set
{
if
(
IsBoardValid
(
value
)
&&
Solve
(
value
)
!=
null
)
boardState
=
value
;
}
// checks if the board is valid and solvable before setting the variable.
set
{
setBoardState
(
value
);
}
}
// checks if the board is valid and solvable before setting the variable.
private
bool
setBoardState
(
int
[,]
newState
)
{
int
[,]
copy
=
boardState
;
boardState
=
newState
;
if
(
IsBoardValid
(
newState
)
&&
Solve
()
==
SOLUTIONS
.
UNIQUE
)
return
true
;
else
{
boardState
=
copy
;
return
false
;
}
}
// a methode for solving the whole board. It uses the private SolveStep methode untill the whole board is solved
public
Board
Solve
()
public
SOLUTIONS
Solve
()
{
// two variables for storing the result and the next solveStep
int
[,]
result
=
board
ToSolv
e
;
int
[,]
result
=
board
Stat
e
;
int
[,]
step
;
// keep looping until the SolveStep returns null
...
...
@@ -44,9 +65,12 @@ namespace PuzzlePlayer_Namespace
for
(
int
i
=
0
;
i
<
result
.
GetLength
(
0
);
i
++)
for
(
int
j
=
0
;
j
<
result
.
GetLength
(
1
);
j
++)
if
(
result
[
i
,
j
]
==
emptySpace
)
return
null
;
{
return
SOLUTIONS
.
NONE
;
}
return
result
;
boardState
=
result
;
return
SOLUTIONS
.
UNIQUE
;
}
// abstract methode for solving one step
...
...
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