Simple Tic Tac Toe game with undo mechanics:
This is an example of using immutable tables with my open source runtime immutability implementation presented here:
Game architecture
Game architecture and 3 different versions of the game are described in details in README.
Basically it shows the power of developing a game with immutable tables (though in release, runtime immutability can/should be discarded) and how easy is to implement undo mechanics when immutable game states are tracked in a game history stack.
It also shows an architecture, where game is divided into 3 separate parts (“streams”) that are responsible for input, game logic and visual representation and are connected through a common contract of immutable data (game_logic_input
and game_state
).
It’s kind of inspired by Flow-based Programming that was introduced to me by @dlannan, but I wouldn’t say it’s “pure” FBP.
Streams here can be presented on a graph, where each [ module ]
connects with each other through immutable data:
The parts can be combined freely in game.script - there could be a version with mouse and/or keyboard inputs and visual representation in console outputs only or in graphical game window too.
For example:
-
console_game_example
uses only numeric keys (1-9, as if numeric keyboard is a game board) inputs and console prints, e.g.:
Current Player: O
DEBUG:SCRIPT: 1 - - X
DEBUG:SCRIPT: 2 - O -
DEBUG:SCRIPT: 3 X - -
Graph:
[ input\numeric_keyboard.lua ]
→ game_logic_input
→ [ logic\tic_tac_toe.lua ]
→ new_game_state
→ [ visual\console_print.lua ]
-
visual_game_example
uses only mouse inputs and visual representation is in game window (using label components), e.g.:
Graph:
[ input\mouse.lua ]
→ game_logic_input
→ [ logic\tic_tac_toe.lua ]
→ new_game_state
→ [ visual\label_print.lua ]
Source code:
License: MIT
Copyright: Paweł Jarosz 2024
This project includes immutable
module as a Defold dependency library. It can be used in your Defold projects as Dependency library: Point release version in Dependency
in your game.project
, e.g.: