state

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2022 License: Unlicense Imports: 4 Imported by: 0

Documentation

Overview

Package state implements Sokoban state structure and provides other helper functions.

Index

Constants

View Source
const (
	BLANK        = 0x0
	BOX          = 0x1
	OBSTACLE     = 0x2
	PLAYER       = 0x4
	GOAL         = 0x8
	BOXONGOAL    = GOAL | BOX
	PLAYERONGOAL = GOAL | PLAYER
)

State tiles integer representations

View Source
const (
	BLANKCHAR        = "⬜"
	BOXCHAR          = "🟩"
	OBSTACLECHAR     = "🟥"
	PLAYERCHAR       = "🐈"
	GOALCHAR         = "⭕"
	BOXONGOALCHAR    = "✅"
	PLAYERONGOALCHAR = "😿"
)

State tiles human-readable representation (for both input and output)

View Source
const (
	UP
	DOWN
	LEFT
	RIGHT
)

Directions enum

View Source
const BORDER = 1

Added border for states (should never be less than 1)

Variables

This section is empty.

Functions

This section is empty.

Types

type PQ

type PQ []State

PQ is the underlying states priority queue.

func (PQ) Len

func (pq PQ) Len() int

func (PQ) Less

func (pq PQ) Less(i, j int) bool

func (*PQ) Pop

func (pq *PQ) Pop() any

func (*PQ) Push

func (pq *PQ) Push(x any)

func (PQ) Swap

func (pq PQ) Swap(i, j int)

type State

type State struct {
	Tiles [][]int

	Moves int
	// contains filtered or unexported fields
}

State is the main structure that stores the Sokoban board in Tiles, and the number of moves to get to this state in Moves.

func NewState

func NewState(puzzlePath string, costFunc func(*State) *int) State

NewState takes a the puzzle file path in puzzlePath, and the cost function in costFunc, and returns a state (mostly a start state).

func (*State) Cost

func (s *State) Cost() *int

Cost returns the cost of a state

func (*State) Equals

func (s *State) Equals(o *State) bool

Equlas checks if s is identical to o.

func (*State) IsSolved

func (s *State) IsSolved() bool

IsSolved checks if s is a solution state

func (*State) Path

func (s *State) Path() []State

Path returns the path from the oldest ancestor of s to s itself

func (*State) Pos

func (s *State) Pos() [2]int

Pos returns the player position (x,y) in s

func (*State) States

func (s *State) States() []State

States returns all the possible states from s

func (*State) StatesMap

func (s *State) StatesMap() map[int]State

StatesMap maps the possible states from s to their direction enum (UP/DOWN/LEFT/RIGHT)

func (*State) String

func (s *State) String() string

String returns a human-readable representation of s.

Jump to

Keyboard shortcuts

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