// 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
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"
Thanks for the good bits of knowledge there, guys!Temporary tactic is to use the reverse button mode on the bot so that in the fight, they start in fired mode
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!~
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.
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.Sorry the bot file is just a line of NUL's, its fubar.
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.)
Jesus you two - that is amazing!! Thank you so much!!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.
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.
The moment I pressed the Save AI button, my entire PC crashed. Seriously, this happened. I wish I were joking.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.
After booting back up and looking in game, the whole bot is now an error and can't be accessed.
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.
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.
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.