common

package
v0.0.0-...-88544f8 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UpLeftBack     CornerIndex = 1
	DownLeftFront  CornerIndex = 2
	DownRightBack  CornerIndex = 3
	UpRightFront   CornerIndex = 4
	UpLeftFront    CornerIndex = 5
	DownLeftBack   CornerIndex = 6
	DownRightFront CornerIndex = 7
	UpRightBack    CornerIndex = 8

	// Short form
	ULB = UpLeftBack
	DLF = DownLeftFront
	DRB = DownRightBack
	URF = UpRightFront
	ULF = UpLeftFront
	DLB = DownLeftBack
	DRF = DownRightFront
	URB = UpRightBack

	// For iteration purposes
	FirstCornerIndex CornerIndex = 1
	LastCornerIndex  CornerIndex = 8
)
View Source
const (
	UpLeft     EdgeIndex = 1
	DownLeft   EdgeIndex = 2
	UpRight    EdgeIndex = 3
	DownRight  EdgeIndex = 4
	LeftBack   EdgeIndex = 5
	LeftFront  EdgeIndex = 6
	RightFront EdgeIndex = 7
	RightBack  EdgeIndex = 8
	UpFront    EdgeIndex = 9
	DownFront  EdgeIndex = 10
	DownBack   EdgeIndex = 11
	UpBack     EdgeIndex = 12

	// Short form
	UL = UpLeft
	DL = DownLeft
	UR = UpRight
	DR = DownRight
	LB = LeftBack
	LF = LeftFront
	RF = RightFront
	RB = RightBack
	UF = UpFront
	DF = DownFront
	DB = DownBack
	UB = UpBack

	// For iteration purposes
	FirstEdgeIndex EdgeIndex = 1
	LastEdgeIndex  EdgeIndex = 12
	EdgeIndexCount int       = 12
)
View Source
const (
	Up    Side = 0
	Down  Side = 1
	Left  Side = 2
	Right Side = 3
	Front Side = 4
	Back  Side = 5

	// Short form
	U = Up
	D = Down
	L = Left
	R = Right
	F = Front
	B = Back

	FirstSide Side = Up
	LastSide  Side = Back
	SideCount      = int(LastSide) + 1
)

WARN: Do not change values It is required for `corner_for` to work properly

View Source
const ArticleExampleSolution = "F L R' D2 B2 U " +
	"F2 D2 L R' F R2 F B2 R B' R2 B R B " +
	"L' U2 R' U2 D2 R2 D2 L' F2 L D2 L' " +
	"L2 R2 B2 R2 F2 R2 D2 U2 B2 U2 R2 U2 R2 U2"

Variables

View Source
var (
	CrownCornerUp    = [4]CornerIndex{1, 8, 4, 5}
	CrownCornerDown  = [4]CornerIndex{2, 7, 3, 6}
	CrownCornerLeft  = [4]CornerIndex{1, 5, 2, 6}
	CrownCornerRight = [4]CornerIndex{4, 8, 3, 7}
	CrownCornerFront = [4]CornerIndex{5, 4, 7, 2}
	CrownCornerBack  = [4]CornerIndex{8, 1, 6, 3}
)
View Source
var (
	CrownEdgeUp    = [4]EdgeIndex{12, 3, 9, 1}
	CrownEdgeDown  = [4]EdgeIndex{10, 4, 11, 2}
	CrownEdgeLeft  = [4]EdgeIndex{1, 6, 2, 5}
	CrownEdgeRight = [4]EdgeIndex{3, 8, 4, 7}
	CrownEdgeFront = [4]EdgeIndex{9, 7, 10, 6}
	CrownEdgeBack  = [4]EdgeIndex{12, 5, 11, 8}
)
View Source
var AllMoves []Move = makeAllMoves()
View Source
var CornerCoordMap = map[CubeCoord]CornerIndex{
	{Side: Up, FaceCoord: FaceCoord00}:    UpLeftBack,
	{Side: Left, FaceCoord: FaceCoord00}:  UpLeftBack,
	{Side: Back, FaceCoord: FaceCoord02}:  UpLeftBack,
	{Side: Down, FaceCoord: FaceCoord20}:  DownLeftFront,
	{Side: Left, FaceCoord: FaceCoord20}:  DownLeftFront,
	{Side: Back, FaceCoord: FaceCoord22}:  DownLeftFront,
	{Side: Down, FaceCoord: FaceCoord22}:  DownRightBack,
	{Side: Right, FaceCoord: FaceCoord22}: DownRightBack,
	{Side: Back, FaceCoord: FaceCoord20}:  DownRightBack,
	{Side: Up, FaceCoord: FaceCoord22}:    UpRightFront,
	{Side: Right, FaceCoord: FaceCoord00}: UpRightFront,
	{Side: Front, FaceCoord: FaceCoord02}: UpRightFront,
	{Side: Up, FaceCoord: FaceCoord20}:    UpLeftFront,
	{Side: Left, FaceCoord: FaceCoord02}:  UpLeftFront,
	{Side: Front, FaceCoord: FaceCoord00}: UpLeftFront,
	{Side: Down, FaceCoord: FaceCoord20}:  DownLeftBack,
	{Side: Left, FaceCoord: FaceCoord20}:  DownLeftBack,
	{Side: Back, FaceCoord: FaceCoord22}:  DownLeftBack,
	{Side: Down, FaceCoord: FaceCoord02}:  DownRightFront,
	{Side: Right, FaceCoord: FaceCoord20}: DownRightFront,
	{Side: Front, FaceCoord: FaceCoord22}: DownRightFront,
	{Side: Up, FaceCoord: FaceCoord02}:    UpRightBack,
	{Side: Right, FaceCoord: FaceCoord02}: UpRightBack,
	{Side: Back, FaceCoord: FaceCoord00}:  UpRightBack,
}
View Source
var CornerIndexMap = map[CornerIndex]CornerCoords{
	UpLeftBack: {
		A: CubeCoord{Side: Up, FaceCoord: FaceCoord00},
		B: CubeCoord{Side: Left, FaceCoord: FaceCoord00},
		C: CubeCoord{Side: Back, FaceCoord: FaceCoord02},
	},
	DownLeftFront: {
		A: CubeCoord{Side: Down, FaceCoord: FaceCoord20},
		B: CubeCoord{Side: Left, FaceCoord: FaceCoord20},
		C: CubeCoord{Side: Back, FaceCoord: FaceCoord22},
	},
	DownRightBack: {
		A: CubeCoord{Side: Down, FaceCoord: FaceCoord22},
		B: CubeCoord{Side: Right, FaceCoord: FaceCoord22},
		C: CubeCoord{Side: Back, FaceCoord: FaceCoord20},
	},
	UpRightFront: {
		A: CubeCoord{Side: Up, FaceCoord: FaceCoord22},
		B: CubeCoord{Side: Right, FaceCoord: FaceCoord00},
		C: CubeCoord{Side: Front, FaceCoord: FaceCoord02},
	},
	UpLeftFront: {
		A: CubeCoord{Side: Up, FaceCoord: FaceCoord20},
		B: CubeCoord{Side: Left, FaceCoord: FaceCoord02},
		C: CubeCoord{Side: Front, FaceCoord: FaceCoord00},
	},
	DownLeftBack: {
		A: CubeCoord{Side: Down, FaceCoord: FaceCoord20},
		B: CubeCoord{Side: Left, FaceCoord: FaceCoord20},
		C: CubeCoord{Side: Back, FaceCoord: FaceCoord22},
	},
	DownRightFront: {
		A: CubeCoord{Side: Down, FaceCoord: FaceCoord02},
		B: CubeCoord{Side: Right, FaceCoord: FaceCoord20},
		C: CubeCoord{Side: Front, FaceCoord: FaceCoord22},
	},
	UpRightBack: {
		A: CubeCoord{Side: Up, FaceCoord: FaceCoord02},
		B: CubeCoord{Side: Right, FaceCoord: FaceCoord02},
		C: CubeCoord{Side: Back, FaceCoord: FaceCoord00},
	},
}
View Source
var EdgeFaceMap = map[CubeCoord]EdgeFace{
	{Side: Up, FaceCoord: FaceCoord10}:    {UpLeft, 0},
	{Side: Left, FaceCoord: FaceCoord01}:  {UpLeft, 1},
	{Side: Down, FaceCoord: FaceCoord10}:  {DownLeft, 0},
	{Side: Left, FaceCoord: FaceCoord21}:  {DownLeft, 1},
	{Side: Up, FaceCoord: FaceCoord12}:    {UpRight, 0},
	{Side: Right, FaceCoord: FaceCoord01}: {UpRight, 1},
	{Side: Down, FaceCoord: FaceCoord12}:  {DownRight, 0},
	{Side: Right, FaceCoord: FaceCoord21}: {DownRight, 1},
	{Side: Left, FaceCoord: FaceCoord10}:  {LeftBack, 0},
	{Side: Back, FaceCoord: FaceCoord12}:  {LeftBack, 1},
	{Side: Left, FaceCoord: FaceCoord12}:  {LeftFront, 0},
	{Side: Front, FaceCoord: FaceCoord10}: {LeftFront, 1},
	{Side: Right, FaceCoord: FaceCoord10}: {RightFront, 0},
	{Side: Front, FaceCoord: FaceCoord12}: {RightFront, 1},
	{Side: Right, FaceCoord: FaceCoord12}: {RightBack, 0},
	{Side: Back, FaceCoord: FaceCoord10}:  {RightBack, 1},
	{Side: Up, FaceCoord: FaceCoord21}:    {UpFront, 0},
	{Side: Front, FaceCoord: FaceCoord01}: {UpFront, 1},
	{Side: Down, FaceCoord: FaceCoord01}:  {DownFront, 0},
	{Side: Front, FaceCoord: FaceCoord21}: {DownFront, 1},
	{Side: Down, FaceCoord: FaceCoord21}:  {DownBack, 0},
	{Side: Back, FaceCoord: FaceCoord21}:  {DownBack, 1},
	{Side: Up, FaceCoord: FaceCoord01}:    {UpBack, 0},
	{Side: Back, FaceCoord: FaceCoord01}:  {UpBack, 1},
}
View Source
var EdgeIndexMap = map[EdgeIndex]EdgeCoords{
	UpLeft: {
		A: CubeCoord{Side: Up, FaceCoord: FaceCoord10},
		B: CubeCoord{Side: Left, FaceCoord: FaceCoord01},
	},
	DownLeft: {
		A: CubeCoord{Side: Down, FaceCoord: FaceCoord10},
		B: CubeCoord{Side: Left, FaceCoord: FaceCoord21},
	},
	UpRight: {
		A: CubeCoord{Side: Up, FaceCoord: FaceCoord12},
		B: CubeCoord{Side: Right, FaceCoord: FaceCoord01},
	},
	DownRight: {
		A: CubeCoord{Side: Down, FaceCoord: FaceCoord12},
		B: CubeCoord{Side: Right, FaceCoord: FaceCoord21},
	},
	LeftBack: {
		A: CubeCoord{Side: Left, FaceCoord: FaceCoord10},
		B: CubeCoord{Side: Back, FaceCoord: FaceCoord12},
	},
	LeftFront: {
		A: CubeCoord{Side: Left, FaceCoord: FaceCoord12},
		B: CubeCoord{Side: Front, FaceCoord: FaceCoord10},
	},
	RightFront: {
		A: CubeCoord{Side: Right, FaceCoord: FaceCoord10},
		B: CubeCoord{Side: Front, FaceCoord: FaceCoord12},
	},
	RightBack: {
		A: CubeCoord{Side: Right, FaceCoord: FaceCoord12},
		B: CubeCoord{Side: Back, FaceCoord: FaceCoord10},
	},
	UpFront: {
		A: CubeCoord{Side: Up, FaceCoord: FaceCoord21},
		B: CubeCoord{Side: Front, FaceCoord: FaceCoord01},
	},
	DownFront: {
		A: CubeCoord{Side: Down, FaceCoord: FaceCoord01},
		B: CubeCoord{Side: Front, FaceCoord: FaceCoord21},
	},
	DownBack: {
		A: CubeCoord{Side: Down, FaceCoord: FaceCoord21},
		B: CubeCoord{Side: Back, FaceCoord: FaceCoord21},
	},
	UpBack: {
		A: CubeCoord{Side: Up, FaceCoord: FaceCoord01},
		B: CubeCoord{Side: Back, FaceCoord: FaceCoord01},
	},
}
View Source
var FaceCoord00 = FaceCoord{/* contains filtered or unexported fields */}
View Source
var FaceCoord01 = FaceCoord{/* contains filtered or unexported fields */}
View Source
var FaceCoord02 = FaceCoord{/* contains filtered or unexported fields */}
View Source
var FaceCoord10 = FaceCoord{/* contains filtered or unexported fields */}
View Source
var FaceCoord11 = FaceCoord{/* contains filtered or unexported fields */}
View Source
var FaceCoord12 = FaceCoord{/* contains filtered or unexported fields */}
View Source
var FaceCoord20 = FaceCoord{/* contains filtered or unexported fields */}
View Source
var FaceCoord21 = FaceCoord{/* contains filtered or unexported fields */}
View Source
var FaceCoord22 = FaceCoord{/* contains filtered or unexported fields */}

Functions

func ApplySequence

func ApplySequence(cube Cube, moves []Move)

func Shuffle

func Shuffle(cube Cube, r *rand.Rand, move_count int)

func SideToString

func SideToString(s Side) rune

Types

type CornerCoords

type CornerCoords struct {
	A, B, C CubeCoord
}

type CornerIndex

type CornerIndex uint8

type Cube

type Cube interface {
	IsSolved() bool
	Apply(Move)
	Get(CubeCoord) Side
	NewSolver() Solver
	Clone() Cube
	Blueprint() string
}

type CubeCoord

type CubeCoord struct {
	Side      Side
	FaceCoord FaceCoord
}

type EdgeCoords

type EdgeCoords struct {
	A, B CubeCoord
}

type EdgeFace

type EdgeFace struct {
	Index   EdgeIndex
	FaceNmb uint8
}

type EdgeIndex

type EdgeIndex uint8

type EdgeOrientation

type EdgeOrientation bool

type FaceCoord

type FaceCoord struct {
	// contains filtered or unexported fields
}

func NewFaceCoord

func NewFaceCoord(line, column int) (fc FaceCoord, err error)

func (FaceCoord) Column

func (fc FaceCoord) Column() int

func (FaceCoord) IsCorner

func (fc FaceCoord) IsCorner() bool

