| Zer |
| Posted: Jun 26 2009, 03:39 PM |
 |
|
New Member

Group: Just Joined
Posts: 1 (0 robots)
Member No.: 1519
Joined: 26-June 09

|
I'm someone who has very little coding experience. I've done some QBasic for one semester in college and to be honest I found the whole course to be boring. The teaching methods used by me teacher were pretty bad, so we ended up just bringing games into the class on old floppy disks, mainly Scorched Earth. I've tinkered with a few bots in the past but never really got around to making one of my own. I have recently planned out and executed a bot that runs almost how I'd like it to. Anyways onto the bot.
It is not fully commented but really it's easy code to understand. I don't use complex math and I used a few messy ways to get things more to what I had in mind for my original bot. Initially I wanted my bot to move around in a rather erratic pattern, but the co-ordinate system I've coded in is only accurate to right angles, I didn't add in any trigonometry to have the bot calculate angular distances from walls. If anything that would be my 2nd priority just after getting a more efficient scanning routine going. As it is now my bot will move, stop and run a 360 degree scan and turn 90 degrees to begin moving again. I've disected a few other bots to get a sort of base going for my own bot. As such I would like to thank the creator of Tutor_Bot, who I based some of my code off of. Mainly I've used and modified some of his event handlers for being detected and detecting mines/cookies.
If anyone could give me any pointers as to how I could get this bot to scan while it is on the move that would be a huge help. Somethings I'd like to tackle on my own are the trigonometric calculations, and having the turret/rader point away from the nearest walls to increase chances of detecting enemies. Of course any comments and criticisms are always welcome.
[spoiler=Click to see code]| RSL | Init
{
name("T-1") version("0.50b") author("Zer") regcore(NetCore) regdtcrobot(FoundTarget,1) regcldcookie(AcquireBattery,9) regcldmine(RecordMine,9) regcldmissile(EvasiveAction,2) regcldrobot(Collision,2) regdtccookie(FoundBattery,3) regdtcmine(DetectMine,4) regping(LocCompromised,2) regdtcwall(MovementRoutines,3) regcldwall(WallCollision,2) regdtcwall(detectwall,5) lockgun(true) gosub(Boot)
}
Boot
{
if(_gamenbr == 1) mines = 0 batteries = 0 ping_count = 0 collisions = 0 r = 0 trk = 0 rt = 0 b = 0 endif }
NetCore
{
scan() if( _bodyaim % 90 != 0 ) bodyleft( _bodyaim % 90 ) endif gosub(Movementroutines) }
DetectWall
{
gosub(FindTargets)
}
WallCollision
{ stop() bodyleft(90) gosub(Movementroutines)
}
FoundTarget
{ if(_dtcteamid == 0 or _dtcteamid ! == _teamid) r = 1 mode = 0 gosub(Terminate) endif }
AcquireBattery
{
batteries = batteries + 1
}
RecordMine
{ mines = mines + 1
}
EvasiveAction
{ ahead(-25)
}
Collision
{
back(25) bodyright(45) collisions = collisions + 1 gosub(FindTargets) }
FoundBattery
{
if(_energy > 200) fire(1) clear(_dtccookie) else() syncall() waitfor(_bodyrmn == 0) ahead(_scandist + 10) waitfor(_movermn == 0) endif }
DetectMine
{
if(_energy < 30) gosub(FindTargets) else() if(_scandist < 500) fire(1) endif endif
}
LocCompromised
{ if(_pingfreindly) print("Pinged by SkyNet") else gosub(EvasiveAction) endif
}
Terminate
{
if(_dtcenergy > _energy) stop() if(_scandist > 400 or _energy < 30) fire(1) elseif (_scandist > 400) fire(3) elseif (_scandist > 200) fire(5) else() fire(7) endif gosub(TrackTarget) else() syncall() waitfor(_bodyrmn == 0) ahead(_scandist + 10) waitfor(_movermn == 0) if(_scandist > 400 or _energy < 30) fire(1) elseif (_scandist > 400) fire(3) elseif (_scandist > 200) fire(5) else() fire(7) endif gosub(TrackTarget) endif }
Movementroutines
{ rt = 0 db = _arenawidth - _xpos // establish distance to east wall dd = _arenawidth - db // establish distance to west wall dc = _arenaheight - _ypos // establish distance to north wall da = _arenaheight - dc // establish distance to south wall if(_heading > 315 or _heading < 45) // Determines if the robot is facing North distance = dc // Sets the robot's distance from the North wall elseif(_heading < 135) // Determines if the robot is facing East distance = db // Sets the robot's distance from the East wall elseif(_heading < 225) // Determines if the robot is facing South distance = da // Sets the robot's distance from the South wall elseif(_heading < 315) // Determines if the robot is facing West distance = dd // Sets the robot's distance from the West wall endif if( _bodyaim % 90 != 0 ) // Makes sure the robot is facing a right angle bodyleft( _bodyaim % 90 ) // If not, then turn body left to compensate endif if(distance < 25) // If distance to wall is under 28 units bodyleft(90) // Turn left 90 degrees gosub(FindTargets) // Go to subprogram "FindTargets" ahead(distance - 25) // Ahead 28 units scan() // Redundant scan call else() // Else (If distance to wall is over 25 units ahead(distance - 25) // Distance - 25 units scan() // Redundant scan call endif }
TrackTarget
{
if(r == 1) waitfor(_radarrmn == 0) radarleft(30) scan() r = 0 else() gosub(findtargets) endif
}
FindTargets
{
if(b == 1) radarright(5) scan() b = 1 rt = rt + 5 if(rt == 360) rt = 0 gosub(MovementRoutines) else() gosub(FindTargets) endif else() radarleft(5) scan() b = 0 rt = rt + 5 if(rt == 360) rt = 0 gosub(MovementRoutines) else() gosub(FindTargets) endif endif
} | [/spoiler]
|
| chess123mate |
| Posted: Jul 13 2009, 06:08 AM |
 |
|
Logical Programmer
    
Group: Members
Posts: 575 (24 robots)
Member No.: 936
Joined: 3-February 07

|
I believe that regascan allows your bot to scan while moving, though I haven't done anything with it. Otherwise, use "blocking(off)" and try handling some of your events in the core section, especially the movement of your radar, since the 'core' will be run every turn regardless of what your bot is doing. Unfortunately, using 'blocking(off)' has the side effect of requiring more careful organization, since if you're not careful you'll end up telling your bot to go backwards in one part of your code and forwards in a different one (sometimes this happens in consecutive turns, too, which can be really annoying, as your bot won't get anywhere ).
However, just adding "scan()" to the core and putting "blocking(off)" should work for basic bots. Look in the help section for the variables such as "_movingrmn", which tells you if your bot is moving or not. |
| Droxius |
| Posted: Jul 25 2009, 02:16 PM |
 |
|

New Member

Group: Just Joined
Posts: 2 (0 robots)
Member No.: 1526
Joined: 25-July 09

|
Why exactly do you keep a count of the mines, cookies, collisions, etc?
just curious.
--------------------
| RSL | //Success is the ability to go from one failure to the next //without any loss of enthusiasm
Boom { If ( energy > 0 and _robotsalive > 2) FIRE ( 7 ) Endif } |
|
|