2048 AI- Monte Carlo+Bruteforce

PasiduPerera
Analytics Vidhya
Published in
5 min readApr 7, 2021

--

Introduction:

This code is an extension of Edwins original Monte Carlo Code which improves on the heuristic function and also adds a brute force function onto the code so that it improves the codes time efficiency.

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.

After Edwin created the updated code, as you can see from the terminal output, it is able to consistently achieve grids of 2048/4096.

import random
import…

--

--