Mathematical Analysis of 2048, The Game

Similar documents
Graph Application in The Strategy of Solving 2048 Tile Game

Using Artificial intelligent to solve the game of 2048

Lu 1. Game Theory of 2048

2048: An Autonomous Solver

Unit 12: Artificial Intelligence CS 101, Fall 2018

AI Plays Yun Nie (yunn), Wenqi Hou (wenqihou), Yicheng An (yicheng)

game tree complete all possible moves

Learning to Play like an Othello Master CS 229 Project Report. Shir Aharon, Amanda Chang, Kent Koyanagi

Adversarial Search. CS 486/686: Introduction to Artificial Intelligence

CMS.608 / CMS.864 Game Design Spring 2008

Overview. Equipment. Setup. A Single Turn. Drawing a Domino

Intro to Java Programming Project

CS 188: Artificial Intelligence Spring Announcements

2008 Excellence in Mathematics Contest Team Project A. School Name: Group Members:

Codebreaker Lesson Plan

Adversarial Search. CS 486/686: Introduction to Artificial Intelligence

COMP3211 Project. Artificial Intelligence for Tron game. Group 7. Chiu Ka Wa ( ) Chun Wai Wong ( ) Ku Chun Kit ( )

Google DeepMind s AlphaGo vs. world Go champion Lee Sedol

mywbut.com Two agent games : alpha beta pruning

Problem C The Stern-Brocot Number System Input: standard input Output: standard output

Documentation and Discussion

CSE 573: Artificial Intelligence Autumn 2010

CSE548, AMS542: Analysis of Algorithms, Fall 2016 Date: Sep 25. Homework #1. ( Due: Oct 10 ) Figure 1: The laser game.

Algorithms for Data Structures: Search for Games. Phillip Smith 27/11/13

22c:145 Artificial Intelligence

Heuristic Search with Pre-Computed Databases

Solutions of problems for grade R5

CS221 Project Final Report Gomoku Game Agent

Introduction Solvability Rules Computer Solution Implementation. Connect Four. March 9, Connect Four 1

Monte Carlo based battleship agent

CS 229 Final Project: Using Reinforcement Learning to Play Othello

Olympiad Combinatorics. Pranav A. Sriram

A Memory-Efficient Method for Fast Computation of Short 15-Puzzle Solutions

Genbby Technical Paper

COMP9414: Artificial Intelligence Problem Solving and Search

Adversarial Search 1

CS 771 Artificial Intelligence. Adversarial Search

CS 188: Artificial Intelligence. Overview

Analyzing Games: Solutions

A1 Problem Statement Unit Pricing

Artificial Intelligence. Topic 5. Game playing

CS-E4800 Artificial Intelligence

Checkpoint Questions Due Monday, October 7 at 2:15 PM Remaining Questions Due Friday, October 11 at 2:15 PM

Keywords- Fuzzy Logic, Fuzzy Variables, Traffic Control, Membership Functions and Fuzzy Rule Base.

Adversarial Search and Game- Playing C H A P T E R 6 C M P T : S P R I N G H A S S A N K H O S R A V I

Announcements. CS 188: Artificial Intelligence Spring Game Playing State-of-the-Art. Overview. Game Playing. GamesCrafters

AI Approaches to Ultimate Tic-Tac-Toe

For slightly more detailed instructions on how to play, visit:

The patterns considered here are black and white and represented by a rectangular grid of cells. Here is a typical pattern: [Redundant]

Software user guide. Contents. Introduction. The software. Counter 1. Play Train 4. Minimax 6

Real-Time Connect 4 Game Using Artificial Intelligence

Introduction to Spring 2009 Artificial Intelligence Final Exam

arxiv: v1 [math.co] 12 Jan 2017

Comparing Methods for Solving Kuromasu Puzzles

The Galaxy. Christopher Gutierrez, Brenda Garcia, Katrina Nieh. August 18, 2012

a b c d e f g h 1 a b c d e f g h C A B B A C C X X C C X X C C A B B A C Diagram 1-2 Square names

Lecture 20 November 13, 2014

Mistilings with Dominoes

Practice Session 2. HW 1 Review

Heuristics, and what to do if you don t know what to do. Carl Hultquist

Artificial Intelligence Search III

Learning from Hints: AI for Playing Threes

A GRAPH THEORETICAL APPROACH TO SOLVING SCRAMBLE SQUARES PUZZLES. 1. Introduction

Tetris: A Heuristic Study

CSC 380 Final Presentation. Connect 4 David Alligood, Scott Swiger, Jo Van Voorhis

Unit-III Chap-II Adversarial Search. Created by: Ashish Shah 1

Find the items on your list...but first find your list! Overview: Definitions: Setup:

Adversarial Search. Hal Daumé III. Computer Science University of Maryland CS 421: Introduction to Artificial Intelligence 9 Feb 2012

General Certificate of Secondary Education For submission in 2017

Jamie Mulholland, Simon Fraser University

Lecture Notes on Game Theory (QTM)

Easy Games and Hard Games

COMP219: COMP219: Artificial Intelligence Artificial Intelligence Dr. Annabel Latham Lecture 12: Game Playing Overview Games and Search

Chapter 4 Number Theory

Playing Othello Using Monte Carlo

Sudoku Touch. 1-4 players, adult recommended. Sudoku Touch by. Bring your family back together!

CS 188: Artificial Intelligence Spring 2007

UNIT 13A AI: Games & Search Strategies. Announcements

Artificial Intelligence. Minimax and alpha-beta pruning

Game Playing for a Variant of Mancala Board Game (Pallanguzhi)

EXPLORING TIC-TAC-TOE VARIANTS

The 21 st Century Wireless Classroom Network for AP Calculus

Set 4: Game-Playing. ICS 271 Fall 2017 Kalev Kask

Optimal Yahtzee performance in multi-player games

Game Playing State of the Art

Recent Progress in the Design and Analysis of Admissible Heuristic Functions

Othello/Reversi using Game Theory techniques Parth Parekh Urjit Singh Bhatia Kushal Sukthankar

Creating a New Angry Birds Competition Track

CS221 Project Final Report Automatic Flappy Bird Player

Rotational Puzzles on Graphs

A Real-Time Algorithm for the (n 2 1)-Puzzle

Techniques for Generating Sudoku Instances

CMPT 310 Assignment 1

Section 1.6 The Factor Game

Let's Play Math Games! Activities for Learning, Inc. 2017

Selected Game Examples

Lumines Strategies. Greg Aloupis, Jean Cardinal, Sébastien Collette, and Stefan Langerman

STUDENT S BOOKLET. Geometry 2. Contents. Meeting 7 Student s Booklet. May 24 UCI. 1 Circular Mountains 2 Rotations

B1 Problem Statement Unit Pricing

Use of Sticks as an Aid to Learning of Mathematics for classes I-VIII Harinder Mahajan (nee Nanda)

Transcription:

Advances in Applied Mathematical Analysis ISSN 0973-5313 Volume 12, Number 1 (2017), pp. 1-7 Research India Publications http://www.ripublication.com Mathematical Analysis of 2048, The Game Bhargavi Goel DPS Vasant Kunj, D 6/5, Vasant Vihar, New Delhi- 110057, India Abstract The game 2048 took the internet by storm, spawning countless rip-offs. People around the world have poured millions of hours trying to create the 2048 tile. Besides the addictive game play, the game also presents an interesting opportunity to explore mathematics. The paper attempts to analyse the game mathematically, through Mathematical Induction, Number Theory, Fuzzy Theory and Topology, in the process also attempting to find the optimal strategy to ensure victory. Keywords: Mathematical Analysis, 2048, Pascals Triangle, Optimization INTRODUCTION 2048 is sliding block puzzle game developed by Gabriele Cirulli. It s a game played on a 4x4 grid with tiles numbered 2 n where n represents a natural number. The objective of the game is to combine tiles of the same number to eventually form the number 2048. The user can move in the four cardinal directions and after every move a new tile is generated randomly in the grid which is either numbered 2 or 4 with a probability of about.10. A move is legal if at least one tile can be slid into an empty spot or if the tiles can be combined in the chosen direction. The game ends when the user does not have any legal moves left. One cannot help but ask the question, since the game is based on mathematics, whether moves can be optimised to improve our score by applying different concepts of mathematics. Mathematical Induction At the start of the game, we are given two tiles in random locations. The tiles could be either numbered 2 or 4 with the probability as discussed earlier. By observation, one can see that the grid can only contain numbers which are of the form 2 n. We can also prove this mathematically through the use of mathematical induction.

2 Bhargavi Goel Step 1: The tiles given in the beginning are both 2s, one 2 one 4 or both 4s. In all, there are 2!2! -1 = 3 cases. The numbers here can be represented in the form 2 n. Step 2: Let us assume that after k steps, the numbers in the grid can be represented in the form of 2 n. Step 3: In (k+1) th step, the following cases arise- I. We slid the tile into an empty spot, no tiles combined with one another II. We combined two or more existing tiles with one another III. A combination of cases 1 and 2 In all the three cases, a new tile will be randomly generated, which will be numbered 2 or 4 and by default can be represented as a power of 2. In the first case, we have the only one new number in addition to the ones at k th step which could all be expressed in powers of 2. In the other case, since the tiles numbered 2 r would combine to make tile numbered 2 r+1, all the tiles could still be represented in powers of 2. So we can say that at any point of time the grid will only have numbers which can be represented in the form of 2 n. Maximal tile From the previous discussion, we know that all the tiles are of the form 2 n, so the maximal tile will also be of the same form. Let us assume 2 r is the maximal tile where rϵn. To create this tile, 2 tiles of 2 r-1 are required, to create tile of 2 r-1, two tiles of 2 r-2 are required and so on. The number of tiles is limited by the space on the grid which is 16 spaces, which means r = 16. So 2 16 =65536 is the maximal tile if we get 2 at the end. Assuming that we get lucky and get tiles numbered 4 towards the end; 2 r+1 will be the maximal tile. So 2 17 =131072 will be the maximal tile. Maximum possible sum (Sn) All the tiles are of the form 2 n. Assuming the best case scenario that there are no two tiles of the same number and that we have the highest numbered tiles in the grid that is possible, on can easily see that they will form a Geometric Progression (GP). Also, since we are considering best case scenario, we can take the lowest number to be 4 instead of 2. The sum, Sn will be given by- Sn = 2 2 + 2 3 + 2 4 + + 2 17. = 2(2 17-1)/(2-1) 2 1 = 262142 2 = 262140 If 2 is the last tile instead of 4, then the sum would be Sn = 2 1 + 2 3 + 2 4 + + 2 17 = 2(2 17-1)/(2-1) - 2 2 = 262142-4 = 262138

Mathematical Analysis of 2048, The Game 3 Or we can just do- Sn = 262140 2 =262138 MINIMUM NUMBER OF TURNS TO WIN (Tmin) The game is won by creating the 2048 tile (although one can choose to keep playing till no more legal moves are left). Since the tiles are randomly generated; 2 with a probability of 0.9 (P2 = 0.9) and 4 with a probability of 0.1 (P4 = 0.1); we cannot give an exact number for Tmin, however we can give a range for it. I. Assuming the best-case scenario that all the tiles we get are of number 4 and that every move we make results in the merging of 2 tiles into 1. Now, to make 2048 we need at least 512 tiles (512x4=2048). But we start with 2 tiles so that means we need 512-2=510 turns so that we get all the required tiles. The last tile we get will have to be combined to make 8, then 8s into 16, 16s into 32 and so on until we combine 1024s into 2048 So we get, Tmin = 512 2 + 9 = 519 turns The probability of getting all 4 numbered tiles is 0.1 519 = 10-519 II. Consider a case in which we get all tiles numbered 2 rather than 4. Proceeding as above, we need 1024 tiles to make 2048 and then combine the last tile we get with another 2 numbered tile to eventually get 2048. In this case Tmin = 1024-2 + 10 = 1032 turns The probability of getting all 2 numbered tiles is 0.9 1032 ~ 6.0x10-48 So the minimum number of turns required to win the game, assuming we play a perfect game is in the range of [519, 1032]. Fuzzy Theory If a player plays the game, will he be able to confidently say that he can win the game? Furthermore if "n" number of players start playing at the same time, can any or all say that they can win the game? Now if we consider the same with "n" number of players, m times, then again the answer on victory over the game before finishing it is not sure. Consider S = {P1, P2, P3,..., P11} is a set of eleven player who played the game. P1 fails to win but he reached 32 P2 fails to win but he reached 64 P3 fails to win but he reached 32 P4 fails to win but he reached 128 P5 fails to win but he reached 512 P6 fails to win but he reached 256

4 Bhargavi Goel P7 fails to win but he reached 128 P8 fails to win but he reached 1024 P9 fails to win but he reached 512 P10 fails to win but he reached 256 P11 fails to win but he reached 64 Now consider P8, who was closer to victory compared to rest except P9. Similarly, P5 was closer to victory compared to rest except P9 and P8. Now between P1 and P2, P1 is less close to victory than P2. From the above discussion, we find that the victory over the game is not a sure event but we can talk about the degree of win for each player, giving us a glimpse of Fuzzy Theory which helps us to know to which extent player was close to win. Basically, Fuzzy theory enables us to know the degree of truth of an event (whether precise or imprecise) at any defined instant. Define Membership function m: S -> [0, 1] as given in Table 1. Given below is a graph (Graph 1), in which X-axis represents player and Y-axis represents their corresponding membership values Table 1: Membership values of Players Player Membership value (m-value) 1 0.1 2 0.3 3 0.1 4 0.5 5 0.7 6 0.6 7 0.5 8 0.9 9 0.7 10 0.6 11 0.3 Graph 1: m Values of corresponding players 1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 m-values 0 5 10 15 From above fuzzy graph we can see that no payer has m-value 1, that is, no one wins but we can easily examine how close the players are to winning and we can even compare their closeness of victory. Topology for optimality To win the game, we must combine similar numbered tiles which combine to form a bigger numbered tile for example, two tiles numbered 2 n can be combined to form a tile numbered 2 n+1. Since we can only move in the four cardinal directions, the two tiles

Mathematical Analysis of 2048, The Game 5 must be adjacent to each other, either horizontally or vertically. This connects the game with topology. In an ideal configuration, the tiles must not only be adjacent to similar numbered tile but the higher numbered tile so formed must be adjacent to another tile of the same number and so on with the highest numbered tile being left in the end. It is preferable to have monotonicity in the grid along a line. The position of head should be at a place where it can combine with other tiles easily without the new randomly generated tile breaking the chain midway. In other words, it would be better that the highest numbered tile is at the corner of the grid. The resulting configuration would be a snake line ( Image 1 ). Image 1: Snake line through the grid [1] However, practically such a configuration is hard to achieve due to non-deterministic nature of the game. The tiles will not land always exactly where we need them to be. So this can be classified as a case for Best-Case Optimality. Since we are actually combining two adjacent tiles to form a new higher number, which is actually the sum of the two tiles, it is similar to Pascal Triangle (Image 2). The snake line (Hoang, 2014) in the above discussion, sounds good but is hard to replicate since it restricts the movement to only a single direction. But in Pascal s triangle, we need only restrict two directions and can even use third one although sparingly. Experimenting with this, we find the gameplay not only smoother but are also able to create the 2048 tile with ease and win the game (Image 3). This approach is closer to the stochastic optimality for the original game. Image 2: Pascal triangle overlaid on grid Image 3: Gameplay using optimality condition

6 Bhargavi Goel For Robust optimisation however, this approach is also impractical since the tile is no longer randomly generated. It will pop up in places which are least optimal according to minimax tree. In this case though the concept remains same and following the Pascal triangle as closely as possible, the best score that I got was 1176 (Image 4). CONCLUSION The paper has successfully shown that behind the simple game, there lies a world of mathematics to explore. Mathematical concepts helped us to analyse the game and understand how to form an optimum strategy and maximise our score. The above analysis can be taken forwarded to develop an Artificial Intelligence Agent to maximise the score. This paper is an attempt at showing the game in different light and help students to learn mathematics in an interesting way by applying the concepts learned in classroom. At the same time, it is hoped that it will inspire researchers to explore the relatively newer and emerging fields for applied mathematics. Image 4: Gameplay for Robust Optimisation REFERENCES [1] Hoang, L.N. (2014) The addictive mathematics of the 2048 tile game. Available at: http://www.science4all.org/article/2048-game/ (Accessed: 7 May 2016) [2] "2048 Game". 2048 game. N.p., 2016. Web. 7 May 2016. [3] 2048 Available at: http://gabrielecirulli.github.io/2048/ (Accessed: 7 May 2016) [4] Available at: http://cs.gettysburg.edu/~tneller/papers/ccsce14-2048.pdf (Accessed: 12 June 2016). [5] N. (2015) The game of 2048. Available at: http://marilynburnsmathblog.com/ wordpress/the-game-of-2048/ (Accessed: 3 July 2016) [6] Probability that random moves in the game 2048 will win (2017) Available at: http://math.stackexchange.com/questions/727076/probability-that-randommoves-in-the-game-2048-will-win (Accessed: 23 May 2016).

Mathematical Analysis of 2048, The Game 7 [7] Available at: http://ai2-s2-pdfs.s3.amazonaws.com/457c/553393d38c438aa 745bd459cfdaeb94784dc.pdf (Accessed: 21 May 2016) [8] Available at: http://www.cs.put.poznan.pl/wjaskowski/pub/papers/szubert 2014_2048.pdf (Accessed: 23 June 2016).

8 Bhargavi Goel