Author Topic: Robot Rumble 2.0 AI Thread  (Read 4502 times)

Offline WhamettNuht

  • *
  • Posts: 1302
  • Rep: 12
  • Robot Building Drag Queen
    • View Profile
    • Awards
  • Discord: WhamettNuht #1457
Robot Rumble 2.0 AI Thread
« on: July 29, 2019, 04:22:52 PM »
Hi all! I'm really into this game at the moment, even more so with the incorporation of flippers! (One of my favourite weapon types IRL haha)
I couldn't really see any topics started for this yet, but figured it couldn't hurt to start off a thread for the different AI possibilities in the game (as a potential way of helping to develop the game further through community input? Idk lol it's a good idea in my head).

I've started having a look into the MiniScript coding language, however in case there's someone who has a couple good bits figured out, it could be a great way to start off a chain of community AI codes!

To start things off, here is the basic code currently available to us:

Code: [Select]
// Welcome to Robot AI Programming 101!
// This code is written in a language called MiniScript,
// which is designed to be simple and easy to learn.
// For more details, go to: http://miniscript.org
//
// <--- This is a comment (2 forward slashes). It is completely ignored by the compiler.


//// Outputs:
// drive - the forward/backward drive signal
// turn - the left/right turning signal
// lever1, lever2 - controller analog sticks #1 and #2
// button1, button2, button3, and button4 - controller buttons


//// Inputs:
// See complete list of AI input variables shown to the left.


//// FUNCTIONS AND THEIR VARIABLES
// In this block, we are declaring all of the functions and any of the variables they might need.
// An example function declaration:
// add = function(x,y)
//       return x+y
// end function


//// BUILT-IN FUNCTIONS


// getWaypoints(p1)
//
// getWaypoints is a built-in function that computes the navmesh waypoints to travel
// to a point in the arena.
// It takes one arguments:
// p1 = position to travel to (a map of x, y, z values)
// getWaypoints returns a list of position maps of the form [{x0,y0,z0},{x1,y1,z1},{x2,y2,z2}]
// Example usage: nextWaypoint = getWaypoints(enemy.position)[0]


// getClosestPointOnHazard(p1)
//
// getClosestPointOnHazard is a built-in function that finds the closest point on the
// surface of an arena hazard.
// It takes 1 argument:
// p1 = position #1 (a map of x, y, z values)
// getWaypoints returns a position map of the form {x0,y0,z0
// Example usage: hazardPoint = getClosestPointOnHazard(myRobot.position)


// driveToward(p1)
//
// driveToward is a built-in function that computes the drive (forward/backward) signal
// required to drive toward a point.
// It takes 1 argument:
// p1 = position #1 (a map of x, y, z values)
// driveToward returns a number: +1 = forward, 0 = stop, -1 = backward
// Example usage: drive = driveToward(nextWaypoint)


// turnToward(p1)
//
// turnToward is a built-in function that computes the turn (left/right) signal
// required to drive toward a point.
// It takes 1 argument:
// p1 = position #1 (a map of x, y, z values)
// turnToward returns a number: +1 = right, 0 = stop turning, -1 = left
// Example usage: turn = turnToward(nextWaypoint)



//// USER-CREATED FUNCTIONS

// isVector is a fuction that tests if the given map has x, y, and z components.
// It takes 1 arguments:
// v = some variable
// example usage: if isVector(myVariable) == true then
isVector = function(v); vx = v.hasIndex("x"); vy = v.hasIndex("y"); vz = v.hasIndex("z"); if vx*vy*vz == 1 then; return true; else; return false; end if;end function
   
// getDistance is a function that computes the distance betwen two points in meters.
// It takes 2 arguments:
// v1 = position #1 (a map of x, y, z values)
// v2 = position #2 (a map of x, y, z values)
// example usage: distance = getDistance(p1,p2)
getDistance = function(v1,v2); return sqrt((v2.x-v1.x)*(v2.x-v1.x) + (v2.y-v1.y)*(v2.y-v1.y) + (v2.z-v1.z)*(v2.z-v1.z)); end function
       
// getMyRobot is a function that returns a map of our robot.  Sometimes our robot is not robots[0].
// It takes no arguments.
// example usage: myRobot = getMyRobot()
getMyRobot = function(); for robot in robots; if robot.tag == myTag then; return robot; end if; end for; end function
           
// getNearestEnemy is a function that returns a map of the closest robot to us that is not us.
// It takes no arguments.
// example usage: enemy = getNearestEnemy()
getNearestEnemy = function(); pos = getMyRobot().position;nearestEnemyDistance = 1000000;nearestEnemy = {};for robot in robots;if robot.tag != myTag then;testDistance = getDistance(pos,robot.position);if testDistance < nearestEnemyDistance then;nearestEnemyDistance = testDistance;nearestEnemy = robot;end if;end if;end for;return nearestEnemy;end function
               
               
//// MAIN EVENT LOOP
///This is our main event loop.  It runs continuously.
// In order to  keep running, it needs the following:
// An opening statement: while 1
// A bunch of events to execute
// A brief wait statement: wait(0.01)
// A closing statement: end while
               
while 1

    // Get a reference to self and nearest enemy.
    e = getNearestEnemy()
    me = getMyRobot()
   
    // Always try to attack.
    drive = driveToward(e.position)
    turn = turnToward(e.position)
   
    distance = getDistance(me.position,e.position)
    if(distance < 2) then
        button1 = true
    else if distance >= 2 then
        button1 = false
    end if
    aistate = "attacking"
                   
    // If inverted, try to self-right.
    // Do this by driving backward and turning button1 on.
    // Depending on the location of the self righting mechanism,
    // this might need to be assigned to a different button.
    if me.upValue < 0 then
        if floor(time)%4 < 2 then
            drive = -1
            button1 = true
        else
            drive = 1
            buttonn1 = false
        end if
        aistate = "self-righting"
    end if
   
    // If immobile, try to get unstuck.
    // Do this by driving forward, then backward, toggling button1 on and off
    // every 2 seconds.
    if me.isImmobile() then
        if floor(me.immobileTimerRemaining)%4 < 2 then
            drive = -1
            button1 = false
        else
            drive = 1
            button1 = true 
        end if
        aistate = "trying to get unstuck"
    end if
   

    yield
end while
               

The kinda stuff I'm already stumped with is how to define the smart zones, how to link them to certain motors & pnumatics, ect.
I figured once that is underway the game's AI will really be able to take shape amongst all of us!

Feel free to add and discuss as you want to below! :)
Damn I should probably put something fancy in this bit huh?

Offline Gulden

  • Am I still considered active?
  • Posts: 1330
  • Rep: 7
  • Currently trying to make a Riff in Time and Space.
    • https://www.youtube.com/c
  • Awards Donated money for site hosting 2019 BOTM Winner
    • View Profile
    • Awards
  • Discord: Gulden#1901
Re: Robot Rumble 2.0 AI Thread
« Reply #1 on: July 29, 2019, 05:41:27 PM »

Code: [Select]
while 1

    // Get a reference to self and nearest enemy.
    e = getNearestEnemy()
    me = getMyRobot()
   
    // Always try to attack.
    drive = driveToward(e.position)
    turn = turnToward(e.position)
   
    distance = getDistance(me.position,e.position)
    if(distance < 2) then
        button1 = true
    else if distance >= 2 then
        button1 = false
    end if
    aistate = "attacking"               

Easiest way to AI flippers and hammers currently (as far as I know) is replacing the "2"s in this section with a number between 0.5 and 1.  The smaller the number, the closer they need to be to fire the weapon.

However, note that if you ever edit the AI, it will be unable to distinguish dead robots from live ones.
I have several opinions.

Offline CodeSilver23

  • RR2 Enthusiast and Design Innovator
  • Heavyweight
  • Posts: 561
  • Rep: -2
  • Stars v Legends founder, Inventor of the Wheel-fix
    • https://www.youtube.com/c
    • View Profile
    • Youtube Channel
    • Awards
  • See profile for gamer tags: Yes
  • Discord: CodeSilverGaming
Re: Robot Rumble 2.0 AI Thread
« Reply #2 on: July 29, 2019, 08:03:10 PM »
I would like to add that 0.4 is good for rear hinged flippers, 0.2 for front hinged flippers, and 0.6-0.7 for hammers.
Accomplishments:

Offline WhamettNuht

  • *
  • Posts: 1302
  • Rep: 12
  • Robot Building Drag Queen
    • View Profile
    • Awards
  • Discord: WhamettNuht #1457
Re: Robot Rumble 2.0 AI Thread
« Reply #3 on: July 30, 2019, 04:07:11 AM »
Thanks for the good bits of knowledge there, guys!

The 0.# codes are indeed a good temporary method of controlling the flippers. Would anyone happen to know which value controls what happens when the robots 'activate' as they still seem to have something in them which says 'Active = fire 'button 1' meaning my bots end up on their butts before they've even fought anyone lol.

Thanks!~

EDIT: After looking through the code briefly, I think the reason the robots are firing 'button 1' has to do with immobility settings. I've noticed when 'activate' is actioned, the game has already started an immobility countdown on the bots. This in turn must cause the robots to go 'Oh look, I'm inverted/stuck, let me fire button 1 until the countdown goes away'. I'm still trying to figure out which setting would tell the AI not to fire it's weapon upon instant countdown (maybe like a second or 2 would be acceptable and still make the robot able to self right should it actually get stuck). I'll have more of a play around later.
« Last Edit: July 30, 2019, 06:19:10 AM by WhamettNuht »
Damn I should probably put something fancy in this bit huh?

Offline kix

  • RR2 dev
  • *
  • Posts: 3452
  • Rep: -3
  • H
    • View Profile
    • Awards
Re: Robot Rumble 2.0 AI Thread
« Reply #4 on: July 30, 2019, 06:13:43 AM »
Thanks for the good bits of knowledge there, guys!

The 0.# codes are indeed a good temporary method of controlling the flippers. Would anyone happen to know which value controls what happens when the robots 'activate' as they still seem to have something in them which says 'Active = fire 'button 1' meaning my bots end up on their butts before they've even fought anyone lol.

Thanks!~
Temporary tactic is to use the reverse button mode on the bot so that in the fight, they start in fired mode

Offline cjbruce

  • Super Heavyweight
  • Posts: 963
  • Rep: 11
    • View Profile
    • Awards
Re: Robot Rumble 2.0 AI Thread
« Reply #5 on: August 03, 2019, 04:01:44 PM »
So sorry to be so late to the thread!

Smartzones aren't hooked up yet, so all the AI is good for at the moment is driving toward the nearest enemy.

Once the new damage system is tweaked appropriately, I am planning to refocus my attention on AI.  I figured there wasn't really a point to developing an AI system when we don't yet know what "damage" means.

Also, right now miniscript is generating huge amounts of garbage, and is consuming way more CPU time than it should.  My MacBook Pro drops a lot of frames with 4 AI robots running.  I have been working directly with Joe Strout, the creator of the miniscript language.  It looks like the problems are with the game, and not the language itself, so I'm confident that we can get things running smoothly once we have time to focus on it.

Offline WhamettNuht

  • *
  • Posts: 1302
  • Rep: 12
  • Robot Building Drag Queen
    • View Profile
    • Awards
  • Discord: WhamettNuht #1457
Re: Robot Rumble 2.0 AI Thread
« Reply #6 on: August 04, 2019, 04:58:27 PM »
So sorry to be so late to the thread!

Smartzones aren't hooked up yet, so all the AI is good for at the moment is driving toward the nearest enemy.

Once the new damage system is tweaked appropriately, I am planning to refocus my attention on AI.  I figured there wasn't really a point to developing an AI system when we don't yet know what "damage" means.

Also, right now miniscript is generating huge amounts of garbage, and is consuming way more CPU time than it should.  My MacBook Pro drops a lot of frames with 4 AI robots running.  I have been working directly with Joe Strout, the creator of the miniscript language.  It looks like the problems are with the game, and not the language itself, so I'm confident that we can get things running smoothly once we have time to focus on it.

No problem at all! I can imagine you have plenty to do on the game aswell as in your own life haha!

That's a fair order of work. I'd imagine getting the damage system right will take a hella lot of trial and error.

I must admit I haven't had many problems when it comes to processing CPU, ect, but I am running a (somewhat old) custom gaming laptop aha. It's cool that you're liasing with the guy who wrote the language you're using though! Can't be anything better than working with the source haha!
Damn I should probably put something fancy in this bit huh?

Offline KupaTec

  • Antweight
  • Posts: 63
  • Rep: 6
    • View Profile
    • Awards
Re: Robot Rumble 2.0 AI Thread
« Reply #7 on: December 04, 2019, 05:33:10 AM »

Don't let the name fool you, this complete AI for Limited Spin Motor powered weapons is great for Hammers, Flippers, Lifters, and even Overheads with a little extra tuning!

Grab the latest version [HERE] (V1.1)


PLEASE MAKE SURE TO BACKUP YOUR BOT BEFORE EDITING/ADDING AI

If you have any feedback, suggestions, or questions I'm more active on the RA2 Central Discord than I am here (though who isn't at this point) so drop me a message or whatever on there!

« Last Edit: December 07, 2019, 04:30:42 PM by KupaTec »

Offline WhamettNuht

  • *
  • Posts: 1302
  • Rep: 12
  • Robot Building Drag Queen
    • View Profile
    • Awards
  • Discord: WhamettNuht #1457
Re: Robot Rumble 2.0 AI Thread
« Reply #8 on: December 04, 2019, 06:26:08 AM »
Oh my god that looks amazing!! Cannot wait to try it out when I'm back on my laptop! Cheers man!
Damn I should probably put something fancy in this bit huh?

Offline KupaTec

  • Antweight
  • Posts: 63
  • Rep: 6
    • View Profile
    • Awards
Re: Robot Rumble 2.0 AI Thread
« Reply #9 on: December 06, 2019, 01:13:10 PM »
Updated HAMMER AI to V1.1, changelog in AI

Offline Hobo Droo

  • Official Veteran
  • *
  • Posts: 43
  • Rep: 7
  • Former Cheater
    • View Profile
    • Awards
Re: Robot Rumble 2.0 AI Thread
« Reply #10 on: December 07, 2019, 12:24:46 AM »
I have also made a flipper AI. However, this one works for burst motors instead of spinner motors.
Made before hammer AI 1.1 but inspired by 1.0
Huge thanks to KupaTec for teaching me everything I know about RR2 AI.

https://pastebin.com/J3SP1T5h
kevin the cube is gone in fortnite

Offline WhamettNuht

  • *
  • Posts: 1302
  • Rep: 12
  • Robot Building Drag Queen
    • View Profile
    • Awards
  • Discord: WhamettNuht #1457
Re: Robot Rumble 2.0 AI Thread
« Reply #11 on: December 07, 2019, 04:05:47 AM »
Jesus you two - that is amazing!! Thank you so much!!

Has anyone worked out/remember how to edit the AI string in the .rr2bot file? I have so many AI's to update now but I would prefer to do it via Notepad++ lol.
Damn I should probably put something fancy in this bit huh?

Offline powerrave

  • Giga Heavyweight
  • Posts: 5372
  • Rep: 2
    • View Profile
    • Awards
  • See profile for gamer tags: Yes
Re: Robot Rumble 2.0 AI Thread
« Reply #12 on: December 07, 2019, 04:59:45 AM »
I don't want to be the bane of people's happiness here but I've tried the Hammer AI 1.1 and the results are far less than desirable. Having build a hammer bot and having spent about 4 hours to make it look pretty, today I decided to cope/paste the hammer AI into the game's AI editor to see if it'll work for my bot. The moment I pressed the Save AI button, my entire PC crashed. Seriously, this happened. I wish I were joking.

After booting back up and looking in game, the whole bot is now an error and can't be accessed. The file is still around so I guess I'll attach it to this comment. Perhaps someone here can somehow restore it or can at least get some useful info from digging through this wreck.
(I sure hope this file is the right one. It's the highest number file name and was my latest creation.)
"Always be yourself, unless you're a loser"


Offline kix

  • RR2 dev
  • *
  • Posts: 3452
  • Rep: -3
  • H
    • View Profile
    • Awards
Re: Robot Rumble 2.0 AI Thread
« Reply #13 on: December 07, 2019, 06:58:58 AM »
I don't want to be the bane of people's happiness here but I've tried the Hammer AI 1.1 and the results are far less than desirable. Having build a hammer bot and having spent about 4 hours to make it look pretty, today I decided to cope/paste the hammer AI into the game's AI editor to see if it'll work for my bot. The moment I pressed the Save AI button, my entire PC crashed. Seriously, this happened. I wish I were joking.

After booting back up and looking in game, the whole bot is now an error and can't be accessed. The file is still around so I guess I'll attach it to this comment. Perhaps someone here can somehow restore it or can at least get some useful info from digging through this wreck.
(I sure hope this file is the right one. It's the highest number file name and was my latest creation.)
Sorry the bot file is just a line of NUL's, its fubar.

Offline powerrave

  • Giga Heavyweight
  • Posts: 5372
  • Rep: 2
    • View Profile
    • Awards
  • See profile for gamer tags: Yes
Re: Robot Rumble 2.0 AI Thread
« Reply #14 on: December 07, 2019, 07:33:49 AM »
Well... That sucks big time.
"Always be yourself, unless you're a loser"


Offline KupaTec

  • Antweight
  • Posts: 63
  • Rep: 6
    • View Profile
    • Awards
Re: Robot Rumble 2.0 AI Thread
« Reply #15 on: December 07, 2019, 04:28:05 PM »
Jesus you two - that is amazing!! Thank you so much!!

Has anyone worked out/remember how to edit the AI string in the .rr2bot file? I have so many AI's to update now but I would prefer to do it via Notepad++ lol.
I haven't messed around with the .rr2bot file but you can copy paste from and to the AI window in the Test Lab. That's how made and tweak my AI's at least.

The moment I pressed the Save AI button, my entire PC crashed. Seriously, this happened. I wish I were joking.

After booting back up and looking in game, the whole bot is now an error and can't be accessed.
Holy crap, I am so sorry! I've tested the AI thoroughly (or at least thought I had) and hadn't run into any issues yet so I thought we were all good. This is a terrible development and, again, I am sorry that happened.

Offline powerrave

  • Giga Heavyweight
  • Posts: 5372
  • Rep: 2
    • View Profile
    • Awards
  • See profile for gamer tags: Yes
Re: Robot Rumble 2.0 AI Thread
« Reply #16 on: December 07, 2019, 04:53:36 PM »
Reading back in the AI txt, I believe I had not changed my motor key inputs to what the txt tells to use. While that is an incorrect way to do things, I don't think it should be causing a system crash upon saving AI. Was this tested by you or others? Asking just to make sure. I don't think there was more in play at the time though.
"Always be yourself, unless you're a loser"


Offline KupaTec

  • Antweight
  • Posts: 63
  • Rep: 6
    • View Profile
    • Awards
Re: Robot Rumble 2.0 AI Thread
« Reply #17 on: December 07, 2019, 05:45:30 PM »
Reading back in the AI txt, I believe I had not changed my motor key inputs to what the txt tells to use. While that is an incorrect way to do things, I don't think it should be causing a system crash upon saving AI.
Yeah, there shouldn't be a reason as far as I can see for that to cause a failure. In fact while I was testing the new turning/driving logic I didn't have a weapon wired up at all so that shouldn't've been an issue.

Was this tested by you or others? Asking just to make sure. I don't think there was more in play at the time though.
V0.8-1.0 was tested by myself and Robo. V1.1 by myself on two different pcs alongside an irl friend on a third pc. I don't know if anyone has used it in any other builds other than myself and Robo however. Rest assured I'll be trying to get to the bottom of this myself as I would hate to put anyone else through this error.

For now all I can suggest is backing up your bot files before adding/editing AI as the game is in early alpha. I know this comes too late for yourself but should (hopefully) help prevent issues like this in the future.

Offline powerrave

  • Giga Heavyweight
  • Posts: 5372
  • Rep: 2
    • View Profile
    • Awards
  • See profile for gamer tags: Yes
Re: Robot Rumble 2.0 AI Thread
« Reply #18 on: December 07, 2019, 06:14:56 PM »
Just now went to try again either way, despite saying in my own showcase I didn't want to. Seemed to work fine now. May have been a 1 time thing. Still, has to have come from somewhere.
"Always be yourself, unless you're a loser"


Offline KupaTec

  • Antweight
  • Posts: 63
  • Rep: 6
    • View Profile
    • Awards
Re: Robot Rumble 2.0 AI Thread
« Reply #19 on: December 07, 2019, 06:40:54 PM »
Just now went to try again either way, despite saying in my own showcase I didn't want to. Seemed to work fine now. May have been a 1 time thing. Still, has to have come from somewhere.

Oh man I'm glad to see you got it working. Hopefully we will see your beaut in SvL? I'll keep seeing if I can replicate it but it's good to know it may have been a one off thing.