Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 21 of 21

Thread: Robo Code - The funny Java Programming Game

  1. #1
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Robo Code - The funny Java Programming Game

    Well, Robocode is a game based on live combat between robots. It was developed by IBM to inspire upcoming Java programmers, and persuade them that Java can be fun. So I thought I'd have a look see what it's all about. I'll have a look later when i can get home, once I can if people are interested in this then there is the chance to program your own robots, and I will run the competitions and record all the results.

    So who fancies joining in and programming some robots?

    Robocode Home

    Bit of fun

    Chris


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Thumbs up Re: Robo Code - The funny Java Programming Game

    This looks cool! I've never seen this before!! Count me in

    I'll take a better look when I'm at home too tonight.

    A Java Programming Forums robot would be fun!!
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Robo Code - The funny Java Programming Game

    I have just started installing everything for Eclipse using this tutorial:

    Robocode/Developers Guide for building Robocode - RoboWiki

    Gets the brain cells working! I'm going to set this up again when I get home. I'm looking forward to playing with it.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  4. #4
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Robo Code - The funny Java Programming Game

    If we can get 4 people interested in this, then we could do a team battle where by 2v2 and then you create a team of robots between you? and limit the number of robots to the team to a max of 4, so it would be 4 robots vs 4 robots. But deleoped by 2v2 if that makes sense

    Chris

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Robo Code - The funny Java Programming Game

    ooh! i'd like to do that! I think one of our classes had us do stuff with robo code, but then the class ended and we never did anything.

  6. #6
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Robo Code - The funny Java Programming Game

    Well thats 3 if JavaPF is still up for it give him something to do when he's board at work lol!

    Chris

  7. #7
    Member
    Join Date
    Aug 2009
    Posts
    53
    Thanks
    2
    Thanked 3 Times in 2 Posts

    Default Re: Robo Code - The funny Java Programming Game

    Seems promising. Will check this out

  8. #8
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Robo Code - The funny Java Programming Game

    Glad you are interested Hopefully it will get somewhere. I have an idea for a team, just need someone to help me put it together muhahaha I have a few ideas actually lol!

    Chris

  9. #9
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Robo Code - The funny Java Programming Game

    hehe, now to set it up... dang, that's a long process

    edit:

    So, Robocode let's you set up a team of robots for competition, not just one. I think if we got a few more people together, we could have our own little tourney
    Last edited by helloworld922; August 12th, 2009 at 08:39 PM.

  10. #10
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Robo Code - The funny Java Programming Game

    lol by that do you mean setting it up to run with Eclipse? cause if not then its really simple hehe xD

    But yes you can do team robots, I haven't attempted as my robots are still pathetic lol! So team is just out of the window for now.

    Chris

  11. #11
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Robo Code - The funny Java Programming Game

    I'm in! I well want to get this going guys. Hopefully get Eclipse setup properly asap
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  12. #12
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Robo Code - The funny Java Programming Game

    Awsome! Then i think we have 4!!! Which could make this fun, Eclipse doesn't take long to setup took me about 3 mins

    I vote team picking hehe

    Chris

  13. #13
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Robo Code - The funny Java Programming Game

    Hehe, I might have a look at this later, looks cool

    // Json

  14. #14
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Robo Code - The funny Java Programming Game

    oooh more people

    This could turn out quite nicely. Now I just need to learn Java and how to make my bot good and I can be a contender!

    Chris

  15. #15
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Robo Code - The funny Java Programming Game

    LOL @ now I just need to learn Java
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  16. #16
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Robo Code - The funny Java Programming Game

    Hehe. There are a few notes that may be helpful to you guys when setting up eclipse:

    Java SDK 6 seems to work perfectly fine (they say you must use Java SDK 5). I did get a bunch of errors in the other projects, but I don't think they're used cause I can run the program no problem. (All the errors were library missing errors)

    You can create a new project in Eclipse and use that to program your robots (the Robocode Editor is quite poor). It will ask you if you want to link different projects into the build path, say yes (or, manually add robocode.api).

    I haven't figured out how Robocode packages the JAR files yet, but for now you can code in Eclipse, then copy/paste into the Robocode Editor.

  17. #17
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Robo Code - The funny Java Programming Game

    if you go to the robocode wiki, it tells you how to set it all up. So you can fully code and compile in Eclipse. Then click run to lunch robo code, and you set the extra location for the robots you make in Eclipse, then you can just add them into battles easily.

    Chris

  18. #18
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Robo Code - The funny Java Programming Game

    Well just to get the ball rolling, here is a random robot lol! Normally loses, but its different and shows a few things that you can do I guess.

    package cjsmith;
     
    import robocode.AdvancedRobot;
    import robocode.HitRobotEvent;
    import robocode.ScannedRobotEvent;
     
    public class RandomJoe extends AdvancedRobot {
    	public void run(){
    		turnRight(90-getHeading());
    		ahead(getBattleFieldWidth()/2 - (getX()-50));
    		turnLeft(90);
    		ahead(getBattleFieldHeight()/2 - (getY()-50));
    		while(true){
    			setAhead(50);
    			setTurnLeft(50);
    			setTurnGunRight(180);
    			execute();
    		}
    	}
     
    	public void onScannedRobot(ScannedRobotEvent sre){
    		stop();
    		if(sre.getDistance() < 100) fire(3);
    		if(sre.getDistance() < 200) fire(2);
    		else fire(1);
    		resume();
    	}
     
    	public void onHitRobot(HitRobotEvent hre){
    		turnRight(90-getHeading());
    		ahead(getBattleFieldWidth()/2 - (getX()-50));
    		turnLeft(90);
    		ahead(getBattleFieldHeight()/2 - (getY()-50));
    	}
    }

  19. #19
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Robo Code - The funny Java Programming Game

    Ok, here's what i did to install:
    1. Install Java JDK (5 or newer)
    2. Go here and download the latest robocode installer
    3. Run the .jar file you downloaded and choose a place to install (ex: C:/Program Files/Robocode)
    4. Start-up Eclipse. Follow these instructions for setting up Eclipse (i find this order works the best): *Note: This is a little different than the order they have on their website!
    4a. Robocode/Eclipse/Create a Project - RoboWiki
    4b. Robocode/Eclipse/Create a Robot - RoboWiki
    4c. Robocode/Eclipse/Debugging Robot - RoboWiki
    4c. Robocode/Add a Robot Project - RoboWiki

    Have fun!
    Last edited by helloworld922; August 14th, 2009 at 08:14 PM.

  20. #20
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Robo Code - The funny Java Programming Game

    Here's my second attempt at a robot. (my first was a test bot) Still working on making the targeting account for movement

    public class Captain extends TeamRobot
    {
        boolean targeting;
        double  trackingX;
        double  trackingY;
     
        public void run ()
        {
            // initialize
            this.setAdjustGunForRobotTurn(true);
            this.setAdjustRadarForGunTurn(true);
            this.setAdjustRadarForRobotTurn(true);
            this.turnTo(0);
            double direction = Math.PI;
            targeting = false;
            int count = 0;
            while (true)
            {
                // scan for a robot
                count++;
                if (!targeting)
                {
                    this.turnRadarLeft(Rules.RADAR_TURN_RATE);
                }
                else
                {
                    if (count > 10)
                    {
                        count = 0;
                        targeting = false;
                        continue;
                    }
                    this.scanRegion(trackingX, trackingY, Rules.RADAR_TURN_RATE_RADIANS);
                }
            }
        }
     
        /**
         * Track a robot and broadcast it's location to allies
         * 
         * @param e
         */
        public void trackRobot (ScannedRobotEvent e)
        {
            // calculate x,y coord of robot being tracked
            // broadcast name, heading, (x,y), and velocity of robot
            // update radar
            targeting = true;
            System.out.println("Tracking " + e.getName());
            // calculate their x,y
            double ourHeading = Math.PI / 2 - this.getHeadingRadians();
            double theirHeading = Math.PI / 2 - this.getHeadingRadians() - e.getBearingRadians();
            trackingX = this.getX() + e.getDistance() * Math.cos(theirHeading);
            trackingY = this.getY() + e.getDistance() * Math.sin(theirHeading);
            System.out.println("They are at (" + trackingX + " , " + trackingY + ")");
            System.out.println("Our bearing is " + 180 * ourHeading / Math.PI);
            System.out.println("Their bearing rel. is " + e.getBearing());
            System.out.println("Their bearing is " + 180 * theirHeading / Math.PI);
            System.out.println("Turning gun to fire...");
            this.turnGunToRadians(-theirHeading + Math.PI / 2);
            this.fire(1);
        }
     
        public void onScannedRobot (ScannedRobotEvent e)
        {
            trackRobot(e);
        }
     
        /**
         * Turns the robot to a specific global degree
         * 
         * @param deg
         */
        public void turnTo (double deg)
        {
            while (deg >= 360)
            {
                deg -= 360;
            }
            while (deg < 0)
            {
                deg += 360;
            }
            double heading = this.getHeading();
            if (deg - heading > 180)
            {
                // need to turn CW
                this.turnRight(360 - deg - heading);
            }
            else
            {
                // need to turn CCW
                this.turnLeft(heading - deg);
            }
        }
     
        /**
         * Turns the robot to a specific global radian
         * 
         * @param rad
         */
        public void turnToRadians (double rad)
        {
            while (rad >= 2 * Math.PI)
            {
                rad -= 2 * Math.PI;
            }
            while (rad < 0)
            {
                rad += 2 * Math.PI;
            }
            double heading = this.getHeadingRadians();
            if (rad - heading > Math.PI)
            {
                // need to turn CW
                this.turnRightRadians(2 * Math.PI - rad - heading);
            }
            else
            {
                // need to turn CCW
                this.turnLeftRadians(heading - rad);
            }
        }
     
        /**
         * Scans a region with point (x,y) at the center. Maximum region radius is PI, minimum is 0
         * 
         * @param x
         * @param y
         * @param arcRad
         */
        public void scanRegion (double x, double y, double arcRad)
        {
            if (arcRad > Math.PI)
            {
                arcRad = .95 * Math.PI;
            }
            if (arcRad < 0)
            {
                arcRad = 0;
            }
            double mid;
            if (x * y > 0)
            {
                mid = Math.atan((this.getX() - x) / (this.getY() - y));
            }
            else
            {
                mid = Math.atan((x - this.getX()) / (y - this.getY()));
            }
            turnRadarToRadians(mid + Math.PI - arcRad / 2);
            turnRadarToRadians(mid + +Math.PI + arcRad / 2);
        }
     
        /**
         * Turns the radar to a specific global position
         * 
         * @param rad
         */
        public void turnRadarToRadians (double rad)
        {
            while (rad >= 2 * Math.PI)
            {
                rad -= (2 * Math.PI);
            }
            while (rad < 0)
            {
                rad += (2 * Math.PI);
            }
            double heading = this.getRadarHeadingRadians();
            if (rad - heading > Math.PI)
            {
                // need to turn CW
                this.turnRadarRightRadians(2 * Math.PI - rad - heading);
            }
            else
            {
                // need to turn CCW
                this.turnRadarLeftRadians(heading - rad);
            }
        }
     
        /**
         * Turns the gun to a specific global position
         * 
         * @param deg
         */
        public void turnGunTo (double deg)
        {
            while (deg >= 360)
            {
                deg -= 360;
            }
            while (deg < 0)
            {
                deg += 360;
            }
            double heading = this.getGunHeading();
            if (deg - heading > Math.PI)
            {
                // need to turn CW
                this.turnGunRight(360 - deg - heading);
            }
            else
            {
                // need to turn CCW
                this.turnGunLeft(heading - deg);
            }
        }
     
        /**
         * Turns the gun to a specific global position
         * 
         * @param rad
         */
        public void turnGunToRadians (double rad)
        {
            while (rad >= 2 * Math.PI)
            {
                rad -= (2 * Math.PI);
            }
            while (rad < 0)
            {
                rad += (2 * Math.PI);
            }
            double heading = this.getGunHeadingRadians();
            if (rad - heading > Math.PI)
            {
                // need to turn CW
                this.turnGunRightRadians(2 * Math.PI - rad - heading);
            }
            else
            {
                // need to turn CCW
                this.turnGunLeftRadians(heading - rad);
            }
        }
    }

  21. #21
    Junior Member
    Join Date
    Sep 2009
    Location
    Romania
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Smile Re: Robo Code - The funny Java Programming Game

    Sounds cool, I was actually looking for such games.

    But now... I don`t know if I know enough Java...

    I`ll try it anyway ...



    At last ! A cool game, which is not time-wasting !
    System.out.println(Signature.getSignature());

Similar Threads

  1. Programmer for a Java based game project
    By Takkun in forum Project Collaboration
    Replies: 4
    Last Post: June 14th, 2010, 05:47 PM
  2. How to change html data into excel in java?
    By rgupta31 in forum File I/O & Other I/O Streams
    Replies: 14
    Last Post: May 29th, 2009, 10:43 AM
  3. Hello java programming forums
    By DnB in forum Member Introductions
    Replies: 2
    Last Post: February 9th, 2009, 07:38 AM
  4. How to make java based animation?
    By JavaPF in forum The Cafe
    Replies: 1
    Last Post: June 7th, 2008, 06:55 AM