From ab705ebeaa6859276aa7ed76b01361ff576f0477 Mon Sep 17 00:00:00 2001 From: Gast 102 Date: Thu, 21 Jul 2016 16:04:02 +0200 Subject: [PATCH 1/3] stand... --- JRobots-Competition-standalone.bat | 0 src/EmptyBot.java | 17 ----------------- 2 files changed, 17 deletions(-) mode change 100644 => 100755 JRobots-Competition-standalone.bat delete mode 100644 src/EmptyBot.java diff --git a/JRobots-Competition-standalone.bat b/JRobots-Competition-standalone.bat old mode 100644 new mode 100755 diff --git a/src/EmptyBot.java b/src/EmptyBot.java deleted file mode 100644 index 53260a0..0000000 --- a/src/EmptyBot.java +++ /dev/null @@ -1,17 +0,0 @@ -import jrobots.utils.*; -import jrobots.simulation.simulationObjects.JRobot2015_3; - -/** A minimal functional Bot, ready for being programmed. - *

Please enter the documentation via the method actions(). - *

Please rename uniquely. The individual name will be displayed in the GUI. - * @see JRobot2015_2#actions() - */ -public class EmptyBot extends JRobot2015_3 { - private static final long serialVersionUID = 1L; - - @Override - protected void actions() { - // TODO implement brain - } - -} From e79c2a433242955b391377894e131aaf8a2d920a Mon Sep 17 00:00:00 2001 From: Gast 102 Date: Thu, 21 Jul 2016 16:15:36 +0200 Subject: [PATCH 2/3] stand... --- src/Black_Bierbauch_Uno.java | 279 +++++++++++++++++++++++++++++++++++ 1 file changed, 279 insertions(+) create mode 100644 src/Black_Bierbauch_Uno.java diff --git a/src/Black_Bierbauch_Uno.java b/src/Black_Bierbauch_Uno.java new file mode 100644 index 0000000..b3507d2 --- /dev/null +++ b/src/Black_Bierbauch_Uno.java @@ -0,0 +1,279 @@ +import java.awt.Color; +import java.util.Random; + +import jrobots.utils.Angle; +import jrobots.utils.ProximityScan; +import jrobots.utils.SonarTrace; +import jrobots.utils.Vector; +import jrobots.simulation.simulationObjects.JRobot2015_3; +import jrobots.simulation.simulationObjects.Pilot; + + + +public class Black_Bierbauch_Uno extends JRobot2015_3 { + private static final long serialVersionUID = 1L; + private Angle a = new Angle(0,"d"); + private int t = 0; + private int value =0; + private int time = 36; + private double energy = 0.27; + + public Black_Bierbauch_Uno(){ + super(); + this.setNameColor(Color.WHITE); + this.setBodyColor(Color.yellow); + this.setTurretColor(Color.RED); + this.setAutopilot(LEFT, 1); + System.out.println(this.getEnergy()); + + + + } + + @Override + protected void actions() { + t++; + value = value + 1; + Random r = new Random(); + int d = r.nextInt(480); + if(d< value){ + time = 72; + energy = 0.54; + } + else{ + time = 36; + energy = 0.27; + + } + + this.farbe(); + this.vectorScan(); + if(t % time == 0 ){ + Scan(); + + } + if(this.getLastSonarTrace() != null && t % time == 1){ + this.fire(); + } + + + + + if(t % 1200 == 0){ + + this.end(); + } + + //System.out.println("Boost"); + } + + + + + + + + + + public void drive(){ + + if(t % 48 == 0){ + a = a.add(new Angle(45, "d")); + this.setAutopilot(a, 1); + + } + } + + public void end(){ + + this.setAutopilot(getOrientation().getNextQuadrant(), 1); + this.setBoost(); + } + + + + + public void farbe(){ + Random r = new Random(); + if(t % 5 == 0){ + int i = r.nextInt(8); + if(i== 0){ + this.setTurretColor(Color.BLACK); + } + else if(i== 1){ + this.setTurretColor(Color.BLUE); + } + else if(i== 2){ + this.setTurretColor(Color.YELLOW); + } + else if(i== 3){ + this.setTurretColor(Color.GREEN); + } + else if(i== 4){ + this.setTurretColor(Color.MAGENTA); + } + else if(i== 5){ + this.setTurretColor(Color.WHITE); + } + else if(i== 6){ + this.setTurretColor(Color.CYAN); + } + else if(i== 7){ + this.setTurretColor(Color.PINK); + } + + i = r.nextInt(8); + if(i== 0){ + this.setBodyColor(Color.BLACK); + + } + else if(i== 1){ + this.setBodyColor(Color.BLUE); + } + else if(i== 2){ + this.setBodyColor(Color.YELLOW); + } + else if(i== 3){ + this.setBodyColor(Color.GREEN); + } + else if(i== 4){ + this.setBodyColor(Color.MAGENTA); + } + else if(i== 5){ + this.setBodyColor(Color.WHITE); + } + else if(i== 6){ + this.setBodyColor(Color.CYAN); + } + else if(i== 7){ + this.setBodyColor(Color.PINK); + } + + i = r.nextInt(8); + if(i== 0){ + this.setNameColor(Color.BLACK); + } + else if(i== 1){ + this.setNameColor(Color.BLUE); + } + else if(i== 2){ + this.setNameColor(Color.YELLOW); + } + else if(i== 3){ + this.setNameColor(Color.GREEN); + } + else if(i== 4){ + this.setNameColor(Color.MAGENTA); + } + else if(i== 5){ + this.setNameColor(Color.WHITE); + } + else if(i== 6){ + this.setNameColor(Color.CYAN); + } + else if(i== 7){ + this.setNameColor(Color.PINK); + } + + } + } + + public void proScan(){ + + + ProximityScan p = this.getProjectileRadar(); + if(p != null && p.speed != null){ + System.out.println("S"+t); + Vector v = new Vector(); + for(int i = 1; i<4; i++){ + v = p.predict(this.getTime()+0.03*i); + System.out.println(v.distanceTo(getPosition())); + if(v.distanceTo(getPosition())<30){ + + this.setAutopilot(a.add(new Angle(90,"d")), 1); + + System.out.println("boo"+i); + + + + } + break; + } + + } + } + + + public void vectorScan(){ + + + ProximityScan p = this.getProjectileRadar(); + if(p != null && t % 10 == 0){ + double my_X = this.getPosition().getX(); + double my_Y = this.getPosition().getY(); + + double pro_X = p.pos.getX(); + double pro_Y = p.pos.getY(); + + Vector v = p.predict(1/24); + double pro_X2 = v.getX(); + double pro_Y2 = v.getY(); + + double pro_steigung = (pro_Y - pro_Y2)/(pro_X - pro_X2); + double pro_t = pro_Y - pro_steigung*pro_X; + double pro_y_schnitt = pro_steigung * my_X +pro_t; + this.addDebugArrow(p.pos, new Vector(my_X,pro_y_schnitt)); + if(this.getPosition().distanceTo(new Vector(my_X,pro_y_schnitt)) < 30){ + Vector vec = new Vector(pro_X-pro_X2, pro_Y-pro_Y2); + System.out.println("DING" + t + " "+ vec.getAngle()); + + if(my_Y < pro_y_schnitt){ + + this.setAutopilot(vec.getAngle().add(new Angle(75,"d")), 1); + } + else{ + + this.setAutopilot(vec.getAngle().add(new Angle(-75,"d")), 1); + } + } + } + } + + + +public final double Raketenzeit(){ + + return this.getPosition().distanceTo(GegnerScan()) / getProjectileSpeed(); + +} + +public Vector GegnerScan(){ + + return this.getLastSonarTrace().location; + +} + +public void Scan(){ + + this.setSonarEnergy(this.getEnergy()-this.getEnergyConsumptionEngine()-energy); + getLastSonarTrace(); +} + + +public void fire(){ + Vector v = this.GegnerScan(); + + + this.setLaunchProjectileCommand(v.sub(this.getPosition()).getAngle()); + this.addDebugCrosshair(v); +} + + + + +} + + + + + From 453598635774e964bbedcd6edd1209f9ceef2108 Mon Sep 17 00:00:00 2001 From: Gast 102 Date: Thu, 21 Jul 2016 16:17:20 +0200 Subject: [PATCH 3/3] stand... --- src/Fool2.java | 259 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 259 insertions(+) create mode 100644 src/Fool2.java diff --git a/src/Fool2.java b/src/Fool2.java new file mode 100644 index 0000000..8d745d2 --- /dev/null +++ b/src/Fool2.java @@ -0,0 +1,259 @@ +import jrobots.utils.*; + +import java.lang.Math; +import java.util.Random; + +import jrobots.simulation.simulationObjects.JRobot2015_3; + + + + + + +import java.awt.*; + +public class Fool2 extends JRobot2015_3 { + private static final long serialVersionUID = 1L; + + private SonarTrace oldScan = null; + private SonarTrace newSonar = null; + private double multiply = 1; + private double lastAngle = 0.0; + private double distance = Double.MAX_VALUE; + private double distanceY = 0; + private double distanceX = 0; + private int counter = 0; + private double frame = 0; + private ProximityScan lastScan = null; + private ProximityScan newScan = null; + + private int counterps = 0; + private float r; + private float g; + private float b ; + Random rand = new Random(); + private int boostcounter; + + public Fool2() { + this.setNameColor(Color.CYAN); + this.setBodyColor(Color.MAGENTA); + this.setTurretColor(Color.PINK); + newScan = this.getProjectileRadar(); + this.boostcounter = 15; + counter = 12; + this.setAutopilot(new Angle ( 45 , "d"), 3); + } + + @Override + protected void actions() { + if(this.counter == 12 && this.getEnergy() < 0.3) + { + this.Scan(); + counter = 0; + } + + + this.drive () ; + + if (counterps == 1){ + this.dodeg4(newScan); + this.counterps = 0; + } + if (this.getEnergy () > 0.3){ + this.fire(); + } + + MisileScan(); + counter++; + boostcounter++; + float r = rand.nextFloat(); + float g = rand.nextFloat(); + float b = rand.nextFloat(); + Color randomColor = new Color(r, g, b); + Color randomColor2 = new Color(b, g, r); + Color randomColor3 = new Color(b, r, g); + this.setTurretColor(randomColor); + this.setBodyColor(randomColor2); + this.setNameColor(randomColor3); + } + + /** + * Modelierung des Schussverhaltens. + **/ + private void fire() { + if (this.newSonar != null) { + Vector scanPos = this.Scan().location.sub(this.getPosition()); + if (this.getEnergy() > 0.6 && this.getHealth() > 0.75){ + this.setLaunchProjectileCommand(scanPos.getAngle()); + this.setLaunchProjectileCommand(scanPos.getAngle()); + } + else { + this.setLaunchProjectileCommand(scanPos.getAngle()); + } + } + } + + + private Vector predictTarget(Vector currentScan) { + double max = 1.5; + double min = .25; + double con = GetIdeal(min, max); + double futureTime = this.getTime() + (currentScan.getLength() / super.getProjectileSpeed()) * con; + Vector prediction = LinearPredictor.predict(newSonar, this.oldScan, futureTime).sub(this.getPosition()); + + return prediction; + } + + private double GetIdeal(double min, double max) { + double ideal; + double v = this.distance / (max-min); + ideal = (min +(v/100)*max) -0.01; + //System.out.println(distance); + if(v > 85 / (max-min)) { + ideal = max; + } else if(v < 20 / (max-min)) { + ideal = min; + } + if(v < 10 / (max-min)) + ideal = .2; + if(v < 5 / (max-min)) { + ideal = .175; + } + return ideal; + } + + /** + * Zeichnen von Debug Pfeilen und Linien. + **/ + //private void drawDebugTarget() { + //Vector scanPos = this.getLastSonarTrace().location.sub(this.getPosition()); + + // if (scanPos != null && oldScan != null) { + // this.addDebugArrow(new Vector(this.getPosition().getX() + 50, this.getPosition().getY()), this.getPosition()); + //this.addDebugArrow(this.getPosition(), new Vector(this.getPosition().getX() + 50, this.getPosition().getY())); + //this.addDebugLine(this.getPosition(), scanPos); + // } + //} + + private void dodgeMisiles(ProximityScan ps) { + if(this.getTime() != frame && ps != null) { + this.newScan = this.getProjectileRadar(); + if(newScan != null) { + double tan = (newScan.pos.getY()-lastScan.pos.getY()) /(newScan.pos.getX()-lastScan.pos.getX()); + tan = tan*(-1); + tan = Math.atan(tan); + + if(this.distanceY < 0) { + this.lastAngle = tan -90; + } else { + this.lastAngle = tan +90; + } + + tan = Math.toDegrees(tan); + this.setAutopilot(new Angle(tan, "d"), 10.0); + } + if (this.newScan.pos.distanceTo(this.getPosition())< 17) { + this.setBoost(); + } + } + + } + +private void dodeg4 (ProximityScan ps) { + if(this.getTime() != frame ) { + this.newScan = this.getProjectileRadar(); + if(newScan != null) { + double tan = 0; + double wink = 0; + if (this.lastScan.pos.getY()< this.newScan.pos.getY()){ + tan = ((this.newScan.pos.getX() - this.lastScan.pos.getX())) / ((this.newScan.pos.getY() - this.lastScan.pos.getY())); + } + else if (this.lastScan.pos.getY()> this.newScan.pos.getY()){ + tan = ((this.newScan.pos.getY() - this.lastScan.pos.getY()) ) / ((this.newScan.pos.getX() - this.lastScan.pos.getX())); + } + if (this.getPosition().getY()> this.newScan.pos.getY()){ + wink = ((this.newScan.pos.getX() - this.getPosition().getX())) / ((this.newScan.pos.getY() - this.getPosition().getY())); + } + else if (this.getPosition().getY()< this.newScan.pos.getY()){ + wink = ((this.newScan.pos.getY() - this.getPosition().getY()) ) / ((this.newScan.pos.getX() - this.getPosition().getX())); + } + Angle d = new Angle (0, "d"); + if (tan != 0 && wink != 0 ){ + Angle tan1 = new Angle (Math.toDegrees(tan), "d"); + Angle wink1 = new Angle (Math.toDegrees(wink), "d"); + if (tan1.angle > wink1.angle ){ + d = new Angle (tan1.angle -90, "d" ); + } + else if (tan1.angle < wink1.angle ){ + d = new Angle (tan1.angle +90, "d" ); + } + else if (tan1.angle == wink1.angle ){ + d = new Angle (tan1.angle -75, "d" ); + //this.setBoost() ; + //this.boostcounter = 0; + System.out.println ("direct hit"); + } + } + + + + + //System.out.println (d.toString()); + this.setAutopilot(d, 5.00); + if (this.newScan.pos.distanceTo(this.getPosition())< 15 && this.boostcounter > 20) { + this.setBoost(); + this.boostcounter = 0; + } + } + + } +} + + + + + +private SonarTrace Scan() { + if(this.getEnergy()> 0.13) { + this.oldScan = this.newSonar; + //System.out.println(this.oldScan); + this.setSonarEnergy(0.07); + this.newSonar = this.getLastSonarTrace(); + //Vector scanPos = this.getLastSonarTrace().location.sub(this.getPosition()); + if(newSonar != null){ + this.distance = this.newSonar.location.distanceTo(this.getPosition()); + + this.distanceY = this.newSonar.location.getY() - this.getPosition().getY(); + //System.out.println(this.distanceY); + this.distanceX = this.newSonar.location.getX() - this.getPosition().getX(); + //if(this.getEnergy()> 0.2) + //System.out.println(distance); + } + //drawDebugTarget(); + counter = 0; + } + return this.newSonar ; +} + private void MisileScan() { + lastScan = this.getProjectileRadar(); + frame = this.getTime(); + if(lastScan != null) { + counterps = 1; + } + } + /** + * Modelierung des Fahrverhaltens. + **/ + + public void drive () { + if (this.newSonar != null) { + + if (this.newSonar.location.distanceTo(this.getPosition()) < 40){ + this.setAutopilot(this.newSonar.location.sub(this.getPosition()).getAngle().add(new Angle (180, "d")) , 4); + } + else if (this.newSonar.location.distanceTo(this.getPosition())> 80){ + this.setAutopilot(this.newSonar.location.sub(this.getPosition()).getAngle(), 4); + } + } + } +}