Assignment 1: Advanced Programming
Assignment 1: Advanced Programming
Advanced Programming
Gautam Kumar
1
PotatoKarel
SkylineKarel
2
}
if (frontIsBlocked() && leftIsClear()) {
turnLeft();
}
else if (frontIsBlocked()) {
turnAround();
}
move();
}
}
private void jumpHurdle() {
turnRight();
move();
turnRight();
}
LumberjackKarel
public class LumberjackKarel extends SuperKarel {
public void run() {
turnLeft();
while (frontIsClear()) {
move();
}
turnRight();
while (leftIsBlocked()) {
if (noBeepersPresent()) {
putBeeper();
}
move();
if (leftIsBlocked() && noBeepersPresent()) {
putBeeper();
}
turnAround();
move();
while (beepersPresent()) {
pickBeeper();
turnAround();
move();
putBeeper();
turnAround();
move();
}
turnAround();
move();
}
}
AriadneKarel
public class AriadneKarel extends SuperKarel {
public void run() {
scan();
turnRight();
moveDown();
private void moveDown() {
scan();
moveOver();
}
private void moveOver() {
turnRight();
pickBeeper();
move();
turnLeftScan();
turnLeft();
for(int i=0;i<2;i++)
{
pickBeeper();
move();
}
pickBeeper();
turnLeft();
move();
pickBeeper();
turnRightMove();
pickBeeper();
turnLeft();
for(int i=0;i<2;i++)
{
move();
pickBeeper();
}
turnRightMove();
turnRightScan();
turnLeftScan();
pickBeeper();
private void scan(){
while(frontIsClear())
{
if(beepersPresent()){
pickBeeper();
}
move();
}
}
private void turnLeftScan(){
turnLeft();
scan();
}
private void turnRightScan(){
turnRight();
scan();
}
private void turnRightMove(){
turnRight();
4
move();
}
EggHuntKarel
public class EggHuntKarel extends SuperKarel {
public void run() {
move();
turnLeftScanMove();
pickBeeper();
turnRightMove();
turnRightMove();
pickBeeper();
turnRight();
scan();
turnLeftScanMove();
turnAround();
turnRightMove();
pickBeeper();
turnRightMove();
pickBeeper();
checkBeeper();
turnRightMove();
turnRight();
scan();
turnLeftScanMove();
move();
pickBeeper();
turnAround();
scan();
turnLeftScanMove();
move();
pickBeeper();
turnLeftMove();
turnRight();
checkBeeper();
turnRightMove();
move();
turnRightMove();
pickBeeper();
move();
}
private void scan() {
for (int i = 0; i < 3; i++) {
move();
}
}
/* to check if front is clear and to pick beeper */
private void checkBeeper() {
while (frontIsClear()) {
move();
}
if (beepersPresent()) {
pickBeeper();
}
}
/* to turn right and to move */
private void turnRightMove(){
turnRight();
move();
}
/* to turn Left and to move */
5
private void turnLeftMove(){
turnLeft();
move();
}
/* to turn Left and to scan */
private void turnLeftScan(){
turnLeft();
scan();
}
/* to turn Left and to move and scan*/
private void turnLeftScanMove(){
turnLeftScan();
turnLeftMove();
}