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
55b0a16b
Commit
55b0a16b
authored
3 months ago
by
bionic85
Browse files
Options
Downloads
Patches
Plain Diff
binary generator is nu echt helemaal done
parent
4c71273a
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/Binary.cs
+14
-7
14 additions, 7 deletions
PuzzlePlayer/Binary.cs
with
14 additions
and
7 deletions
PuzzlePlayer/Binary.cs
+
14
−
7
View file @
55b0a16b
...
@@ -101,22 +101,29 @@ namespace PuzzlePlayer_Namespace
...
@@ -101,22 +101,29 @@ namespace PuzzlePlayer_Namespace
boardState
=
(
int
[,])
generatedBoard
.
Clone
();
boardState
=
(
int
[,])
generatedBoard
.
Clone
();
// generate a list with all positions
List
<(
int
,
int
)>
allPositions
=
new
List
<(
int
,
int
)>
();
for
(
int
i
=
0
;
i
<
boardState
.
GetLength
(
0
);
i
++)
for
(
int
j
=
0
;
j
<
boardState
.
GetLength
(
1
);
j
++)
allPositions
.
Add
(
new
(
i
,
j
));
Random
rnd
=
new
Random
();
Random
rnd
=
new
Random
();
//remove spaces until the board is unsolvable, then go one step back
//remove spaces until the board is unsolvable, then go one step back
while
(
true
)
while
(
true
)
{
{
int
[,]
copy
=
(
int
[,])
boardState
.
Clone
();
if
(
allPositions
.
Count
==
0
)
int
x
=
rnd
.
Next
(
boardState
.
GetLength
(
0
));
break
;
int
y
=
rnd
.
Next
(
boardState
.
GetLength
(
1
));
if
(
boardState
[
x
,
y
]
!=
emptySpace
)
int
i
=
rnd
.
Next
(
allPositions
.
Count
);
boardState
[
x
,
y
]
=
emptySpace
;
(
int
x
,
int
y
)
=
allPositions
[
i
];
int
copy
=
boardState
[
x
,
y
];
// create a copy in case it is not possible to solve the puzzle anymore
boardState
[
x
,
y
]
=
emptySpace
;
allPositions
.
RemoveAt
(
i
);
if
(
Solve
(
true
)
==
SOLUTIONS
.
NONE
)
if
(
Solve
(
true
)
==
SOLUTIONS
.
NONE
)
{
{
boardState
=
(
int
[,])
copy
.
Clone
();
boardState
[
x
,
y
]
=
copy
;
// restore the copy if there are no solutions found
break
;
}
}
}
}
// save the generated board for testing the users solution and the use of a reset button
// save the generated board for testing the users solution and the use of a reset button
...
...
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