This repo implements a web-based Gravity Connect-4 with OCaml backend and ReScript frontend, communicating via Dream.
What is Gravity Connect-4?
- Whoever connects 4 pieces in a row, column, or diagonal wins the game
- In Gravity Connect-4, pieces fall to the lowest available spot in the column
dune clean && dune build
dune test && bisect-ppx-report html # optional
cd src
npm install
npm run start
then visit http://localhost:8080 to play the game!
🎮 3 Levels of Agent Difficulty to Test Your Skills
- 🟢 Easy: Powered by the Minimax Algorithm – Perfect for beginners.
- 🟡 Medium: Enhanced with Alpha-Beta Pruning – A balanced challenge awaits!
- 🔴 Hard: Masterfully crafted with Monte-Carlo Tree Search – Can you outsmart the smartest?
🧩 Classic Gameplay + 2 Exciting New Variants!
- Traditional Mode: Relive the nostalgic experience you love!
- Random Blocker Mode: Adds unpredictability with randomly placed blockers.
- Reward Mode: Reach the special reward spot to place an extra blocker – strategy at its finest!
🤝 Choose Who Goes First!
- You First: Take control of the game and strategize your way to victory.
- Agent First: Bring your A-game against our powerful AI opponents.
📏 Customizable Board Sizes (6x6 to 12x12)
- Compact Boards: Perfect for quick, casual games.
- Larger Boards: Explore endless strategies and more thrilling challenges!
🌟 Your Perfect Blend of Strategy, Fun, and Competition Awaits! 🌟
In "./src/lib", there are 3 general functors (minimax, alpha_beta and mcts) implementing 3 different algorithms for games involving 2 competitive players.
They can be allpied to any Game compatible with Game Type and get the agent for that game.
In "./src", there are several executables to play the connect4 game with agent. For example, you can use
dune exec ./src/play_bonus_mcts.exe
to execute the command line game for BONUS playmode versus an agent based on MCTS.
Besides, you can use
dune exec ./src/pvp_bonus.ml
to execute the pvp game mode.