Need thoughts on AI

Solu9

You can change this now in User CP.
Reaction score
216
So I'm trying to figure out the best way to code an AI for a racing map.
So far I have thought of a couple of possible ways.

I should mention that the racers have no default movement, so all movement is triggered. That includes acceleration, current/max speed, breaking and turning.

My main headache is how I should trigger the AI controlled racers. They need to be able to detect turn and kinda foresee how much turning is needed for that specific turn.
I also need to code how much the AI has to slow down and if breaking is needed.

Option 1.
I create a lot of regions and use them as pointers. When an AI controlled racer enters a region a new course is set to the next region. This could involve "set TempPoint = random point in NextRegion".
This will also create some diversity in the paths the AI will take.

Option 2.
Constantly set a point in front of the AI racer proportional to that racer's current speed. Then check if that point is a part of the racetrack or not.
If not, a new point is set with a different angle. This is repeated until the point is on the racetrack. I then calculate the distance to that point and make the AI racer stop acceleration or activate breaking and calculate a new course.

I believe the second option is far more difficult to pull of.
I would like to hear what you think. And if you have a better way of coding the AI.

Note:
The attachment is mainly for the first option. Instead of three regions I would probably use on large region.

Edit:
Typos.
 

Attachments

  • AI-01.jpg
    AI-01.jpg
    714.4 KB · Views: 339

thorhunter

You can change this now in User CP.
Reaction score
32
Good AI is extremely complex issue and should be by no means implemented on such low level of coding as you suggest.

The main purpose of an AI is to imitate human behavior, so an AI should be based on sets of principles similar to those of a player, such as controls.

If you can describe better how your game works from player perspective, I can help you design the AI.
 

Solu9

You can change this now in User CP.
Reaction score
216
Good AI is extremely complex issue and should be by no means implemented on such low level of coding as you suggest.

Aye. Indeed.
But I need to start somewhere right? :) This will be the first time I'll try my hands at some more in-depth AI. I'll post some triggers regarding how I handle the player controls.

I use the arrow keys to determine actions.

Acceleration in this case. Similar are used for tuning left/right and breaking.
Trigger:
  • Acceleration Press
    • Events
      • Player - Player 1 (Red) Presses the Up Arrow key
    • Conditions
    • Actions
      • Set booAccelerating = True

Trigger:
  • Acceleration Release
    • Events
      • Player - Player 1 (Red) Releases the Up Arrow key
    • Conditions
    • Actions
      • Set booAccelerating = False


This is the main trigger to determine the cause of action.
It's still in the construction phase, so I excuse the confusing setup.
The pick all units in unit group in the top is irrelevant at the moment since there is only the player controlled racer.
Eventually this trigger would be used only for the AI. But to give you some indication on how I have coded the controls so far.
Trigger:
  • Untitled Trigger 002
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in ugVroomers and do (Actions)
        • Loop - Actions
          • Camera - Set Player 1 (Red)'s camera Rotation to rVroomer_Angle over 0.00 seconds
          • Set pVroomer_Current = (Position of (Picked unit))
          • Custom script: set udg_rHeightOffset = GetLocationZ (udg_pVroomer_Current)
          • Camera - Set (Owner of (Picked unit))'s camera Distance to target to (rHeightOffset + 1200.00) over 0.00 seconds
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • booTurningLeft Equal to True
            • Then - Actions
              • Set rVroomer_Angle = (rVroomer_Angle + 3.00)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • rVroomer_Angle Greater than 360.00
                • Then - Actions
                  • Set rVroomer_Angle = (rVroomer_Angle - 360.00)
                • Else - Actions
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • booTurningRight Equal to True
            • Then - Actions
              • Set rVroomer_Angle = (rVroomer_Angle - 3.00)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • rVroomer_Angle Less than 0.00
                • Then - Actions
                  • Set rVroomer_Angle = (rVroomer_Angle + 360.00)
                • Else - Actions
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • booAccelerating Equal to True
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • rVelocity_Current Less than rVelocity_Max
                • Then - Actions
                  • Set rVelocity_Current = (rVelocity_Current + rAcceleration)
                  • Set pVroomer_Offset = (pVroomer_Current offset by rVelocity_Current towards rVroomer_Angle degrees)
                  • Unit - Move (Picked unit) instantly to pVroomer_Offset, facing rVroomer_Angle degrees
                • Else - Actions
                  • Set rVelocity_Current = rVelocity_Max
                  • Set pVroomer_Offset = (pVroomer_Current offset by rVelocity_Max towards rVroomer_Angle degrees)
                  • Unit - Move (Picked unit) instantly to pVroomer_Offset, facing rVroomer_Angle degrees
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • rVelocity_Current Less than or equal to 0.00
                • Then - Actions
                  • Set rVelocity_Current = 0.00
                • Else - Actions
                  • Set rVelocity_Current = (rVelocity_Current - 1.00)
                  • Set pVroomer_Offset = (pVroomer_Current offset by rVelocity_Current towards rVroomer_Angle degrees)
                  • Unit - Move (Picked unit) instantly to pVroomer_Offset, facing rVroomer_Angle degrees
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • booBreaking Equal to True
                • Then - Actions
                  • Set pVroomer_Current = (Position of (Picked unit))
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • rVelocity_Current Greater than 0.00
                    • Then - Actions
                      • Set rVelocity_Current = (rVelocity_Current - rBreak)
                      • Set pVroomer_Offset = (pVroomer_Current offset by rVelocity_Current towards rVroomer_Angle degrees)
                      • Unit - Move (Picked unit) instantly to pVroomer_Offset, facing rVroomer_Angle degrees
                    • Else - Actions
                      • Set rVelocity_Current = 0.00
                • Else - Actions
          • Custom script: call RemoveLocation (udg_pVroomer_Current)
          • Custom script: call RemoveLocation (udg_pVroomer_Offset)
      • Cinematic - Clear the screen of text messages for (All players)
      • Game - Display to (All players) the text: ((String(rVelocity_Current)) + ( / + (String(rVelocity_Max))))
 

