24 Point Network Game (Rust TUI)
A multiplayer, terminal-based implementation of the classic 24 Game logic puzzle, written in Rust. This project features a TCP client-server architecture, allowing multiple players to compete simultaneously in real-time using a clean Text User Interface (TUI).
🎮 Game Overview
The objective is simple: given four randomly generated numbers, use arithmetic operations to calculate the value 24.
Players compete in a shared lobby. The first player to submit a valid expression that equals 24 wins the round and gains a point.
🚀 Features
- Multiplayer: Support for multiple clients connecting to a central server.
- Real-time TUI: Split-screen interface showing game status, live chat/logs, and an interactive input field.
- Smart Input: Custom keyboard shortcuts for complex math operations (like auto-parentheses).
- Rate Limiting: Prevents spamming to ensure fair play.
- No Penalty Mode: Incorrect answers do not deduct points, encouraging experimentation.
📜 Game Rules
- The Cards: Each round, the server generates 4 random numbers (integers between 1 and 10).
- The Goal: Construct a mathematical expression that equals exactly 24.
- Valid Operators:
- Addition (
+) - Subtraction (
-) - Multiplication (
*) - Division (
/) - Exponentiation/Power (
^) - Parentheses
()for grouping.
- Constraints:
- You must use all four numbers provided.
- You must use each number exactly once.
- You can use the operators as many times as needed.
- Winning a Round: The first player to submit a correct expression gets +1 point. The round ends immediately, and the next set of numbers is generated.
- Game Over: The game ends after a set number of rounds (default: 10). The player with the highest score wins.
⌨️ Controls & Input
The input system is designed for speed and convenience in a terminal environment.
| Key / Input | Action |
|---|---|
| Number Keys | Input numbers (0-9) |
| Operators | Input +, -, *, / |
. (Dot) |
Auto-Bracket: Wraps your entire current expression in parentheses (...) and moves the cursor to the end. |
↑ (Up Arrow) |
Power: Inserts the exponentiation symbol ^. |
| Enter | Submit your answer or command. |
| Esc | Quit the game client. |
Commands
Type these into the input bar:
/start- Start the game (if currently waiting)./pass- Vote to skip the current difficult puzzle./score- Check your current score./players- List all connected players and their scores./help- Show the help menu.
🛠️ Installation & Usage
Prerequisites
- Rust installed.
1. Build the Project
2. Run the Server
Start the game server. You can specify the number of rounds and the port.
# Syntax: cargo run -- server [rounds] [IP:Port]
# Example (Start 10 rounds on default port):
# Example (Start 20 rounds on specific port):
3. Run the Client(s)
Connect to the server. Open a new terminal window for each player.
# Syntax: cargo run -- client <Nickname> <IP:Port>
🧩 Example Gameplay
Server gives numbers: 3, 3, 8, 8
Player Input:
8 / ( 3 - 8 / 3 )
Result:
- Correct! The player wins the round.
Using Special Controls:
If you have typed 2+2 and want to multiply the result by 6:
- Current input:
2+2 - Press
.(Dot) -> Becomes(2+2) - Type
*6-> Becomes(2+2)*6-> 24.
📝 License
This project is open-source. Feel free to fork and modify!