Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Abdi Danny 2019 ZHAC232 100938755 FINAL YEAR PROJECT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Abdi Danny (2019) ZHAC232
Abdi Danny 2019 ZHAC232 100938755 FINAL YEAR PROJECT
Commits
d53d2a20
Commit
d53d2a20
authored
1 year ago
by
DannyAbdi
Browse files
Options
Downloads
Patches
Plain Diff
slight changes to accomodate minmax
parent
1bf7ea14
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!1
Single and Multi-Agent Pathfinding in Maze games
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
playerController.py
+17
-0
17 additions, 0 deletions
playerController.py
with
17 additions
and
0 deletions
playerController.py
+
17
−
0
View file @
d53d2a20
...
...
@@ -2,6 +2,7 @@ from config import *
from
dfs
import
*
from
bfs
import
*
from
dijkstra
import
*
from
game
import
*
class
PlayerController
:
...
...
@@ -14,6 +15,8 @@ class PlayerController:
def
__init__
(
self
,
player
,
maze
):
self
.
player
=
player
self
.
maze
=
maze
self
.
player_position
=
(
1
,
1
)
self
.
enemy_positions
=
self
.
get_enemy_positions
()
self
.
dfs_solver
=
DFS
()
self
.
bfs_solver
=
BFS
()
self
.
dijkstra_solver
=
None
...
...
@@ -30,17 +33,31 @@ class PlayerController:
if
direction
[
pygame
.
K_UP
]:
new_y
-=
TILE_SIZE
new_position
=
(
self
.
player_position
[
0
]
-
1
,
self
.
player_position
[
1
])
elif
direction
[
pygame
.
K_DOWN
]:
new_y
+=
TILE_SIZE
new_position
=
(
self
.
player_position
[
0
]
+
1
,
self
.
player_position
[
1
])
elif
direction
[
pygame
.
K_LEFT
]:
new_x
-=
TILE_SIZE
new_position
=
(
self
.
player_position
[
0
],
self
.
player_position
[
1
]
-
1
)
elif
direction
[
pygame
.
K_RIGHT
]:
new_x
+=
TILE_SIZE
new_position
=
(
self
.
player_position
[
0
],
self
.
player_position
[
1
]
+
1
)
else
:
return
if
self
.
is_valid_position
(
new_position
):
self
.
player_position
=
new_position
if
self
.
check_collision
(
new_x
,
new_y
):
self
.
player
.
x
=
new_x
self
.
player
.
y
=
new_y
def
is_valid_position
(
self
,
position
):
x
,
y
=
position
return
0
<=
x
<
len
(
self
.
maze
.
current_level
)
and
0
<=
y
<
len
(
self
.
maze
.
current_level
[
0
])
and
\
self
.
maze
.
current_level
[
x
][
y
]
!=
1
"""
Checks if the player will collide with walls at the specified position.
...
...
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