Onwards!

Tags

, , , , , , , , ,

So, now that robocode is largely finished what am I going to do with myself?!

Well, our mid term exams are starting next week so my focus has switched to them, and in the background I’m working on a review for the PS Vita game Wipeout 2048 for a new games news / reviews blog style site that a couple of guys at a forum I frequent have opened up. Interesting stuff!

Our Robot!

Tags

, , , ,

Here is the code to the robot we worked on. Fr Robo Komodo shall be missed =****(

 

 

package sf ;
import java.awt.Color ;
import robocode.* ;

public class FatherRoboKomodo extends Robot
{
boolean clockwise = false ;
long time = 0 ;

public void run ()
{
findNearestWall () ;
walls () ;
}

public void findNearestWall ()
{
double battleFieldWidth = getBattleFieldWidth () ;
double battleFieldHeight = getBattleFieldHeight () ;
double angleFacing = getHeading () ;
double xPos = getX () ;
double yPos = getY () ;
double distanceToLeftWall = xPos ;
double distanceToBottomWall = yPos ;
double distanceToRightWall = (battleFieldWidth – xPos) ;
double distanceToTopWall = (battleFieldHeight – yPos) ;
double [] distanceToWalls = { distanceToLeftWall , distanceToBottomWall , distanceToRightWall , distanceToTopWall } ;

if ( smallest ( distanceToWalls ) == distanceToLeftWall ) {

if ( angleFacing <= 90 ) {
turnLeft ( 90 + angleFacing ) ;
} else if ( angleFacing > 270 ) {
turnLeft ( angleFacing – 270 ) ;
} else if ( angleFacing < 270 && angleFacing > 90 ) {
turnRight ( 270 – angleFacing ) ;
}

} else if ( smallest ( distanceToWalls ) == distanceToBottomWall ) {

if ( angleFacing > 180 ) {
turnLeft ( angleFacing – 180 ) ;
} else if ( angleFacing < 180 ) {
turnRight ( 180 – angleFacing ) ;
}

} else if ( smallest ( distanceToWalls ) == distanceToRightWall ) {

if ( angleFacing < 90 ) {
turnRight ( 90 – angleFacing ) ;
} else if ( angleFacing >= 270 ) {
turnRight ( 360 – angleFacing + 90 ) ;
} else if ( angleFacing > 90 && angleFacing < 270 ) {
turnLeft ( angleFacing – 90 ) ;
}

} else if ( smallest ( distanceToWalls ) == distanceToTopWall ) {

if ( angleFacing < 180 ) {
turnLeft ( angleFacing ) ;
} else if ( angleFacing > 180 ) {
turnRight ( 360 – angleFacing ) ;
}

}
}

public void findFurthestWall ()
{

double sentryAllowance = ( getHeight () * 1.5 ) ;
double battleFieldWidth = getBattleFieldWidth () ;
double battleFieldHeight = getBattleFieldHeight () ;
double angleFacing = getHeading () ;
double xPos = getX () ;
double yPos = getY () ;
double distanceToLeftWall = xPos ;
double distanceToBottomWall = yPos ;
double distanceToRightWall = (battleFieldWidth – xPos) ;
double distanceToTopWall = (battleFieldHeight – yPos) ;
double [] distanceToWalls = { distanceToLeftWall , distanceToBottomWall , distanceToRightWall , distanceToTopWall } ;

if ( smallest ( distanceToWalls ) == distanceToLeftWall ) {

if ( angleFacing <= 90 ) {
turnLeft ( 90 + angleFacing ) ;
} else if ( angleFacing > 270 ) {
turnLeft ( angleFacing – 270 ) ;
} else if ( angleFacing < 270 && angleFacing > 90 ) {
turnRight ( 270 – angleFacing ) ;
}

back (battleFieldWidth – xPos – sentryAllowance) ;

} else if ( smallest ( distanceToWalls ) == distanceToBottomWall ) {

if ( angleFacing > 180 ) {
turnLeft ( angleFacing – 180 ) ;
} else if ( angleFacing < 180 ) {
turnRight ( 180 – angleFacing ) ;
}

back (battleFieldHeight – yPos – sentryAllowance) ;

} else if ( smallest ( distanceToWalls ) == distanceToRightWall ) {

if ( angleFacing < 90 ) {
turnRight ( 90 – angleFacing ) ;
} else if ( angleFacing >= 270 ) {
turnRight ( 360 – angleFacing + 90 ) ;
} else if ( angleFacing > 90 && angleFacing < 270 ) {
turnLeft ( angleFacing – 90 ) ;
}

back (xPos – sentryAllowance) ;

} else if ( smallest ( distanceToWalls ) == distanceToTopWall ) {

if ( angleFacing < 180 ) {
turnLeft ( angleFacing ) ;
} else if ( angleFacing > 180 ) {
turnRight ( 360 – angleFacing ) ;
}

back (yPos – sentryAllowance) ;

}
}

public void walls ()
{
double sentryAllowance = ( getHeight () * 1.5 ) ;
double battleFieldWidth = getBattleFieldWidth () ;
double battleFieldHeight = getBattleFieldHeight () ;
turnGunLeft (90) ;

while ( true ) {
double xPos = getX () ;
double yPos = getY () ;

if ( clockwise == true ) {

if ( getHeading () == 180 ) {

back ( battleFieldHeight – yPos – sentryAllowance ) ;
turnRight ( 90 ) ;

} else if ( getHeading () == 0 ) {

back ( yPos – sentryAllowance ) ;
turnRight ( 90 ) ;

} else if ( getHeading () == 270 ) {

back ( battleFieldWidth – xPos – sentryAllowance ) ;
turnRight ( 90 ) ;

} else if ( getHeading () == 90 ) {

back ( xPos – sentryAllowance ) ;
turnRight ( 90 ) ;

}

} else if ( clockwise == false ) {

if ( getHeading () == 0 ) {

ahead ( battleFieldHeight – yPos – sentryAllowance ) ;
turnLeft ( 90 ) ;

} else if ( getHeading () == 180 ) {

ahead ( yPos – sentryAllowance ) ;
turnLeft ( 90 ) ;

} else if ( getHeading () == 90 ) {

ahead ( battleFieldWidth – xPos – sentryAllowance ) ;
turnLeft ( 90 ) ;

} else if ( getHeading () == 270 ) {

ahead ( xPos – sentryAllowance ) ;
turnLeft ( 90 ) ;

}

}

changeColour () ;
}
} //walls

public void onHitRobot ( HitRobotEvent e )
{
stop() ;
findFurthestWall() ;

if ( clockwise == true ) {

clockwise = false ;

} else {

clockwise = true ;

}

}//hit robot

public void changeColour ()
{
setAllColors ( new Color ( ( (int) ( Math.random () * 256 ) ) , ( ( int ) ( Math.random () * 256 ) ) , ( ( int ) ( Math.random () * 256 ) ) ) ) ;
}//colour

public void onScannedRobot ( ScannedRobotEvent e )
{

double biggestFireDistance = Math.sqrt(getBattleFieldWidth()*getBattleFieldWidth() + getBattleFieldHeight()*getBattleFieldHeight()); //max firedistance = diagonal
double bulletPercentage = ( 100 – ( ( ( e.getDistance () ) / biggestFireDistance ) * 100 ) ) ;

fire ( Rules.MAX_BULLET_POWER * bulletPercentage / 100 ) ;
}//scan

public void onHitByBullet(HitByBulletEvent e)
{
if (e.getTime() > time + 30){

time = e.getTime() ;

if(getHeading()% 90 == 0) {//stops this from happening if turning

if(clockwise == false){

if (e.getBearing() >= 270 || e.getBearing() <= 90) {//if you are heading towards the direction of opponent who fired the bullet

stop () ;
findFurthestWall () ;
turnRight(90) ;
clockwise = true ;

}

}else{

if(e.getBearing() >= 90 && e.getBearing() <= 270) {//same as above, just in opposite direction

stop() ;
findFurthestWall () ;
turnRight(90) ;
clockwise = false ;

}

}

}

}
}

//————————————————–Some Calculation Methods————————————————–\\

public double smallest ( double [] numbers )
{

double smallest = numbers [0] ;

for ( int i = 0 ; i < numbers.length ; i++ ) {

if ( numbers [i] < smallest ) {
smallest = numbers [i] ;
}

}

return smallest ;
}
}

Internal Robocode Competition Results

Tags

, , ,

I mentioned that I was working on a robocode robot in my about page, well, the internal university competition was held on Tuesday at 7pm. Our robot did well, getting to the final but unfortunately falling at the final hurdle against a bot with a great targeting system.

It wasn’t completely done and dusted, however, as the winning robot was a one man team and the university wanted to have a three man team representing them. To decide who would join the winner and represent the University of Limerick at the games fleadh all of our losing bots were thrown into one battle, in which we were victorious (winning all ten rounds, may I add!).

As we are / were a group of three, two of our names were drawn out of a hat to join the winner at the games fleadh. Unfortunately I was the unlucky soul not to be drawn! Regardless, I will be helping out where I can with the robot in preparation for the competition and will probably travel to the games fleadh in support of the university.