645 Checkerboard Karel Answer - Verified

The 645 Checkerboard

/* This program makes Karel create a checkerboard pattern * of tennis balls in any size world. */ function start() // Start by laying the very first row putBallRow(); // Continue loop as long as Karel can move up to a new street while (frontIsClear()) if (facingEast()) transitionEastToWest(); else transitionWestToEast(); // Handles rows that start with a ball function putBallRow() putBall(); while (frontIsClear()) move(); if (frontIsClear()) move(); putBall(); // Handles rows that start with an empty space function skipBallRow() while (frontIsClear()) move(); putBall(); if (frontIsClear()) move(); // Turns left and transitions Karel up to face West function transitionEastToWest() if (ballsPresent()) turnLeft(); if (frontIsClear()) move(); turnLeft(); skipBallRow(); // If last row ended on a ball, next starts empty else turnLeft(); if (frontIsClear()) move(); turnLeft(); putBallRow(); // If last row ended empty, next starts with a ball // Turns right and transitions Karel up to face East function transitionWestToEast() if (ballsPresent()) turnRight(); if (frontIsClear()) move(); turnRight(); skipBallRow(); else turnRight(); if (frontIsClear()) move(); turnRight(); putBallRow(); // Turn Right Helper Function function turnRight() turnLeft(); turnLeft(); turnLeft(); Use code with caution. Why This Solution Passes Verification 645 checkerboard karel answer verified

Join our Telegram Channel
Join us on WhatsApp
Download Android App
Follow us on X (Twitter)