package Kaja.sandbox.sandbox; /*Generated by MPS */ import JavaKaja.runtime.KajaFrame; import JavaKaja.runtime.Direction; public class MarkSniffer extends KajaFrame { public MarkSniffer() { } protected void perform() { // Searches for a mark on a custom playground, using a very primitive strategy buildSimplePlayground_from_library_PlaygroundDefinition_routine(); trace("Playground is ready."); searchForMark_routine(); trace("Found a mark!"); } public void safeStep_routine() { if (!(isWall())) { if (canMove()) { moveKaja(); pause(); } else { reportError("Oops, There's a wall in front of me. I can't make a step forward."); } } else { turnRight_from_library_Common_routine(); } } public void searchForMark_routine() { if (isMark()) { pickAll_from_library_Filling_routine(); while (!(heading(Direction.west))) { try { turnLeft(); pause(); } finally { } } } else { safeStep_routine(); searchForMark_routine(); } } public void buildSimplePlayground_from_library_PlaygroundDefinition_routine() { if (isAllowedRow(1) && isAllowedCol(4)) { addWall(1, 4); minipause(); } else { reportError("Attempted to build wall outside of the playground!"); } if (isAllowedRow(2) && isAllowedCol(4)) { addWall(2, 4); minipause(); } else { reportError("Attempted to build wall outside of the playground!"); } if (isAllowedRow(4) && isAllowedCol(3)) { if (!(isFull(4, 3))) { addMark(4, 3); minipause(); } else { reportError("Cannot drop. The cell is already full."); return; } } else { reportError("Attempted to drop marks outside of the playground!"); } } public void buildMaze_from_library_PlaygroundDefinition_routine() { if (isAllowedRow(4) && isAllowedCol(1)) { addWall(4, 1); minipause(); } else { reportError("Attempted to build wall outside of the playground!"); } if (isAllowedRow(4) && isAllowedCol(2)) { addWall(4, 2); minipause(); } else { reportError("Attempted to build wall outside of the playground!"); } if (isAllowedRow(4) && isAllowedCol(4)) { addWall(4, 4); minipause(); } else { reportError("Attempted to build wall outside of the playground!"); } if (isAllowedRow(4) && isAllowedCol(5)) { addWall(4, 5); minipause(); } else { reportError("Attempted to build wall outside of the playground!"); } if (isAllowedRow(5) && isAllowedCol(5)) { addWall(5, 5); minipause(); } else { reportError("Attempted to build wall outside of the playground!"); } if (isAllowedRow(6) && isAllowedCol(5)) { addWall(6, 5); minipause(); } else { reportError("Attempted to build wall outside of the playground!"); } if (isAllowedRow(7) && isAllowedCol(5)) { addWall(7, 5); minipause(); } else { reportError("Attempted to build wall outside of the playground!"); } if (isAllowedRow(8) && isAllowedCol(5)) { addWall(8, 5); minipause(); } else { reportError("Attempted to build wall outside of the playground!"); } if (isAllowedRow(8) && isAllowedCol(4)) { addWall(8, 4); minipause(); } else { reportError("Attempted to build wall outside of the playground!"); } if (isAllowedRow(8) && isAllowedCol(3)) { addWall(8, 3); minipause(); } else { reportError("Attempted to build wall outside of the playground!"); } if (isAllowedRow(8) && isAllowedCol(2)) { addWall(8, 2); minipause(); } else { reportError("Attempted to build wall outside of the playground!"); } if (isAllowedRow(8) && isAllowedCol(1)) { addWall(8, 1); minipause(); } else { reportError("Attempted to build wall outside of the playground!"); } if (isAllowedRow(5) && isAllowedCol(1)) { if (!(isFull(5, 1))) { addMark(5, 1); minipause(); } else { reportError("Cannot drop. The cell is already full."); return; } } else { reportError("Attempted to drop marks outside of the playground!"); } } public void turnRight_from_library_Common_routine() { for (int indexVariable_ormfpz_a0e = 0; indexVariable_ormfpz_a0e < 3; indexVariable_ormfpz_a0e++) { try { turnLeft(); pause(); } finally { } } } public void turnAround_from_library_Common_routine() { try { turnLeft(); pause(); } finally { } try { turnLeft(); pause(); } finally { } } public void fetch_from_library_Common_routine() { if (isMark()) { if (isMark()) { removeMark(); pause(); } else { reportError("Nothing to pick. The cell is empty."); } turnAround_from_library_Common_routine(); } else { if (canMove()) { moveKaja(); pause(); } else { reportError("Oops, There's a wall in front of me. I can't make a step forward."); } fetch_from_library_Common_routine(); if (canMove()) { moveKaja(); pause(); } else { reportError("Oops, There's a wall in front of me. I can't make a step forward."); } } } public void fillup_from_library_Filling_routine() { while (!(isFull())) { if (!(isFull())) { addMark(); pause(); } else { reportError("Cannot drop. The cell is already full."); } } } public void pickAll_from_library_Filling_routine() { while (isMark()) { if (isMark()) { removeMark(); pause(); } else { reportError("Nothing to pick. The cell is empty."); } } } public static void main(String[] args) { MarkSniffer script = new MarkSniffer(); script.initializeComponents(); script.run(); } }