916 Checkerboard V1 Codehs Fixed
Place an if (frontIsClear()) check directly before the second move() command inside your row functions. 3. Infinite Loops at the Ceiling
If you see white lines between your squares, ensure you are calculating SQUARE_SIZE using getWidth() / 8 . If you hardcode a number like 50 on a canvas that isn't exactly 400 , the grid won't fit perfectly. 2. Rectangles Overlapping the Border
A checkerboard pattern relies on the coordinates of the grid. For any cell located at row i and column j : Add the row index and the column index together ( i + j ). If the sum is , the cell gets a 0 . If the sum is odd , the cell gets a 1 .
var board = []; for (var i = 0; i < 8; i++) board[i] = []; for (var j = 0; j < 8; j++) if ((i + j) % 2 === 0) board[i][j] = "black"; else board[i][j] = "white"; 916 checkerboard v1 codehs fixed
The most efficient way to determine the color of a square is by checking the sum of its coordinates:
(frontIsClear()) move(); putBall();
Always insert your row-ending actions (like a line break or moving a turtle graphics pointer down) outside the inner column loop, but inside the outer row loop. Alternative Karel / JavaScript Implementation Note Place an if (frontIsClear()) check directly before the
. If you just print strings or append a row of ones, you'll likely see errors like: "You should set some elements of your board to 1" "You will need to use an assignment statement"
: Solid rows or columns of the same color instead of alternating pattern.
In this assignment, your goal is to build the initial framework for a checkers game board. The program's task is to create an 8x8 grid where the number 1 represents a checker piece and 0 represents an empty square. If you hardcode a number like 50 on
Many students fail this one because they try to "shortcut" the board creation by appending pre-made lists. Here’s how to fix your code so it passes every test case. The Problem: Why Your Code Isn't Passing The autograder for this exercise specifically checks for assignment statements
You’re usually asked to create a checkerboard pattern (alternating black and red squares) using a graphics library (like graphics.py or JavaScript’s Graphics in CodeHS).