model

package
v0.0.0-...-1c404c5 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitPool

func InitPool(db int) *redis.Pool

Sets up the global Redis connection

func Subscribe

func Subscribe(key string, callback func(*Game))

Subscribe creates a Redis subscription for a key

Types

type Game

type Game struct {
	Key      string `redis:"-"`
	Type     game.Type
	Black    string
	White    string
	Size     int
	Handicap int
	Turn     int
	BlackScr int
	WhiteScr int
	Ko       int
	Last     string
	Board    [][]int `redis:"-"`
}

Game holds the parameters representing a game of Go

func Load

func Load(key string) (*Game, error)

Load returns a game from the database for a provided key

func New

func New(gtype game.Type, name string, color string, size int, hdcp int) (*Game, error)

New creates a game using a hash of the game parameters

func Recent

func Recent() []*Game

Recent returns a slice of recently created games

func (*Game) Join

func (g *Game) Join(name string) string

Join adds a player to a game

func (*Game) Move

func (g *Game) Move(color string, p Point) error

Move makes a move at a given coordinate and saves the game

func (*Game) Pass

func (g *Game) Pass(color string) error

Pass increments the turn number without making a move

func (*Game) ZeroSize

func (g *Game) ZeroSize() int

ZeroSize returns one less than the game board size

type Point

type Point struct {
	X int
	Y int
}

Point holds x and y coordinates of a point on a game board

func (Point) CheckLife

func (point Point) CheckLife(grid [][]int) ([]Point, error)

CheckLife searches for dead groups around a point and removes them

Jump to

Keyboard shortcuts

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