diff options
author | Robby Zambito <contact@robbyzambito.me> | 2022-01-22 15:45:37 -0500 |
---|---|---|
committer | Robby Zambito <contact@robbyzambito.me> | 2022-01-22 15:45:37 -0500 |
commit | 3190e15d7929bf043a892bd21bf2ba54f68c2a1a (patch) | |
tree | 50f061d6efd1ef8f21d1c3224a248902d1743eaa /content/posts/using-lisp-for-game-ai | |
parent | 21d5fa2b46156ab1db54fd146168853fb860c8c7 (diff) |
Added "Using Lisp for Game AI"
Diffstat (limited to 'content/posts/using-lisp-for-game-ai')
-rw-r--r-- | content/posts/using-lisp-for-game-ai/index.md | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/content/posts/using-lisp-for-game-ai/index.md b/content/posts/using-lisp-for-game-ai/index.md new file mode 100644 index 0000000..3eed062 --- /dev/null +++ b/content/posts/using-lisp-for-game-ai/index.md @@ -0,0 +1,46 @@ +--- +title: "Using Lisp for Game AI" +date: 2022-01-22T14:25:47-05:00 +draft: true +--- + +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](https://en.wikipedia.org/wiki/Editor_war#Humor) 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](https://guix.gnu.org/) package manager and operating system, which has given me a reason to start giving Lisp a serious try. +Guix uses the [GNU Guile](https://www.gnu.org/software/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](https://en.wikipedia.org/wiki/Reversi), 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](https://git.robbyzambito.me/robby/othello-ai.git/). +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.](https://git.robbyzambito.me/robby/othello-ai.git/tree/src/main/scala/me/robbyzambito/othello/Main.scala) + +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](https://git.robbyzambito.me/robby/othello-ai-guile-c.git/). + +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](https://git.robbyzambito.me/robby/othello-ai-guile-c.git/tree/strategies). + +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](https://git-send-email.io/), or [get in touch with me however works best](/about) and I will add it to the repository. + +My next desire is to create an AI for the game [Rocket League](https://en.wikipedia.org/wiki/Rocket_League) which is implemented in Lisp. +There is a [community of people](https://rlbot.org/) 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. |