9.1.6 Checkerboard V1 Codehs May 2026
CodeHS Exercise 9.1.6: Checkerboard, v1 , the primary goal is to create a 2D list (a "grid") representing a checkers board using 1s for pieces and 0s for empty squares. Exercise Objectives Grid Initialization
: Create an 8x8 grid (list of lists) representing a game board. Specific Pattern top 3 rows bottom 3 rows should contain 1s. middle 2 rows should contain only 0s. Output Requirement : Use a provided print_board function to display the grid in a human-readable format. Key Logical Steps Initialize the Board : Create an empty list, typically named Fill the Top Rows
: Use a loop to append three rows, each containing eight 1s. Fill the Middle Rows : Append two rows of eight 0s. Fill the Bottom Rows : Append another three rows of eight 1s. Function Call : Pass the completed list to the print_board Common Implementation Strategies Simple Append board.append([1] * 8)
within loops is the most straightforward method for version 1. Nested Loops
: Some variations or autograders may require initializing the board with 0s first and then using nested loops to selectively assign to specific indices (e.g., board[i][j] = 1 Autograder Requirements : To pass all tests on , ensure you are using assignment statements 9.1.6 checkerboard v1 codehs
if the prompt specifically requests them, as simply printing the pattern without storing it in a grid may cause errors. Typical Pitfalls Incorrect Function Placement : Defining the print_board function inside another block or incorrectly indenting it. Missing Middle Rows
: Forgetting that the middle two rows (index 3 and 4 in an 8-row grid) must remain empty (0s). Bypassing Assignment
: Attempting to print the pattern directly instead of modifying the elements within a list structure. specific Python code
for these requirements, or are you looking for the logic behind Checkerboard v2 CodeHS Exercise 9
Common student mistakes and debugging tips
- Off-by-one errors: using 1-based indices without adjusting parity.
- Wrong parity formula: using (r % 2 == c % 2) is equivalent but be explicit which parity maps to token a.
- Concatenating with spaces unintentionally: ensure tokens are concatenated exactly as intended.
- For graphical output, forgetting to clear or reset pen/color between squares may produce artifacts.
5. Implementation (JavaScript for CodeHS Karel)
function start()// Fill the current row starting with beeper presence based on row parity function fillRow() // Determine if first cell should have a beeper // For row 1: have beeper, row 2: no beeper, etc. // We check if we are on a beeper to decide pattern var startWithBeeper = beepersPresent();
while (frontIsClear()) move(); if (startWithBeeper) // Alternate pattern: after moving, we want opposite // Better approach: move, then if column index is even/odd // But simpler: use a counter
However, a more reliable approach:
function start() var row = 1; while (true) // Determine if row starts with beeper var startWithBeeper = (row % 2 == 1);// Fill the row var col = 1; while (true) if (startWithBeeper) if (col % 2 == 1) putBeeper(); else if (col % 2 == 0) putBeeper(); if (frontIsClear()) move(); col++; else break; // Move to next row if (facingEast()) if (leftIsClear()) turnLeft(); move(); turnLeft(); row++; else break; // Optional: return to start turnAround(); while (frontIsClear()) move(); turnAround();
Simplified and cleaner version (recommended for CodeHS submission): if (frontIsClear()) move()
function start() // Create checkerboard pattern var row = 1; while (true) for (var i = 0; i < 100; i++) // max columns if (row % 2 == 1) if (i % 2 == 0) putBeeper(); else if (i % 2 == 1) putBeeper(); if (frontIsClear()) move(); else break;// Go to next row if (leftIsClear()) turnLeft(); move(); turnLeft(); row++; else break;
Informative feature: "9.1.6 checkerboard v1 (CodeHS)"
Key Requirements:
- Canvas Size: 400x400 pixels.
- Grid Structure: 8 rows, 8 columns (8x8 = 64 squares).
- Square Size: 50x50 pixels (since 8 * 50 = 400).
- Colors: Typically gray (
Color.gray) and black (Color.black), or sometimes red and black. - Starting Color: Top-left corner (row 0, column 0) = Gray.
- Alternating Pattern: Adjacent squares (left/right and up/down) must have opposite colors.