About
NessAi (Smart VR Chess Using Deep Learning AI) is a Chess AI which focuses on using a deep belief neural network in order to play chess at the highest possible level with the given hardware limitations. It will be based on top of Python and utilise Tensorflow to manage the training and instances in terms of AI. The AI will be trained on a Nvidia GTX 1060, taking advantage of parallel computing to run multiple games of chess simultaneously. The goal is to have the software capable of running on an external supercomputer, with that said, I will be contacting different organisations that offer supercomputing services for the purposes of research and development in the scientific field, and I will be asking if they offer anything for students.
VR will serve as the front end of the project (or user side), and is intended to be able to run using a low amount of processing power, that way, it will be able to run on mobile devices and work with low fidelity VR headsets such as Google Cardboard, the Samsung Gear, the Nintendo Labo VR Kit and more. The front end will be designed and developed in Unity, making for easy cross platform development across Windows and IOS. Due to the large library of assets available in the Unity store, finding assets such as Chess pieces should be a cinch. Meaning more meaningful work can be put into the implementation of the AI and user interaction.
The AI instances will be trained on a large standardised dataset. Such datasets should be in repletion considering prominence of such a game as Chess. String manipulation is a very simple thing to do, especially with python so the format of game files can be easily translated into something usable for NessAI. The objective is for the AI to be able to generate its own training data after an allotment of using the standardised dataset, meaning it could potentially go beyond the limitations of how humans play chess.

Research
Week One
This week I sat down with Roshan to talk about the idea I had, he mentioned that there might be a problem with how the player interacts with the system, I mentioned it was like chess with extra steps. And with that, we decided that it would be better if we used VR or AR to recreate the chess board for the user to interact with.
I made a start on an overview and started honing in on the scope of the project and a high level evaluation of the project. I decided the best options to go with so far are Unity for the front end and VR, as I already have experience in Unity and C#. As of now, Python and Tensorflow are the best options for the backend, as Tensorflow is a machine learning framework built in Python.
These decisions were made with basic knowledge on the topics so it may change. I did look into some research related to Chess AI and tensorflow and found a library that implements DeepChess, which is from a group of people who have used a “combination of unsupervised pre training and supervised training" in order to train an AI to play chess with no prior knowledge of the rules of chess. This AI was the first machine learning AI that was able to reach grandmaster-level chess performance. See the research paper here (http://www.cs.tau.ac.il/~wolf/papers/deepchess.pdf).
The library that implements DeepChess can be found here - https://github.com/oripress/DeepChess. This will be a useful reference as it uses Tensorflow for learning. That said, I will avoid using code directly from this library so that I have a chance to understand the AI and develop something unique. The code I write may also have slightly different requirements to the DeepChess library.
Media
Week Two
This week I wasn’t able to make it into class so I did research at home. I researched a couple of different examples of other AI that have played Chess and have determined a couple of different methods that would an AI would be able to play Chess with.
The first and seemingly easiest to implement method would be through the use of Search trees, and using an AI to determine the chance of winning from a board layout.
Based on the research done up to this point, it seems the best way to implement an AI into chess would be through the combination of an AI which will determine the chance of winning based on a chess board and the use of a search tree to determine the move to make and how many layers to predict. The nodes will be evaluated by the minimax algorithm.
The biggest problem is the processing power. Parallel computing and the use of GPUs can improve this, but the processing power and efficiency of the AI will determine the strength of the AI.
On average, there are around 35 different moves that a player can make, meaning that in the following diagram, each node will have 35 (on average) children, and each of those children will have 35 (on average) children. This gets very messy very fast, which each layer representing a turn, the AI can only look only look at so many layers deep before the processing power needed is incomprehensible.
Alpha-beta pruning will need to be implemented for any reasonable results and to save an enormous amount of processing power.
Media
Week Three
This week I worked on trying to get an ai version of chess running on my on computer. The rationale for this task being that I would be able to analyse this code in the future and have an AI being trained on my own PC.
I used the framework that I found a couple of weeks ago on github, called DeepChess, It was very time consuming to actually get the project up and running, since the project required an older version of Python as well as older versions of its dependencies.
I found out that the type of network that I will likely be using is a Deep Belief Network. This is a type of deep neural network that contains hidden layers. To quote the Wikipedia page: “When trained on a set of examples without supervision, a DBN can learn to probabilistically reconstruct its inputs. The layers then act as feature detectors.[1] After this learning step, a DBN can be further trained with supervision to perform classification.[2]"
This means that a data set of games will be needed for unsupervised training.
Media
Week Four
This week was focused more on planning and working on the documentation so that the project will be able to run smoothly and the stakeholder (Roshan) will have a stronger understanding of my project and what I am trying to accomplish.
I managed to finalise the Project brief and submit it on time. And I felt good about how it all ended up.
You can see below, a couple of pages from the document.
I had trouble with the implementation step as there are not really any set dates in terms of the completion of the project.
I also had trouble with the word count, and had to remove over 400 words to reach a reasonable threshold of around 1100
Media
Week Five
This week I started to understand how Neural networks really work and how they can be used as a sort of an estimating function and the different purposes it can serve.
I looked into what is called an AutoEncoder neural network. This is a neural network which is designed to encode data or noise. In my case, take in a chess board, and be able to reconstruct a meaningful value which can be used to make predictions.
I also started to get a better understanding of how weights can be used in order for the output to be a better representation of the data. In the example to the right of this paragraph, the weights are represented as h, the inputs are represented as X, and the outputs are represented as the x with the ^ accent above it.
Each of the inputs are fed into the weights and are multiplied by the value of the weight, then the output is given. The weights can be changed in order to bias the inputs to create a preferred output.
Media
Week Six
This week I started working on how I can create a link between Python and a Visual Studio project in C# so that I can connect the Chess AI to the Unity front end. The objective is to have a python script run, and have a Unity project read what is happening in python.
I managed to get a python server up and running and got it to the point where I could make a request to the server and read the parameters as a string.
The Server then responds with a “World". Unity was able to send the request and receive the word and display it on the screen.
I used event listeners to detect when the status has updated and then changed the text object accordingly.
Media
Week Seven
I wasn’t able to come into class this week so I spent time at home to make sure that all of the work gets in. Luckily i’m the only one in my group so I’m not affecting anyone else’s performance.
This week I mainly worked on the upcoming Research and development proposal. It seems that some of the requirements of the Research and development proposal are vague to say the least.
From what I can see, the Research proposal is similar to the first assignment, the project topic brief. Although the proposal has more of a focus on the research aspect, and looking at more areas, such as Technology research, Social research, Legal/Political research and Economic research.
Were also supposed to layout all of our planning, gantt charts, WBS, tasks, etc. To help with that, I will be using planhammer to come up with the tasks.
Media
Week Eight
This week I mainly spent working on the planning for the Research project.
This involved coming up with all of the different tasks that would be required in order to complete NessAI within the given time frame.
It was tricky to come up with more tasks as I am still unsure of how much I actually know about the tasks that I will be taking on. Due to this, I expect this list to grow as I progress through the tasks and discover the true depth and extent of these tasks I have set for myself.
Luckily I have been able to access planhammer after sending emails to the developers requesting a student license so that I can use their software. With the planhammer software, it is much easier to be able to generate Gantt charts and the WBS tasks for the project.
The main limitation is that I do not know the dates that the assignments of Advanced Studio 2 are due, and Planhammer requires specific dates. Due to this, I am using some rough estimates of when the assignments would be due, and made sure I am working with one technology fully before I even start the research of the next part, unless of course it is a prerequisite.
This week was also very focused on increasing the depth and complexity of my previous analysis into the research papers which were studied in the project brief. This involved diving more into the papers to foster a stronger understanding of the concepts and algorithms developed by true professionals in the field.
Media
Week Nine
I wasn’t able to come into class this week due to needing to get an X-Ray for dental surgery. That said, I still worked hard at home to make sure I am keeping up to date. This week I mainly worked on taking the existing research I had done for the project brief, and then expanding upon it, and in the process, understanding how I can develop a better project.
I was able to considerable increase the depth of the research as can be seen by the screen shots below.
Media

