/ConnectFour

Primary LanguageScalaApache License 2.0Apache-2.0

ConnectFour

Running

  • Install Java 8 JDK
  • Install SBT
  • Clone this GitHub repo
  • Open a shell (command prompt) and navigate to project directory
  • execute the following command:
sbt run
  • Have fun!

About

  • Scala
  • Everything is immutable
  • Uses Type Classes for printing the game state, giving instructions, and transitioning from one state to another.
    • Decouples data and behavior
    • Compartmentalizes logic per game state
    • Implicit proof required in order to compile
  • Use of types in place of primitives to prevent mistakes
  • Everything is values and only real side effects is printing in Main
  • Game loop is tail recursive
    • Functional looping rather than while or for statement
  • No libraries
    • I've created my own limited versions of some things which exist in ScalaZ or Cats libraries for simplicity
  • Use specs2 for testing
    • Tests run in parallel by default
    • Has a Given When Then syntax but chose not to do that to save time
  • Formatted source with scalafmt
    • Can setup to auto-format on compile but didn't want to introduce plugin for simplicity

Further thoughts

  • Set up compiler settings so if basic warnings and bad practices used then will just not compile
  • Set up Wart Remover (compiler linter) to catch other bad practices and prevent compilation if violated
  • Could look at using state monad or indexed state monad possibly for state transitions
  • Bad input goes back to original state with no really notifications
  • Could introduce packages and scope type creation to go through smart constructors which provide errors or validations if the type can not be realized
  • Eliminate some of the boilerplate of pattern matching on sealed trait co-product with shapeless type class derivation
  • Updating nested immutable collections is a bit painful
    • Use Lens to update easier
  • Still a little bit of primitive obsession with newlines and empty strings.
    • Should make this a list of case classes and add the newlines in Main