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
0e381e41
Commit
0e381e41
authored
3 months ago
by
bionic85
Browse files
Options
Downloads
Patches
Plain Diff
Implemented Maze draw Function
parent
55b0a16b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
PuzzlePlayer/Binary.cs
+1
-13
1 addition, 13 deletions
PuzzlePlayer/Binary.cs
PuzzlePlayer/Board.cs
+13
-0
13 additions, 0 deletions
PuzzlePlayer/Board.cs
PuzzlePlayer/Maze.cs
+146
-0
146 additions, 0 deletions
PuzzlePlayer/Maze.cs
PuzzlePlayer/PuzzleForm.cs
+0
-3
0 additions, 3 deletions
PuzzlePlayer/PuzzleForm.cs
with
160 additions
and
16 deletions
PuzzlePlayer/Binary.cs
+
1
−
13
View file @
0e381e41
...
@@ -69,19 +69,7 @@ namespace PuzzlePlayer_Namespace
...
@@ -69,19 +69,7 @@ namespace PuzzlePlayer_Namespace
}
}
}
}
// static meathode for filling a int[,] with -1
public
static
int
[,]
GetClearBoard
(
int
boardSize
)
{
int
[,]
result
=
new
int
[
boardSize
,
boardSize
];
// fill the board with empty spaces (-1)
for
(
int
i
=
0
;
i
<
boardSize
;
i
++)
{
for
(
int
j
=
0
;
j
<
boardSize
;
j
++)
result
[
i
,
j
]
=
emptySpace
;
}
return
result
;
}
// generates a random solvable board
// generates a random solvable board
public
override
void
Generate
()
public
override
void
Generate
()
...
...
This diff is collapsed.
Click to expand it.
PuzzlePlayer/Board.cs
+
13
−
0
View file @
0e381e41
...
@@ -44,6 +44,19 @@ namespace PuzzlePlayer_Namespace
...
@@ -44,6 +44,19 @@ namespace PuzzlePlayer_Namespace
public
int
[,]
boardState
;
public
int
[,]
boardState
;
public
int
[,]
lastGeneratedBoard
;
public
int
[,]
lastGeneratedBoard
;
// static meathode for filling a int[,] with -1
public
static
int
[,]
GetClearBoard
(
int
boardSize
)
{
int
[,]
result
=
new
int
[
boardSize
,
boardSize
];
// fill the board with empty spaces (-1)
for
(
int
i
=
0
;
i
<
boardSize
;
i
++)
{
for
(
int
j
=
0
;
j
<
boardSize
;
j
++)
result
[
i
,
j
]
=
emptySpace
;
}
return
result
;
}
// checks if the board is valid and solvable before setting the variable.
// checks if the board is valid and solvable before setting the variable.
...
...
This diff is collapsed.
Click to expand it.
PuzzlePlayer/Maze.cs
0 → 100644
+
146
−
0
View file @
0e381e41
using
System
;
using
System.Buffers.Binary
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.Drawing
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
static
System
.
Runtime
.
InteropServices
.
JavaScript
.
JSType
;
namespace
PuzzlePlayer_Namespace
{
/*
* all the info about the maze is stored in the mazeState int[,]
* this way the boardState can be used to keep track off the spaces that the player has visited
*
* if the player has not yet visited a space then it is equal to the emptyspace constant
* if the player did visit the space then it is equal to 1
*
* The maze board consists of cells with a number between 1 and 15
* the number represents where the walls are
* 1111 is 15 in binary the first bit is the top wall, second bit the right wall, etc. continuing clockwise
* _
* | | fully surounded is 15, so 1111 in binary
* -
* _
* | right side open is 11, so 1011 in binary
* -
*
* -1 means that the cell is empty so there are no walls anywhere
*
* the topleft corner is always the starting point (left wall), and the bottom right corner is always the end point (right wall)
*
*/
class
Maze
:
Board
{
int
[,]
mazeState
;
public
Maze
(
int
size
=
3
)
{
boardState
=
GetClearBoard
(
size
);
mazeState
=
GetClearBoard
(
size
);
// example thingy
mazeState
[
0
,
0
]
=
5
;
mazeState
[
1
,
0
]
=
3
;
mazeState
[
2
,
0
]
=
11
;
mazeState
[
0
,
1
]
=
11
;
mazeState
[
1
,
1
]
=
8
;
mazeState
[
2
,
1
]
=
6
;
mazeState
[
0
,
2
]
=
12
;
mazeState
[
1
,
2
]
=
4
;
mazeState
[
2
,
2
]
=
5
;
boardState
[
0
,
2
]
=
1
;
}
// two funcions to go from number to walls and back
private
int
getNumberFromWalls
(
bool
top
,
bool
right
,
bool
bottom
,
bool
left
)
{
int
result
=
0
;
if
(
top
)
result
++;
if
(
right
)
result
+=
2
;
if
(
bottom
)
result
+=
4
;
if
(
left
)
result
+=
8
;
if
(
result
==
0
)
return
emptySpace
;
//if there are no walls then the space is empty
return
result
;
}
private
(
bool
,
bool
,
bool
,
bool
)
getWallsFromNumber
(
int
number
)
{
if
(
number
==
emptySpace
)
return
(
false
,
false
,
false
,
false
);
//if the place is empty then there are no walls
// bitwise and opperations to check each bit
bool
top
=
(
number
&
1
)
!=
0
;
bool
right
=
(
number
&
2
)
!=
0
;
bool
bottom
=
(
number
&
4
)
!=
0
;
bool
left
=
(
number
&
8
)
!=
0
;
return
(
top
,
right
,
bottom
,
left
);
}
public
override
void
Draw
(
Graphics
gr
,
Rectangle
r
)
{
Size
tilesize
=
new
Size
(
r
.
Width
/
boardState
.
GetLength
(
0
),
r
.
Height
/
boardState
.
GetLength
(
1
));
Pen
wall
=
new
Pen
(
Color
.
Black
,
tilesize
.
Width
/
5
);
for
(
int
i
=
0
;
i
<
boardState
.
GetLength
(
0
);
i
++)
for
(
int
j
=
0
;
j
<
boardState
.
GetLength
(
1
);
j
++)
{
Rectangle
currentRect
=
new
Rectangle
(
r
.
X
+
i
*
tilesize
.
Width
,
r
.
Y
+
j
*
tilesize
.
Height
,
tilesize
.
Width
,
tilesize
.
Height
);
// draw the space blue if the player has visited it
if
(
boardState
[
i
,
j
]
==
1
)
gr
.
FillRectangle
(
Brushes
.
Blue
,
currentRect
);
// draw board outline
gr
.
DrawRectangle
(
Pens
.
LightGray
,
currentRect
);
// drawing walls
(
bool
top
,
bool
right
,
bool
bottom
,
bool
left
)
=
getWallsFromNumber
(
mazeState
[
i
,
j
]);
if
(
top
)
gr
.
DrawLine
(
wall
,
currentRect
.
Left
,
currentRect
.
Top
,
currentRect
.
Right
,
currentRect
.
Top
);
if
(
right
)
gr
.
DrawLine
(
wall
,
currentRect
.
Right
,
currentRect
.
Top
,
currentRect
.
Right
,
currentRect
.
Bottom
);
if
(
bottom
)
gr
.
DrawLine
(
wall
,
currentRect
.
Left
,
currentRect
.
Bottom
,
currentRect
.
Right
,
currentRect
.
Bottom
);
if
(
left
)
gr
.
DrawLine
(
wall
,
currentRect
.
Left
,
currentRect
.
Bottom
,
currentRect
.
Left
,
currentRect
.
Top
);
}
// draw an indication of where the start and end from the maze are
gr
.
DrawString
(
"START"
,
SettingForm
.
mainFont
,
Brushes
.
Red
,
r
.
Left
,
r
.
Top
+
tilesize
.
Height
/
2
);
gr
.
DrawString
(
"END"
,
SettingForm
.
mainFont
,
Brushes
.
Red
,
r
.
Right
-
tilesize
.
Width
/
4
,
r
.
Bottom
-
tilesize
.
Height
/
2
);
}
protected
override
List
<
Move
>
GetSolveList
(
int
[,]
boardToSolve
)
{
throw
new
NotImplementedException
();
}
// https://en.wikipedia.org/wiki/Maze_generation_algorithm#Randomized_depth-first_search
public
override
void
Generate
()
{
throw
new
NotImplementedException
();
}
public
override
void
TileInput
(
Point
p
,
int
x
)
{
throw
new
NotImplementedException
();
}
}
}
This diff is collapsed.
Click to expand it.
PuzzlePlayer/PuzzleForm.cs
+
0
−
3
View file @
0e381e41
...
@@ -79,9 +79,6 @@ namespace PuzzlePlayer_Namespace
...
@@ -79,9 +79,6 @@ namespace PuzzlePlayer_Namespace
Board
=
b
;
Board
=
b
;
CreateUI
();
CreateUI
();
Board
.
boardState
[
1
,
1
]
=
1
;
Board
.
boardState
[
2
,
2
]
=
0
;
}
}
private
void
CreateUI
()
//sets up ui elements
private
void
CreateUI
()
//sets up ui elements
{
{
...
...
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