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
a2856307
Commit
a2856307
authored
4 months ago
by
bionic85
Browse files
Options
Downloads
Patches
Plain Diff
small things
parent
a56ff07b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
PuzzlePlayer/Binair.cs
+1
-18
1 addition, 18 deletions
PuzzlePlayer/Binair.cs
PuzzlePlayer/Board.cs
+20
-3
20 additions, 3 deletions
PuzzlePlayer/Board.cs
with
21 additions
and
21 deletions
PuzzlePlayer/Binair.cs
+
1
−
18
View file @
a2856307
...
...
@@ -71,26 +71,9 @@ namespace PuzzlePlayer_Namespace
throw
new
NotImplementedException
();
}
protected
override
int
[,]
Solve
Step
(
int
[,]
currentBoardStat
e
)
protected
override
List
<
int
[,
]
>
Get
Solve
List
(
int
[,]
boardToSolv
e
)
{
// list with all the possible moves
List
<
int
[,
]>
moves
=
new
List
<
int
[,
]>
();
int
[,]
result
=
currentBoardState
;
// generate all possible moves
//TODO
throw
new
NotImplementedException
();
// if there are no moves found then null is returned
if
(
moves
.
Count
==
0
)
return
null
;
// return one of the possible moves
Random
rnd
=
new
Random
();
return
moves
[
rnd
.
Next
(
0
,
moves
.
Count
-
1
)];
}
}
}
This diff is collapsed.
Click to expand it.
PuzzlePlayer/Board.cs
+
20
−
3
View file @
a2856307
...
...
@@ -11,6 +11,7 @@ namespace PuzzlePlayer_Namespace
/*
* 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
* GetSolveList and IsBoardValid need to be overwriten in a subclass of Board
*/
public
abstract
class
Board
{
...
...
@@ -23,8 +24,8 @@ namespace PuzzlePlayer_Namespace
set
{
if
(
IsBoardValid
(
value
)
&&
Solve
(
value
)
!=
null
)
boardState
=
value
;
}
// checks if the board is valid and solvable before setting the variable.
}
// a
virtual
methode for solving the whole board. It uses the
abstract
SolveStep methode untill the whole board is solved
public
virtual
int
[,]
Solve
(
int
[,]
boardToSolve
)
// a methode for solving the whole board. It uses the
private
SolveStep methode untill the whole board is solved
public
int
[,]
Solve
(
int
[,]
boardToSolve
)
{
// two variables for storing the result and the next solveStep
int
[,]
result
=
boardToSolve
;
...
...
@@ -48,7 +49,23 @@ namespace PuzzlePlayer_Namespace
}
// abstract methode for solving one step
protected
abstract
int
[,]
SolveStep
(
int
[,]
currentBoardState
);
private
int
[,]
SolveStep
(
int
[,]
currentBoardState
)
{
// get a list with all the possible moves
List
<
int
[,
]>
moves
=
GetSolveList
(
currentBoardState
);
// if there are no moves found then null is returned
if
(
moves
.
Count
==
0
)
return
null
;
// return one of the possible moves
// (if the first one is always chosen than that may lead to expected behavior. For example if the possible moves are checked in a certain order)
Random
rnd
=
new
Random
();
return
moves
[
rnd
.
Next
(
0
,
moves
.
Count
-
1
)];
}
// a abstract methode to get a list of all possible moves
protected
abstract
List
<
int
[,
]>
GetSolveList
(
int
[,]
boardToSolve
);
// abstract methode for generating a random board
public
abstract
void
Generate
();
...
...
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