Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xno

Functional Noughts and Crosses

Libraries used

Concepts

  • Functional Reactive Programming - Bacon
  • Immutability - Mori
  • Basic Lenses - Enhancing Mori
  • View is a function of state - React

Design

Attributes

Two players - X and O.

Game board - 3 by 3 grid of buttons.

Reset button - Reset the board and start a new game.

Forfeit button - Ends the game, the non-active player wins.

Scores - Each player has a score, initially set to 0. Winning a game increases your score by 1.

Types

A coordinate system is used to reference the grid locations. A scalar value is either A, B, or C. A pair of scalar values make up a location. Locations identify grid locations, e.g:

  • (A, A) is left-top
  • (B, A) is middle-top
Scalar = A | B | C
Loc = Scalar * Scalar

A player is either X or O.

Player = X | O

A board is a mapping from locations to players.

Board = Map Loc Player

The game can be in one of three modes: Active, Draw, or Won.

Play = Active | Draw | Won

Score is defined as an association between players and natural numbers.

Score = Map Player Nat

A game is the combination of:

  • a current Player
  • a state of Play
  • a Board state
  • and a Score table
Game = Player * Play * Board * Score

An operation that changes a game is called an Action.

Action = Game -> Game

Actions include:

  • Resetting the game
  • A player taking their go
  • A player forfeiting the current game

Arcitechture

Possible instances for Player, Scalar, and Play are modelled as strings:

var X = "X"
var O = "O"
var A = "A"
var B = "B"
//  etc.

A location is a Mori hash_map with two keys:

var Loc = function (col, row) {
    return M.hash_map('col', col, 'row', row) }

A Board is a Mori hash_map from locations to players.

var initBoard = M.hash_map()

Score is a Mori hash_map from Players to Naturals. The initial Score has both players associated with 0.

var initScore = M.hash_map(X, 0, O, 0)

A Game has a current Player, Play, Board, and Score.

var initGame = M.hash_map(
  'player', X,          //  Player X to go first
  'play', Active,       //  Ready for play
  'board', initBoard,   //  The empty board
  'score', initScore    //  Initial scores
)

About

Functional Noughts and Crosses

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages