Sign InCoursewareNuggetsTutorials CoursesCodePad

Computational Thinking

Drawing a Chessboard

"Want to play chess?" Asks Andrew. "Sure!" Tali grins, "But we need a chessboard."

Before trying to draw a chessboard, we need to understand what a chessboard looks like. A chessboard consists of 64 small squares with alternating light and dark colors.

To solve a problem, we can first break it down into smaller manageable parts. Once we solve the smaller parts, we can then merge our solutions to solve the bigger problem. Let's draw a chessboard using this strategy.

Computational Thinking Process

  1. Decomposition: Divide the chessboard into 8 rows. Each row can be further divided into 8 squares. If we know how to draw a square, we can put 8 such squares together to draw a row. Then put 8 of such rows together to draw the whole chessboard.
  2. Patterns: All the squares have the same size with alternating colors. Therefore, odd numbered rows repeat, and even numbered rows also repeat.
  3. Abstration: Only focus on the important aspects. If we define a function to draw a square, we can simply call this function when we draw a row of squares, ignoring the implementation details of how to draw a square. Similarly, we can define a function to draw a row of squares and use it when we draw a chessboard.
  4. Algorithms: Put together algorithms to draw a chessboard. Compare each algorithm to come up with our final solution.
    • We can draw each 64 squares one at a time. Because of the repetitions, we want to use a loop. However, at the end of each row, the pen moves to the start of the next row. We need a conditional check to treat the special case.
    • We can draw one row at a time. Our loop will repeat 8 times. However, the odd numbered rows and even numbered rows have different color patterns. We need a conditional check to treat them differently.
    • We can draw two rows at a time. Our loop will repeat 4 times. We don't need conditional checks to treat special cases. But we still need to be careful to put the pen in a correct location after drawing each square and each row of squares.
    We choose the last algorithm as our final solution because it saves us some conditional checks and the code is easier to understand.
© CS Wonders·About·Gallery·Fun Facts·Cheatsheet