reversi

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 1 Imported by: 0

README

reversi

A pure-Go Reversi (Othello) rules engine — no protocol, no I/O, standard library only.

LegalSquares lists playable squares, Place applies a move and flips all closed lines, and Advance decides who moves next — computing passes and game-over deterministically from the position, so a pass is never a separate message (which would only be a desync surface in networked play).

b := reversi.Start()
for _, sq := range reversi.LegalSquares(b, 1) { // +1 = Black, moves first
    nb, err := reversi.Place(b, 1, sq)
    if err == nil {
        next, passed, over := reversi.Advance(nb, 1)
        _ = next; _ = passed; _ = over
        b = nb
        break
    }
}
black, white := reversi.Counts(b)
_ = black; _ = white

Install

go get github.com/richardwooding/reversi

Extracted from kibitz.

License

MIT

Documentation

Overview

Package reversi is a pure-Go Reversi (Othello) rules engine — no protocol, no I/O, standard library only.

Extracted from https://github.com/richardwooding/kibitz

Sides are +1 (Black, P1, moves first) and -1 (White, P2). Passes are a pure function of the position, so they are COMPUTED by Advance and never sent over the wire — a pass message would only be a desync surface.

Index

Constants

This section is empty.

Variables

View Source
var ErrIllegalPlace = errors.New("reversi: illegal placement")

Functions

func Advance

func Advance(b Board, justMoved int8) (next int8, passed, over bool)

Advance decides who moves after side just moved: the opponent if it has a move; otherwise the mover again (a computed pass); otherwise the game is over (covers two-pass and full-board endings identically).

func Counts

func Counts(b Board) (black, white int)

Counts returns the disc totals.

func LegalSquares

func LegalSquares(b Board, side int8) []int8

LegalSquares lists every square where side may place.

Types

type Board

type Board [64]int8

Board cells: 0 empty, +1 black, -1 white. Index = row*8 + col.

func Place

func Place(b Board, side, sq int8) (Board, error)

Place validates and applies a placement, flipping all closed lines.

func Start

func Start() Board

Start is the standard central position.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL