You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
\item \lect Complete the following snippet of the python script with the necessary constraint statements.
The script reads a file that represents a \texttt{size\_x} $\times$ \texttt{size\_y} grid, which includes walkable cells denoted by '$\_$'.
Write constraints for the variables \texttt{coords\_x} and \texttt{coords\_y} such that the variables can only take values that are within the boundaries of the grid and can only represent walkable cells.
\begin{pythonSourceCode} from z3 import *
... size_y = len(grid) size_x = len(grid[0])
coords_x = Int("coords_x") coords_y = Int("coords_y")
# Enforce that the position is in the grid, use size_x and size_y solver.add(coords_x >= 0) solver.add(coords_x < size_x) solver.add(coords_y >= 0) solver.add(coords_y < size_y)
# Enforce that the coordinates can only be a valid cell for i in range(size_y): for j in range(size_x): if grid[i][j] != "_": solver.add(Not(And(coords_y == i, coords_x == j)))
\end{pythonSourceCode}
|