#pragma once
#include <vector>
#include <iostream>
#include "Enemy.h"
#include "Vector2D.h"
#define TILE_SIZE 20
#define MAP_WIDTH 800/TILE_SIZE
#define MAP_HEIGHT 600/TILE_SIZE
//http://www.policyalmanac.org/games/aStarTutorial.htmusingnamespace std;
struct CGrid
{
Vector2D Position;
bool Empty;
// Heuristic values
int F;
int G,H;
};
class CPathfinder
{
public:
CPathfinder(void);
~CPathfinder(void);
CGrid World_Map[MAP_WIDTH][MAP_HEIGHT];
CGrid End_Point_Grid;
void Process (void); // find out which grid to go
void MoveToGrid (CEnemy Enemy_Obj); // go to grid
// open list is a list for nodes to be considered
vector<Vector2D> Open_List;
// closed list is the list where the nodes are thrown into after being considered in open list
vector<Vector2D> Closed_List;
private:
Vector2D EndPoint;
};
So I'm having problem in how to calculate which grid to go to. Cause once i have a list of Positions to go to, i dont think i should have a problem.
So I was just wondering if anyone know of any links that is useful in helping me to do pathfinding algorithm because the links I found were either too vague or too hard for me to understand. Or is anyone willing to give me the algorithm.
The first node to consider is the one you're standing on. When that doesn't work, close it and open all of its neighbors you haven't considered yet. Always consider the open node with least cost+heuristic. Note that you shouldn't use Vector2D for nodes - how will you know which way you came from, once you find the target?