Excal's Forum Posts

  • Here's another update. The AI is slowly coming along, but it's not complete. However, this is significant progress, at least to me anyway.

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

    The 'default behavior' is mostly implemented, but it only works for a single AI program. During the computer's turn, the AI will pathfind to the nearest player target, then pathfind again to find a series of moves, then move accordingly. At the end of the movement, attack highlighting occurs, which is what you see in the picture.

    The .capx is mostly commented, but a lot of it is very complex and potentially confusing. I apologize to anyone who might be using it for reference at the moment - I will clean up the events and try to optimize some of the tasks once I am completely finished with the AI behavior.

  • 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!

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

  • 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?

  • 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" />

  • The comparison?

    The BoardSpaces condition?

  • The functions that trigger a console warning are the player highlighting function, computer highlighting function, and building a direction list.

    One thing about all three functions - they are recursive and call themselves until 'stop conditions' are met. However, they appear to be working perfectly, even if Chrome gives me a warning.

    As to the actual issue of the local static text 'dirs' always equaling "", I think I'm going to just make it global and see if the scope change solves the issue.

  • Here is a quick debug 101 for problems like this, or how I would approach finding out what is wrong.

    First, add log messages. This way you can easily see what is happening during runtime (the debugger has tool that can do similar stuff, but I am a bit old school). These log messages are displayed in browsers log and tell you what exactly is going on in your variables.

    <img src="https://dl.dropboxusercontent.com/u/19921470/debug2.PNG" border="0" />

    I assume you mean debugger breakpoints? I have no idea how to set those, as I assumed they would be under the System object but couldn't find any breakpoint events :(

    Here is the output:

    <img src="https://dl.dropboxusercontent.com/u/19921470/debug.PNG" border="0" />

    This suggests your problem is related to the second comparison in the event.

    Another thing: It seems you use separate functions (copy pasted?) for AI and player movement. It's generally bad practice to copy paste same code to two places, and you should look for a way to use same functions for AI and player programs if they do the same thing.

    Yes, I use separate functions for AI and player movement. The main reasoning is that the player movement function checks for different things than the computer movement one. The computer movement function also has more parameters due to the AI needing more instructions for movement and targeting, etc.

    UPDATE: No idea why there is an error with the function call. Both functions appear to be working perfectly for highlighting movement.

    And also; commenting your events is very, very useful when you come back to your project after two week vacation or show it off to people in the forums :P. I generally write short comment above every function about what it should do, what do the input variables mean and describe any return variables. At least for me this is a must, that way I don't have to spend anytime wondering what these events do :)

    Almost everything in the project is commented. Some of the newer stuff that I'm trying to debug isn't, but I usually add comments once things are fixed up.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I've done some more testing with the debugger. The problem isn't the backtracking - that part should be working. However, for some odd reason my string isn't being updated properly.

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

    My dirs variable is a local static text.

    The PathToDestination function is only called once due to a 'trigger once' clause. Any idea why my string is always empty?

    BoardGame.capx

  • Excal: I am learning via your learning :) You made your learning a community project - very cool. Tons of inputs from various minds. A peek over my should type deal.

    I think sharing of code is why the open source movement is so strong in the first place. It's a great way to learn. A lot of questions people ask in this forum are already implemented in various projects already, but most people aren't willing to share their .capx for numerous reasons that I understand.

    For those curious, this is my open source project. I'm glad it has helped you, DUTOIT, and I hope it can help others!

  • Now I feel guilty.

    But as others have pointed out, the problem is twofold: newbies don't want to take the time to learn, and those who do help tend to solve the problem and not explain how it was solved.

    If you explain how something is solved to me, I might have follow-up questions that expand on the method you used and how it might apply to other situations. This helps me understand your solution and be able to apply it to more than one project.

    Another issue is that there's no obvious learning path. If there was a stickied post titled "Learn to use C2" with links to tutorials to follow in order, then that might really help. Reading the manual is not going to teach us how to use C2. It's a great reference, but it does not actually give us steps to follow.

  • My issue lies in the backtracking, as I'm not sure what exactly the round(cos(90)) stuff is doing. Could you elaborate a bit more on that part?

    R0J0hound

  • R0J0hound

    Thanks for the more detailed explanation.

    I've gotten the direction and distance working, but it's building the backwards list that isn't working for me.

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

    My dirs = "" at all times, and I'm not sure why.

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

    Added two new fields for the highlight function. Each highlighted square now shows how far away it is from the current active object, as well as which direction:

    1 = left, 2 = right, 3 = up, 4 = down

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

    In the above picture, the computer AI selects an object based on highest range, determines the closest player object to it, and sets it as the target. Then it highlights all available moves the program can move:

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

    However, what it needs to do next is construct a direction list so it knows how to move from its current square to the square closest to the target.

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

    I call the PathToDestination function earlier (scroll up).

    However, my "dirs" variable always equals "" and I'm not sure why. Can someone take a look?

    vee41 maybe? I know, I ask you too much :(

    R0J0hound, my events are based on your example, except instead of creating the squares on the board and then moving, I highlight the squares, then assign distance and direction variables only to the highlighted squares.

    BoardGame.capx

  • I'll try to figure out what is going on, but an explanation of implementation from someone who has implemented direction backtracking would be nice.