GitHub快速开始

API 参考取自源码中的 Go 文档注释,以英文书写。

package match3

import "github.com/nsgo-dev/game/pkg/match3"

概述

Package match3 is experimental: its API and documented formats may change in a minor release. See the API stability policy. provides deterministic match detection for grid puzzles.

索引

类型

type Board struct {
	Width, Height int
	Cells         []int
}

Board is a rectangular deterministic match-3 grid. Zero cells are empty.

func New(width, height int, cells []int) Board

New returns a board with a copy of cells.

func (b Board) At(x, y int) int

At returns the cell at x,y, or zero outside the board.

func (b Board) Matches() []Point

Matches returns all cells belonging to horizontal or vertical runs of three or more equal non-zero pieces, sorted by row then column.

func (b *Board) Swap(a, c Point) bool

Swap exchanges adjacent cells and reports whether the resulting board has a match.

type Level struct {
	// Version is the level format version and must be 1.
	Version int `yaml:"version"`
	// Width is the number of columns and must be at least 3.
	Width int `yaml:"width"`
	// Height is the number of rows and must be at least 3.
	Height int `yaml:"height"`
	// Moves is the maximum number of moves and must be positive.
	Moves int `yaml:"moves"`
	// Goal is the target score or progress count and must be positive.
	Goal int `yaml:"goal"`
	// Cells contains one tile value for every cell in row-major order.
	Cells []int `yaml:"cells"`
}

Level is a validated version-one match-3 level definition.

func ParseLevel(data []byte) (Level, error)

ParseLevel decodes and validates a version-one level YAML document.

func (l Level) Validate() error

Validate checks the level version, dimensions, limits, and cell count.

type Point struct{ X, Y int }

Point identifies a cell by its column and row.