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
9425199b
Commit
9425199b
authored
3 months ago
by
Floris
Browse files
Options
Downloads
Plain Diff
Merge branch 'Skyscrapers'
parents
84fbc29f
fd99135d
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/PuzzleForm.cs
+9
-13
9 additions, 13 deletions
PuzzlePlayer/PuzzleForm.cs
PuzzlePlayer/Skyscrapers.cs
+118
-0
118 additions, 0 deletions
PuzzlePlayer/Skyscrapers.cs
with
128 additions
and
40 deletions
PuzzlePlayer/Board.cs
+
1
−
27
View file @
9425199b
...
...
@@ -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
);
...
...
@@ -109,20 +96,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/PuzzleForm.cs
+
9
−
13
View file @
9425199b
...
...
@@ -12,17 +12,16 @@ namespace PuzzlePlayer_Namespace
{
internal
class
PuzzleForm
:
Form
{
public
readonly
string
puzzleType
;
private
readonly
Button
solvebutton
;
private
readonly
Button
hintbutton
;
private
readonly
Button
generatebutton
;
private
readonly
Button
restartbutton
;
private
readonly
Button
UPDATEBUTTON
;
private
readonly
Label
titlebox
;
private
readonly
Label
informationbox
;
private
Rectangle
boardspace
;
private
readonly
MenuStrip
menuStrip
;
private
readonly
ToolStripMenuItem
menuSettings
;
private
readonly
BufferedGraphics
bufferedGraphics
;
private
Board
board
;
public
Board
Board
//updating the Board member will immediately call board.Draw method so that the board is updated visually
...
...
@@ -34,9 +33,7 @@ namespace PuzzlePlayer_Namespace
this
.
Invalidate
();
}
}
private
readonly
Button
UPDATEBUTTON
;
public
readonly
string
puzzleType
;
public
PuzzleForm
(
Board
b
,
Size
s
=
default
)
//takes Board and Size parameter and sets up the PuzzleForm window.
{
...
...
@@ -100,7 +97,6 @@ namespace PuzzlePlayer_Namespace
TextAlign
=
ContentAlignment
.
BottomRight
,
Font
=
SettingForm
.
mainFont
,
};
menuStrip
.
Items
.
Add
(
menuSettings
);
this
.
Controls
.
Add
(
menuStrip
);
...
...
@@ -199,12 +195,12 @@ namespace PuzzlePlayer_Namespace
private
void
UpdateUI
()
//resizes the boardspace rectangle and updates the rest of the ui around the new boardspace size
{
bufferedGraphics
.
Graphics
.
Clear
(
this
.
BackColor
);
boardspace
.
Size
=
FitBoard
(
new
Size
(
Board
.
boardState
.
GetLength
(
0
),
Board
.
boardState
.
GetLength
(
1
)),
new
Size
(
this
.
Width
-
350
,
this
.
Height
-
1
25
),
Board
.
drawFactor
);
generatebutton
.
Location
=
new
Point
(
boardspace
.
Right
+
30
,
55
);
hintbutton
.
Location
=
new
Point
(
boardspace
.
Right
+
30
,
1
35
);
solvebutton
.
Location
=
new
Point
(
boardspace
.
Right
+
30
,
215
);
restartbutton
.
Location
=
new
Point
(
boardspace
.
Right
+
30
,
2
95
);
UPDATEBUTTON
.
Location
=
new
Point
(
boardspace
.
Right
+
30
,
3
7
5
);
boardspace
.
Size
=
FitBoard
(
new
Size
(
Board
.
boardState
.
GetLength
(
0
),
Board
.
boardState
.
GetLength
(
1
)),
new
Size
(
this
.
Width
-
350
,
this
.
Height
-
1
00
),
Board
.
drawFactor
);
generatebutton
.
Location
=
new
Point
(
boardspace
.
Right
+
30
,
30
);
hintbutton
.
Location
=
new
Point
(
boardspace
.
Right
+
30
,
1
10
);
solvebutton
.
Location
=
new
Point
(
boardspace
.
Right
+
30
,
190
);
restartbutton
.
Location
=
new
Point
(
boardspace
.
Right
+
30
,
2
70
);
UPDATEBUTTON
.
Location
=
new
Point
(
boardspace
.
Right
+
30
,
35
0
);
this
.
Invalidate
();
}
public
static
Size
FitBoard
(
Size
gamesize
,
Size
maxboardsize
,
int
drawfactor
)
//returns the largest rectangle smaller than MaxBoardSize that fits the given GameSize well
...
...
@@ -251,7 +247,7 @@ namespace PuzzlePlayer_Namespace
return
;
}
Point
tile
=
GetTile
(
new
Size
(
Board
.
boardState
.
GetLength
(
0
),
Board
.
boardState
.
GetLength
(
1
)),
boardspace
,
Control
.
MousePosition
);
if
(!(
tile
.
X
>=
0
&&
tile
.
X
<
Board
.
boardState
.
GetLength
(
0
)
&&
tile
.
Y
>=
0
&&
tile
.
Y
<
Board
.
boardState
.
GetLength
(
1
)))
return
;
//if tile is
in
bounds
if
(!(
tile
.
X
>=
0
&&
tile
.
X
<
Board
.
boardState
.
GetLength
(
0
)
&&
tile
.
Y
>=
0
&&
tile
.
Y
<
Board
.
boardState
.
GetLength
(
1
)))
return
;
//if tile is
out of
bounds
if
(!(
Board
.
lastGeneratedBoard
[
tile
.
X
,
tile
.
Y
]
==
Board
.
emptySpace
))
return
;
//if tile is a given
switch
(
k
)
{
...
...
This diff is collapsed.
Click to expand it.
PuzzlePlayer/Skyscrapers.cs
0 → 100644
+
118
−
0
View file @
9425199b
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.Drawing
;
using
System.Drawing.Text
;
using
System.IO
;
using
System.Linq
;
using
System.Security.Cryptography.Xml
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Windows.Forms
;
using
System.Windows.Forms.Design
;
using
System.Windows.Forms.VisualStyles
;
namespace
PuzzlePlayer_Namespace
{
internal
class
Skyscrapers
:
Board
{
public
int
[,]
visionState
;
public
string
[,]
candidateState
;
public
Skyscrapers
(
int
boardSize
=
6
)
{
boardState
=
GetClearBoard
(
boardSize
+
2
);
lastGeneratedBoard
=
GetClearBoard
(
boardSize
+
2
);
candidateState
=
new
string
[
boardSize
+
2
,
boardSize
+
2
];
description
=
"lol"
;
drawFactor
=
1
;
candidateState
[
1
,
1
]
=
"123"
;
candidateState
[
2
,
3
]
=
"1734"
;
candidateState
[
4
,
4
]
=
"123456789"
;
boardState
[
1
,
1
]
=
1
;
boardState
[
2
,
2
]
=
2
;
boardState
[
3
,
3
]
=
3
;
boardState
[
4
,
4
]
=
4
;
}
public
override
void
Draw
(
Graphics
gr
,
Rectangle
r
)
{
Size
tilesize
=
new
Size
(
r
.
Width
/
boardState
.
GetLength
(
0
),
r
.
Height
/
boardState
.
GetLength
(
1
));
int
stringsize
=
Math
.
Min
(
tilesize
.
Height
/
2
,
tilesize
.
Width
);
StringFormat
stringFormat
=
new
StringFormat
();
stringFormat
.
LineAlignment
=
StringAlignment
.
Center
;
stringFormat
.
Alignment
=
StringAlignment
.
Center
;
gr
.
FillRectangle
(
Brushes
.
Beige
,
r
.
X
+
tilesize
.
Width
,
r
.
Y
+
tilesize
.
Height
,
r
.
Width
-
2
*
tilesize
.
Width
,
r
.
Height
-
2
*
tilesize
.
Height
);
for
(
int
i
=
0
;
i
<
boardState
.
GetLength
(
0
);
i
++)
{
for
(
int
j
=
0
;
j
<
boardState
.
GetLength
(
1
);
j
++)
{
if
(
i
==
0
||
i
==
boardState
.
GetLength
(
0
)
-
1
||
j
==
0
||
j
==
boardState
.
GetLength
(
1
)
-
1
)
{
if
(
boardState
[
i
,
j
]
!=
emptySpace
)
{
gr
.
DrawString
(
Convert
.
ToString
(
boardState
[
i
,
j
]),
new
Font
(
"Verdana"
,
stringsize
/
2
),
Brushes
.
Black
,
(
int
)(
r
.
X
+
((
double
)
i
+
0.5
)
*
tilesize
.
Width
),
(
int
)(
r
.
Y
+
((
double
)
j
+
0.5
)
*
tilesize
.
Height
),
stringFormat
);
}
}
else
{
gr
.
DrawRectangle
(
Pens
.
DarkGray
,
r
.
X
+
i
*
tilesize
.
Width
,
r
.
Y
+
j
*
tilesize
.
Height
,
tilesize
.
Width
,
tilesize
.
Height
);
if
(
boardState
[
i
,
j
]
!=
emptySpace
)
{
gr
.
DrawString
(
Convert
.
ToString
(
boardState
[
i
,
j
]),
new
Font
(
"Verdana"
,
stringsize
),
Brushes
.
Black
,
(
int
)(
r
.
X
+
((
double
)
i
+
0.5
)
*
tilesize
.
Width
),
(
int
)(
r
.
Y
+
((
double
)
j
+
0.5
)
*
tilesize
.
Height
),
stringFormat
);
}
else
{
if
(
candidateState
[
i
,
j
]
==
null
)
continue
;
foreach
(
char
c
in
candidateState
[
i
,
j
])
{
gr
.
DrawString
(
Convert
.
ToString
(
c
),
new
Font
(
"Verdana"
,
stringsize
/
3
),
Brushes
.
Black
,
(
int
)(
r
.
X
+
((
double
)
i
+
0.25
*
((
char
.
GetNumericValue
(
c
)
-
1
)
%
3
+
1
))
*
tilesize
.
Width
),
(
int
)(
r
.
Y
+
((
double
)
j
+
0.25
*
Math
.
Ceiling
(
char
.
GetNumericValue
(
c
)
/
3
))
*
tilesize
.
Height
),
stringFormat
);
}
}
}
}
}
}
public
override
SOLUTIONS
Solve
(
bool
CheckOnly
)
{
return
SOLUTIONS
.
NONE
;
}
public
override
void
Generate
()
{
}
public
override
void
TileInput
(
Point
?
p
,
Keys
k
)
{
if
(
p
==
null
)
return
;
double
center
=
((
double
)
boardState
.
GetLength
(
0
)
-
1
)
/
2
;
if
(
Math
.
Abs
(((
Point
)
p
).
X
-
center
)
==
center
&&
Math
.
Abs
(((
Point
)
p
).
Y
-
center
)
==
center
)
return
;
int
num
=
(
int
)
k
-
48
;
if
(
num
>
0
&&
num
<=
boardState
.
GetLength
(
0
)
-
2
)
boardState
[((
Point
)
p
).
X
,
((
Point
)
p
).
Y
]
=
num
;
}
protected
override
List
<
Move
>
GetSolveList
(
int
[,]
boardToSolve
)
{
return
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