PPaste!

moves

Home - All the pastes - Authored by Thooms

Raw version

1
2
3
4
5
6
7
def move(pos, mov, size):
    deltas = [(-1,0),(0,1),(1,0),(0,-1)]
    x, y = pos
    dx, dy = deltas[mov]
    nx = max(0, min(size - 1, x + dx))
    ny = max(0, min(size - 1, y + dy))
    return nx, ny