Question: { Explain the A* Search Algorithm Coding below // A C++ Program to implement A* Search Algorithm #include using namespace std; // Returns true if


![true if the cell is not blocked else false if (grid[row][col] ==](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f0779fd26b8_29566f0779f6fe6f.jpg)






{ "Explain the A* Search Algorithm Coding below" // A C++ Program to implement A* Search Algorithm #include using namespace std; // Returns true if the cell is not blocked else false if (grid[row][col] == 1) return (true); else return (false); #define ROW 9 #define COL 10 } // Creating a shortcut for int, int pair type typedef pair int, int> Pair; // A Utility Function to check whether destination cell has // been reached or not bool isDestinatikolint row, int col, Pair dest) // Creating a shortcut for pairint, pair> type typedef pair double, pair> Raic if (row == dest.ficst &.& col == dest.second) return (true); else return (false); } // A structure to hold the destesacx parameters struct cell { // Row and Column index of its parent // Note that 0= 0) && (row = 0) && (col (%0.269) "Disturisecond; } // If the destination cell is the same as source cell if (isDestinatigolscs.fucst scssesong, dest) == true) { Briat ("We are already at the destination "); return; } return; 1 // A Function to find the shortest path between // a given source cell to a destination cell according // to A* Search Algorithm void aStar Searchlint grid][COL), Pair scs, Pair dest) // Create a closed list and initialise it to false which means // that no cell has been included yet // This closed list is implemented as a barlean 2D array bool slesedList[ROW][COL); Dosetllesedlist, false, sizes (slosedlist)); // Declare a 2D array of structure to hold the details //of that cell cell sell Details[ROW][COL); int i, j; // If the source is out of range if (isValid (scs.ficat, CsessRod) == false) 1 Briath. ("Source is invalid "); return; } for (i=0; (Popped Cell (11) N-acth (i-1, j] S-South (i+1, j) E-Fast i j+1) W-West 1,1-1) N.E--> North-East.(i-1, j+1) N.W-> North-West.li-1, j-1) S.E-> South-East.li+1, 3+1) S.W--> South-West.li+1, j-1)*/ // To store the 'g', 'h' and 'f' of the 8 successors double sNexy, Next, tex 1st Successor (North) while Marsalist.ecorte)) { Raicp = *arsobist.begin(); // Remove this vertex from the open list srealist.scase grenlist.begin()); // Only process this cell if this is a valid one if (isValidli-1, j) == true) { // If the destination cell is the same as the // current successor if (isDestinatigoli-1, j, dest) == true) // Add this vertex to the closed list cell Details[i-1Ul-Raceat..=j; } } } 1/--------- 2nd Successor (South) // Only process this cell if this is a valid one if (isValidli+1, j) == true) { // If the destination cell is the same as the // current successor if (ispestinatigoli+1, j, dest) == true) // Set the Parent of the destination cell cellDetails[i-1JD).Baceot.j = U cel Details[i-1][il-Bareo.i= 1; Briott ("The destination pathways from klia to new york "); trasePath (cel Details, gest); found Rest = true; return; } // If the successor is already on the closed // list or if it is blocked, then ignore it. // Else do the following else if (slosedList[i-1101] == false 8.& isUnBleskedlerid, 1-1, 1) == true) { New = cell Details like +1.0; bNexs = calculateHValue (1-1, j, gest); Nexc=gNex+bNews // If it isn't on the open list, add it to // the open list. Make the current square // the parent of this square. Record the 1/f,g, and h costs of the square cell OR // If it is on the open list already, check // to see if this path to that square is better, // using 'f' cost as the measure. if (cellDetails[i-110].f == FLT_MAX || cellDetails[i-1][i].f> (New) { grenlist.insertl.bake.raid ex Dake.baidi-1, 1); // Set the Parent of the destination cell cellDetails[i+1]).parent. = 1; cellDetails[i+1][1] Barent.. =; Briotfl"The destination pathways from kli to new york "); trasePathlcellDetails, sest); foundDest = true; return; } // If the successor is already on the closed // list or if it is blocked, then ignore it. // Else do the following else if (slesedListli+1][i] == false &.&. islo Beskedigrid, i+1, j) == true) New = cellDetails[i][ila + 1.0; bNext = calculateHValueli+1, , dest); Nexx = NexNew // Update the details of this cell cel Details[i-10).f - Nero cellDetails[i-1101-8 - New cell Details[i-1].h=bNews cellDetails[i-1]U-Recent i = 1; // If it isn't on the open list, add it to // the open list. Make the current square // the parent of this square. Record the // f, g, and h costs of the square cell // OR // If it is on the open list already, check // to see if this path to that square is better, // using 'f' cost as the measure. if (cell Details[i+110).f == FLT_MAX || cellDetails[i+210].f> New) { Sosobist. Dastlake. Raic (New wake. Raic (1+1, 1); // Update the details of this cell cell Details[i+1][i] f = exc cell Details[i+1]01-9 = New cell Details[i+1]0).h=hNews cell Details[i+1][il-raceat.i=1; cel Details[i+1][il-Raceat.-j; // Else do the following else if (slosedListlili+1] == false && isUnBlesked (grid, i j+1) == true) { SNex = cell Details[i] Oil: +1.0; bNext = salsulateHValue li, j+1, sest); Nex = NexNexx // If it isn't on the open list, add it to // the open list. Make the current square // the parent of this square. Record the // f, g, and h costs of the square cell OR } } 1/----------- 3rd Successor (East) // Only process this cell if this is a valid one if (isValid li, j+1) == true) // If it is on the open list already, check // to see if this path to that square is better, // using 'f' cost as the measure. if (cell Details[i]j+11.6 == FLT_MAX || cellDetails[i][j+111 > New) { sredlist.insertl.bake. Raid deyi Dake Rais .j+1); // Update the details of this cell cel Details[i][j+111-flexo cellDetails[i][j+11.5 = New cel Details[i][j+1).h = Nex cellDetails[i][j+11. Baceat. = 1; cel Details[i[i+1].parent.i=1; } // If the destination cell is the same as the // current successor if (is Destinati oli, j+1, dest) == true) { // Set the Parent of the destination cell cellDetails[i][j+11. Bareot. 1 cellDetails[i][j+1l.Barent i = 1; Briottl"The destination pathways from klia to new york "); trasePathlcellDetails, plest): foundDest = true; return; 1 11- ------ 4th Successor (West) // If the successor is already on the closed // list or if it is blocked, then ignore it. // Only process this cell if this is a valid one if (isValid, j-1) == true) // If the destination cell is the same as the // current successor if (isDestinatigoli, j-1, dest) == true) { // Set the Parent of the destination cell cellDetails[i][i-11. Baceot. - cellDetails[i][i-11. Baceot.-j; Briottl"The destination pathways from kliz to new york "); trasePathlcellDetails, sest); foundDest = true; return; } // Update the details of this cell cel Details[i][j-1].f = Nexo cellDetails[i][j-1)-9 = New cellDetails[i][i-1].h=bNex cel Details[i][j-1].pacent i = 1; cel Details[i][j-1).Receat.i=j; } } 1/----------- Sth Successor (North-East) // If the successor is already on the closed // list or if it is blocked, then ignore it. // Else do the following else if (slesedListlilli-1] == false && isto Bleskeslerid, i, j-1) == true) { sNew.= cel Details like +1.0; bNexs = calculateHXalueli, j-1, dest); Next= Nex+ Nex: // Only process this cell if this is a valid one if (isValidli-1j+1) == true) { // If the destination cell is the same as the // current successor if (isDestinatigoli-1, j+1, dest) ==true) // Set the Parent of the destination cell cellDetails[i-1][i+1]-Raceat.= 1; cel Details[i-1][j+1) Bacent..=j; Briott ("The destination pathways from kli to new vack "); trasePath (cel Details, sext); foundDest true; return; } // If it isn't on the open list, add it to // the open list. Make the current square // the parent of this square. Record the // f, g, and h costs of the square cell OR // If it is on the open list already, check // to see if this path to that square is better, // using 'f' cost as the measure. if (cel Details[i][i-1 f ==FLT_MAX || cel Details[i][-1.f> New) { srsalist.insert nake. Baic New wake Raic ,j-1))); // If the successor is already on the closed // list or if it is blocked, then ignore it. // Else do the following else if (slosedList[i-1][i+1] == false && isUnBleskedIgrid, i-1, j+1) ==true) { SNew = cell Details 11.5 +1.414; bNext = salculateHValveli-1, j+1, dest); News News New Briott ("The destination pathways from blia to new york "); trasePath (cell Details, dest); fguod Rest = true; return; 1 // If it isn't on the open list, add it to // the open list. Make the current square // the parent of this square. Record the // f, g, and h costs of the square cell OR // If it is on the open list already, check // to see if this path to that square is better, // using 'f' cost as the measure. if (cel Details[i-1][i+1].f == FLT_MAX || cellDetails[i-1][i+1].f> New) greolist.insertl.make.Raic (fNew Dake-Bairl-1, j+1))); // If the successor is already on the closed // list or if it is blocked, then ignore it. // Else do the following else if (slesedListii-1][i-1] == false && isUn Bleskelgrid, i-1, j-1) == true) gNew = cellDetails[i][i].3 +1.414; Nex = calculateHValue(1-1, 1-1, dest); fNexNexNews // Update the details of this cell cellDetails[i-1][i+1].f = Nex cellDetails[i-1][+1.3 = Nex cel Details[i-1][j+1).h - News cel Details[i-1][j+1).BRCEDD.i= cellDetails[i-1][i+1].Baceot.i=1; } } } // 5th Successor (North-West) // Only process this cell if this is a valid one if (isValid (i-1, 3-1) == true) // If it isn't on the open list, add it to // the open list. Make the current square // the parent of this square. Record the // f, g, and h costs of the square cell OR // If it is on the open list already, check // to see if this path to that square is better, // using 'f' cost as the measure. if (cell Details[i-1][i-1].f == FLT_MAX || cel Details[i-1][i-1].f>fNew) { arsobist.insert/bake.Bric (Nexx pake. Raic (i-1, j-1)}); // Update the details of this cell cel Details[i-1])-1].f = New cellDetails[i-1][i-1].5 = Nex cellDetails[i-1][i-1].h=bNews cel Details[i-1]0-1).Baceot. B cellDetails[1-1)01-11.parent.=j; } // If the destination cell is the same as the // current successor if (isDestination. (i-1, j-1, dest) == true) // Set the Parent of the destination cell cellDetails[i-1]||-1)-Raceat.i= 1; cellDetails[i-1][i-1).Baceot.i.= 1; 1/--------- 7th Successor (South-East) if (cellDetails[i+1][i+1].f == FLT_MAX || cellDetails[i+1][i+1].f> (New) 1 srealist.insertiakeBricles make Rais (i+1, 3+1))); // Only process this cell if this is a valid one if (isValidli+1, j+1) ==true) // If the destination cell is the same as the // current successor if (isDestinatigoli+1, j+1, pest) ==true) { // Set the Parent of the destination cell cellDetails[i+1][j+1).Baceat. = 1; cellDetails[i+1][j+1).parent.j=j; Briott ("The destination pathways from kli to new vack "); trasePath (cell Details, dest); found Dest = true; return; } // Update the details of this cell cellDetails[i+1][i+1].f = flex cellDetails[i+1][j+1].5 =gNew cellDetails[i+1][i+1].h =bNews cellDetails[i+1][j+1).Baceat. cel Details[i+1][i+1].gaceat.j= j; } } } IX- 8th Successor (South-West) // If the successor is already on the closed // list or if it is blocked, then ignore it. // Else do the following else if (slesedbistli+1][i+1] == false && islableskelgrid, i+1, j+1) ==true) { New = cel Details lila +1.414; Next = calculateHValueli+1, j+1, dest); Nex= Nexe+hNex == // Only process this cell if this is a valid one if (isValid (i+1, j-1) == true) { // If the destination cell is the same as the // current successor if (isDestinatirali+1, j-1, sest) true) { // Set the Parent of the destination cell cellDetails[i+1][-1). Recent. = 1; cellDetails[i+1]0-1).Recent..=j; Briottl"The destination pathways from kli to new york in"); trasePathlcellDetails, dest); feuod Rest=true; return; } // If it isn't on the open list, add it to // the open list. Make the current square // the parent of this square. Record the // f, g, and h costs of the square cell // OR // If it is on the open list already, check // to see if this path to that square is better, // using 'f' cost as the measure. // If the successor is already on the closed // list or if it is blocked, then ignore it. // Else do the following Rciatfil"Failed to find the Destination Cell "); return; else if (slesedListli-110-1] == false&.& is Un Blocked grid, i+1, j-1) == true) { gNew = cel Details like +1.414; bNext = calculateHValueli+1, j-1, dest); fex = Nex+bNews } // If it isn't on the open list, add it to // the open list. Make the current square // the parent of this square. Record the // f, g, and h costs of the square cell OR // If it is on the open list already, check // to see if this path to that square is better, // using 'f' cost as the measure. if (cell Details[i+1][i-1].f == FLT_MAX || cellDetails[i+1][i-1].f>fNew) 1 grenlist.insertlake Baic New make. Baidi+1, j-1)]); // Update the details of this cell cell Details[i+1J0-1).f = flex cellDetails[i+1][i-1].3 = Nex cell Details[i+1][i-1].h = b News cell Details[i+1][i-1].Baceot.i= cell Details[i+1][-1).Bacent.i- j; } // Driver program to test above function int main() 1 /* Description of the Grid- 1--> The cell is not blocked 0--> The cell is blocked / int grid[ROW][COL] = { {1,0,1,1,1,1,0,1,1,1}, {1,1,1,0,1,1,1,0,1,1} (1,1,1,0,1,1,0,1,0,1}, {0,0,1,0,1,0,0,0,0,1}, {1,1,1,0,1,1,1,0, 1,0}, {1,0,1,1,1,1,0,1,0,0}, {1,0,0,0,0,1,0,0,0,1} {1,0,1,1,1,1,0,1,1,1}, {1,1,1,0,0,0,1,0,0,1} }; // Source is the left-most bottom-most corner Pair scs = wake Raido, 2); // Destination is the left-most top-most corner Pair gest=bake.raidlo, 8); } aStar Searchigrid, s6 dest); return(0); // When the destination cell is not found and the open // list is empty, then we conclude that we failed to // reach the destiantiga cell. This may happen when the // there is no way to destination cell (due to blockages) if (found Rsat == false) { "Explain the A* Search Algorithm Coding below" // A C++ Program to implement A* Search Algorithm #include using namespace std; // Returns true if the cell is not blocked else false if (grid[row][col] == 1) return (true); else return (false); #define ROW 9 #define COL 10 } // Creating a shortcut for int, int pair type typedef pair int, int> Pair; // A Utility Function to check whether destination cell has // been reached or not bool isDestinatikolint row, int col, Pair dest) // Creating a shortcut for pairint, pair> type typedef pair double, pair> Raic if (row == dest.ficst &.& col == dest.second) return (true); else return (false); } // A structure to hold the destesacx parameters struct cell { // Row and Column index of its parent // Note that 0= 0) && (row = 0) && (col (%0.269) "Disturisecond; } // If the destination cell is the same as source cell if (isDestinatigolscs.fucst scssesong, dest) == true) { Briat ("We are already at the destination "); return; } return; 1 // A Function to find the shortest path between // a given source cell to a destination cell according // to A* Search Algorithm void aStar Searchlint grid][COL), Pair scs, Pair dest) // Create a closed list and initialise it to false which means // that no cell has been included yet // This closed list is implemented as a barlean 2D array bool slesedList[ROW][COL); Dosetllesedlist, false, sizes (slosedlist)); // Declare a 2D array of structure to hold the details //of that cell cell sell Details[ROW][COL); int i, j; // If the source is out of range if (isValid (scs.ficat, CsessRod) == false) 1 Briath. ("Source is invalid "); return; } for (i=0; (Popped Cell (11) N-acth (i-1, j] S-South (i+1, j) E-Fast i j+1) W-West 1,1-1) N.E--> North-East.(i-1, j+1) N.W-> North-West.li-1, j-1) S.E-> South-East.li+1, 3+1) S.W--> South-West.li+1, j-1)*/ // To store the 'g', 'h' and 'f' of the 8 successors double sNexy, Next, tex 1st Successor (North) while Marsalist.ecorte)) { Raicp = *arsobist.begin(); // Remove this vertex from the open list srealist.scase grenlist.begin()); // Only process this cell if this is a valid one if (isValidli-1, j) == true) { // If the destination cell is the same as the // current successor if (isDestinatigoli-1, j, dest) == true) // Add this vertex to the closed list cell Details[i-1Ul-Raceat..=j; } } } 1/--------- 2nd Successor (South) // Only process this cell if this is a valid one if (isValidli+1, j) == true) { // If the destination cell is the same as the // current successor if (ispestinatigoli+1, j, dest) == true) // Set the Parent of the destination cell cellDetails[i-1JD).Baceot.j = U cel Details[i-1][il-Bareo.i= 1; Briott ("The destination pathways from klia to new york "); trasePath (cel Details, gest); found Rest = true; return; } // If the successor is already on the closed // list or if it is blocked, then ignore it. // Else do the following else if (slosedList[i-1101] == false 8.& isUnBleskedlerid, 1-1, 1) == true) { New = cell Details like +1.0; bNexs = calculateHValue (1-1, j, gest); Nexc=gNex+bNews // If it isn't on the open list, add it to // the open list. Make the current square // the parent of this square. Record the 1/f,g, and h costs of the square cell OR // If it is on the open list already, check // to see if this path to that square is better, // using 'f' cost as the measure. if (cellDetails[i-110].f == FLT_MAX || cellDetails[i-1][i].f> (New) { grenlist.insertl.bake.raid ex Dake.baidi-1, 1); // Set the Parent of the destination cell cellDetails[i+1]).parent. = 1; cellDetails[i+1][1] Barent.. =; Briotfl"The destination pathways from kli to new york "); trasePathlcellDetails, sest); foundDest = true; return; } // If the successor is already on the closed // list or if it is blocked, then ignore it. // Else do the following else if (slesedListli+1][i] == false &.&. islo Beskedigrid, i+1, j) == true) New = cellDetails[i][ila + 1.0; bNext = calculateHValueli+1, , dest); Nexx = NexNew // Update the details of this cell cel Details[i-10).f - Nero cellDetails[i-1101-8 - New cell Details[i-1].h=bNews cellDetails[i-1]U-Recent i = 1; // If it isn't on the open list, add it to // the open list. Make the current square // the parent of this square. Record the // f, g, and h costs of the square cell // OR // If it is on the open list already, check // to see if this path to that square is better, // using 'f' cost as the measure. if (cell Details[i+110).f == FLT_MAX || cellDetails[i+210].f> New) { Sosobist. Dastlake. Raic (New wake. Raic (1+1, 1); // Update the details of this cell cell Details[i+1][i] f = exc cell Details[i+1]01-9 = New cell Details[i+1]0).h=hNews cell Details[i+1][il-raceat.i=1; cel Details[i+1][il-Raceat.-j; // Else do the following else if (slosedListlili+1] == false && isUnBlesked (grid, i j+1) == true) { SNex = cell Details[i] Oil: +1.0; bNext = salsulateHValue li, j+1, sest); Nex = NexNexx // If it isn't on the open list, add it to // the open list. Make the current square // the parent of this square. Record the // f, g, and h costs of the square cell OR } } 1/----------- 3rd Successor (East) // Only process this cell if this is a valid one if (isValid li, j+1) == true) // If it is on the open list already, check // to see if this path to that square is better, // using 'f' cost as the measure. if (cell Details[i]j+11.6 == FLT_MAX || cellDetails[i][j+111 > New) { sredlist.insertl.bake. Raid deyi Dake Rais .j+1); // Update the details of this cell cel Details[i][j+111-flexo cellDetails[i][j+11.5 = New cel Details[i][j+1).h = Nex cellDetails[i][j+11. Baceat. = 1; cel Details[i[i+1].parent.i=1; } // If the destination cell is the same as the // current successor if (is Destinati oli, j+1, dest) == true) { // Set the Parent of the destination cell cellDetails[i][j+11. Bareot. 1 cellDetails[i][j+1l.Barent i = 1; Briottl"The destination pathways from klia to new york "); trasePathlcellDetails, plest): foundDest = true; return; 1 11- ------ 4th Successor (West) // If the successor is already on the closed // list or if it is blocked, then ignore it. // Only process this cell if this is a valid one if (isValid, j-1) == true) // If the destination cell is the same as the // current successor if (isDestinatigoli, j-1, dest) == true) { // Set the Parent of the destination cell cellDetails[i][i-11. Baceot. - cellDetails[i][i-11. Baceot.-j; Briottl"The destination pathways from kliz to new york "); trasePathlcellDetails, sest); foundDest = true; return; } // Update the details of this cell cel Details[i][j-1].f = Nexo cellDetails[i][j-1)-9 = New cellDetails[i][i-1].h=bNex cel Details[i][j-1].pacent i = 1; cel Details[i][j-1).Receat.i=j; } } 1/----------- Sth Successor (North-East) // If the successor is already on the closed // list or if it is blocked, then ignore it. // Else do the following else if (slesedListlilli-1] == false && isto Bleskeslerid, i, j-1) == true) { sNew.= cel Details like +1.0; bNexs = calculateHXalueli, j-1, dest); Next= Nex+ Nex: // Only process this cell if this is a valid one if (isValidli-1j+1) == true) { // If the destination cell is the same as the // current successor if (isDestinatigoli-1, j+1, dest) ==true) // Set the Parent of the destination cell cellDetails[i-1][i+1]-Raceat.= 1; cel Details[i-1][j+1) Bacent..=j; Briott ("The destination pathways from kli to new vack "); trasePath (cel Details, sext); foundDest true; return; } // If it isn't on the open list, add it to // the open list. Make the current square // the parent of this square. Record the // f, g, and h costs of the square cell OR // If it is on the open list already, check // to see if this path to that square is better, // using 'f' cost as the measure. if (cel Details[i][i-1 f ==FLT_MAX || cel Details[i][-1.f> New) { srsalist.insert nake. Baic New wake Raic ,j-1))); // If the successor is already on the closed // list or if it is blocked, then ignore it. // Else do the following else if (slosedList[i-1][i+1] == false && isUnBleskedIgrid, i-1, j+1) ==true) { SNew = cell Details 11.5 +1.414; bNext = salculateHValveli-1, j+1, dest); News News New Briott ("The destination pathways from blia to new york "); trasePath (cell Details, dest); fguod Rest = true; return; 1 // If it isn't on the open list, add it to // the open list. Make the current square // the parent of this square. Record the // f, g, and h costs of the square cell OR // If it is on the open list already, check // to see if this path to that square is better, // using 'f' cost as the measure. if (cel Details[i-1][i+1].f == FLT_MAX || cellDetails[i-1][i+1].f> New) greolist.insertl.make.Raic (fNew Dake-Bairl-1, j+1))); // If the successor is already on the closed // list or if it is blocked, then ignore it. // Else do the following else if (slesedListii-1][i-1] == false && isUn Bleskelgrid, i-1, j-1) == true) gNew = cellDetails[i][i].3 +1.414; Nex = calculateHValue(1-1, 1-1, dest); fNexNexNews // Update the details of this cell cellDetails[i-1][i+1].f = Nex cellDetails[i-1][+1.3 = Nex cel Details[i-1][j+1).h - News cel Details[i-1][j+1).BRCEDD.i= cellDetails[i-1][i+1].Baceot.i=1; } } } // 5th Successor (North-West) // Only process this cell if this is a valid one if (isValid (i-1, 3-1) == true) // If it isn't on the open list, add it to // the open list. Make the current square // the parent of this square. Record the // f, g, and h costs of the square cell OR // If it is on the open list already, check // to see if this path to that square is better, // using 'f' cost as the measure. if (cell Details[i-1][i-1].f == FLT_MAX || cel Details[i-1][i-1].f>fNew) { arsobist.insert/bake.Bric (Nexx pake. Raic (i-1, j-1)}); // Update the details of this cell cel Details[i-1])-1].f = New cellDetails[i-1][i-1].5 = Nex cellDetails[i-1][i-1].h=bNews cel Details[i-1]0-1).Baceot. B cellDetails[1-1)01-11.parent.=j; } // If the destination cell is the same as the // current successor if (isDestination. (i-1, j-1, dest) == true) // Set the Parent of the destination cell cellDetails[i-1]||-1)-Raceat.i= 1; cellDetails[i-1][i-1).Baceot.i.= 1; 1/--------- 7th Successor (South-East) if (cellDetails[i+1][i+1].f == FLT_MAX || cellDetails[i+1][i+1].f> (New) 1 srealist.insertiakeBricles make Rais (i+1, 3+1))); // Only process this cell if this is a valid one if (isValidli+1, j+1) ==true) // If the destination cell is the same as the // current successor if (isDestinatigoli+1, j+1, pest) ==true) { // Set the Parent of the destination cell cellDetails[i+1][j+1).Baceat. = 1; cellDetails[i+1][j+1).parent.j=j; Briott ("The destination pathways from kli to new vack "); trasePath (cell Details, dest); found Dest = true; return; } // Update the details of this cell cellDetails[i+1][i+1].f = flex cellDetails[i+1][j+1].5 =gNew cellDetails[i+1][i+1].h =bNews cellDetails[i+1][j+1).Baceat. cel Details[i+1][i+1].gaceat.j= j; } } } IX- 8th Successor (South-West) // If the successor is already on the closed // list or if it is blocked, then ignore it. // Else do the following else if (slesedbistli+1][i+1] == false && islableskelgrid, i+1, j+1) ==true) { New = cel Details lila +1.414; Next = calculateHValueli+1, j+1, dest); Nex= Nexe+hNex == // Only process this cell if this is a valid one if (isValid (i+1, j-1) == true) { // If the destination cell is the same as the // current successor if (isDestinatirali+1, j-1, sest) true) { // Set the Parent of the destination cell cellDetails[i+1][-1). Recent. = 1; cellDetails[i+1]0-1).Recent..=j; Briottl"The destination pathways from kli to new york in"); trasePathlcellDetails, dest); feuod Rest=true; return; } // If it isn't on the open list, add it to // the open list. Make the current square // the parent of this square. Record the // f, g, and h costs of the square cell // OR // If it is on the open list already, check // to see if this path to that square is better, // using 'f' cost as the measure. // If the successor is already on the closed // list or if it is blocked, then ignore it. // Else do the following Rciatfil"Failed to find the Destination Cell "); return; else if (slesedListli-110-1] == false&.& is Un Blocked grid, i+1, j-1) == true) { gNew = cel Details like +1.414; bNext = calculateHValueli+1, j-1, dest); fex = Nex+bNews } // If it isn't on the open list, add it to // the open list. Make the current square // the parent of this square. Record the // f, g, and h costs of the square cell OR // If it is on the open list already, check // to see if this path to that square is better, // using 'f' cost as the measure. if (cell Details[i+1][i-1].f == FLT_MAX || cellDetails[i+1][i-1].f>fNew) 1 grenlist.insertlake Baic New make. Baidi+1, j-1)]); // Update the details of this cell cell Details[i+1J0-1).f = flex cellDetails[i+1][i-1].3 = Nex cell Details[i+1][i-1].h = b News cell Details[i+1][i-1].Baceot.i= cell Details[i+1][-1).Bacent.i- j; } // Driver program to test above function int main() 1 /* Description of the Grid- 1--> The cell is not blocked 0--> The cell is blocked / int grid[ROW][COL] = { {1,0,1,1,1,1,0,1,1,1}, {1,1,1,0,1,1,1,0,1,1} (1,1,1,0,1,1,0,1,0,1}, {0,0,1,0,1,0,0,0,0,1}, {1,1,1,0,1,1,1,0, 1,0}, {1,0,1,1,1,1,0,1,0,0}, {1,0,0,0,0,1,0,0,0,1} {1,0,1,1,1,1,0,1,1,1}, {1,1,1,0,0,0,1,0,0,1} }; // Source is the left-most bottom-most corner Pair scs = wake Raido, 2); // Destination is the left-most top-most corner Pair gest=bake.raidlo, 8); } aStar Searchigrid, s6 dest); return(0); // When the destination cell is not found and the open // list is empty, then we conclude that we failed to // reach the destiantiga cell. This may happen when the // there is no way to destination cell (due to blockages) if (found Rsat == false)