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
fd99135d
Commit
fd99135d
authored
3 months ago
by
Floris
Browse files
Options
Downloads
Patches
Plain Diff
skyscraper...
parent
59e7a713
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
PuzzlePlayer/Board.cs
+1
-27
1 addition, 27 deletions
PuzzlePlayer/Board.cs
PuzzlePlayer/PuzzlePlayer.cs
+1
-1
1 addition, 1 deletion
PuzzlePlayer/PuzzlePlayer.cs
PuzzlePlayer/Skyscrapers.cs
+3
-24
3 additions, 24 deletions
PuzzlePlayer/Skyscrapers.cs
with
5 additions
and
52 deletions
PuzzlePlayer/Board.cs
+
1
−
27
View file @
fd99135d
...
...
@@ -60,19 +60,6 @@ namespace PuzzlePlayer_Namespace
}
// checks if the board is valid and solvable before setting the variable.
public
bool
setBoardState
(
int
[,]
newState
)
{
int
[,]
copy
=
boardState
;
boardState
=
newState
;
if
(
IsBoardValid
(
newState
)
&&
Solve
(
false
)
==
SOLUTIONS
.
UNIQUE
)
return
true
;
else
{
boardState
=
copy
;
return
false
;
}
}
public
abstract
void
Draw
(
Graphics
gr
,
Rectangle
r
);
// a methode for solving the whole board. It uses the private SolveStep methode untill the whole board is solved
...
...
@@ -108,20 +95,7 @@ namespace PuzzlePlayer_Namespace
}
// abstract methode for solving one step
private
Move
?
SolveStep
(
int
[,]
currentBoardState
)
{
// get a list with all the possible moves
List
<
Move
>
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
)];
}
public
virtual
Point
Hint
()
{
return
new
Point
(
0
,
0
);
}
// a abstract methode to get a list of all possible moves
protected
abstract
List
<
Move
>
GetSolveList
(
int
[,]
boardToSolve
);
...
...
This diff is collapsed.
Click to expand it.
PuzzlePlayer/PuzzlePlayer.cs
+
1
−
1
View file @
fd99135d
...
...
@@ -10,7 +10,7 @@ namespace PuzzlePlayer_Namespace
{
internal
static
void
Main
(
string
[]
args
)
{
Application
.
Run
(
new
PuzzleForm
(
new
Skyscrapers
(
6
)
));
Application
.
Run
(
new
MainForm
(
));
}
}
...
...
This diff is collapsed.
Click to expand it.
PuzzlePlayer/Skyscrapers.cs
+
3
−
24
View file @
fd99135d
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.Drawing
;
using
System.Drawing.Text
;
using
System.IO
;
...
...
@@ -9,6 +10,7 @@ using System.Text;
using
System.Threading.Tasks
;
using
System.Windows.Forms
;
using
System.Windows.Forms.Design
;
using
System.Windows.Forms.VisualStyles
;
namespace
PuzzlePlayer_Namespace
{
...
...
@@ -96,30 +98,7 @@ namespace PuzzlePlayer_Namespace
public
override
void
Generate
()
{
boardState
=
GetClearBoard
(
boardState
.
GetLength
(
0
));
candidateState
=
new
string
[
boardState
.
GetLength
(
0
),
boardState
.
GetLength
(
1
)];
Random
random
=
new
Random
();
void
RandomFillLine
(
int
direction
)
{
List
<
int
>
options
=
new
List
<
int
>();
for
(
int
i
=
0
;
i
<
boardState
.
GetLength
(
0
)
-
2
;
i
++)
options
.
Add
(
i
+
1
);
int
deficit
=
0
;
if
(
boardState
[
1
,
1
]
!=
emptySpace
)
{
options
.
Remove
(
boardState
[
1
,
1
]);
deficit
++;
}
for
(
int
i
=
deficit
;
i
<
boardState
.
GetLength
(
0
)
-
2
;
i
++)
{
int
index
=
random
.
Next
(
options
.
Count
);
boardState
[
1
+
i
*
(
1
-
direction
),
1
+
i
*
direction
]
=
options
[
index
];
options
.
RemoveAt
(
index
);
}
}
RandomFillLine
(
0
);
RandomFillLine
(
1
);
return
;
}
public
override
void
TileInput
(
Point
?
p
,
Keys
k
)
...
...
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