Winning Strategy in Programming Game Robocode

Slides:



Advertisements
Similar presentations
Application a hybrid controller to a mobile robot J.-S Chiou, K. -Y. Wang,Simulation Modelling Pratice and Theory Vol. 16 pp (2008) Professor:
Advertisements

Projectile Motion.
Generated Waypoint Efficiency: The efficiency considered here is defined as follows: As can be seen from the graph, for the obstruction radius values (200,
Graduate Capstone Project Breaking Walls: Developing a Successful Robot in Robocode Chris Velez Summer 2011 Advisor :Dr. Xiang.
Design, Implementation, & Impact Jeffrey Santos Hofstra University May, 2010.
Kinematics in Two Dimensions; Vectors
Unit 8 POE Ballistic Device
SuperCorners. Problem The Corners sample robot has a simple strategy: first, move into a corner of the arena, and second sweep the gun back and forth.
Objectives: 1.Be able to prove the Law of Sines using Right Triangle Trigonometry. 2.Be able to apply the Law of Sines on various triangles. 3.Be able.
STROUD Worked examples and exercises are in the text PROGRAMME F8 TRIGONOMETRY.
Lecture 12 Statistical Inference (Estimation) Point and Interval estimation By Aziza Munir.
Department of Electrical Engineering, Southern Taiwan University Robotic Interaction Learning Lab 1 The optimization of the application of fuzzy ant colony.
Integrals  In Chapter 2, we used the tangent and velocity problems to introduce the derivative—the central idea in differential calculus.  In much the.
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
Assignments. AnatomyBot.java Create a robot that turns all of it parts independently (vehicle, gun, and radar). Turn the vehicle left 360 o Turn the gun.
Chapter 4 Two-Dimensional Kinematics. Units of Chapter 4 Motion in Two Dimensions Projectile Motion: Basic Equations Zero Launch Angle General Launch.
CHAPTER 6 MOTION IN 2 DIMENSIONS.
Seminar for Participants An Introduction on Robocode.
1 Copyright © Cengage Learning. All rights reserved. 6. The Trigonometric Functions 6.7 Application Problems.
Inductive and Deductive Reasoning  The pre-requisites for this chapter have not been seen since grade 7 (factoring, line constructions,..);
Projectile Motion. 3-2 The Components of a Vector Even though you know how far and in which direction the library is, you may not be able to walk there.
Chapter 3 Two-Dimensional Motion and Vectors. Section 3-1: Introduction to Vectors Physical quantities such as length, area, volume, mass, density, and.
Trigonometric Functions of Angles 6. Introduction The Law of Sines cannot be used directly to solve triangles if we know either: Two sides and the angle.
Chapter 6 The Definite Integral.  Antidifferentiation  Areas  Definite Integrals and the Fundamental Theorem  Areas in the xy-Plane  Applications.
Law of Cosines Section 5.2 For any oblique triangle the Law of Cosines is:
Chapter 1 Introduction and Mathematical Physics. 1.1 The Nature of Physics Physics helps to explain our physical world. Application of physics have been.
Brain Teaser During the Little League baseball season, every team plays every other team in the league ten times. If there are ten teams in the league,
Localization by TDOA ©Thomas Haenselmann – Department of Computer Science IV – University of Mannheim Lecture on Sensor Networks Historical Development.
Copyright © Cengage Learning. All rights reserved.
INTRODUCTION TO STATISTICS
Copyright © Cengage Learning. All rights reserved.
Motion in Two Dimensions
Winning Strategy in the Programming Game Robocode
Law of Cosines Section 7.3.
Introduction In the real world, if you needed to verify the size of a television, you could get some measuring tools and hold them up to the television.
Introduction to Summary Statistics
4.1 Vectors in Physics Objective: Students will know how to resolve 2-Dimensional Vectors from the Magnitude and Direction of a Vector into their Components/Parts.
Introduction to Summary Statistics
THEODOLITE TRAVERSING BY S N Nanaware
Introduction to Summary Statistics
Introduction to Summary Statistics
Introduction to Summary Statistics
Elementary Statistics
Motion in Two Dimensions
Introduction to Summary Statistics
5.1 The Unit Circle.
3x 2x -5 x + 11 (4x + 7)° 90° (8x - 1)°.
Law of Cosines Section 3.2.
Introduction to Summary Statistics
Introduction to Summary Statistics
Soh-Cah-Toa, Law of Sines, Law of Cosines
07/12/2018 Starter L.O. To be able to Solve a quadratic by factorising
KS4 Mathematics A6 Quadratic equations.
Introduction to Summary Statistics
Vectors and Two-Dimensional Motion
Chapter 6 The Definite Integral
Projectile Motion.
Kinematics Vectors and Motion
COMPASS Practice Test D
Introduction to Summary Statistics
Law of Cosines.
Law of Cosines Section 6.2.
Concepts and Calculations Bullet Trajectory Concepts and Calculations.
Introduction to Summary Statistics
Linear Regression Dr. Richard Jackson
CO Games Concepts Week 12 Collision Detection
Tutorial 6 The Definite Integral
Introduction to Summary Statistics
Vector Operations Unit 2.3.
Presentation transcript:

Winning Strategy in Programming Game Robocode CSC 303 Casmon Gordon Advisor- Dr Xiang Fu

Introduction Robode: Programming Game. * Robots Controls in Java.         *  Public API for Programmers (Players). Many robots included with game. Walls robot was the most successful. Robocode is a programming game where the robots in the game are controlled using Java programs. There are a variety of robots that are included with the game. It was observed that the Walls robot was the most successful when the battlefield is comprised of all the included robots.

Walls Robot The Walls robot movement predictable. The Walls robot will always move in predictable ways. When the battle begins it will always move to the edge of the battlefield and then travel along its edges in a clockwise direction. Due to the fact that Walls travels in a straight line, its future path can easily be calculated. Trigonometry can be used to calculate the angle at which to fire a bullet that will hit the Walls robot as it travels in its path.

The Problem The Walls robot moves very fast. The default shooting algorithm will target and fire at Walls current location. Due to the Walls speed, Walls would have moved by the time the bullet reaches.

Objective Design WallsKiller robot. Defeats Walls robot effectively. Goals? Win every battle! Hit ratio above 90%. Energy level above 80. The objective was to design a robot named WallsKiller, which is specifically built to defeat the Walls robot effectively. Its goals is to win every battle, achieving a hit ratio above 90% and having an average energy level of above 80.

Targeting Strategy Where will Walls be?. Wallskiller needs smart shooting algorithm. Wallskiller needs to determine where the Walls robot will be and fire at that location. The robot utilizes a custom shooting algorithm that uses trigonometry and solves quadratic equations in order to accurately calculate the trajectory to fire bullets in order to hit the fast moving Walls robot.

Bullet Avoidance The WallsKiller robot : Avoids getting hit by the Walls robot’s bullets. Detects that Walls has opened fire. Moves away! The WallsKiller robot was designed to avoid getting hit by the Walls robot’s bullets. The algorithm detects when there is a change in the energy level of the Walls robot which indicates that the Walls robot has fired a bullet. The WallsKiller will then move to a position that is perpendicular to the Walls robot’s heading, reducing the likelihood that the bullet fired will hit the WallsKiller robot.

Robot Anotomy The tank or robot consists primarily of a gun, a radar and the vehicle itself. The gun has the ability to rotate in order to shoot at targets. The radar also rotates in order to detect enemy tanks on the battlefield.

Cosine Rule Cosine Rule: c2 = a2 + b2 – 2ab*cos(A) In trigonometry, the cosine rule governs the size of edges and the angles in a triangle. The square of one edge of the triangle, is the sum of the square of the other two edges and minus their product with the cosine of the angle.

Quadratic Equations Quadratic formula: For an equation of the form At2 + Bt + C, the variable t can be determined by using the following formula shown.

Relationship Between Tanks Positions The corners of the triangle represent the position of the WallsKiller tank, the current position of the Walls tank and the future position of the Walls tank at which the bullet will hit it. As shown, v1 = the velocity of the bullet; v2 = the velocity of the enemy tank; and d = the distance between both tanks. The future location of Walls can be determined by calculating v2*t. Also the position where the bullet will hit the Walls robot can be found by calculating v1*t.

Relationship Between Angles Alpha and Beta The relationship between angles alpha and beta are illustrated. We are going to compute the angle beta, so later we can apply the rule of cosine. As shown in this slide, there are three angles: Angle 1, Angle 2, and Angle 3 closely related to beta. They can be obtained using the formulas:   Angle 1 = heading of enemy tank = ScannedRobotEvent.getHeading() Angle 2 = heading of the WallsKiller = AdvancedRobot.getHeading() Angle 3 = the bearing of the enemy tank = ScannedRobotEvent.getBearing()

Finding Beta Sum of angles equals 180 degrees. Solve for beta: Hence (180-Angle 1)+(Angle2 + Angle 3)+180-beta=180 Solve for beta: beta = 180-Angle 1+ Angle 2 + Angle 3 Therefore beta = 180 - ScannedRobotEvent.getHeading() + AdvancedRobot.getHeading() + ScannedRobotEvent.getBearing() The three angles that make up the triangle must add up to 180 degrees. Therefore the following applies: (180-Angle 1)+(Angle2 + Angle 3)+180-beta=180 Solving for beta we get the following: beta = 180-Angle 1+ Angle 2 + Angle 3 Therefore beta = 180 - ScannedRobotEvent.getHeading() + AdvancedRobot.getHeading() + ScannedRobotEvent.getBearing()

Finding the Time Substituting and solving we get: (v1*t)2 = d2 + (v2*t)2 – 2(d*v2*t)*cos(beta) d2 + (v2*t)2 – 2(d*v2)*cos(beta) *t - (v1*t)2 = 0 (v22 - v12)t2 – 2*d*v2*cos(beta) *t + d2 = 0 This equation is quadratic form. Apply cosine rule! Using the triangles described previously and substituting the values such that a=d, b=v2*t and c=v1*t we get: (v1*t)2 = d2 + (v2*t)2 – 2(d*v2*t)*cos(beta) d2 + (v2*t)2 – 2(d*v2)*cos(beta) *t - (v1*t)2 = 0 (v22 - v12)t2 – 2*d*v2*cos(beta) *t + d2 = 0  This equation is in the quadratic form: (At2 + Bt + C=0) and can be used to solve for t  Let A = v22 – v12, B= -2*d*v2*cos(beta), and C= d2

Finding Alpha Determine the value for alpha. Use cosine rule. Substitute the three edges of the triangle : (v2*t)2 = d2 + (v1*t)2 – 2(d*v1*t)cos(alpha) Now that t can be determined, we can use the cosine rule again to determine the value for alpha. Substituting the three edges of the triangle such that a= d, b=v1*t, and c=v2*t we get the following: (v2*t)2 = d2 + (v1*t)2 – 2(d*v1*t)cos(alpha)

Finding Alpha Simplifying and solving for alpha we get: Therefore:

Fire Angle Calculation Direct fire angle: fireAngle = (AdvancedRobot.getHeading() + ScannedRobotEvent.getBearing()) - AdvancedRobot.getGunHeading(); If we were to shoot directly at the Walls tank, the fireAngle equation would be   fireAngle = (AdvancedRobot.getHeading() + ScannedRobotEvent.getBearing()) - AdvancedRobot.getGunHeading();

Fire Angle Calculation Direct fire will miss! Offset angle alpha added to fire angle: fireAngle = (AdvancedRobot.getHeading() + ScannedRobotEvent.getBearing() + alpha) - AdvancedRobot.getGunHeading(); However because the tank would have moved away by the time the bullet would reach it, the calculated offset angle alpha is added to the firing angle resulting in the following equation represented by: fireAngle = (AdvancedRobot.getHeading() + ScannedRobotEvent.getBearing() + alpha) - AdvancedRobot.getGunHeading();

Shooting Performace for Ranges As shown, the hit rate of the WallsKiller robot varies for different ranges. Due to precision errors associated with calculation the WallsKiller robot may sometimes miss the Walls robot at longer ranges. In order to improve the performance of the WallsKiller robot, a statistical sample of the hit rates for various ranges is performed to determine the optimal range at which to shoot the Walls robot.

Machine Learning The WallsKiller robot: Collects battle data. Perform runtime data analysis. Determines optimal range! The WallsKiller robot has the ability to perform runtime data analysis of past battles to determine the optimal range at which to shoot the Walls robot. The WallsKiller robot collects and stores hit rate information for given ranges. After a threshold has been reached, which is a pre-determined value for the maximum number of records, the WallsKiller robot will perform analysis of the data it has collected to determine the range at which it was most successful. When this range is determined, WallsKiller will use this range to shoot the Walls robot.

Machine Learning Details Manipulates Data via text file. File size limitations. Data analysis The WallsKiller robot stores and manipulates data via a text file. The data in the text file is a set of comma delimited key value pairs. Due to file size restrictions (~200K), the WallsKiller robot is not allowed to store more than approximately 2000 lines of data. This means that a larger statistical sample could not be taken for each gun range of the WallsKiller robot. When this file’s maximum size is reached, WallsKiller robot will then analyze the data to determine the best range at which the hit rate is the highest.   The samples for each range were taken for 50 turns of Robocode after which the data was collected and stored.

Frequency of Data for Ranges The graph above illustrates the occurrences of data for the respective ranges. This shows that even though the best hit rate of 100% was achieved at the 100 range, it can be considered a statistical outlier and can be ignored since there was only one hit at that range. This is also the case for the 1000 range where there was only two occurrences.

Check If Bullet Will Miss In order to improve accuracy, WallsKiller robot first calculates where the bullet will hit the Walls robot. If this position is outside the battlefield then the WallsKiller will not fire until the predicted hit location is within the battlefield. The fire control system has a private function calcEnemyProjectedLocation( ) that calculates the projected location of the Walls robot. It does this by using the distance (enemyVelocity * t) to determine the Walls robot’s absolute bearing. It then uses the absolute bearing along with other battle data and sine and cosine functions to determine the Walls robot’s projected X and Y coordinates. These coordinates are then checked to see if they are within the battlefield. If they are not within the battlefield then the WallsKiller will not open fire.

Conclusion The WallsKiller robot is very effective! Sometimes misses at longer ranges. Learns and adapts. Achieved its goals! The WallsKiller robot is very effective at killing the Walls robot. However, due to precision errors associated with calculation the WallsKiller robot may sometimes miss the Walls robot at longer ranges. To resolve this problem, the WallsKiller robot will at runtime collect, store and analyze battle data from past battles to determine the optimal range at which to shoot the Walls robot. WallsKiller achieved all its goals of winning every battle, achieving a hit ratio above 90% and having an average energy level of above 80.