For some of my programs, I need a basic pathfinding program to have enemies continue to move towards the player. Would something like this article mentions work in Ti-Basic for this purpose? Thanks.

https://en.wikipedia.org/wiki/Pathfinding
Yes, any pathfinding algorithm CAN be implemented in TI-Basic.

However, some implementations will be faster than others.

You might want to ask yourself, "Do I really need to have actual pathfinding in my game?".

Here are some *much* faster alternatives:
1) Random. Have your enemy attempt to move in a direction, and move it (unless it runs into a wall)
2) Kerm showed an excellent example of "pathfinding" in his book, and it worked something like this (pseudocode):

Code:
Create a random number (1-4) and store it to A.
If A=1 and there isn't a tile at (X+1,Y)
Increment X.
If A=2 and there isn't a tile at (X-1,Y)
Decrement X.
If A=3 and there isn't a tile at (X,Y+1)
Increment Y.
If A=4 and there isn't a tile at (X,Y-1)
Decrement X.
There was an entire contest around pathfinding algorithms. Here is a link to that. We received a handful of entries, and some of them worked. The only thing is that these were written with quite restrictive constraints in place, to make it more of a challenge. Therefore, they might not be the most efficient algorithms around. I remember seeing at least 2 very clever entries. I probably still have the code for them somewhere, but I think out of respect for the authors, they should be the ones to step up and share their code if they want to do so.
Also, keep in mind that the pathfinding algorithms that had to be created for this contest absolutely had to come up with correct paths to reach the endpoint. In a game however, the "grid" would probably be the entire screen rather than a 10x10 matrix. Also, it's not a big deal if the enemies don't calculate an entire path to reach the destination, you could instead, just make them move one unit of distance towards the target at every iteration, making sure to split the X and Y components into 2 distinct motions, so that the enemy could make its way around obstacles or walls.
Thanks for all of the advice. I decided to go with the method Kerm shows. However, even after I added detection for it hitting a wall, it is getting the domain error when all it is doing is putting a space at where the enemy was so that it doesn't leave a trail.

Here is new code after a couple hours of hitting it with a hammer, and it still not working Bad Idea Mad Smile .

Code:

Repeat G=45
   getKey->G
   randInt(1,10)->L
   If L<5
   Then
      randInt(1,4)->Z
   If Z=1 and (G-1>1)
   Then
      // Move up
      Output(G,H," "
      G-1->G
      Output(G,H,"+
   End
   If Z=2 and (G+1<10)
   Then
      // Move down
      Output(G,H," "
      G+1->G
      Output(G,H,"+
   End
   If Z=3 and (H+1<26)
   Then
      // Move right
      Output(G,H," "
      H+1->H
      Output(G,H,"+
   End
   If Z=4 and (H-1>1)
   Then
      // Move left
      Output(G,H," "
      H-1->H
         Output(G,H,"+
      End
   If G=45
   Output(D,C,"*
   If G=24
   Then
      Output(D,C,"
      C-1->C
      Output(D,C,"*
   End
   If G=25
   Then
      Output(D,C,"
      D-1->D
      Output(D,C,"*
   End
   If G=26
   Then
      Output(D,C,"
      C+1->C
      Output(D,C,"*
   End
   If G=34
   Then
      Output(D,C,"
      D+1->D
      Output(D,C,"*
   End
21tmccauley wrote:
Thanks for all of the advice. I decided to go with the method Kerm shows. However, even after I added detection for it hitting a wall, it is getting the domain error when all it is doing is putting a space at where the enemy was so that it doesn't leave a trail.

Here is new code after a couple hours of hitting it with a hammer, and it still not working Bad Idea Mad Smile .

Code:

Repeat G=45
   getKey->G
   randInt(1,10)->L
   If L<5
   Then
      randInt(1,4)->Z
   If Z=1 and (G-1>1)
   Then
      // Move up
      Output(G,H," "
      G-1->G
      Output(G,H,"+
   End
   If Z=2 and (G+1<10)
   Then
      // Move down
      Output(G,H," "
      G+1->G
      Output(G,H,"+
   End
   If Z=3 and (H+1<26)
   Then
      // Move right
      Output(G,H," "
      H+1->H
      Output(G,H,"+
   End
   If Z=4 and (H-1>1)
   Then
      // Move left
      Output(G,H," "
      H-1->H
         Output(G,H,"+
      End
   If G=45
   Output(D,C,"*
   If G=24
   Then
      Output(D,C,"
      C-1->C
      Output(D,C,"*
   End
   If G=25
   Then
      Output(D,C,"
      D-1->D
      Output(D,C,"*
   End
   If G=26
   Then
      Output(D,C,"
      C+1->C
      Output(D,C,"*
   End
   If G=34
   Then
      Output(D,C,"
      D+1->D
      Output(D,C,"*
   End


What do you mean by "it is getting the domain error when all it is doing is putting a space at where the enemy was so that it doesn't leave a trail. "
I believe he is saying that the white-space (used to prevent a trail from the enemies path) isn't displaying within the boundaries of the screen. Wink
I'll give the code a whirl to see if I can find the issue

EDIT: I found the issue, you're using the same variable (G) for both the getKey and the white space location. You also have no declaration for the variables so they aren't getting set up correctly at the beginning of the program.
Just replace the getKey stuff with variable K, add 2 or so "End"s to the very end of your program, also set variables G,H,C,D and K to 1 at the very beginning of the program. This should fix everything to a working state.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement