Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dineshgowda24/tic-tac-toe
🎮 Tic Tac Toe implementation over network 🌐
https://github.com/dineshgowda24/tic-tac-toe
golang network tic-tac-toe
Last synced: about 1 month ago
JSON representation
🎮 Tic Tac Toe implementation over network 🌐
- Host: GitHub
- URL: https://github.com/dineshgowda24/tic-tac-toe
- Owner: dineshgowda24
- License: mit
- Created: 2023-02-25T03:54:08.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-02-25T13:15:18.000Z (almost 2 years ago)
- Last Synced: 2024-06-21T18:09:43.732Z (7 months ago)
- Topics: golang, network, tic-tac-toe
- Language: Go
- Homepage:
- Size: 3.35 MB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Tic Tac Toe
## Features
- Game can be extended to NxN board
- Game can be played by 2 players:
1. Human vs Dumb Computer
2. Human vs Human
3. Human vs Smart Computer
- Game can be played over the network.## Components
### Player
```go
type Player interface {
Play(*board.Board) int
Notify(data string) error
Move() Move
Name() string
Exit() error
}
```Player is an interface who can play.
- Concrete implementations include `Human`, `RandomComputer`
1. `Human` - Takes input from STDIN
2. `RandomComputer` - Generates a random input.
3. `SmartComputer` - Generates input based on context of the game. It Makes decisions to winFor SmartComputer implementations, I had look at references for [minimax algorithms](https://www.youtube.com/watch?v=trKjYdBASyQ&t=772s&ab_channel=TheCodingTrain)
### Board
Board stores all the use inputs, validates if the input is valid.
Internally it stores a one dimensional array of `integer`.```go
type Board struct {
moves int // moves represents the total number of valid moves made on board
size int // size of NxN matrix, represents N
grid []int // one dimensional array representing NxN matrix
}
```### Game
Game has the context of board and players. It drives the whole tic-tac-toe game.
It validates when the game is completed and returns.```go
type Game struct {
board *board.Board // tic tak toe board
playerOne player.Player
playerTwo player.Player
}
```## Set up
### Requirements
- [Golang](https://golang.org/dl/)
Once `Go` is installed run the below command
```go
make build
./play
```### Playing over the network
1. Start the server.
```shell
go run main.go server
```2. Connect to the server.
```shell
nc 127.0.0.1 8080
```It needs to players to connect, so run the `nc` command twice in different terminal session.
### Running the cli
```shell
go run main.go cli
```## Demo
### Smart Computer
### Starting the server
### Connecting to the server