Robby Zambito

22 Jan 2022

Using Lisp for Game AI

The relationship I have had with Lisp until recently has basically amounted to: “It sounds interesting, it seems highly polarizing, and I have no immediate reason to learn it”.

It sounded interesting to me because I have heard people describe it as both being very simple, and having features that other languages lack. People seem to have very strong opinions, both for and against the use of Lisp. Some express a nearly religious fascination with Lisp, while others express a hatred toward the syntax which is very unfamiliar to those coming from other programming languages.

Last year I started using the GNU Guix package manager and operating system, which has given me a reason to start giving Lisp a serious try. Guix uses the GNU Guile implementation of Scheme, which has an interesting ability to be embedded in C programs, similar to Lua.

When I was in college I took an AI class, where one of my projects was to implement a game, and make an AI that would play the game. The game I chose to implement was Othello, which my family has played a lot with each other. At the time, my go-to programming language was Scala, so that’s what I used to create the project. This project wasn’t particularly flexible; to change which AI was used, the user had to modify the code and recompile the game. You can see in the main function, I had some pre-defined configurations commented out so I could easily uncomment what I wanted to use.

Since I’m familiar with C, I decided an interesting way to expand my knowledge of Lisp would be to recreate this project using C for the game logic, and using Scheme for the AI. I have created this project, it can be found here.

If you wish to give it a try, you can clone the project using:

git clone https://git.robbyzambito.me/robby/othello-ai-guile-c.git

You can see the dependencies required for building in the manifest.scm file. If you have the Guix package manager installed on your system (it can be installed on any GNU/Linux distro) you can simply use the guix shell command to spawn a shell with the required dependencies. When you have a shell with the dependencies, simply run make to build. You can find the output under the newly created ./bin folder.

The game works by specifying a script to use for each player as command line arguments. If no script is specified for a certain player, the game will prompt for a move from standard input. Some example scripts can be found under the strategies directory.

I encourage you to try writing your own scripts! If you write a script that you’d like to share, feel free to either email me a patch, or get in touch with me however works best and I will add it to the repository.

My next desire is to create an AI for the game Rocket League which is implemented in Lisp. There is a community of people who create bots for Rocket League, and run tournaments which they compete their bots against each other. I think it would be particularly fun to try to make a bot which tries to adapt to the opponents behaviour. Given how easy it is to dynamically generate and evaluate code using Lisp, I think it would be interesting to try making the bot adapt to the opponent by continuously building a knowledge bank about the opponents behaviour, and using that knowledge to create or modify strategies to more conistently outplay the opponent.