. Multiplying the current loop index by the square size gives the perfect starting point for each tile.
: The create_rectangle function requires the top-left coordinate and the bottom-right coordinate
function start(): turn off beeper auto-placement var row = 1 while (front is clear or left is clear): placeRow(row) if (front is clear): moveToNextRow() row++
The canvas is 400×400, but squares don't align perfectly. Fix: Calculate the window size dynamically from the square size and number of squares, as shown in the constants above.
rect.setColor(Color.BLACK);
Try implementing this yourself using the logic above. If you get stuck, ask your teacher or a classmate for help — working through the logic is how you learn best!
Used to detect if a sum of indices is even or odd ( ), which helps determine where to place a '1'.
So, why is the 9.1.6 Checkerboard V1 so important? This project holds significant value for several reasons:
// Loop through each row for (int row = 0; row < ROWS; row++) // Loop through each column in the current row for (int col = 0; col < COLUMNS; col++)
By checking if (r + c) is divisible by 2 using the modulo operator ( % ), you can cleanly alternate colors. Step-by-Step Code Implementation
if (frontIsClear()) move(); col++; else break;
Defining NUM_ROWS and NUM_COLS at the top of your script is a programming best practice. If you later want to change your checkerboard into a
remain all zeros, as these represent the empty "no-man's land" in the middle of a checkers game.
You need to create a checkerboard pattern (alternating black and red squares) using a grid of squares, typically with n rows and n columns (often n = 8 for a standard checkerboard).
Square Size=Canvas WidthNumber of ColumnsSquare Size equals the fraction with numerator Canvas Width and denominator Number of Columns end-fraction
. Multiplying the current loop index by the square size gives the perfect starting point for each tile.
: The create_rectangle function requires the top-left coordinate and the bottom-right coordinate
function start(): turn off beeper auto-placement var row = 1 while (front is clear or left is clear): placeRow(row) if (front is clear): moveToNextRow() row++
The canvas is 400×400, but squares don't align perfectly. Fix: Calculate the window size dynamically from the square size and number of squares, as shown in the constants above. 9.1.6 checkerboard v1 codehs
rect.setColor(Color.BLACK);
Try implementing this yourself using the logic above. If you get stuck, ask your teacher or a classmate for help — working through the logic is how you learn best!
Used to detect if a sum of indices is even or odd ( ), which helps determine where to place a '1'. Fix: Calculate the window size dynamically from the
So, why is the 9.1.6 Checkerboard V1 so important? This project holds significant value for several reasons:
// Loop through each row for (int row = 0; row < ROWS; row++) // Loop through each column in the current row for (int col = 0; col < COLUMNS; col++)
By checking if (r + c) is divisible by 2 using the modulo operator ( % ), you can cleanly alternate colors. Step-by-Step Code Implementation Used to detect if a sum of indices
if (frontIsClear()) move(); col++; else break;
Defining NUM_ROWS and NUM_COLS at the top of your script is a programming best practice. If you later want to change your checkerboard into a
remain all zeros, as these represent the empty "no-man's land" in the middle of a checkers game.
You need to create a checkerboard pattern (alternating black and red squares) using a grid of squares, typically with n rows and n columns (often n = 8 for a standard checkerboard).
Square Size=Canvas WidthNumber of ColumnsSquare Size equals the fraction with numerator Canvas Width and denominator Number of Columns end-fraction