Accname

2D-Graphics enthusiast
Reaction score
1,463
I would go with a list of points from the beginning to the end of the track. The AI tries to move from one point to the next in the correct order. There could be a small error margin build in to better imitate human behavior.

In pseudo-code it might look like this:

Code:
set GoalReached = false
set TargetPoint = first point in list
while ( not GoalReached )
    if (distance to TargetPoint) < CHECK_DISTANCE
        if ( point list has no more points left)
            GoalReached = true
        else
            set TargetPoint = next point in list
            TargetPoint.x += random (ERROR_MARGIN)
            TargetPoint.y += random (ERROR_MARGIN)
        end
    end
    if ( not GoalReached )
        move towards TargetPoint
    end
end
 

Solu9

You can change this now in User CP.
Reaction score
216
Sorry for double posting but I'm fed up with the code being messed up when editing.

I just wanted to post the reals set up so you have those data as well.
Trigger:
  • Set up Vroomer stats
    • Events
    • Conditions
    • Actions
      • Set rAcceleration = 1.50
      • Set rBreak = 5.00
      • Set rVelocity_Current = 0.00
      • Set rVelocity_Max = 100.00
      • Set rVroomer_Angle = 0.00
 

Solu9

You can change this now in User CP.
Reaction score
216
I would go with a list of points from the beginning to the end of the track. The AI tries to move from one point to the next in the correct order. There could be a small error margin build in to better imitate human behavior.

So kinda option 1?
With the default movement system of Warcraft 3 removed, remember I have to code this movement. The racers will not automatically find a path. So for corners I would have to use a lot of regions.
Or how do you suggest?

Note:
The error margin I cowered by using "random point" in next region the racer would be directed at.
 

Varine

And as the moon rises, we shall prepare for war
Reaction score
808
You could set dummy points around the center of the track instead of using regions and reference them in order.
 

Accname

2D-Graphics enthusiast
Reaction score
1,463
I was rather thinking about points which are placed across the race track. 2 adjacent points need to be connected by a straight line.
I have taken my precious time to construct a crude graphic to illustrate:
Racing Game AI.png


Green = Unpathable terrain
Brown = Race Track
White = Points
Pink = Lines connecting the points (Do not need to be modeled in code)
Yellow = Error Margin for AI
 

Solu9

You can change this now in User CP.
Reaction score
216
Whoo! Visuals! I love it.

Right I can do something like that. That was also kinda what I had in mind.
Now. The AI racers also accelerate and thus needs to break or stop accelerating when nearing a corner. So I need to detect how far away a corner is, and calculate if deceleration or breaking is needed.
 

Accname

2D-Graphics enthusiast
Reaction score
1,463
You can define a behavior per point. For example, on some points they are supposed to accelerate up to a certain speed, on some others they decelerate.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top