From 1cbfa643b25f331dc93072c2d5fc7bfc73aac178 Mon Sep 17 00:00:00 2001 From: Patricia Aas Date: Wed, 6 Oct 2021 14:44:01 +0200 Subject: [PATCH] Add a exercise to module 13 --- exercises/12/hello_cout/README.md | 2 ++ exercises/12/hello_fmt/README.md | 2 ++ exercises/13/README.md | 2 ++ .../navigate_codebase/README.md} | 28 +++++++++---------- exercises/README.md | 11 ++++++++ 5 files changed, 30 insertions(+), 15 deletions(-) rename exercises/{project-structure.md => 13/navigate_codebase/README.md} (82%) diff --git a/exercises/12/hello_cout/README.md b/exercises/12/hello_cout/README.md index f77e257..477f0cf 100644 --- a/exercises/12/hello_cout/README.md +++ b/exercises/12/hello_cout/README.md @@ -1,3 +1,5 @@ +[< Back](../README.md) + # Exercise: Hello std::cout on Godbolt.org ## Background: Compiler Explorer diff --git a/exercises/12/hello_fmt/README.md b/exercises/12/hello_fmt/README.md index 29029ad..5bc4608 100644 --- a/exercises/12/hello_fmt/README.md +++ b/exercises/12/hello_fmt/README.md @@ -1,3 +1,5 @@ +[< Back](../README.md) + # Exercise: Hello {fmt} on Godbolt ## Background: {fmt} diff --git a/exercises/13/README.md b/exercises/13/README.md index 40bdec3..6a17e3c 100644 --- a/exercises/13/README.md +++ b/exercises/13/README.md @@ -1 +1,3 @@ [< Back](../README.md) + +* [Exercise: Navigating the code](navigate_codebase/README.md) \ No newline at end of file diff --git a/exercises/project-structure.md b/exercises/13/navigate_codebase/README.md similarity index 82% rename from exercises/project-structure.md rename to exercises/13/navigate_codebase/README.md index 3a1a773..5c1f218 100644 --- a/exercises/project-structure.md +++ b/exercises/13/navigate_codebase/README.md @@ -1,4 +1,8 @@ -# Pac-Man +[< Back](../README.md) + +# Exercise: Navigating the code + +## Background: Pac-Man project The project is split into three parts (solutions). @@ -7,7 +11,7 @@ The project is split into three parts (solutions). and call the `run()` function - **pacman_tests** - All of the unit tests for the game -## libpacman +### libpacman The libpacman solution has 3 main parts. @@ -16,7 +20,7 @@ The libpacman solution has 3 main parts. - **GameState** - A class that holds all of the state for Pac-Man. Contains classes like the Ghosts, PacMan and the Pellets PacMan eats -## Updating the game state +### Updating the game state Within the `Game.cpp` file there is a function called `run()`, this function draws the current game state to screen `canvas.update(gameState);` but it only calls the game state update function at a fixed interval, it also sends @@ -26,37 +30,31 @@ Then in the `step()` function in `GameState.cpp` the magic happens. Each object state of the game world is checked. Did Pac-Man just eat a pellet? Are the ghosts touching Pac-Man? Which direction is Pac-Man moving? -## The game board +### The game board The game board is stored as a two dimensional array of integers in the `Board.cpp` file. The array itself is only accessible within that file, which is why we export helper functions that use the array as a global variable. This exporting happens in `Board.hpp` -## Ghosts +### Ghosts All ghosts inherit from the parent Ghost class defined in `Ghost.hpp/cpp`, there are a couple of pure virtual functions those ghosts need to implement, otherwise you are not able to create an instance of them. A ghost stores its current location, its current target and other state regarding if it is frightened or not. At each `update()` call a ghost needs to decide what its target is and which direction it should turn next. -## Pac-Man +### Pac-Man Pac-Man has similar state to a Ghost, like direction and position. Pac-Man's behavior is also similar in `update()` as we need to determine where to place Pac-Man in the next game state. But the information on which direction to turn comes from the player (or a bot). -## Unit tests +### Unit tests Because updates of game state and drawing the game on screen are completely separate, we can create game state within unit tests and give it arbitrary delta time and call whatever functions we want to simulate the game being played. Most unit tests only focus on one single class but some (like `testFruits`) use the `GameState` class. -## Ghosts characters and algorithms +## Exercise -These will probably become relevant -* https://en.wikipedia.org/wiki/Ghosts_(Pac-Man) -* [Video: Pac-Man Ghost AI Explained](https://youtu.be/ataGotQ7ir8) -* https://gameinternals.com/understanding-pac-man-ghost-behavior -* https://www.gamasutra.com/view/feature/3938/the_pacman_dossier.php?print=1 -* https://www.slideshare.net/grimlockt/pac-man-6561257 -* http://donhodges.com/pacman_pinky_explanation.htm +1. Familiarize yourself with the codebase by trying to find the files that contain the code mentioned in the slides diff --git a/exercises/README.md b/exercises/README.md index aa5c509..fbf8a92 100644 --- a/exercises/README.md +++ b/exercises/README.md @@ -23,3 +23,14 @@ ## Advanced * [Advanced](advanced/README.md) + +## Ghosts characters and algorithms + +These will probably become relevant +* https://en.wikipedia.org/wiki/Ghosts_(Pac-Man) +* [Video: Pac-Man Ghost AI Explained](https://youtu.be/ataGotQ7ir8) +* https://gameinternals.com/understanding-pac-man-ghost-behavior +* https://www.gamasutra.com/view/feature/3938/the_pacman_dossier.php?print=1 +* https://www.slideshare.net/grimlockt/pac-man-6561257 +* http://donhodges.com/pacman_pinky_explanation.htm +* \ No newline at end of file