Today you will start working on your own. We issue two challenges; one for Robocode and the other for Sonic Pi. For the next 8 days you will work on the challenge. You still can ask us questions using the known mechanisms. We also can coach you in private if you don’t want to give away any secrets.
You need to submit your code (Sonic Pi or Robocode) by midnight, April 19th. We will post instructions on exactly how to submit your work.
During next week we will continue to publish some code snippets both for Robocode and Sonic Pi. It is worth coming back to the site to get inspired!
Robocode Ultimate Challenge
We have coded 3 different robots together. Each new one more cunning and lethal than the previous. Now it is your turn to code a robot that will compete against robots coded by other kids in the Home Challenge.
Here is your ultimate Robocode challenge.
Think about what you want your robot to do, so you create requirements first:
- How about a wall sitter that moves to a wall and moves up and down the wall? At least you only must scan the 180 degrees in front of you and you cannot be attacked from behind.
- How about a bot that circles an enemy and constantly shoots at it?
- What about a bot that tries to race towards an enemy, increasing the power of its gun as it gets closer?
- Or one that tries to work out where an enemy is moving to and sends a bullet where it thinks the enemy is going to be?
Sonic Pi Ultimate Challenge
Now you know the basics of Sonic Pi it is time to compose your masterpiece. Time to make some amazing music of your own.
Here is your ultimate Sonic Pi challenge
You are challenged to create your own song:
- Think of what kind of song you want to make, is it a rock song? A dance track, rap? Something completely different?
- How many instruments will there be in your band?
- Will you have a bassline? Backing harmonies? What kind of drums will you use – A looped sample or your own creation?
- Maybe you want to record your own samples and use them? Maybe your family helps as background chorus. Maybe you can click your fingers or clap your hands and use that?
- Or use everyday objects or sounds to make music?
How do we change the Color
We had that question earlier today from someone else and put some notes on it here: http://swisscoderdojo.org/code-snippets
in short, you can put the following code in your run() method:
setColors(bodycolor, guncolor, radarcolor);
and your choice of colours are: black, blue, brown, gray, green, orange, purple, red, white yellow
How do I get to turn my Robot to the robot I scanned?
Very similar to how we did the Day3 robot.
Before we explain it, you can find all the variables and methods for your tank here: https://robocode.sourceforge.io/docs/robocode/robocode/JuniorRobot.html
To turn your tank towards a scanned enemy you must modify the the onScannedRobot() method and use the turnTo(degrees) method. There is a variable available to you called scannedAngle which is set to the direction (in degrees) that an enemy is scanned at. The scannedAngle variable is set right before the onScannedRobot() method is called, but it is reset as soon as your gun or your tank starts to turn. The reason this is important is that you want to turn your tank towards the enemy, and then make sure your gun is pointed towards the enemy after your tank is rotated. So you will have to create a local variable to store the scannedAngle so that you can turn both your tank and the gun towards the enemy. Here is what your onScannedRobot() method should look like:
public void onScannedRobot() {
int iScanAngle = scannedAngle;
turnTo(iScanAngle);
turnGunTo(iScanAngle);
}
Ive made a robot similar to RamFire. How do I keep the gun pointing at the Robot I fire and when it ‘runs’ away but put the gun back afterwards?
Predictive Aiming is tricky, but possible. You will have to abandon the JuniorRobot class and start extending the Robot class instead. There is a great tutorial online that deals with Predictive Aiming. Lesson 4 covers it, but here is the full series online:
Lesson 2 (battlefield)
Lesson 3 (scanning)
Lesson 4 (gun)
Lesson 5 (movement)
Also an interesting tutorial on IBMs developer site
IBM Robocode – tracking your opponent
How do I turn the gun back to the same angle as the wheels?
Hi Dillon
Check https://robocode.sourceforge.io/docs/robocode/robocode/JuniorRobot.html
bearGunTo(int angle)
Turns the gun to the specified angle (in degrees) relative to body of this robot.
Which means bearGunTo(0) turns the gun straight ahead.
I tried it but it said “The method bearGunTo(int) is undefined for the type TheEnd”
Are you using a JuniorRobot? The method is defined for JuniorRobot
turnGunTo(heading);
where do I send the robot?
Check this post on the website http://swisscoderdojo.org/2020-spring-home-challenge-submission-rules-and-judging-criteria
Also had sent e-mail this afternoon about it
public void onHitRobot(HitRobotEvent e) {
setTurnGunRight(getHeading() – getGunHeading() + e.getBearing());
if (e.getBearing() >= 0) {
turnDirection = 1;
} else {
turnDirection = -1;
}
turnRight(e.getBearing());
if (e.getEnergy() > 16) {
fire(3);
} else if (e.getEnergy() > 10) {
fire(3);
} else if (e.getEnergy() > 4) {
fire(3);
} else if (e.getEnergy() > 2) {
fire(3);
} else if (e.getEnergy() > .4) {
fire(3);
}
bearGunTo(0);
ahead(40); // Ram him again!
}
That is my onHitRobot
Dillon that method is part of the Robot class and not the JuniorRobot class. If you want me to look at your code, please email your java file to us at home.challenge@swisscoderdojo.org and also tell me in the email what you want your robot to do or what it is not doing for you and I will try and help.
I used advancedrobot
how do you put the sonic pie in a mp3 file or where you can send it to family
Hi Arjun
Sonic Pi doesn’t allow saving the file directly to mp3. But from within Sonic Pi you can click the rec (record) button top/middle, this saves the melody into a .wav file:
– hit the record button
– hit run (the melody plays and records at the same time)
– once the melody has stopped playing hit the rec button again – this will stop the recording and prompt you for a filename to save the file.
The file has filetype .wav, which plays on windows.
If you need an mp3 file you can convert it using windows media player or the open source program vlc (https://www.videolan.org/vlc/download-windows.html). There are also online converters available which do the job (you find these by doing a Google search); please check with your parents before using any of the online tools.
how many projects are we supposed to submit for the spring home challenge 2020?
Just one submission