Implement tile coding, a key feature construction method for reinforcement learning with continuous state spaces.
Tile coding converts continuous state variables into a sparse binary feature representation by overlaying multiple offset grids (tilings) across the state space. Each tiling partitions the space into tiles, and a given state activates exactly one tile per tiling. The offsets between tilings ensure that nearby states share some (but not all) active tiles, providing smooth generalization.
Given:
state: a list of floats representing the continuous state (one value per dimension)num_tilings: the number of tilings to overlaytiles_per_dim: a list of integers specifying how many tiles each dimension is divided into (per tiling)state_low: a list of floats for the lower bound of each dimensionstate_high: a list of floats for the upper bound of each dimensionFor each tiling, the grid is uniformly offset. The tile width for dimension d is (state_high[d] - state_low[d]) / tiles_per_dim[d]. Each tiling t (0-indexed) has its grid shifted by t * tile_width_d / num_tilings in dimension d. The tile index for a dimension is obtained by flooring the adjusted position, then clipping to valid bounds [0, tiles_per_dim[d] - 1].
Tile indices within a tiling are flattened using row-major (C-style) ordering. Global tile indices are computed by offsetting each tiling's local index by t * tiles_per_tiling, where tiles_per_tiling is the product of all tiles_per_dim values.
Return a tuple of: