2048 AI – Day One: Introduction

Today marks the start of my 2048 project! As a recap of my previous project, in my Artificial Intelligence course at university we were tasked with creating an AI to solve a task. My group decided to work on creating an AI that plays the game 2048. If you’re unaware, 2048 has the player combining same-valued blocks on a 4×4 grid from 2 -> 4 -> 8, all the way up until the achieve “2048”. Our inspiration for this project comes from a previous project of mine, where I created a 2048 clone in the Java-based language Processing. Our final implementation used an A*-adjacent search algorithm that analyzed the game board after different moves, and chose the best possible “value” of the board based on this value.

My main goal of this project is to be able to run the algorithm and visualize it in the browser. I figured there would be two ways to do so:

  1. Re-write the entire code base using JavaScript, having it run locally
  2. Improve upon the existing C++ code base and interact somehow with the browser to run server-side.

After doing some research, I learned using CGI (Common Gateway Interface) with Apache can execute programs and allow for dynamic content to be generated on a webpage. Since I plan to host a recipe repository site in the future, I thought this would be a good way to learn how to use Apache and host a dynamic website, as all my previous web experience has mostly been hosting static content using Nginx.

So, my current plan is to rewrite and improve upon the current C++ code base, firstly. Then, I will find a way to run this code off of my web server using Apache, and provide the output as a CSV to then be displayed in browser. Finally, I would like some way to visualize the game being run, most likely either using WebGL or p5.js.

So, I began to rewrite the entire project. In the past, I have used JavaDocs on another university project, and decided to try something similar for this project. After googling documentation software for C++, I learned about Doxygen, a documentation tool for many languages that can compile to HTML, LaTeX, and other formats. After reading the documentation, I learned that it supports JavaDoc style documentation, as well as inline documentation for methods and attributes. As an example, the following code snippet generates a test class with inline documentation for attributes and some methods.

/**
 *  A test class. More details for the test class.
 */
class TestClass {
    int val1;  /**< an integer value */
    char val2; /**< a character value */

    /**
     *  A test method taking an int and a char
     * @param a an integer parameter
     * @param c a character parameter
     * @returns the return integer
     */
    int test( int a, char c );

};

To run, simply generate a Doxyfile with

doxygen -g

The Doxyfile includes a lot of configuration options when the documentation files are created. For my use case, I wanted HTML files to be generated so they can then be uploaded along with my program to the web. Additionally, I preferred the “autobrief” style of JavaDocs, where the first line/sentence is interpreted to be the brief description, and any subsequent lines/sentences will be included in the detailed description. All of these options were configured by changing the following lines in the Doxyfile

GENERATE_HTML = YES
GENERATE_LATEX = NO
JAVADOC_AUTOBRIEF = YES

Finally, the HTML documentation can be generated with

doxygen Doxyfile

And voila! With that, documentation has begun. So far, I have implemented header files for the Block and Grid classes (albeit with minimal documentation), as well as a simple main and Makefile for later. Moving forward, I plan to finish the Block and Grid header files and documentation, and begin working on rewriting the previous implementations of each. My next post will most likely begin going into detail on my design of the 2048 mechanics, as well as any changes I make from the original implementation.

The repository for my project thus far can be found here. That’s all I have to share for today, toodles!


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *