compass

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OuterRingGroup       RingGroup = 0b100
	MiddleRingGroup      RingGroup = 0b010
	InnerRingGroup       RingGroup = 0b001
	OuterMiddleRingGroup           = OuterRingGroup | MiddleRingGroup
	OuterInnerRingGroup            = OuterRingGroup | InnerRingGroup
	MiddleInnerRingGroup           = MiddleRingGroup | InnerRingGroup
)

RingGroup 的合法值

Variables

This section is empty.

Functions

func CheckSolution

func CheckSolution(compass Compass, solution Steps) (bool, error)

CheckSolution 检查罗盘解决结果

Types

type Compass

type Compass struct {
	// 内圈
	InnerRing Ring
	// 中圈
	MiddleRing Ring
	// 外圈
	OuterRing Ring
	// 圈分组
	// 可以同时旋转的一个或多个圈组成一个分组
	RingGroups []RingGroup
}

Compass 引航罗盘

func ParseCompass

func ParseCompass(compass string) (Compass, error)

ParseCompass 解析字符串表示的罗盘信息

func (*Compass) IsRingGroupSupported

func (compass *Compass) IsRingGroupSupported(rg RingGroup) bool

IsRingGroupSupported 判断指定圈分组是否是当前罗盘支持的

func (*Compass) Standardize

func (compass *Compass) Standardize() *Compass

Standardize 标准化

func (*Compass) String

func (compass *Compass) String() string

String 转为字符串表示

func (*Compass) Validate

func (compass *Compass) Validate() error

Validate TODO 合法化

type Ring

type Ring struct {
	// 位置
	// 指针从目标位置(即罗盘正左方向)沿顺时针方向旋转到当前位置所需旋转的角度处以 60 度,
	// 比如 0 表示目标位置, 3 表示指针指向正右方向
	// 因为一周是 360 度,因此该字段有效范围是: 0-5
	Location int
	// 旋转速度
	// 单位为 60 度,符号表示旋转方向,正数表示顺时针旋转,负数表示逆时针旋转
	// 比如: -1 表示每次逆时针旋转 60 度; 2 表示每次顺时针旋转 120 度
	Speed int
}

Ring 引航罗盘中的一圈

func ParseRing

func ParseRing(ring string) (Ring, error)

ParseRing 解析字符串表示的罗盘圈

type RingGroup

type RingGroup uint8

RingGroup 引航罗盘圈分组

func ParseRingGroup

func ParseRingGroup(ringGroup string) (RingGroup, error)

ParseRingGroup 解析字符串表示的罗盘圈组

func ParseRingGroups

func ParseRingGroups(ringGroups string) ([]RingGroup, error)

ParseRingGroups 解析字符串表示的罗盘圈组列表

func (RingGroup) Name

func (rg RingGroup) Name() string

Name 返回名

func (RingGroup) ShortName

func (rg RingGroup) ShortName() string

ShortName 返回简写名

func (RingGroup) String

func (rg RingGroup) String() string

String 返回字符串表示

type Solver

type Solver interface {
	// Solve 求解引航罗盘
	Solve(ctx context.Context, compass Compass) (Steps, error)
}

Solver 引航罗盘求解器

func NewDefaultSolver

func NewDefaultSolver(opts SolverOptions) (Solver, error)

NewDefaultSolver 创建一个默认引航罗盘求解器

type SolverOptions

type SolverOptions struct {
	// 日志记录器
	Logger logr.Logger
}

SolverOptions Solver 的设置选项

type Step

type Step struct {
	// 转动的圈分组
	RingGroup RingGroup
	// 转动次数
	Count int
}

Step 转动引航罗盘的步骤

func (*Step) String

func (step *Step) String() string

String 转为字符串表示

func (*Step) Validate

func (step *Step) Validate() error

Validate 合法化

type Steps

type Steps []Step

Steps 转动引航罗盘的步骤组合

func (Steps) Standardize

func (steps Steps) Standardize() Steps

Standardize 标准化

func (Steps) String

func (steps Steps) String() string

String 转为字符串表示

func (Steps) Validate

func (steps Steps) Validate() error

Validate TODO 合法化

Jump to

Keyboard shortcuts

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