Minimax Arena is a game of four in a row against an AI, made with plain JavaScript and the HTML5 canvas. The AI looks ahead with the minimax algorithm, and you can change any of its settings while you play. The project builds on the free minimax tutorial on spicyyoghurt.com.
This download gives you the complete project behind Minimax Arena. See how all the pieces fit together, or use the AI as a head start on a game of your own.
What's included:
- The complete code, fully commented and split into JavaScript modules, with no libraries or build tools
- The AI in its own folder, without any drawing code, ready to use in your own game: the rules of four in a row, minimax with alpha-beta pruning, a transposition table, iterative deepening and an evaluation function
- A Web Worker that runs the AI in the background, so the page doesn't freeze while the AI thinks
- Three modes: You vs AI, Two players and AI vs AI
- Sounds that the code makes itself, so there are no sound files
- A config file with the starting options, the settings of both AIs and the colors
- A README and a license
The game itself has:
- An AI that looks up to 12 moves ahead, or as far as it can in up to 5 seconds
- Undo, a hint and a choice of who goes first
- Two AIs that play game after game, take turns going first and keep score
- Switches for alpha-beta pruning, middle columns first and the transposition table, so you can see how much work each one saves
- A slider for every number in the evaluation function, and one for how often the AI makes a mistake on purpose
- Boards from 4 to 10 columns wide and 4 to 9 rows high
- Views you can turn on and off: the score of every column, the lines the evaluation function counts and move numbers on the discs
- Falling discs, sound and number keys to drop a disc
- A button that copies the settings of both AIs as code
- A board that fits any screen and stays sharp, from phone to desktop
What you can do with it:
You can use the code in your own games and projects, including ones you sell. You don't have to credit us in your project. Just keep the short comment with our name at the top of each code file you use from this package. You can release your project anywhere, for example online or in an app store. Here's what you can't do:
- publish your project's source code, for example in a public repository, if it contains code from this package
- sell or share the code from this package on its own, for example in another source code package
- release Minimax Arena itself, unchanged or with only minor changes
LICENSE.txt in the zip has the full terms.
To run the project, you need a modern browser and a local web server, such as the Live Server extension for Visual Studio Code. The README explains how.
Want to learn how minimax works? The free tutorial builds an unbeatable tic-tac-toe AI step by step, and then takes it to four in a row, with alpha-beta pruning and an evaluation function: