Tutorial Robocode
Tutorial Robocode
JOGOS DE COMBATE ?
Guerreiros sarados e
musculosos ?
Ferozes e Belicosas
criaturas se aniquilando em
um ambiente
completamente hostil?
Agora podemos brincar
O que é Robocode ?
Benefícios do
Robocode …
• OO
• Threading • Eventos
• Packaging • Inner classes
• Herança • Java docs
• Polimorfismo • How to duck…
• Código API
Você ainda não ficou
interessado em aprender
Robocode ???
Trabalhe
em equipe
• Você cria e outros
usam seus Robots
• Troca de idéas &
• Você pode participar
técnicas
de um time
• Participar de ligas
• Já Existem
internacionais
Excelentes times
E agora ficou interessado
em aprender
Robocode ???
Instalação e pré-requisitos …
Java VM 1.3.x ou superior
Instalação no Windows
São necessários três exaustivos passos ….
– Entre no site robocode.alphaworks.ibm.com
- Faça o download
- Execute robocode-setup.jar (autosetup)
Instalação no Linux
Apenas um ÚNICO passo ….
No site robocode.alphaworks.ibm.com faça
download & rode …
java –jar robocode-setup.jar
O que você tem …
Precisamos da … AdvancedRobot
AdvancedRobot
while (round is not over) do
call the rendering subsystem to draw robots, bullets, explosions
for each robot do
wake up the robot
wait for it to make a blocking call, up to a max time interval
end for
clear all robot event queue
move bullets, and generate event into robots' event queue if applicable
move robots, and generate event into robots' event queue if applicable
do battle housekeeping and generate event into robots' event queue
if applicable
delay for frame rate if necessary
end do
Herdando a Classe
AdvancedRobot
• Chamadas a API não bloqueadas.
• Podemos mudar a ação de um robot.
• Um turno em Robocode é chamado tick (se
refere ao clock), um gráfico relacionado pode
ser chamado pelo battlefield.
Métodos da Robot vs
AdvancedRobot
Robot: AdvancedRobot:
•turnRight() •setTurnRight()
•turnLeft() •setTurnLeft()
•turnGunRight() •setTurnGunRight()
•turnGunLeft() •setTurnGunLeft()
•turnRadarRight() •setTurnRadarRight()
•turnRadarLeft() •setTurnRadarLeft()
•ahead() •setAhead()
•back() •setback()
Working with non-
blocking method calls
public class MultiMoveBot extends AdvancedRobot {
...
public void run() {
...
setTurnRight(fullTurn);
setAhead(veryFar);
setTurnGunLeft(fullTurn);
Para executar um
Método
Para obter um controle de um método que foi
bloqueado:
while(true) {
waitFor(new TurnCompleteCondition(this));
toggleDirection();
}
The toggleDirection()
method
private void toggleDirection() {
if (clockwise) {
setTurnLeft(fullTurn);
setBack(veryFar);
setTurnGunRight(fullTurn);
} else {
setTurnRight(fullTurn);
setAhead(veryFar);
setTurnGunLeft(fullTurn);
}
clockwise = !clockwise;
}
Customizando
Eventos …
public void run() {
addCustomEvent(
new Condition("LeftLimit") {
public boolean test() {
return (getHeading() <= quarterTurn);
}
});
addCustomEvent(
new Condition("RightLimit") {
public boolean test() {
return (getHeading() >= threeQuarterTurn);
}
});
}
Chamada do Evento
Customizados
public void onCustomEvent(CustomEvent ev) {
Condition cd = ev.getCondition();
System.out.println("-> " + cd.getName());
if (cd.getName().equals("RightLimit")) {
setTurnLeft(fullTurn);
setTurnGunRight(fullTurn);
} else {
setTurnRight(fullTurn);
setTurnGunLeft(fullTurn);
}
}
Chaves de Sucesso