NPS
2015-08-12 13:54:01 UTC
HI folks!
I'm developing a teambot where the teammates need to perform a random
movement until a message is received from the first robot that have found
the enemy (stationary). After that, all teammates need to turn toward the
enemy. For random movement, I used Crazy Bot algorithm. As we know, Crazy
robot uses waitFor method to block any call until an action is completed.
The problem here is that waaitFor method (from random movement) doesn't
allow them to stop and after turn. Instead of that, the robot turns the
angle I want while perfoming a random movement.
There is below some blocks with an example: the robot which received the
message needs to stop the current random movement and after turns its body
to any angle, 90 degrees,for example. Anyone has an idea to help me?
public void run() {
while (true) {
if (!foundGoal && !message_received)
{// Tell the game we will want to move ahead 40000 -- some large number
setAhead(40000);
setTurnRight(90);
waitFor(new TurnCompleteCondition(this));
setTurnLeft(180);
waitFor(new TurnCompleteCondition(this));
setTurnRight(180);
waitFor(new TurnCompleteCondition(this));
}
}
public void onScannedRobot(ScannedRobotEvent e) {
if(!isTeammate(e.getName()) && !message_received && !foundGoal)
{
foundGoal = true;
double angle = Math.toRadians((heading + bearing) % 360);
scannedX = getX() + Math.sin(angle) * distance;
scannedY = getY() + Math.cos(angle) * distance;
try{
broadcastMessage(scannedX+","+scannedY);
}catch(IOException c){
c.printStackTrace();
}
}
}
public void onMessageReceived(MessageEvent event)
{
message_received = true;
stop();
setTurnLeft(90);
}
I'm developing a teambot where the teammates need to perform a random
movement until a message is received from the first robot that have found
the enemy (stationary). After that, all teammates need to turn toward the
enemy. For random movement, I used Crazy Bot algorithm. As we know, Crazy
robot uses waitFor method to block any call until an action is completed.
The problem here is that waaitFor method (from random movement) doesn't
allow them to stop and after turn. Instead of that, the robot turns the
angle I want while perfoming a random movement.
There is below some blocks with an example: the robot which received the
message needs to stop the current random movement and after turns its body
to any angle, 90 degrees,for example. Anyone has an idea to help me?
public void run() {
while (true) {
if (!foundGoal && !message_received)
{// Tell the game we will want to move ahead 40000 -- some large number
setAhead(40000);
setTurnRight(90);
waitFor(new TurnCompleteCondition(this));
setTurnLeft(180);
waitFor(new TurnCompleteCondition(this));
setTurnRight(180);
waitFor(new TurnCompleteCondition(this));
}
}
public void onScannedRobot(ScannedRobotEvent e) {
if(!isTeammate(e.getName()) && !message_received && !foundGoal)
{
foundGoal = true;
double angle = Math.toRadians((heading + bearing) % 360);
scannedX = getX() + Math.sin(angle) * distance;
scannedY = getY() + Math.cos(angle) * distance;
try{
broadcastMessage(scannedX+","+scannedY);
}catch(IOException c){
c.printStackTrace();
}
}
}
public void onMessageReceived(MessageEvent event)
{
message_received = true;
stop();
setTurnLeft(90);
}
--
You received this message because you are subscribed to the Google Groups "robocode" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robocode+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "robocode" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robocode+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.