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.
 
 

37 lines
1.1 KiB

\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_x and size_y denote the size of the grid
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
# 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] != "_":
#
#
#
\end{pythonSourceCode}