Sequential Grid-Based Movement

Get help using Construct 2

Post » Thu Sep 19, 2013 9:13 am

Yup, the UID of initial boardspace matches the one at boardspaces xi yi. Thus, no more calls.
B
24
S
9
G
7
Posts: 756
Reputation: 7,302

Post » Thu Sep 19, 2013 9:16 am

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!



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...

Excal2013-09-19 10:41:25
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,234

Post » Thu Sep 19, 2013 10:59 am

[QUOTE=Excal] 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?[/QUOTE]

Yes that was what I was aiming for, glad that you spotted it :)
B
24
S
9
G
7
Posts: 756
Reputation: 7,302

Post » Thu Sep 19, 2013 11:59 am

@vee41



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:



Any idea on how to record direction?Excal2013-09-19 12:15:23
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,234

Post » Thu Sep 19, 2013 12:48 pm

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.
B
24
S
9
G
7
Posts: 756
Reputation: 7,302

Post » Thu Sep 19, 2013 12:53 pm

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.
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,234

Post » Fri Sep 20, 2013 12:51 am

@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:



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!Excal2013-09-20 04:37:17
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,234

Previous

Return to How do I....?

Who is online

Users browsing this forum: fearfulelephants and 16 guests