9.1.6 Checkerboard V1 Codehs New! -
# Initialize the board board = []
for i in range(8): # Only modify the top 3 and bottom 3 rows if i < 3 or i > 4: for j in range(8): # If the sum of indices is even, set to 1 if (i + j) % 2 == 0: board[i][j] = 1 Use code with caution. Copied to clipboard 3. Print the Result
remain all zeros, as these represent the empty "no-man's land" in the middle of a checkers game.
The goal of this assignment is to have Karel place beepers on a checkerboard pattern across the entire grid. The Requirements 9.1.6 checkerboard v1 codehs
Finally, you must print the board to match the CodeHS output requirements. 4. The Final Code: 9.1.6 Checkerboard V1
Here is the solution code:
If the of the row and column is odd , it gets the other color. # Initialize the board board = [] for
// 4. Add the rectangle to the Grid to visualize it grid.add(rect, row, col);
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.* .
The 9.1.6 Checkerboard v1 exercise on CodeHS is an excellent way to practice , graphical coordinate systems , and conditional logic . By using the parity formula (row + column) % 2 , you can elegantly alternate colors without complex if-else chains. The goal of this assignment is to have
If your checkerboard is reversed, check your modulo logic ( ≠0is not equal to 0
You need to create a grid where cells alternate colors (usually black and white) to resemble a checkerboard. In CodeHS, this typically involves using the Grid class and the Color constants. The Logic: The "Odd/Even" Rule
The board is represented with 1's and 0's: