Search⌘ K

Initialize the Sudoku Board and Set its Properties

Explore how to initialize the Sudoku game board by creating HTML elements for each cell and storing these in a 9x9 2D array. Learn to track cell fill status using a boolean flag array and apply color coding to distinguish between prefilled and empty cells. This lesson guides you step-by-step to prepare the Sudoku board for further solving algorithms.

Introduction

Let's start by developing the building blocks of our Sudoku game. We'll be using a third-party API that will provide us with a matrix prefilled with the numbers. We will then need to fill the empty cells of the matrix using recursion and backtracking. But before that, we will be performing the following steps to render the Sudoku board on the web page:

  1. Create the HTML div elements for each cell of the Sudoku board.

  2. Write a utility function to load all the div elements for each cell and store them in a 2D array, so that each div element in the 9×99\times 9 2D array corresponds to a cell of the Sudoku board on the HTML page. For example, a div element at position (0, 3) indicates the fourth element in the first row of the Sudoku board. Recall that the indexing of arrays starts from 0.

  3. Write a utility function to initialize a 9×99\times 9 ...