Question: struct path findMinEnergyPath ( Wall w , int reach, int energyCosts [ NUM _ COLOURS ] ) { struct path p = { 0 ,
struct path findMinEnergyPathWall w int reach, int energyCostsNUMCOLOURS
struct path p NULL;
int height WallHeightw;
int width WallWidthw;
struct rock rocks callocheight width, sizeofstruct rock;
int numOfRocks WallGetAllRocksw rocks;
bool explored callocheight sizeofbool;
for int r ; r height; r
exploredr callocwidth sizeofbool;
struct rock prevRock callocheight sizeofstruct rock;
for int r ; r height; r
prevRockr callocwidth sizeofstruct rock;
PQ pq PQNew;
for int i ; i numOfRocks; i
if rocksirow reach
Edge e rocksirow, rocksicol, energyCostsrocksicolour rocksicolour;
PQInsertpq e;
exploredrocksirowrocksicol true;
while PQIsEmptypq
Edge top PQExtractpq;
struct rock cur &rockstoprow width top.col;
if height currow reach
struct rock revPath callocheight width, sizeofstruct rock;
while cur
revPathpnumRockscur;
cur prevRockcurrowcurcol;
procks callocpnumRocks, sizeofstruct rock;
for int i j pnumRocks ; i pnumRocks; i j
procksirevPathj;
freerevPath;
break;
for int i ; i numOfRocks; i
int r rocksirow, c rocksicol, colour rocksicolour;
if exploredrc
continue;
int dr absr currow dc absc curcol;
if dr reach dc reach
continue;
Edge newEdge;
newEdge.weight top.weight energyCostscolour; Store energy as weight
newEdge.row i; Use row to store the index to rocks
newEdge.col c; Optionally, store actual column for reference
newEdge.colour colour; Store colour for additional data
PQInsertpq newEdge;
exploredrc true;
prevRockrc cur;
Clean up memory
freerocks;
for int r ; r height; r
freeexploredr;
freeprevRockr;
freeexplored;
freeprevRock;
PQFreepq;
return p;
Interface to the Wall ADT
DO NOT MODIFY THIS FILE
#ifndef WALLH
#define WALLH
typedef struct wall Wall;
Rock colours
#define NUMCOLOURS
enums are used to create groups of related constants. It is like
creating multiple #defines, except you can also provide a type name.
typedef enum
NONE
GREEN
TEAL
PINK
RED
Colour;
Terminal output colours
#define GRN xBm
#define CYN xBm
#define MAG xBm
#define RD xBm
#define RESET xBm
struct rock
int row;
int col;
Colour colour;
;
Wall WallNewint height, int width;
void WallFreeWall w;
int WallHeightWall w;
int WallWidthWall w;
void WallAddRockWall w struct rock rock;
int WallNumRocksWall w;
Colour WallGetRockColourWall w int row, int col;
int WallGetAllRocksWall w struct rock rocks;
int WallGetRocksInRangeWall w int row, int col, int dist,
struct rock rocks;
int WallGetColouredRocksInRangeWall w int row, int col, int dist,
Colour colour, struct rock rocks;
void WallPrintWall w;
#endif
Priority queue of edges
Edges with smaller weight have higher priority
DO NOT MODIFY THIS FILE
#ifndef PQH
#define PQH
#include
#include "Wall.h
typedef struct PQRep PQ;
typedef struct Edge
int row;
int col;
int weight;
Colour colour;
Edge;
PQ PQNewvoid;
void PQFreePQ pq;
void PQInsertPQ pq Edge e;
Edge PQExtractPQ pq;
bool PQIsEmptyPQ pq;
#endif
please give the IMPLEMENTATION of the fixed findMinEnergyPath, currently it returns no path found!"
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
