9.1.6 Checkerboard V1 Codehs May 2026

Test the program on different world sizes:

Typically for CodeHS 9.1.6:

The 9.1.6 Checkerboard v1 exercise on CodeHS is an excellent way to practice nested loops, graphical coordinate systems, and conditional logic. By using the parity formula (row + column) % 2, you can elegantly alternate colors without complex if-else chains.

Copy the code above, paste it into the CodeHS editor, and run it. You should see a perfect 8×8 checkerboard. If you run into issues, double-check your spelling of Color.GRAY (remember: American English spelling) and ensure you have imported acm.graphics.* and java.awt.*.

Happy coding!

In the CodeHS exercise 9.1.6: Checkerboard v1, the goal is to create a 2D array representing an

checkerboard where squares alternate between two values (usually 0 and 1). Core Concept: The Modulo Pattern

The most efficient way to determine the color of a square at position (row, col) is to check if the sum of the row and column indices is even or odd. Even sum (row + col % 2 == 0): One color (e.g., 0). Odd sum (row + col % 2 != 0): The other color (e.g., 1). Implementation Steps 9.1.6 checkerboard v1 codehs

Initialize the Array: Create a 2D integer array with 8 rows and 8 columns.

Nested Loops: Use a for loop to iterate through each row, and a nested for loop to iterate through each col.

Apply Logic: Inside the loops, use an if-else statement or a simple calculation to assign the value based on the parity of the sum of the indices.

Print: Use a helper method or another nested loop to print the grid so it looks like a board. Sample Code Structure (Java)

int[][] board = new int[8][8]; for (int row = 0; row < 8; row++) for (int col = 0; col < 8; col++) if ((row + col) % 2 == 0) board[row][col] = 0; else board[row][col] = 1; Use code with caution. Copied to clipboard Common Pitfalls

Off-by-one errors: Ensure your loops run from 0 to 7 (less than 8).

Index order: Always use board[row][col] to stay consistent with standard grid notation. Test the program on different world sizes: Typically

Mastering CodeHS 9.1.6: Checkerboard, v1 In the CodeHS "Introduction to Computer Science in Python 3" curriculum, exercise 9.1.6: Checkerboard, v1 introduces students to representing complex grids using

. This specific version focuses on the foundational step of creating a 2D structure where values represent different game states: for a checker piece and for an empty square. The Assignment Objective The goal is to create an

grid stored as a list of lists. Unlike a fully alternating board, version 1 requires a simplified pattern where: top three rows contain alternating pieces ( middle two rows are completely empty (all bottom three rows contain alternating pieces ( Step-by-Step Implementation 1. Initialize the 2D Grid First, create an empty list called

. Use a loop to populate it with 8 rows, each initially filled with zeros to establish the basic structure. 2. Target Specific Rows for Pieces

To match the checkerboard layout, you must use nested loops to iterate through the grid. Use a conditional statement to identify rows (top) and rows 3. Assign Alternating Values

Within those specific rows, use modular arithmetic—specifically (row + column) % 2 —to decide if a cell should be a

. This ensures that adjacent cells never have the same value, creating the classic checkerboard look. 4. Print the Result Finally, pass your populated list to the provided print_board function to visualize the grid in the console. Example Solution Code The challenge is deciding when to use gray

The following structure is commonly used to pass the CodeHS autograder, which requires actual assignment statements (e.g., board[i][j] = 1 ) rather than just printing the expected output. # Function to print the board provided by CodeHS print_board range(len(board)): print( .join([str(x) board[i]])) # 1. Initialize an 8x8 grid with all 0s ): board.append([ # 2. Use nested loops to place checker pieces (1s) # Top 3 rows and Bottom 3 rows # Alternating pattern: 1 if (row + col) is even (row + col) % : board[row][col] = # 3. Display the board print_board(board) Use code with caution. Copied to clipboard Common Pitfalls Static Printing: Simply printing the pattern using print("0 1 0 1...")

will fail the autograder. You must actually modify the list elements. Indexing Errors: Remember that Python indices start at grid has indices ranging from Middle Rows: Ensure rows

remain all zeros, as these represent the empty "no-man's land" in the middle of a checkers game.

For further help with 2D lists, check out official resources like the CodeHS Python 3 Course Explore Page or community discussions on Reddit's r/codehs Checkerboard v2

, which introduces different values for red and black pieces?


The challenge is deciding when to use gray and when to use black. There is a simple mathematical trick: look at the sum of the row index and column index.

Let's test this:

This pattern creates a perfect checkerboard.

Contact

Contact