Member-only story

2048 AI Monte Carlo

PasiduPerera
9 min readApr 7, 2021

--

Introduction:

All of the Monte Carlo code is solely written by a friend at my school called Edwin. This was a joint project but the AI aspect is completely done by him.

This was a project undergone inn a group of people which were me and a person called Edwin. While I was responsible for the Highest Score code, Edwin was responsible for the Monte Carlo code and since they are both distinct, I believed that they both deserved their own article. Both have their advantages and disadvantages and in the application of a real AI, the Monte Carlo method would be the only viable option because the Highest Score has a cheaty nature in that it can decide the best board out of an option of many boards. Nonetheless, it is still very satisfying seeing the code get a winning board(2048 tile) in under a second using the code.

To see the results of the codes, I am attaching a graph of the results of the code so you can gauge its performance for yourself. Note, our scoring system is slightly different to the real scoring system of 2048 where the score is decided by the sum of all the tiles on the grid.

import random
import numpy as np
import sys
import time
from itertools import product

ROW_LENGTH = 4
STARTING_NUMBERS = 2
CHANCE_OF_TWO= 90
PLAYER_SCORE = 0
TOTAL_MOVES=0
NUMBER_OF_RUNS=1
POSSIBLE_MOVES=["up", "right", "down", "left"]
SIMULATIONS=50…

--

--

PasiduPerera
PasiduPerera

Written by PasiduPerera

Economics Student at Cambridge University

No responses yet

Write a response