645 Checkerboard Karel Answer Verified

6.4.5: Checkerboard Karel , you must program Karel to place beepers in a checkerboard pattern across any rectangular world, regardless of size. Logic for a Robust Solution

(frontIsClear()) move(); paintRow(); // Paint the final row /* * Paints a single row with alternating colors. */ paintRow()

The "Two Beepers" Bug: Does Karel ever place two beepers next to each other at the start of a new row?

paint(Color.red);

void fillRowAlternate() // Move across the row placing beepers every other square. while (frontIsClear()) move(); if (!beepersPresent()) // Only place on every other square: if the square behind has a beeper, skip; else put. if (!beepersPresentBehind()) putBeeper();

and you can choose to follow the rest of the videos in order if you like however if not.. YouTube·Tiffany Arielle Solution to Karel the Robot Assignment 1: Problem 3

fillRow(): Places beepers in alternating corners while moving toward a wall.

If no beeper is at the end: Karel moves up and places a beeper immediately. 3. Generalize for Any World Size

Powered by Dhru Fusion [Lite Plus]]