Development
Week One
This week I created a fresh repository for NessAI. In the source folder, I had two folders, one for the Unity project, and one for the AI/server. The idea is to have a python server running where the board and moves can be sent to, from which, an AI will analyse the board, and send a move response back.
I started with baby steps, by making a simple ping pong script. Where I am able to press a button in unity, which runs a script to send a message to an instance of the python server script, which will respond with pong only if ping was sent in the header.
This means that I am able to take make a request from unity asynchronously by pressing a button, have a specific message be sent with it, and then read that message with a local python server, send a response based on the contents of the message. Finally, I can read that response and display it to the user.
It’s definitely a good start but there is lots to do, next week I plan to learn the basics of tensorflow and create a basic chess board and find some models for the chess pieces.
Media
Week Two
This week I worked on creating a system that uses raycasts to detect which square on a grid is highlighted, then change the color to a selected material (in the example below it is shown as a pink/purple colour.
The system is also able to detect when a square is clicked on, and from there, the material on the square changes to a selected material colour (green in this case). When clicked, a unity script will send an asynchronous message to a python server, which listens to the message, and just responds the same thing.
I started installing Tensorflow but i’ve been having some trouble getting it running. With that, I tried using tools that I haven't tried before. I used Postman to help with sending requests to the python server and inspecting all the data, and I used Spyder with Anaconda to develop with Python and run python in an enclosed environment. I’m also using Jupyter Notebook as a lot of resources can be shown in it. I’m still learning more about these tools but I think they will be of great use.
Media
Week Three
This week I implemented a chess logic library into the Unity project to manage the moves on the client side of things. The library I chose was ChessDotNet, it is under the MIT License so it allows for Commercial use. With this chess logic in place, I was able to generate a collection of Chess pieces. I used a free asset from the unity asset store called Low Poly Chess Set, and attached my own scripts so that they can be attached to a certain position on a chess board.
I wasn’t able to come into the class but lots of progress was made.
Media
Week Four
This week I implemented the stockfish engine into a python server script which takes in a Chess board in Fen format and returns the best move it can find. After I got it working on localhost I moved it onto an AWS EC2 instance.
I added the ability for AI to move a piece on the chess board and used asynchronous communication between C# and the AWS server so that the client does not freeze in VR upon attempts at communication.
Media
Week Five
This week I started gathering training data which I would be able to use for the training phase of the project. I started by going to https://theweekinchess.com/twic and downloading some archived pro chess games. Next I created a python script which would take these PGN game files and remove a lot of the data that was irrelevant to me. This includes meta data such as where the game was played, the date, the different players and so on. With the remaining data, I sorted it into a json file, making it easier to process later on.
Media
Week Six
This week I started trying to work with Tensorflow and different AI models. I started with the standard tensorflow hello world equivalent which was where you would have an AI be trained on Shakespear plays, then the AI would “make up" its own Shakespeare plays.
To contextualise this project, I tried using the training data I gathered last week to see what happened. After about an hour and a half of training, the results were mostly just gibberish, although this was to be expected based on the type of model I was using.
Media
Week Seven
This week I worked on turning what I had in unity and tried turning it into an App which I could put on my Iphone XR. Considering I only have a windows laptop, no android phones, and no macs lying around, this task was made more difficult.
I started by installing a virtual machine, for which I used VMWare. I installed the same version of Unity which I had been using on my main working machine. Due to being on a VM, Unity was basically unusable, but all I needed to do was to install it and build to IOS.
After building to IOS, I had an xcode project, which I added my own certifications to so that I could install the app onto my phone. Finally I had the app on my IPhone XR and it worked! There were some problems I found with the project straight away, such as you are stuck in one position and it was hard to see some of the pieces.
Media
Week Eight
This week I went back to working on the AI. I installed numerous existing ChessAI’s which work on top of tensorflow, such as https://github.com/Zeta36/chess-alpha-zero, https://github.com/erikbern/deep-pink and https://github.com/LeelaChessZero/lc0.
I attempted to create differant environments in anaconda for each of the projects but I couldn't get the repositorys running in any meaningful capicity. This was due to the differant applications that also needed to be installed on the computer such as Nvidia Toolkit and CUDA.
Media
Week Nine
This week I took the advice of our course manager and tried taking some of the same repositorys from last week and run them in a differant environment.
Whilst this solution did seemingly work at certain points, every now and then I would get module errors or some other errors which I wouldn't get at other times. Overall it was too inconsistant and the project wouldn't transfer well into a cloud environment such as AWS or GCloud or so on.
Media
Week Ten
This week I decided that Instead of using an chess "AI" model, I would use the chess "engine" model. This means that instead of having an AI that would be trained and get stronger over time, I would instead use an engine which will "look into the future" of a chess game the best it can to predict moves using preset methods.
I decided to use the stockfish chess engine, since it is an open source chess engine and one of the strongest chess engines (if not the strongest) in the world. It's also easy to implement since it also has a pip library which can call the binarys stored on the OS. I downloaded the binaries from stockfishchess.org.
Media
Week Eleven
This week I worked on adding a difficulty setting for the game. In theory, I should be able to change the depth at which the chess engine looks ahead. If the engine looks one move ahead, the move it thinks is best probably isn't very good. On the other hand, if the engine looks 10 moves ahead, it should make a good move. Luckily, the stockfish pip library made this easy to change, I can just change the stockfish's objects depth.
The hard part of implementing this feature was implementing it in the UI and the game screen. Since before the chess game just started when you ran the game, I needed to change things so that the game would only start after selecting a difficulty. I created three buttons for easy, normal and hard and made them all clickable from within the VR headset. Since i'm not the best chess player, adjusting this was difficult to do well.
Media
Week Twelve
This week I created my final prototype build before the presentation. Building my project is a bit of a pain because I don't have a mac. This means I have to build the unity project into an xcode project, open that xcode project up in a VM, add my own signing, then build it to my phone. If I made a small mistake, then I would need to repeat the process.
I decided that instead of sticking with AWS, I would try using Google cloud services. This is partially because I want to try it and partially because AWS services are about to start charging me. I created a trial account with Google cloud services, created a new linux VM instance and SSHed into it. After installing python 3, pip and my projects files onto the instance, I ran it and it didn't work.
The first problem was that getting the file directory with os.path.dirname(__file__) didn't work the same as in windows, I had to instead use os.getcwd(). I added something to the top of the server script to first determine the OS (see code below). It was also important to know the OS since I would have to run differant type of binarys depending on if the system was running Windows or Linux.
Media
Image by InspiredImages from Pixabay