SearchingĪs we have all building blocks, let’s examine the algorithm by itself. I leave this function for analysis on your own. We perform the same procedure for all rows, columns, and sections. def is_invalid(b): # rows for i in range(5): row = b row = row if len(row) = 0: continue _, counts = np.unique(row, return_counts=True) if(counts.max() > 1): return True # columns for i in range(5): row = b row = row if len(row) = 0: continue _, counts = np.unique(row, return_counts=True) if(counts.max() > 1): return True for s in sections: vals = for y,x in s: vals.append(b) vals = np.array(vals) vals = vals if len(vals) = 0: continue _, counts = np.unique(vals, return_counts=True) if(counts.max() > 1): return True return False Last helper - checking if a board is invalid. Just need to check if there are no zeros. Next, function to check if a board is completed. The field is represented by a tuple - (y,x) coordinates on the board. import numpy as np board = np.array(,, ,, ]) Glyphs are represented as consecutive numbers. ![]() We will code along explanations.įirst things first - the representation of the board. Therefore I decided to use a simple algorithm called backtracking search. The problem is relatively simple - the board and number of glyphs is small. We start with an initial state s₀ - the game gives it. Therefore, if a state is complete and is not invalid - it is the solution.
0 Comments
Leave a Reply. |