import math


def snake(state):
    """
    Returns the heuristic value of b

    Snake refers to the "snake line pattern" (http://tinyurl.com/l9bstk6)
    Here we only evaluate one direction; we award more points if high valued tiles
    occur along this path. We penalize the board for not having
    the highest valued tile in the lower left corner
    """

    snake = []
    for i in range(4):
        snake.extend(reversed(state.grid[:, i]) if i % 2 == 0 else state.grid[:, i])

    m = max(snake)
    return sum(x / 10 ** n for n, x in enumerate(snake)) - \
           math.pow((state.grid[3, 0] != m) * abs(state.grid[3, 0] - m), 2)