Robocode
The RoboCode schools have a unique opportunity to provide access to your child's e-mail account, which will publish information about test results, topics and class schedule, workout schedule, and account balance. Additionally, you will always be able to come to the auditorium after the lesson and talk with your teacher or administrator. Robocode is a programming game, where the goal is to develop a robot battle tank to battle against other tanks in Java or.NET. The robot battles are running in real-time and on-screen. Robocode Links - ReadMe for Robocode, which gives a good overview of Robocode - News for Robocode.
In this lesson, we describe the basics of how the scanning works.
Your Lab 3 exercise correpsonds to thisrobocode lesson.
Robot Senses
We'll begin this lesson by discussing your robot's senses. It has only afew.
Sense of Touch
Your robot knows when it's:
- hit a wall (onHitWall),
- been hit by a bullet (onHitByBullet),
- or hit another robot (onHitRobot).
All of these methods pass you events that give you information about whatyou touched.
Sense of Sight
Your robot knows when it's seen another robot, but only if it scans it (onScannedRobot).
Scan events are arguably the most important of all events. Scan eventsgive you information about the other robots on the battlefield. (Some robotsput 90+% of their code in the onScannedRobot method.) The only wayscan events can be generated (practically speaking) is if you move your radar.(If an enemy robot wanders in front of your radar it will generate a scanevent, but you should really take a more proactive stance.)
Also, remember per Lesson 2, the scanner isthe fastest moving part of your robot, so don't be stingy about moving it.
Echo chromecast. Featuring an elegant black and white art design inspired by the works of M.C. Escher, echochrome™ is a puzzle game unlike any other. With gameplay based on optical illusions, players must utilize five simple laws of perspective to join walkways, hide dangers, and create new paths to reach the “echos,” or shadow guides. Echo is an application in which you can listen to how your post sounds like BEFORE the wrath of the world ensues on your post.Results may vary Steps: 1. Before you post anything on any website, in terms of communicating with other folks on the web, copy your post. Click on the Echo extension icon on the upper right corner of your browser. Echochrome was also a playable arcade mini-game in the Bowling Alley/Game Space of PlayStation Home. In 2011, Echochrome was released on Blu-ray as a part of the compilation Move Mind Benders with PlayStation Move support along with Lemmings and Tumble.
If you want to, you can make the robots' scan arcs visible by selectingOptions Menu -> Preferences -> View Options Tab and click on the'Visible Scan Arcs' checkbox. This is handy when debugging.
Other Senses
Your robot also knows when he's died (onDeath), when another robot has died (onRobotDeath -- we will use this one today), or when he's won the round (onWin -- this is where you write the code for your victory dance).
Your robot also is aware of his bullets and knows when a bullet has hit an opponent (onBulletHit), when a bullet hits a wall (onBulletMissed), when a bullet hits another bullet (onBulletHitBullet).
Building A Better Robot
Here's some basic scanning movement. Note again that we call setAdjustRadarForRobotTurn(true) so as to have independent radar movement.
Serial Movements with The Robot Class
You want to find other robots to kill. To do that, you need to scan forother robots. The simplest approach to scanning is to just turn the radararound and around. Your run method could look something like this:
Indeed, our beloved BearingBotfrom last week did exactly that: he rotates his radar and moves closer towhoever he scans.
You may have noticed that BearingBot has a large defect that you can seeif you match him up against an opponent that moves a lot (like, say, Crazy).He scans an opponent, then moves to where he saw him, and by the time he getsthere, the opponent has moved away.
Compound Movements with the AdvancedRobot Class
It would be great if we could do more than one thing at once (scan ANDturn AND fire). Thankfully, the powers that be have provided us with a meansto accomplish this: The AdvancedRobotbase class, which allows us to make non-blocking calls to move the robot andthen executes them all as a compound action. Crazy and SpinBot (and oddlyenough SittingDuck) are all examples of advanced robots.
To change your robot to an advanced robot, just change your classdeclaration from:toNow you're inheriting from AdvancedRobot rather than Robot;now you can use the set* methods provided by the AdvancedRobot class.(We will discuss more about inheritance when we cover chapter 5.)
Sample robot:AdvancedBearingBot a great improvement over 'BearingBot', because hecan do compound movements.
Sample robot:AdvancedTracker - This is a modification of the 'Tracker' sample robot.Per the source code for Tracker, notice how much he improves when you turn himinto an AdvancedRobot.
Important Note: If you make a robot derived from AdvancedRobot, youmust call the execute() method to perform all the queued-up actions.
But AdvancedBearingBot has another large defect which you can see if youmatch him up against more than one opponent: he goes driving all over thebattlefield chasing one robot after another and doesn't get a lotaccomplished. This is because his radar keeps scanning robots, and he chasesevery one he scans. In short, he lacks focus.
Locking Onto an Enemy
Narrow Beam
We can easily lock onto our opponent by constantly turning the radartoward him whenever we scan him. Intuatively, you might think of doingsomething with the scanned robot's bearing like so:
There's a problem with this, though: the ScannedRobotEvent gives us abearing to the scanned robot but it is relative to our tank's position,not our radar's position. How do we resolve this little quandry?
Easy: we find the difference between our tank heading (getHeading())and our radar heading (getRadarHeading())and add the bearing to the scanned robot (e.getBearing()),like so:
Sample robot:NarrowBeam - Uses the above source to lock onto an opponent and nail him.Match him up against as many opponents as you want.
A recurring theme in the computer industry is that the solution to oneproblem leads to the creation of another. Fittingly, having solved the problemof how to lock onto a target, we are now faced with another problem, which thefollowing screenshot illustrates:
Note that NarrowBeam has locked on so tightly to Crazy that he is blithelyunaware that Tracker is killing him from behind.
Oscillating (or 'Wobbling') the Radar
In this technique, every time you see an opponent, you whipsaw the radarback so as to focus on one robot and continuously generate scan events. Thisis an improvement over the narrow beam because you are more aware of nearbyrobots.
To make this work, you need a variable that keeps track of which directionto turn the radar, it will only ever have values of 1 and -1, so it can besmall. You can declare it in your robot like so:The run method can look just like the one above, but in theonScannedRobot method you do the following:Flipping the value of scanDirection creates the oscillating effect.
Sample robot: Oscillator -wobbles his radar to keep track of hist opponent. Note that while he tends totrack an enemy, he'll chase others that are nearby, too.
But we still haven't completely solved the problem with NarrowBeam: otherrobots can still sneak up behind Oscillator and shoot him. Also, Oscillatortends to get a little unfocused, at times.
Enemy Tracking
Using the EnemyBot Class
A further improvement that could be made would be to single out anindividual robot, focus on him, and destroy him completely. The sample robotTracker does this to a limited extent, but we'll do one better with the EnemyBot class you guys all wrote.
To keep track of the information about an enemy robot, you first need tomake a member variable in your robot like so:You will want to reset (clear) your enemy at the top of your runmethod like so:And you need to update the enemy's information in the onScannedRobot methodlike so:From this point, you can use all of the information about the enemy in anyother method of your class.
There is one last detail, though, if the enemy you're tracking dies,you'll want to reset it so you can track another. To do that, implement anonRobotDeath method like so:
Sample robot:EnemyTracker - a robot that uses the EnemyBot class. Note that even thoughhe rotates the radar, he just tracks one enemy. This allows him to keep an eyeon what's going on in the rest of the battlefield while concentrating on histarget.
Slightly Smarter Tracking
Another small optimization could be made here: If a closer robot movesinto view, we probably want to start shooting him instead. You can accomplishthis by modifying your onScannedRobot method like so:
Sample robot:EnemyOrCloser uses the above scanning technique to hit the closest enemy.As he rotates his radar, he will begin tracking any enemy that is closer (evenif someone sneaks up behind him).