Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 121 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ or by starting the file directly from your preferred IDE.

## Exercises

Before changing the code, make sure to branch from main.

### (1) Design a new maze
- __Before changing the code, make sure to branch from main.__
- You don't need to do all exercises. If the [easy] exercises are very easy for you, feel free to skip to more difficult onces.
- You may adapt the exercises to your degree of knowledge or add some tasks that you think are exciting.
- Note: The tasks are roughly labelled by difficulty, but tasks of the same category might still take different amounts of time.

### (1) Design a new maze [easy]
Create and design an additional maze for Pac-man and the ghosts

<details>
Expand All @@ -52,19 +54,39 @@ Create and design an additional maze for Pac-man and the ghosts
- Study the original maze array in [Mazes.py](src/Mazes.py)
- What is the meaning of 0 and 1 in the array?
- Why is the array wrapped in lines of 20 values?
</details>

<details>
<summary>Required knowledge: Classes</summary>

- What is an instance/object?
- How do I create instances of a class? What is a constructor and how do I use it?
- How do I create different instances of a class with different properties?
</details>


### (2) Random start positions [easy]
Make the start positions of ghosts and pacman random.

<details>
<summary>Hints</summary>

- Check in the maze which tiles are valid positions.
- The function `random.choice()` from the python package `random` selects a random item from a list.
- The Maze function `point()` converges a tile offset to a 2d pixel point.
</details>

### (2) Change the ghosts
### (3) Change the ghosts [easy]

Change the number of ghosts in the maze and their starting positions.

_Advanced:_ Give the ghosts their original names and colors.

<details>
<summary>Hints</summary>

- The ghosts are initialised in an array in the [pacman.py](src/pacman.py) file.
- Each ghost in the array is a `Ghost` object. Check out the respective [Ghost](src/agents/Ghost.py) class to find out more.
- Each ghost in the array is a `Ghost` object. Check out the respective [Ghost](src/agents/Ghost.py) class to find out how the ghost color is set.
- Original ghost names and colors:
- Blinky: red
- Pinky: pink
Expand All @@ -73,7 +95,84 @@ _Advanced:_ Give the ghosts their original names and colors.

</details>

### (3) Make the ghosts take better decisions
<details>
<summary>Required knowledge: Classes</summary>

- How do I add new attributes to a class?
- How do I create different instances of a class with different properties? (here: different positions, colors and names)
- _optional_: Inheritance (here: `Ghost` inherits its constructor from `BasesAgent`)

</details>


### (4) Add new pellet types [easy/advanced]

Add a pellet that gives 100 points when Pac-man picks it up.

_Advanced_: Add a pellet that lets Pac-man eat ghosts, when he touches them. After a short time, the ghosts should be revived.


<details>
<summary>Hints</summary>

- Different tile types (e.g. tiles with pellet) are defined in [Mazes.py](src/Mazes.py). With `COMMAND + left click` on the variable name, you can see where and how the pellet tiles are processed in the game logic.
- After adding the 100 points pellet to the game, is it still possible to win?

</details>

### (5) Enhance the steering of Pac-Man [advanced]

Make the steering of Pac-Man more convenient.
- Pac-man should always go forward automatically, the user should not have to click for each step he makes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Pac-man should always go forward automatically, the user should not have to click for each step he makes.
- Pac-man should always go forward automatically, the user should not have to press a key for each step.

- If given the input to change direction, Pac-man changes direction accordingly if he reaches a passage within 3 time steps.


<details>
<summary>Hints</summary>

- One time step is defined as one iteration of `update_world` (see [pacman.py](src/pacman.py)).
- How do the ghosts keep walking smoothly in the same direction? Can we steal the idea?
- How can we implement a timer that counts the time steps in the Pac-man class?

</details>



### (6) Add restart option and highscore [advanced]

- After one game has ended, there should be an option to restart the game.
- Remember previous scores and display a highscore.
- _Advanced_: Save the latest highscore to a file, such that it can be loaded even when the game was closed.
- _Advanced_: Make it possible to progress to a second level after the first level was won (i.e. change the maze).

<details>
<summary>Hints</summary>

- The whole game takes place in the `update_world` function (see [pacman.py](src/pacman.py)), which is called recursively (loop).
- The loop exits when the game end is detected.

</details>


### (7) Add sound [hard]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### (7) Add sound [hard]
### (7) Add sound [difficult]


- Play a sound when the game is won and another when the game is lost.
- Play a sound at special events, e.g. when a special pellet is collected or a ghost is eaten.

<details>
<summary>Hints</summary>

- Research how to play sounds in python (on the internet).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Search for usable sound files on the internet. Before committing them to the repository make sure you have the right to publish them. Alternatively, add them to the .gitignore file.

</details>
<details>
<summary>Required knowledge: Threads</summary>

- Playing sound such that the game does freeze requires threads.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Können wir hier noch ein not einfügen?

Suggested change
- Playing sound such that the game does freeze requires threads.
- Playing sound such that the game does not freeze while playback is active requires threads.

- Threads are used to do multiple things in parallel/on the same time.
</details>

### (8) Make the ghosts take better decisions [hard]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### (8) Make the ghosts take better decisions [hard]
### (8) Make the ghosts take better decisions [difficult]


- Study the current decision-making of the ghosts. How do they decide which way to go?
- The ghosts should _sense_ their surrounding for Pac-man. If Pac-man is within 3 tiles, they should chase him.
Expand All @@ -88,17 +187,28 @@ _Advanced:_ Give the ghosts their original names and colors.

</details>

### (4) Make Pac-man move autonomous
### (9) Make Pac-man autonomous [hard/very hard]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### (9) Make Pac-man autonomous [hard/very hard]
### (9) Make Pac-man autonomous [very difficult]


- Pac-man should no longer be controlled by humans.
- Implement an autonomous agent that controls Pac-man.
- Pac-man should _sense_ his surrounding and avoid ghosts.
- The agent must collect all pellets to win the game.
- The agent should collect all pellets and win the game.

<details>
<summary>Hints</summary>

- Create a new Pacman agent class
- Implement the `step(self, game_state)` method inside the new agent class, which decides for a direction based on the `game_state` parameter
- Replace the old pac-man instance with an instance of your agent class
- Create a new Pac-man agent class.
- Implement the `step(self, game_state)` method inside the new agent class, which decides for a direction based on the `game_state` parameter.
- What could be a simple strategy to move into a direction where pellets are while avoiding ghosts? Can we steal ideas from the ghost behaviour? (We can come far without the use of way planning.)
</details>

<details>
<summary>Advanced: Way Planning and Search Algorithms</summary>

- As a multi-objective way planning task, Pac-mans strategy can become quite complex. Objectives are:
- to collect all pellets
- to avoid ghosts
- to finish fast (preferrably)
- Shortest path algorithms can help to find a way to the next pellets, when there are no pellets nearby anymore: After the maze array is transformed to a graph, one can apply shortest path algorithms (e.g. A*) to navigate fast to the remaining pellets.
- But: Using a search algorithm for the navigation from the start is not recommended: Finding the shortest path that visits all tiles is already NP-hard (Traveling Salesman Problem). And we also need to take ghosts into account!
</details>