Documentation About Graphs Applied To A Pacman Game
Documentation About Graphs Applied To A Pacman Game
Documentation About Graphs Applied To A Pacman Game
A00354694
Camilo Enriquez Delgado
A00354532
Name FR.#1. Find the shortest path between two points on the map
Summarize The program will allow to find the shortest path between two tiles of the map
using Floy-Warshall algorithm
Output A list of the vertices that conform the shortest path from source Vertex to target
Vertex.
Summarize Move Pacman according to the direction preselected by the user if there is no
wall interposing.
Input None
Output Pacman has moved a pixel forward if no wall was in his way.
Summarize Ghosts move according to the tile that has been determined as their target
through the shortest path. It is also taken into account if they are in chase,
scatter or frightened mode, on which the speeds of all the characters depend.
Name FR.#4. Register the player score when a high score is achieved
Summarize When Pacman has lost all his lives along the game and the actual score is
higher than one of the first ten positions, a little window will handle of register
the name of this player, which cannot exceed the four characters.
Input ● The name of the player (cannot exceed the four characters).
Summarize When the player presses the “Higher Scores” button a TableView with all the
previous higher scores will be displayed as long as there is a file with these
previous matches inside it. By default the TableView is displayed empty.
Summarize Allows to request a change in the direction of travel of pacman. It is only set as
the direction of pacman if it is possible, that is, if there is not a wall in the
direction the user wants to go.
Input ● An object of type Direction representing the requested direction of
travel.
Output The direction has been set as requested and will be updated when pacman
reaches a tile.
Summarize Increase in one the total lives of Pacman if he reaches a score divisible by
5000. It is only allowed when pacman has less than 5 lives left, as this is the
maximum amount of lives.
Input None
Summarize Allows to show relevant information about the game and instructions about the
controls or the mechanics of the game.
Input None
Name FR.#9. Level up when Pacman eats all the dots in the maze.
Summarize The stage must lead to next when pacman has eaten all the dots in it.
Input None
Non-Functional requirements:
Summarize The graphical user interface will be made in JavaFX and styled using CSS.
Name NFR.#2. Make the game works either using an adjacency matrix or an
adjacency list representation of the graph that models the maze.
Summarize The graph that represents the maze can be switch between two types of
representations, an Adjacency matrix and list.
Node or Vertex:
These are the most important components in any graph. Nodes are entities whose
relationships are expressed using edges.
Edges:
Edges(also called an “arcs”) are the components that are used to represent the
relationships between various pairs of nodes in a graph. An edge between two nodes
expresses a one-way or two-way relationship between the nodes. They’re ordered
pairs of the form (u, v). The pair is ordered because (u, v) is not the same as (v, u) in
the case of a directed graph(di-graph). The pair of the form (u, v) indicates that there is
an edge from vertex u to vertex v. The edges may contain weight/value/cost.
Edges in an Edges in a
undirected directed
graph graph(di-graph)
Types of nodes:
Root node: The root node is the ancestor of all
other nodes in a graph. It does not have any
ancestors. Each graph consists of exactly one
root node. Generally, you must start traversing a graph from the root node.
The objective of the game is to accumulate as many points as possible by eating dots,
fruits, and blue ghosts. When all of the dots in a stage are eaten, that stage is
completed, and the player will advance to the next. The four ghosts roam the maze
and chase Pac-Man. If any of the ghosts touches Pac-Man, a life is lost. When all lives
have been lost, the game is over. The player begins with three lives, but that amount
can be changed to one, two, or five. The player will receive one extra life bonus after
obtaining 10,000 points. The number of points needed for a bonus life can be changed
to 15,000 or 20,000 or disabled altogether.
Near the corners of the maze are four flashing energizers that allow Pac-Man to eat
the ghosts and earn bonus points. The enemies turn deep blue, reverse direction and
move away from Pac-Man, and usually move more slowly. When an enemy is eaten,
its eyes return to the center ghost box where the ghost is regenerated in its normal
color. The bonus score earned for eating a blue ghost increases exponentially for each
consecutive ghost eaten while a single energizer is active: a score of 200 points is
scored for eating one ghost, 400 for eating a second ghost, 800 for a third, and 1600
for the fourth. This cycle restarts from 200 points when Pac-Man eats the next
energizer. Blue enemies flash white to signal that they are about to return to their
normal color and become dangerous again; the length of time the enemies remain
vulnerable varies from one stage to the next, generally becoming shorter as the game
progresses. In later stages, the enemies begin flashing immediately after an energizer
is consumed, without a solid-blue phase; starting at stage nineteen, the ghosts do not
become edible at all, but still reverse direction. There are fruits that appear twice per
level, directly below the center ghost box; eating one gives 100 to 5,000 points.
Enemy behavior:
Ghosts have three mutually-exclusive modes of behavior they can be in during play:
chase, scatter, and frightened. Each mode has a different objective/goal to be carried
out:
Chase: A ghost's objective in chase mode is to find and capture Pac-Man by hunting
him down through the maze. Each ghost exhibits unique behavior when chasing
Pac-Man, giving them their different personalities: Blinky (red) is very aggressive and
hard to shake once he gets behind you, Pinky (pink) tends to get in front of you and cut
you off, Inky (light blue) is the least predictable of the bunch, and Clyde (orange)
seems to do his own thing and stay out of the way.
Scatter: In scatter mode, the ghosts give up the chase for a few seconds and head for
their respective home corners. It is a welcome but brief rest-soon enough, they will
revert to chase mode and be after Pac-Man again.
Frightened: Ghosts enter frightened mode whenever Pac-Man eats one of the four
energizers located in the far corners of the maze. During the early levels, the ghosts
will all turn dark blue (meaning they are vulnerable) and aimlessly wander the maze for
a few seconds. They will flash moments before returning to their previous mode of
behavior.
-- When time runs out, they return to the mode they were in before being frightened
and the scatter/chase timer resumes. This information is summarized in the following
table (all values are in seconds):
Scatter 7 7 5
Chase 20 20 20
Scatter 7 7 5
Chase 20 20 20
Scatter 5 5 5
Scatter targets:
Each ghost has a fixed target tile it is trying to reach in scatter mode.
Step 3. Searching for creative solutions.
First option: Use an adjacency matrix to model the map
This option requires to associate a two-dimensional matrix where each row and column
represents a vertex in the graph and the value of a cell(i,j) is the cost of going from
vertex i to vertex j, just like the showed previously.
A value of 0 (Although it can also be infinity) indicates that there is no edge from vertex
i to vertex j, for instance, from (0,1) to (1,0) and integer values greater than 0 indicating
the cost of arriving from vertex i to vertex j, for example, from (1,0) to (2,0). The idea
here is doing that Pacman ghosts be capable to move through the corridors which the
Pac-dots, fruits and energizes are going to be allocated as well.
When any of the characters attempt to travel through one of the boxes marked with “0”
(or infinity), these should not be able to do it because the value of this box represents a
wall or no edge between two referenced vertices. In our case we will use a graph
where all the edges will have unit weight, except in the tunnel where the ghosts slow
down and therefore there should be a higher cost. Other edges with a high cost would
be the ones just up the ghosts’ house as ghosts are not allowed to travel them from
bottom to top (although they can do it from top to bottom).
Food and the bonus objects are going to be allocated in their respective vertex.
For this option is necessary the use of an array of lists for each vertex where the
outcoming list of each vertex contains all the edges to their neighbors. For doing this
efficiently we need a list of type dictionary where the keys are the vertices and their
values are their adjacent vertices.
If one of the vertices of the list is not associated with another one means that there is
no edge between those two vertices (although there can be a path going through more
vertices) or there is a “wall” between them. Each edge in the list is associated with a
weight that represents the cost of moving in a determinate part of the maze, where the
cost will be the highest for the ghosts when they try to pass through the tunnel or from
bottom to top when they are in the exit of their house.
Food and the bonus objects are going to be displayed in their location as the original
game being assigned in each respective vertex along all the maze.
Third option: Use a matrix whose components are the map coordinates
The idea is to have a matrix whose boxes have identifiers of the element that is in that
part of the map, for example, in the previous matrix, elements of the map are
represented by a number: (0) Corridor without food, (1) Corridor with food, (2)
Power-pellets, (3) Wall, (4) House of ghosts.
Characters can move through the boxes marked 0 or 1. When Pacman goes through a
box marked 1, the box will change to 0. Characters can be represented by ASCII
characters not present on the map, one character for each ghost and another for
Pacman.
Adjace 1 4 2 2 3 12
ncy
matrix
Adjace 2 3 2 3 2 12
ncy list
Regula 2 1 1 2 1 7
r
matrix
Selection:
The alternative that we will be using is the adjacency matrix, since, although it got the
same score as the adjacency list, we would end up using more space with the list. This
is because we need to use Floyd-Warshall algorithm and we could not figure out how
to implement it natively in the list, so we translated the list into a matrix and performed
Floyd-Warshall in there.
ADT Stack
ADT Queue
Object
Representation
front = a1 ∧ back = an
1. (aQueue.createQueue()).size() = 0
2. (aQueue.enqueue(item)).size() = aQueue().size() +1
3. (aQueue.dequeue()).size() = aQueue.size() - 1
4. (aQueue.createQueue()).isEmpty() = TRUE
5. (aQueue.enqueue(item)).isEmpty() = FALSE
6. (aQueue.createQueue()).dequeue() = ERROR
ADT Graph
Definition A Graph is a collection of finite sets of vertices or nodes (V) and edges
(E). Edges are represented as ordered pairs (u, v) where (u, v) indicates
that there is an edge from vertex u to vertex v. Edges may contain cost,
weight or length. The degree or valency of a vertex is the number of
edges that connect to it.
Object G(V, E) ∧ V = {v1, v2 ... vn-1, vn} ∧ E ⊆ {{x, y} / (x, y) ∈ V2 ∧ x ≠ y}
Representation
1. (aGraph.createGraph()).order() = 0
2. (aGraph.insert(k)).order() = aGraph().order() +1
3. (aGraph.createGraph()).delete(k) = FALSE
4. (aGraph.createGraph().insert(k)).delete(k) = TRUE
5. (aGraph.insert(k)).isEmpty() = FALSE
6. (aGraph.createGraph()).isEmpty() = TRUE
7. (aGraph.insert(k)).getVertex(k) = V(k)
8. (aGraph.createGraph()).getVertex(k) = NIL
9. (aGraph.link(u, v)) → E(u, v) != NIL
SCENARIO SETUP
Name Class under test Stage
setupStage1 Queue
(A)
setupStage2 Queue
setupStage1 Stack
(B)
setupStage2 Stack
setupStageD AdjacencyMatrixGrap
irected h
setupStageU AdjacencyMatrixGrap
ndirected h
setupStageG AdjacencyMatrixGrap
raphWithIsol h
atedVertices
setupStageD AdjacencyListGraph
irected
setupStageU AdjacencyListGraph
ndirected
setupStageG AdjacencyListGraph
raphWithIsol
atedVertices
TEST CASES
Test Objective: Verificate that whenever you create a queue this must be empty and its front null.
Test Objective: Verificate that the method enqueue adds elements inside the queue and the
queue size is increasing by one per each element is added.
Test Objective: Verificate that the method dequeue eliminates elements inside the queue and
the queue size is decreasing by one per each element is eliminated.
Test Objective: Verificate that whenever you create a stack this must be empty and its top null.
Class Method Stage Input Output
Test Objective: Verificate that the method top shows and does not delete the right element
previously added inside the stack. Moreover, the method must throw null when the stack is
empty.
Test Objective: Verificate that the method pop shows and deletes the right element previously
added inside the stack. Moreover, the method must decrease the stack size by one whenever top
is called.
Test Objective: Verificate that the method push adds an element inside the stack and besides
this increases the stack size by one.
Test Objective: Verificate that the method link links a source vertex with another one and
assigns correctly the weight of their relationship when the graph is directed.
Adjacenc
yMatrixGr
aph
Test Objective: Verificate that the method link links a source vertex with another one and
assigns correctly the weight of their relationship when the graph is undirected.
Test Objective: Verificate that the method unlink unlinks a source vertex with another one which
already exist inside the graph when the graph is directed.
Test Objective: Verificate that the method unlink unlinks a source vertex with another one which
already exist inside the graph when the graph is undirected.
Test Objective: Verificate whenever BFS is applied in an undirected graph as from a source
vertex visits all the vertices and besides delivers the correct least stop paths.
Class Method Stage Input Output
Test Objective: Verificate whenever BFS is applied in a directed graph as from a source vertex
visits all the vertices and besides delivers the correct least stop paths.
Test Objective: Verificate whenever DFS is applied in an undirected this visits all the vertices
regardless of the starting point.
Test Objective: Verificate whenever DFS is applied in a directed this visits all the vertices
specifying a source vertex.
Class Method Stage Input Output
Test Objective: Verificate that the method deleteVertex deletes a specified vertex that exist
inside the graph with its edge when is necessary.
Adjacency
MatrixGra
ph
Test Objective: Verificate whenever Dijkstra is applied in a source vertex this gives the correct
shortest path of others selected vertices that already exist inside the graph.
Test Objective: Verificate whenever FloydWarshall is applied in the actual graph this gives the
correct shortest path between two specified vertices.
Test Objective: Verificate whenever Prim is applied in the actual graph this gives the correct
minimum spanning tree with any source vertex when the graph is connected and weighted.
Test Objective: Verificate whenever Kruskal is applied in the actual graph this gives the correct
minimum spanning tree no matter if it is connected or not. Besides the graph has to be weighted
as well.