pathfinding ai problems

This is a discussion on pathfinding ai problems within the C++ Programming forums, part of the General Programming Boards category; I'm working on a pathfinding ai for a strategy game. The idea that I have is to take the initial ...

  1. #1
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179

    pathfinding ai problems

    I'm working on a pathfinding ai for a strategy game. The idea that I have is to take the initial position, look at the four surrounding tiles, and if those are ok (are on valid spaces that haven't been used yet), use them as initial positions in the next loop. Then I can just test each new spot to see if it is the destination and use the number of iterations through the main loop to determine how many steps it took to get there. This seems like an ok way to do it to me, but when I wrote it out in a simple console way, I got some weird system error. I traced it in MSCV and found out that this function:
    Code:
    void addpath(path_t* path,int& numpaths,int oldpath,coord_t newcoord) {
      path_t* temppath = new path_t[numpaths];
      int i;
      for (i = 0; i < numpaths; ++i)
        temppath[i] = path[i];
      delete [] path;
      ++numpaths;
      path = new path_t[numpaths];
      for (i = 0; i < numpaths-1; ++i)
        path[i] = temppath[i];
      delete [] temppath;
      path[numpaths-1].coord = new coord_t[path[oldpath].numcoords+1];
      for (i = 0; i < path[oldpath].numcoords; ++i)
        path[numpaths-1].coord[i] = path[oldpath].coord[i];
      path[numpaths-1].coord[path[oldpath].numcoords] = newcoord;
      path[numpaths-1].numcoords = path[oldpath].numcoords+1;
    }
    was returning unitialized values for path[pathi].numcoords. This doesn't make any sense to me and I was wondering if anyone out there could help me out.
    Attached Files Attached Files
    Illusion and reality become impartiality and confidence.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Game Design Topic #1 - AI Behavior
    By TechWins in forum Game Programming
    Replies: 13
    Last Post: 10-11-2002, 11:35 AM
  2. Ai
    By bobthemighty in forum Game Programming
    Replies: 18
    Last Post: 05-19-2002, 12:44 AM
  3. Technique of all board-like games?
    By Nutshell in forum Game Programming
    Replies: 28
    Last Post: 04-24-2002, 09:19 AM
  4. AI (pathfinding) tutorial
    By dirkduck in forum Game Programming
    Replies: 3
    Last Post: 02-09-2002, 12:04 PM
  5. Replies: 4
    Last Post: 12-12-2001, 12:06 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21