Connect Four playable online or from the console.
You can swap the mode you are playing in any time using the select. This allow you to play as PvP for a few moves and then let the AI take over after your next turn.
To play in the console:
rails game:classic
Player vs. Playerrails game:easy
Player vs. AI (Random)rails game:moderate
Player vs. AI (Depth=2)rails game:hard
Player vs. AI (Depth=3)
You can setup a board by sending in a list of play on the first move. For example,
you can paste [1, 2, 1, 2, 1, 2, 1]
into any move to play those moves.
- Remember to run
bundle
- Run test suite by
rails test
- Start server by
rails s
Interesting code:
- Board
- BasicAi
- ConnectFour Console
- Rake Game Task
- Connect Four Controller
- Connect Four in Vue.js
- Tests
- Persist games to database
- Implement Alpha-Beta pruning to improve recursion costs
- Add scoring for 2 and 3 matching groups that have a possible four slot win or loss preferring the win
- DRY BasicAi
.lookAhead()
and.scoreBoard()
methods - Improve interface for Board.detect_win by creating a BoardState Class,
- potentially add some sort of Coordinates Class to remove some of the complexity of the Board class.
- Implement an AI based on Monte Carlo Tree Search
- AI: hard AI occasionally misses obvious blocks (better scoring solves this)
- Wikipedia Connect Four
- MIT Lecture: Games, Minimax, and Alpha-Beta
- Minimax Algorithm
- Alpha-beta Pruning Variation
- Negamax Variation
- Connect Four Example and Tutorial in C++
- Connect Four in JavaScript
- Monte Carlo Tree Search
- Level 1: Build a playable game of Connect 4 with 2 players, a command line interface being fine. Should have player moves, win detection logic, tie detection, etc.
- Level 2: Implement a standard “AI” for the computer player. A standard computer opponent should block a human from winning when able to, but plays more ad hoc and does not operate with an advanced strategy.
- Level 3: Make it playable online (Heroku or similar) with a SPA web interface, games persisting to a database, etc.
Boss Level
(Bonus): the computer player's decision engine should have a setting for smarter vs standard opponent. The smarter version should employ any sort of intelligent strategy or look-ahead approach you choose, and be able to win most times (assuming it goes first and it’s not playing against a player with the same strategy), though it does not have to play mathematically perfectly.