Sequential Grid-Based Movement

  • Wait, I think I understand what you mean now. In the log it shows the function only being called once when the other recursive functions are called multiple times.

    So it should be called more than once, and it's not. Is that what you mean?

    UPDATE: It's working now! The direction list is now updated so the computer program should know the exact sequence of squares to move!

    <img src="http://i.imgur.com/QJGDceT.png" border="0" />

    UPDATE 2: It turns out I'm going to have to use some sort of pathfinding for this. The problem is that using the nearest highlighted square might cause the computer to run toward an edge or area where no squares exist, and that's not what I want.

    Darn...

    UPDATE 3: I guess it's not so bad. There's some weird inconsistencies like when pathfinding fails to find a path even though there are paths available (the cell size I'm using is smaller than the widths of the actual paths). In the case of pathfinding not working, I just resort to the previous 'use nearest square' method. Now to get my AI programs moving...

    <img src="http://i.imgur.com/mkrQSes.png" border="0" />

  • Wait, I think I understand what you mean now. In the log it shows the function only being called once when the other recursive functions are called multiple times.

    So it should be called more than once, and it's not. Is that what you mean?

    Yes that was what I was aiming for, glad that you spotted it :)

  • vee41

    <img src="http://i.imgur.com/xK2P3fJ.png" border="0" />

    Apparently what I'm doing to determine direction isn't working. The backtracing is working, but since directions are being recorded wrong, it creates a sort of infinite loop.

    So now my question is, is there any way to use your highlighting function to determine the direction the object should move? I'm using the key:

    1 = left

    2 = right

    3 = up

    4 = down

    This is what I tried, but it doesn't always store the direction properly:

    <img src="http://i.imgur.com/NhvAB8N.png" border="0" />

    Any idea on how to record direction?

  • Well the highlighting function is meant just to highlight the squares. You'll need some way to determine which way AI wants to go, and for that, you'll probably want some sort of pathfinding algorithm. :)

    Here's general idea how I've done AI pathfinding in similar boardgame:

    Determine where AI wants to go, then:

    a) Use pathfinding behavior to find path to the target square

    b) Draw a 'move here' token to each square that is along that path

    c) Draw as many squares as the AI token has moves

    d) Move the token to next 'move here' token until there are no more

    Pathfinding behavior does most of the work, I just iterate through all the steps it takes and generate markers where necessary.

  • My program currently uses 2 different systems:

    The first is pathfinding, which 'tags' squares the pathfinding object moves through. The idea is to then select the farthest tagged object and backtrack to the original program.

    The second is simply selecting the highlighted square that is closest to the target (in the case of a pathfinding path not found) and backtrack to the original program.

    The backtracking is important to determine how the program should move.

    Unless, of course, you are suggesting that I also use pathfinding as a method of backtracking, which could work as well. I was just thinking the highlight function itself could somehow assign directions.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • vee41, so now I'm using two different pathfinding objects. One pathfinds to the target, the other starts from the highlighted square closest to the target and pathfinds back to the active object, adding each space's UID to a string as it passes along its way.

    The issue now is that the UID being passed to the string is passed multiple times for each square (since the pathfinding object overlaps each square more than once each second).

    Any idea how to do this? The relevant code can be found here:

    <img src="http://i.imgur.com/BEbo5WN.png" border="0">

    I tried to account for it by doing left(str, 3) not equal space.UID, but that doesn't actually seem to work.

    By the way, if you fire up the .capx and add the local static variable 'dirs' to inspect/watch, it's pretty cool to see it update in realtime during the computer's turn. You'll also see what I mean by the same UID being stored in the string repeatedly ;)

    BoardGame.capx

    UPDATE: Nevermind, I think I got it!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)