Navigation Menu

Skip to content

stefandd/Tic4

Repository files navigation

Tic4

A simple 4x4 Tic Tac Toe playing AI in Lua and Lobster. In addition to four in a row (or column or diagonal), four in a square also win. Other than playing with Lobster as a language that was new to me but which I quite liked, I also wanted to benchmark both languages using constructs that are as equivalent as possible. The negamax modules contain a generic negamax implementation and the tic4 files implement the specific rules for this 4x4 TTT variant.

Examples of winning conditions:

o . . .   . . . .
. o . .   . o o .
. . o .   . o o .
. . . o   . . . .

Playing against it

You can run it to play against the computer (both the tic4 and negamax files are needed in each language) but you have to live with a very simple command line interface for now.

lua/luajit tic4.lua
lobster tic4.lobster

Benchmark mode

One can also run it to benchmark the languages and implementations by calling

lua/luajit tic4.lua bench
lobster tic4.lobster -- bench

This will compute the best move from an empty board to a search depth of 7 starting (a bit more than 1M positions) and report the time this took.

Benchmark results

Below are the results for my machine (i5-4690K @3.5GHz) using the latest Lobster in JIT mode (x64 Release using MingW), the C++-compiled Lobster code (x64 Release using MingW), the Lua 5.4beta, and the HEAD version of Luajit 2.1-beta3. While the Lobster JIT is currently already quite a bit faster than Lua 5.4, the version compiled to C++ (using the --cpp switch) even beats Luajit 2.1 which I think is remarkable given the maturity of Luajit. A different C++ compiler might even increase the advantage...

Benchmark results

About

4x4 Tic Tac Toe playing AI in Lua and Lobster

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published