2048-Python V1

PasiduPerera
Analytics Vidhya
Published in
4 min readMar 26, 2021

--

This is 2048

This is going to be a sequence of posts of the process of creating a AI to run the game 2048. This first post is running 2048 on the terminal, the next will be visualising it and then finally the last post will be the fully implemented AI which will use minimax to choose the best possibility. This project has been done by me and a school friend called Edwin as a joint effort and I accredit him for helping me a lot with making the code as efficient as possibility. I will have extended comments on all of the sections of code so you can follow thorough and see what I have done.

import random
import numpy as np
import sys
import time

“””a possible optimisation is using numpy which if i do, then I will update this article”””

ROW_LENGTH = 4
STARTING_NUMBERS = 5
CHANCE_OF_TWO= 80
CHANCE_OF_FOUR = 99
PLAYER_SCORE = 0
TOTAL_MOVES=0

“””These are all constants that I use and by adjusting these values, you can change the dimensions of the grid so that it is larger or smaller and you can change the number of starting numbers and also the chances of getting certain numbers when the grid updates at the end of each move”””…

--

--