Sie sind auf Seite 1von 19

Mr.

MAMPAN SANGSA

ID: 50052535

1)

Code

import stanford.karel.Karel;

/**

*/

/**

* @author 50052535
*

*/

public class SeasideKarel extends Karel {

/**

* @param args

*/

public void run() {

turnLeft();

putBeeper();

while (frontIsClear()) {

move();

if (noBeepersPresent()) {

putBeeper();

turnRight();

for (int i = 0; i < 4; i++) {

move();

turnRight();
putBeeper();

while (frontIsClear()) {

move();

if (noBeepersPresent()) {

putBeeper();

turnLeft();

for (int i = 0; i < 4; i++) {

move();

turnLeft();

putBeeper();

while (frontIsClear()) {

move();

if (noBeepersPresent()) {

putBeeper();

turnRight();

for (int i = 0; i < 4; i++) {


move();

turnRight();

while (frontIsClear()) {

move();

if (noBeepersPresent()) {

putBeeper();

turnLeft();

public void turnRight() {

turnLeft();

turnLeft();

turnLeft();

}
ขันตอนต่
้ อไป
2)

โค้ ด

import stanford.karel.Karel;

/**

*/

/**
* @author 50052535

*/

public class RuknongKarel extends Karel {

/**

* @param args

*/

public void run() {

move();

for (int i = 0; i < 5; i++) {

pickBeeper();

fillPothole();

public void fillPothole() {

move();

turnRight();

move();
putBeeper();

turnAround();

move();

turnRight();

move();

public void turnRight() {

turnLeft();

turnLeft();

turnLeft();

public void turnAround() {

turnLeft();

turnLeft();

}
ขันตอนต่
้ อไป
3)

โค้ ด

import stanford.karel.Karel;

/**

*/
/**

* @author 50052535

*/

public class BlueKarel extends Karel {

/**

* @param args

*/

public void run() {

while (frontIsClear()) {

move();

if (noBeepersPresent()) {

if (beepersInBag()) {

putBeeper();

if (frontIsBlocked()) {

turnLeft();
}

ขันตอนต่
้ อไป

4)
Code

import stanford.karel.Karel;

/**

*/

/**

* @author 50052535

*/

public class SanookKarel extends Karel {


/**

* @param args

*/

public void run() {

for (int i = 0; i < 7; i++) {

claimUp();

move();

move();

move();

for (int i = 0; i < 5; i++) {

jumpUp();

putBeeper();

move();

for (int i = 0; i < 5; i++) {

jumpDown();

move();
move();

for (int i = 0; i < 7; i++) {

claimDown();

move();

move();

public void claimUp() {

while (frontIsClear()) {

move();

putBeeper();

turnAround();

move();

turnRight();

move();

turnRight();

}
public void turnRight() {

turnLeft();

turnLeft();

turnLeft();

public void turnAround() {

turnLeft();

turnLeft();

public void jumpUp() {

turnLeft();

move();

turnRight();

move();

public void jumpDown() {

turnRight();
move();

turnLeft();

move();

public void claimDown() {

turnRight();

move();

turnRight();

move();

putBeeper();

turnAround();

move();

ขันตอนต่
้ อไป
5)

โค้ ด

import stanford.karel.Karel;

/**

*/

/**

* @author 50052535
*

*/

public class HappyKarel extends Karel {

/**

* @param args

*/

public void run() {

for (int i = 0; i < 28; i++) {

move();

claimUp();

claimDown();

public void claimUp() {

if (frontIsBlocked()) {

if (rightIsBlocked()) {

turnLeft();

}
}

public void claimDown() {

if (rightIsClear()) {

putBeeper();

move();

putBeeper();

turnRight();

move();

putBeeper();

turnRight();

move();

putBeeper();

public void turnRight() {

turnLeft();
turnLeft();

turnLeft();

ขันต่
้ อนต่อไป

Das könnte Ihnen auch gefallen