func (FaceCoord) IsEdge

func (fc FaceCoord) IsEdge() bool

func (FaceCoord) Line

func (fc FaceCoord) Line() int

func (FaceCoord) String

func (fc FaceCoord) String() string

type Move

type Move struct {
	Side     Side
	Rotation Rotation
}

func ArticleExampleShuffleMoveList

func ArticleExampleShuffleMoveList() []Move

func ArticleExampleSolutionMoveList

func ArticleExampleSolutionMoveList() []Move

func ParseMove

func ParseMove(str string) (move Move, err error)

func ParseMoveList

func ParseMoveList(str string) (moveList []Move, err error)

func (Move) IsRedudantWith

func (m Move) IsRedudantWith(o Move) bool

func (Move) Reverse

func (m Move) Reverse() Move

func (Move) String

func (m Move) String() string

type Rotation

type Rotation struct {
	// contains filtered or unexported fields
}

func RotationAntiClockwise

func RotationAntiClockwise() Rotation

func RotationClockwise

func RotationClockwise() Rotation

func RotationHalfTurn

func RotationHalfTurn() Rotation

func RotationNone

func RotationNone() Rotation

func (Rotation) Int

func (r Rotation) Int() int

func (Rotation) IsQuaterTurn

func (r Rotation) IsQuaterTurn() bool

func (Rotation) PositiveInt

func (r Rotation) PositiveInt() int

func (Rotation) Reverse

func (r Rotation) Reverse() Rotation

func (Rotation) String

func (r Rotation) String() string

type Side

type Side uint8

func SideFromLetter

func SideFromLetter(letter rune) (face Side, err error)

func (Side) Letter

func (s Side) Letter() (letter rune)

func (Side) String

func (s Side) String() string

type Solver

type Solver interface {
	Solve(c Cube) []Move
}

Jump to

Keyboard shortcuts

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