Skip to content
Open
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
32 changes: 32 additions & 0 deletions solutions/cpp/pacman-rules/1/pacman_rules.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// eat_ghost returns a boolean value if Pac-Man is able to eat the ghost.
// The function should return true only if Pac-Man has a power pellet active
// and is touching a ghost.
bool can_eat_ghost(bool power_pellet_active, bool touching_ghost) {
// TODO: Please implement the can_eat_ghost function :DONE
return power_pellet_active and touching_ghost;
}

// score returns a boolean value if Pac-Man scored.
// The function should return true if Pac-Man is touching a power pellet or a
// dot.
bool scored(bool touching_power_pellet, bool touching_dot) {
// TODO: Please implement the scored function :DONE
return touching_power_pellet or touching_dot;
}

// lost returns a boolean value if Pac-Man loses.
// The function should return true if Pac-Man is touching a ghost and
// does not have a power pellet active.
bool lost(bool power_pellet_active, bool touching_ghost) {
// TODO: Please implement the lost function :DONE
return !power_pellet_active and touching_ghost;
}

// won returns a boolean value if Pac-Man wins.
// The function should return true if Pac-Man
// has eaten all of the dots and has not lost
bool won(bool has_eaten_all_dots, bool power_pellet_active,
bool touching_ghost) {
// TODO: Please implement the won function :DONE
return !lost(power_pellet_active, touching_ghost) and has_eaten_all_dots;
}