// This program has Karel paint a checkerboard with 8 rows and 8 columns.
function main() {
// Karel starts in the bottom left corner of the world
turnLeft();
// Karel will move up the left side of the world
for (var i = 0; i < 8; i++) {
paintRow();
move();
}
// Karel will move to the top right corner of the world
turnRight();
for (var i = 0; i < 8; i++) {
move();
}
// Karel will move down the right side of the world
turnRight();
for (var i = 0; i < 8; i++) {
paintRow();
move();
}
// Karel will move to the bottom left corner of the world
turnLeft();
for (var i = 0; i < 8; i++) {
move();
}
}
// This function has Karel paint a row of alternating black and white squares
function paintRow() {
for (var i = 0; i < 8; i++) {
paintSquare();
move();
}
turnAround();
for (var i = 0; i < 8; i++) {
move();
}
turnAround();
}
// This function has Karel paint a single square
function paintSquare() {
if (isFacingRight()) {
paint();
} else {
turnRight();
paint();
turnLeft();
}
}
Karel has gotten really into board games lately.
Karel wants to build a checkerboard so that he can play board games with the other dogs.
Write a program that has Karel paint a checkerboard. You can assume that the world will always have 8 rows and 8 columns.
HINT:
Rather than typing out every single move and paint command, think about how you can break this problem down into smaller problems that are repeated.
What functions could you write that would make this problem easier to solve?
2 answers
they need to add code tags to this site (use markdown?), but in any case this is freaking epic