1 / 45

This Week

This Week. Cover as much Robocode strategy as we can Monday: Robocode NN Homework Review Hand in Picbreeder hw if you haven’t Grades: Can’t give you an A if you haven’t at least turned in the assignments

phiala
Download Presentation

This Week

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. This Week • Cover as much Robocode strategy as we can • Monday: Robocode • NN Homework Review • Hand in Picbreeder hw if you haven’t • Grades: Can’t give you an A if you haven’t at least turned in the assignments • Email me if you’d like to double check my records against yours (which assignments you turned in and how many points you received for each)

  2. This Week Continued • Tuesday: Quiz • Explain how a neural network can represent a solution to a particular problem. Explain how you would input data and interpret the output. • Wednesday: Robocode • Thursday: Competition and prizes – My last day (no late robots) • Friday: AI Jeopardy with Dan DeBlasio

  3. Robocode Homework • http://www.cs.ucf.edu/~ahoover/bhcsi2010/

  4. Robocode and Robocode Strategies (taken from citations at the end)

  5. Excellent Sources of Information • My First Robot • http://testwiki.roborumble.org/w/index.php?title=Robocode/My_First_Robot • FAQs • http://testwiki.roborumble.org/w/index.php?title=Robocode/FAQ

  6. From Last Time • Robocode tanks are java programs • We saw this when we added a line of code, compiled, and ran the code • Robocode tanks are event driven • There is a main loop • The main loop can be interrupted by handling different events

  7. From Last Time • The tank default behavior is in a loop defined in run() • Different events interrupt this loop execution

  8. Example • public class MyRobot extends Robot • { • public void run() { • while(true) { • ahead(100); • turnGunRight(360); • back(100); • turnGunRight(360); • } • } • This is an example main loop. This robot doesn’t have any event handlers so it executes these exact actions until it either wins (very unlikely) or dies (very likely).

  9. Example • public class MyRobot extends Robot • { • public void run() { • while(true) { • ahead(100); • turnGunRight(360); • back(100); • turnGunRight(360); • } public void onHitByBullet(HitByBulletEvent e) { turnLeft(90 - e.getBearing()); } } • This example has an event handler. It will continue executing this loop until we get hit by a bullet. When we get hit, we turn toward the enemy.

  10. Inheritance in Java • Ideas: Inhertiance • common components are inherited, rather than duplicated • allows similar though distinct objects to exhibit their common capabilities without requiring the code to be in two places

  11. Inheritance in Java • Class GoldenRetriever extends Dog • GoldenRetriever has any properties that Dog has: • Canis lupus familiaris • Four legs • GoldenRetriever has extra properties not common to all dogs • Gold hair • Playful demeanor • Tall

  12. Inheritance in Java • Class Dog extends Mammal • Mammals have: • Hair • Legs • Lungs • Dogs have: • Canis lupus familiaris • Four legs

  13. Inheritance in Java • To give our robots all of the methods defined in the robot API, we have been extending the Robot class. This is so we don’t have to define all the methods that are already defined for us. • We could also extend the AdvancedRobot class • Note: Beginners • I don’t expect you to fully implement this concept • I do expect you to understand what happens when we extend a class (inherit from a class)

  14. Robocode Basics • Tank properties • Energy • Time • Fire • Radar • Game play • How to determine a winner (not necessarily last tank standing) • How the Robocode engine updates

  15. Tank Basics: Energy • Tanks start with a certain amount of health (energy) • 100 • Tanks lose health by: • getting shot • bumping into things (the walls, other robots) • shooting bullets • fighting for too long • (Note: tanks that hit each other lose equal amounts of health) • Tanks gain health by shooting other tanks • Tanks that run out of health by shooting too much are disabled (If the tanks bullet hits a target it can gain energy back)

  16. Game Play (point distribution) • Robots on the field when another robot dies – 50 points • Last robot alive given extra points – 10 points per dead robot • Every point of fire damage inflicted on target robot – 1 point • Every opponent ram – 2 points per damage inflicted by ramming • Killing a target robot by firing at it– 20% of total damage inflicted • Death by ramming – 30% of total damage inflicted

  17. Tank Basics: Time • Rotating the gun, radar, and vehicle takes time • Vehicle takes the longest amount of time • Radar takes the least amount of time • Bullets take time to hit things (need to shoot where you expect the target to be when the bullet should arrive) • Gun has a short cooldown period in between shots • Radar must be pointed at a target to see it • Detects velocity, bearing, heading, and energy remaining.

  18. Tank Basics: Fire • 3 levels of firing • fire(1) – costs the least health, does the least damage • fire(2) -costs intermediate health, does intermediate damage • fire(3) – costs the most health, does the most damage

  19. Tank Basics: Radar • Infinite range • One degree scan width • Returns enemy position, orientation, bearing, gun angle, and energy. • Tank knows its own position, oreintation, bearing, gun angle, and energy

  20. Game Play (how Robocode updates) • All robots execute their code until taking action • Time is updated • All bullets move and check for collisions • All robots move (heading, acceleration, velocity, distance, in that order) • All robots perform scans (and collect team messages) • The battlefield draws • http://www.dinbedstemedarbejder.dk/Dat3.pdf

  21. Robocode Strategies • Seeing other robots – how the robot controls its radar • Choosing an enemy • Moving – where the robot should go • Targeting and Shooting-when, how powerful and in which direction to shoot. • http://www.dinbedstemedarbejder.dk/Dat3.pdf

  22. Radar Strategies – Seeing other robots • Remember that scanning takes time • Simple – scan 360 degrees (while alive), looking for target robots, remember where these robots are • Problem: Robots aren’t typically evenly distributed

  23. Example: Scan 360 • public class MyFirstRobot extends Robot { public void run() { while (true) { ahead(100); turnGunRight(360); } }   public void onScannedRobot(ScannedRobotEvent e) { fire(1); } }

  24. Radar Strategies – Seeing other robots • Locked scanning strategy – radar finds a target and sticks with it • Implemented by moving the radar back and forth a little to keep track of the robot, it could scan the direction based on the target robot’s heading • Problem: Not good for bigger battles since you could pass by easier to kill robots • Radar can be used to guess when an opponent’s bullet has fired • Any ideas on how we could do this? • Look at what we can gather from the radar API

  25. Example: Target Lock //Follows the robot around the battlefield. public void run() { // ... turnRadarRightRadians(Double.POSITIVE_INFINITY); do { scan(); } while (true); } public void onScannedRobot(ScannedRobotEvent e) { double absoluteBearing = getHeadingRadians() + e.getBearingRadians(); double radarTurn = absoluteBearing - getRadarHeadingRadians(); setTurnRadarRightRadians(Utils.normalRelativeAngle(radarTurn)); // ... }

  26. Radar Strategy – Methods (AdvancedRobots) • scan() - Scans the arena using the radar at its current setting. Robocode calls this for each robot at each turn. • setTurnRadarLeft and turnRadarLeft. • setTurnRadarRight and turnRadarRight • setAdjustRadarForRobotTurn - Enables or disables the radar locking to the vehicle • setAdjustRadarForGunTurn - Enables or disables the radar locking to the gun

  27. Choosing an Enemy • Weakest Enemy – Pick the guy with the lowest health • Problem: This target could be far away. Another robot could dip below target robot’s health in the mean time! • Closest Enemy – Pick the guy closest to you • Problem: He could be the winner. Dying earlier means you receive less points overall

  28. Choosing an Enemy • No explicit methods provided by Robocode • Neural Network Targeting Today if we have time

  29. Movement Strategies (MS) • None – easy to hit • Straight line • Problem: Easy for enemies to predict • Curve • Problem: Also easy for enemies to predict • Oscillating • Random • Problem: Run a larger chance of hitting walls

  30. Movement Strategies (MS) • Anti-gravity – keeps the robot from dangerous areas and attracts it toward advantageous areas • Many different implementations • These and more discussed here – • http://www.dinbedstemedarbejder.dk/Dat3.pdf

  31. Shooting Strategies • Stationary • Linear • Circular • Oscillatory • Movement pattern matching

  32. Shooting Strategies • Stationary – Assume the robot is not going to move and fire directly at the target robot’s current location • Problem: If the target moves, we miss Target Robot Our Robot

  33. Example: Stationary Shooting • onScanRobot() { fire(1); } //This method just fires where we saw the robot without taking into account where it may be going

  34. Shooting Strategies • Linear – Assume that the robot is moving in a straight line, fire at where the robot should be in the time it takes to fire (Assumes constant velocity) • All robot motion can be approximated for a short period of time this way • Problem: Not effective over longer periods of time Target Robot Our Robot X

  35. Shooting Strategies Circular- Assumes the target moves at a constant velocity and angular velocity (slightly better than linear targeting) Problem: Can be avoided by stopping/starting quickly or changing directions sporadically Target Robot Our Robot X

  36. Shooting Strategies • Circular • change in x = cos(initialheading) * radius - cos(initialheading + changeinheading) * radius • change in y = sin(initialheading + changeinheading) * radius - sin(initialheading) * radius

  37. Shooting Strategies Oscillatory – Assumes that the target robot is moving back and forth (not many robots do this) Target Robot Our Robot X

  38. Shooting Strategies • Movement pattern matching – Predicts target robots position based on past moves • Problems: Time expensive Target Robot Our Robot X

  39. Recall how inheritance works • common components are inherited, rather than duplicated • allows similar though distinct objects to exhibit their common capabilities without requiring the code to be in two places

  40. Creating Your Own Event • Note: We’ve been extending the Robot class • If we extend the AdvancedRobot class, we can create our own events

  41. Creating Your Own Event • Events happen when a certain condition is met • E.g. • onScanRobot() – checks to see if another robot is found, returns true if a robot is found, event fires • Event needs to check for some kind of “behavior,” call this a condition • Your robots onCustomEvent(CustomEvent e) method is called when the test condition is true

  42. Creating Your Own Event • addCustomEvent(Condition condition) Registers a custom event to be called when a condition is met. • Condition() Creates a new, unnamed Condition with the default priority. • Condition(String name) Creates a new Condition with the specified name, and default priority. • Condition(String name, int priority) Creates a new Condition with the specified name and priority.

  43. Example: Our own event • public class MyEvent extends AdvancedRobot { ... public void run() { //the condition is given a name “canFire” addCustomEvent(new Condition(“canFire") { public boolean test() { // When the gun has cooled off, test returns true return (getGunHeat() == 0); }; } ); }

  44. Example: Handling our event • public void onMyEvent(CustomEvent ev) { fire(3); }

  45. Citations… • http://people.csail.mit.edu/jacobe/papers/robocode.pdf • http://www.ibm.com/developerworks/java/library/j-tipstrats.html • http://sclab.yonsei.ac.kr/~hjinh/PAPER/IC2004-1.pdf • http://www.dinbedstemedarbejder.dk/Dat3.pdf

More Related