Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

tictactoe source realm

Package tictactoe is a two-player tic-tac-toe realm. The first caller to Join becomes X, the second becomes O; player...

Overview

Package tictactoe is a two-player tic-tac-toe realm. The first caller to Join becomes X, the second becomes O; players then alternate Move calls by cell index (0-8, left-to-right top-to-bottom) until someone wins or the board fills. Reset starts a fresh game once the current one has ended.

Functions 4

func Join

crossing Action
1func Join(cur realm) string
source

Join seats the caller as X (if the seat is open) or O (if X is taken). Panics if both seats are already filled.

func Move

crossing Action
1func Move(cur realm, pos int)
source

Move places the caller's mark at the given cell (0-8) if it is their turn and the cell is empty, then checks for a win or a draw.

func Render

1func Render(path string) string
source

Render draws the current board and game status as markdown.

func Reset

crossing Action
1func Reset(cur realm)
source

Reset clears the board for a new game. Only callable once the current game has ended (someone won or the board is full).

Imports 2

  • chain stdlib
  • strconv stdlib

Source Files 2