Robot Rumble 2.0 > Robot Rumble 2.0

Robot Rumble 2.0 AI Thread

(1/5) > >>

WhamettNuht:
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: ---// 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
               
--- End code ---

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! :)

Gulden:


--- Code: ---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"               
--- End code ---

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.

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

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

kix:

--- Quote from: WhamettNuht 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!~

--- End quote ---
Temporary tactic is to use the reverse button mode on the bot so that in the fight, they start in fired mode

Navigation

[0] Message Index

[#] Next page

Go to full version