-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTilecoder.py
More file actions
36 lines (26 loc) · 966 Bytes
/
Tilecoder.py
File metadata and controls
36 lines (26 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import math
#globals
numTiles = 4 * 9 * 9
numTilings = 4
# -1.2 <= position <= 0.5
# -0.07 <= velocity <= 0.07
tilingSize = 8 # (subset)
# tileSize = (max - min)/tilingSize
positionTileMovementValue = -0.2125/numTilings
velocityTileMovementValue = -0.0175/numTilings
# x = position, y = velocity
def tilecode(x,y,tileIndices):
# update position
x = x + 1.2
# update velocity
y = y + 0.07
for i in range (numTilings):
positionMovementConstant = i * positionTileMovementValue
velocityMovementConstant = i * velocityTileMovementValue
xcoord = int(tilingSize * (x- positionMovementConstant)/1.7)
ycoord = int(tilingSize * (y- velocityMovementConstant)/0.14)
tileIndices[i] = i * 81 + ( ycoord * 9 + xcoord)
def printTileCoderIndices(x,y):
tileIndices = [-1]*numTilings
tilecode(x,y,tileIndices)
print('Tile indices for input (',x,',',y,') are : ', tileIndices)