2048

AI plays 2048

How to archive 2048

Snake Score (used for ExpectiMax)

Snake Score

Matrix transformation:

1
2
3
4
5
6
7
8
9
10
snake_scores = [
    15 - np.transpose(np.flip(snake_score)),
    15 - np.transpose(snake_score),
    15 - np.flip(snake_score),
    15 - np.array(snake_score),
    np.array(snake_score),
    np.flip(snake_score),
    np.transpose(snake_score),
    np.transpose(np.flip(snake_score))
]

Impact: 100%

Direction:



Border Score

Border Score

Matrix transformation: Not needed

Impact: 10%

Direction:



Smoothness Score

Smoothness Score

Matrix transformation:

1
2
3
4
5
6
smoothness_scores = [
    np.array(smoothness_score),
    np.flip(smoothness_score),
    np.transpose(smoothness_score),
    np.transpose(np.flip(smoothness_score))
]

Impact: 1%

Direction:





Further Features

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
def check_score_methods(board):
    # Score -> Impact
    score_methods = [
        # Snake Score
        [check_snake, 1],
        # Border Score
        [check_border, 0.1],
        # Border Smoothness
        [check_smoothness, 0.01],
        # Amount of empty fields
        [check_empty_fields, 0.1],
        # Biggest number in field
        [check_biggest_number, 0.001],
        # Occurrence of same number
        ## -> value
        [check_total_occurrence, 0.01],
        # Occurrence of same number
        ## -> amount
        [check_count_occurrence, 0.1],
        # Occurrence of same number
        ## -> mean
        [check_mean_occurrence, 0.1],
        # Snake Score with one move 
        # "relaxed problem"
        [check_snake_look_ahead, 0.8],
    ]

    # linear combination: 
    # h(n) = c_1 * x_1(n) + c_2 * x_2(n)
    return sum([func[0](board) * func[1] 
                for func in score_methods])





Occurrence Check

Results

Direction overall

Each direction has almost the same probability after 1000 runs.

First Highscore





Heuristic AI

Highscore: 80’620





Search AI

Highscore: 145’288





Comparison (1’000 Runs)





Time Comparison (1 Run)





Less is More 😜

We reduced the code to this simple rules and achieved an amazing result