This creates perfect alternation in both directions, mimicking a real checkerboard.
0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 Use code with caution. Copied to clipboard 9.1.7 checkerboard v2 answers
// Draw the board for (int row = 0; row < board.size(); row++) for (int col = 0; col < board.get(row).size(); col++) int x = col * SQUARE_SIZE; int y = row * SQUARE_SIZE; GRect square = new GRect(x, y, SQUARE_SIZE, SQUARE_SIZE); square.setFilled(true); square.setFillColor(board.get(row).get(col)); add(square); : The condition (i + j) % 2 == 0 is the key
"Yes!" Leo whispered, pumping a fist.
: The condition (i + j) % 2 == 0 is the key. →right arrow prints 0 . →right arrow prints 1 . row++) for (int col = 0
This creates perfect alternation in both directions, mimicking a real checkerboard.
0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 Use code with caution. Copied to clipboard
// Draw the board for (int row = 0; row < board.size(); row++) for (int col = 0; col < board.get(row).size(); col++) int x = col * SQUARE_SIZE; int y = row * SQUARE_SIZE; GRect square = new GRect(x, y, SQUARE_SIZE, SQUARE_SIZE); square.setFilled(true); square.setFillColor(board.get(row).get(col)); add(square);
"Yes!" Leo whispered, pumping a fist.
: The condition (i + j) % 2 == 0 is the key. →right arrow prints 0 . →right arrow prints 1 .