A text-based Tic-Tac-Toe game accessible via SSH, built with Go. Features both CPU opponent and multiplayer modes with room codes.
- ๐ฎ Text-based UI - Beautiful ASCII art game board
- ๐ค CPU Opponent - Play against an AI with balanced difficulty
- ๐ฅ Multiplayer Mode - Play with friends using room codes
- ๐ SSH Access - Connect from anywhere using SSH
- ๐ณ Docker Support - Easy deployment with Docker
The easiest way to run the game is using Docker:
# Build and run with docker-compose
docker-compose up -d
# Or using make
make docker-runConnect to the game:
ssh -p 2222 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null localhost- Go 1.21 or higher
- (Optional) Docker and Docker Compose
# Clone the repository
git clone <your-repo-url>
cd tictactoe-ssh
# Download dependencies
go mod download
# Build the binary
go build -o tictactoe-ssh .
# Run the server
./tictactoe-ssh# Connect to localhost (default port 2222)
ssh -p 2222 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null localhost
# Connect to a remote server
ssh -p 2222 username@your-server.com- Choose option 1 from the main menu
- You play as X, CPU plays as O
- Enter moves as
row col(e.g.,1 2for row 1, column 2)
- Choose option 2 from the main menu
- You'll receive a 6-character room code
- Share this code with your friend
- Wait for them to join
- You play as X (first player)
- Choose option 3 from the main menu
- Enter the room code provided by your friend
- You play as O (second player)
- Enter moves as:
row col(e.g.,1 2) - Board coordinates:
1 2 3 โโโโโฌโโโโฌโโโโ 1 โ โ โ โ โโโโโผโโโโผโโโโค 2 โ โ โ โ โโโโโผโโโโผโโโโค 3 โ โ โ โ โโโโโดโโโโดโโโโ
# Build the Docker image
make docker-build
# Run the container
make docker-run
# View logs
make logs
# Stop the container
make docker-stop
# Clean up
make cleanThe SSH port can be configured via environment variable:
# Set custom port
export SSH_PORT=3000
./tictactoe-sshOr in docker-compose.yml:
environment:
- SSH_PORT=3000
ports:
- "3000:3000"tictactoe-ssh/
โโโ main.go # Application entry point
โโโ pkg/
โ โโโ game/
โ โ โโโ board.go # Game board logic
โ โ โโโ ai.go # CPU opponent AI
โ โ โโโ multiplayer.go # Multiplayer room management
โ โโโ server/
โ โโโ server.go # SSH server implementation
โโโ Dockerfile # Docker build configuration
โโโ docker-compose.yml # Docker Compose configuration
โโโ Makefile # Build and run commands
โโโ go.mod # Go module definition
โโโ README.md # This file
- Uses
gliderlabs/sshlibrary for SSH server functionality - No authentication required (public access)
- Each connection gets its own game session
- Balanced difficulty algorithm:
- Try to win (50% of the time)
- Block opponent from winning (30% of the time)
- Take center if available (40% of the time)
- Take corners (30% of the time)
- Make random moves (more often for easier gameplay)
- Room-based system with 6-character codes
- First player creates room (plays as X)
- Second player joins with code (plays as O)
- Rooms are automatically cleaned up after game ends
-
Copy files to server:
scp -r . user@your-server:/path/to/tictactoe-ssh -
SSH into server:
ssh user@your-server cd /path/to/tictactoe-ssh -
Run with Docker:
docker-compose up -d
-
Configure firewall (if needed):
sudo ufw allow 2222/tcp
The application can be deployed to any cloud provider that supports Docker:
- AWS ECS/Fargate
- Google Cloud Run
- Azure Container Instances
- DigitalOcean App Platform
- Heroku
Simply build the Docker image and deploy it with port 2222 exposed.
# Install dependencies
go mod download
# Run the server
go run main.go
# Or use the convenience script
./run.sh# Run all tests
go test ./...
# Run tests with coverage
go test ./... -cover
# Run tests in verbose mode
go test ./... -v# Install air
go install github.com/cosmtrek/air@latest
# Run with hot reload
air- Ensure the server is running:
docker-compose ps - Check if port 2222 is available:
lsof -i :2222 - Verify firewall settings
- Room codes are case-sensitive
- Rooms are deleted after games end
- Ensure the room creator hasn't disconnected
- Try with verbose mode:
ssh -v -p 2222 localhost - Ensure SSH client is installed
- Check if port is accessible from your network
MIT License - feel free to use and modify as needed.
Contributions are welcome! Please feel free to submit a Pull Request.