Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool recommendMove(const Arena& a, int r, int c, int& bestDir)
- {
- // TODO: Implement this function
- // Delete the following line and replace it with your code.
- int idle_risk = assessRisk(a, r, c);
- if (idle_risk == 0)
- return false;
- int least_risk = idle_risk;
- int north_risk = assessRisk(a, r - 1, c);
- int south_risk = assessRisk(a, r + 1, c);
- int west_risk = assessRisk(a, r, c - 1);
- int east_risk = assessRisk(a, r, c + 1);
- if (north_risk < least_risk && r != 1) {
- least_risk = north_risk;
- bestDir = NORTH;
- }
- if (south_risk < least_risk && r != a.rows()) {
- least_risk = south_risk;
- bestDir = SOUTH;
- }
- if (west_risk < least_risk && c!=1) {
- least_risk = west_risk;
- bestDir = WEST;
- }
- if (east_risk < least_risk && c!=a.cols()) {
- least_risk = east_risk;
- bestDir = EAST;
- }
- // Now let's check if least risk is different from idle risk
- // If it is different, then we would recommend moving
- if (idle_risk < least_risk)
- {
- return true;
- }
- // If it isn't different, simply return false.
- return false;
- // Your replacement implementation should do something intelligent.
- // You don't have to be any smarter than the following, although
- // you can if you want to be: If staying put runs the risk of a
- // rabbit possibly moving onto the player's location when the rabbits
- // move, yet moving in a particular direction puts the player in a
- // position that is safe when the rabbits move, then the chosen
- // action is to move to a safer location. Similarly, if staying put
- // is safe, but moving in certain directions puts the player in
- // danger of dying when the rabbits move, then the chosen action should
- // not be to move in one of the dangerous directions; instead, the player
- // should stay put or move to another safe position. In general, a
- // position that may be moved to by many rabbits is more dangerous than
- // one that may be moved to by few.
- //
- // Unless you want to, you do not have to take into account that a
- // rabbit might be poisoned and thus sometimes less dangerous than one
- // that is not. That requires a more sophisticated analysis that
- // we're not asking you to do.
- }
- int assessRisk(Arena& a, int row, int col)
- {
- int risk = 0;
- if (a.numberOfRabbitsAt(row, col) > 0)
- {
- risk += 99;
- return risk;
- // Do not move here lmao
- }
- else
- {
- risk += a.numberOfRabbitsAt(row - 1, col); // Rabbits above indicated location
- risk += a.numberOfRabbitsAt(row + 1, col); // Rabbits below indicated location
- risk += a.numberOfRabbitsAt(row, col - 1); // Rabbits left of indicated location
- risk += a.numberOfRabbitsAt(row, col + 1); //Rabbits right of indicated location
- return risk;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement