Skip to content

3x3 Tic-tac-toe for 2 friends on Go, in terminal, FP version

License

Notifications You must be signed in to change notification settings

dibikhin/tic-tac-toe-cli-fp-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tic-tac-toe CLI FP Go

A console 3x3 Tic-tac-toe for 2 friends on Go, in terminal, using functional programming.

GoReportCard example Maintainability example branch parameter

How to

Get someone and play locally in your terminal using keyboard only. Cannot play w/ computer yet so can play with yourself at worst :) See how to run below.

Getting Started

Prerequisites

  • Install Go (tested on go1.15.7 linux/amd64)
  • Zero dependencies

Installing

Not needed, runs as is, just clone:

$ cd my_projects/
$ git clone https://github.com/dibikhin/tic-tac-toe-cli-fp-go.git

Running the tests

$ cd tic-tac-toe-cli-fp-go/
$ make test
...
>PASS
>ok      tictactoe/game  0.010s

NOTE: The tests play the game itself too, scroll to see.

Running

$ cd tic-tac-toe-cli-fp-go/
$ make run
> Hey! This is 3x3 Tic-tac-toe for 2 friends :)
>
> X   X
> O X O
> X   O
>
> Press 'x' or 'o' to choose mark for Player 1:

NOTE: Hit ctrl+c to exit.

Building & Starting

$ cd tic-tac-toe-cli-fp-go/
$ make
>Testing...
>...
>Building...
>...
$ make start

Internals

Project Structure

  • /game — The game package
  • go.mod
  • main.go — Entry point
  • Makefile

Overview

  • The UI is CLI
  • The 3x3 size is hardcoded
  • No timeouts for turns
  • Dirty input tolerant

Technical

  • The code has excessive amount of comments for educational purposes
  • The game is one active app (no client/server)
    • Simple but structured
    • Zero deps
    • No patterns overkill
  • A basic DI is under the hood for auto-tests (naive, no too smart DI)
    • a simple IoC in setup.go, can stub/mock the user input strategy
    • an inner DI in the game loop (game ctx in loop.go)
  • Well-tested
    • no mocks (behavior), just stubs (state)
    • 90% code coverage
    • pure and atomic fns mainly (no IO tests)
    • NOTE: The tests play the game itself too. See in the end after expanding the Test section of the Github Actions job 'build'
  • Paradigm: OOP + FP principles, SRP enforced
  • Functional programming: a lot of pure fns; IO extracted but not isolated

Authors

License

This project is licensed under the MIT License — see the LICENSE file for details.

Acknowledgments

Thanks to:

About

3x3 Tic-tac-toe for 2 friends on Go, in terminal, FP version

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published