Last active
July 18, 2017 11:25
-
-
Save tkovs/8b2c51849ca448841be6 to your computer and use it in GitHub Desktop.
oi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Puck; | |
import robocode.*; | |
//import java.awt.Color; | |
public class Tkovs extends AdvancedRobot | |
{ | |
public int strategia; | |
public double life; | |
public void run() { | |
strategia = 1; | |
while (true) { | |
life = getLife(); | |
// Faz a paradinha lá | |
if (strategia == 1) { | |
setAhead(50); | |
setTurnGunRight(180); | |
} else if (strategia == 2) { | |
setAhead(50); | |
setTurnRight(10); | |
setTurnGunRight(50); | |
} | |
// Coisa interessante | |
if (life > 50) { | |
strategia = 1; | |
} else { | |
strategia = 2; | |
} | |
execute(); | |
} | |
} | |
// Se houver contato robótico sensual | |
public void onHitRobot(HitRobotEvent e) { | |
clearAllEvents(); | |
if (e.getBearing() > -90 && e.getBearing() <= 90) { | |
setBack(50); | |
} else { | |
setAhead(50); | |
} | |
execute(); | |
} | |
public void onHitByBullet(HitByBulletEvent event) { | |
clearAllEvents(); | |
setBack(30); | |
execute(); | |
} | |
public void onScannedRobot(ScannedRobotEvent e) { | |
double distance = e.getDistance(); | |
double life = getLife(); | |
if (life < 30) { | |
if (distance < 150) { | |
if (getGunHeat() == 0) { | |
setFire(Rules.MAX_BULLET_POWER); | |
} | |
} | |
} | |
else { | |
if (distance < 300) { | |
if (getGunHeat() == 0) { | |
setFire(Rules.MAX_BULLET_POWER); | |
} | |
else { | |
setFire(Rules.MAX_BULLET_POWER / 2); | |
} | |
} else { | |
setFire(1); | |
} | |
} | |
} | |
public void onWin(WinEvent e) { | |
// playDota(); | |
} | |
public void onHitWall(HitWallEvent e) { | |
clearAllEvents(); | |
if (strategia == 1) { | |
setTurnRight(40); | |
execute(); | |
} else if (strategia == 2) { | |
double angle = e.getBearing(); | |
if (angle > -90 && angle <= 90) { | |
setBack(200); | |
execute(); | |
} else { | |
setAhead(200); | |
execute(); | |
} | |
execute(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment