!!install!! - 9.1.7 Checkerboard V2 Answers
Forgetting to check if (frontIsOpen()) before a second move() inside a row function can cause Karel to crash into the wall, breaking the program.
: The print_board function takes the list of lists and converts each integer to a string, joining them with spaces for a clean visual output.
loops to iterate through each row and column. To create the alternating pattern, check if the sum of the current row index and column index is odd or even: (row + col) % 2 == 1 , set the value to Otherwise, the value remains 3. Print the board Call the provided print_board function, which uses a list comprehension and
FOR row FROM 0 TO total_rows - 1: FOR col FROM 0 TO total_cols - 1: IF (row + col) % 2 == 0: PRINT "X" ELSE: PRINT "O" PRINT NEWLINE Use code with caution. Common Pitfalls and Troubleshooting 9.1.7 checkerboard v2 answers
If you analyze the indices of a standard grid, an undeniable mathematical pattern emerges:
Which (Java, JavaScript, Python) are you using?
Repeat the process using a while(frontIsOpen()) loop to handle variable grid heights. Official 9.1.7 Checkerboard V2 JavaScript Solution Forgetting to check if (frontIsOpen()) before a second
Use a doubly-nested for loop to access every coordinate (row, col) in the grid. The outer loop should iterate from r = 0 to 7. The inner loop should iterate from c = 0 to 7. 3. Apply the Alternating Logic
import java.awt.Color; import acm.graphics.*; import acm.program.*;
When multiplying row * SQUARE_SIZE , ensure your loop counters start at 0 rather than 1 . Starting at 1 shifts your entire checkerboard away from the top-left corner of the canvas, leaving empty gaps. Summary Checklist for Passing Autograders To create the alternating pattern, check if the
This public link is valid for 7 days and shares a thread, including any personal information you added. This link or copies made by others cannot be deleted. If you share with third parties, their policies apply. Can’t copy the link right now. Try again later.
Rules for placing pieces, moving them, capturing opponent pieces, etc.
Start by creating a 2D list (grid) that contains 8 rows and 8 columns, with all elements initially set to 0. 2. Iterate Through Rows and Columns
. In a checkerboard, a cell changes color every time you move one step in any direction. Mathematically, this happens when the sum of the row and column indices switches between even and odd. , the sum is even. , the sum is odd. By setting elements to