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
1f8c09d3
Commit
1f8c09d3
authored
1 year ago
by
DannyAbdi
Browse files
Options
Downloads
Patches
Plain Diff
cleaned code. removed some repeated lines/functions
parent
2f52cd3e
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
game.py
+25
-35
25 additions, 35 deletions
game.py
with
25 additions
and
35 deletions
game.py
+
25
−
35
View file @
1f8c09d3
"""
Class representing the main game logic.
"""
class
Game
:
"""
Initialize the Game object.
:param maze: The maze grid representing the game environment.
"""
def
__init__
(
self
,
maze
):
self
.
maze
=
maze
self
.
player_position
=
(
1
,
1
)
self
.
enemy_positions
=
self
.
get_enemy_positions
()
"""
Find the current position of the player in the maze.
:return: The (row, column) position of the player, or None if not found.
"""
def
get_player_position
(
self
):
for
i
in
range
(
len
(
self
.
maze
)):
for
j
in
range
(
len
(
self
.
maze
[
0
])):
...
...
@@ -11,50 +24,27 @@ class Game:
return
i
,
j
return
None
"""
Find the positions of the enemy agents in the maze.
:return: A list containing the positions of the enemy agents.
"""
def
get_enemy_positions
(
self
):
# Implement logic to find the opponents' positions in the maze
pass
"""
Update the positions of the player and enemy agents based on the current state of the maze.
"""
def
update_positions
(
self
):
# Update the positions of the player and opponents based on the current state of the maze
self
.
player_position
=
self
.
get_player_position
()
self
.
enemy_positions
=
self
.
get_enemy_positions
()
def
move_player
(
self
,
direction
):
# Implement logic to move the player in the specified direction
pass
def
move_opponents
(
self
):
# Implement logic to move the opponents based on their behavior
pass
"""
Check if the game is over.
:return: True if the game is over, False otherwise.
"""
def
check_game_over
(
self
):
# Implement logic to check if the game is over (e.g., player reached the goal or caught by opponent)
pass
def
play_game
(
self
):
# Main game loop
while
not
self
.
check_game_over
():
# Update positions
self
.
update_positions
()
# Move opponents
self
.
move_opponents
()
# Render the game state
self
.
render
()
# Handle player input and move player
player_input
=
self
.
get_player_input
()
self
.
move_player
(
player_input
)
# Game over, print result
print
(
"
Game Over!
"
)
def
render
(
self
):
# Implement logic to render the current state of the maze with player and opponent positions
pass
def
get_player_input
(
self
):
# Implement logic to get player input (e.g., arrow keys) for movement
pass
\ No newline at end of file
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