Documentation
¶
Overview ¶
Example (ParseRing) ¶
tests := []string{ "3+2", "0-1", } for _, test := range tests { ring, err := parseRing(test) if err != nil { panic(err) } fmt.Printf("location: %d, speed: %+d\n", ring.Location, ring.Speed) }
Output: location: 3, speed: +2 location: 0, speed: -1
Example (ParseRingGroup) ¶
rg, err := parseRingGroup("o") if err != nil { panic(err) } fmt.Printf("%s, %s", rg.Name(), rg.ShortName())
Output: Outer, o
Example (ParseRingGroups) ¶
rgs, err := parseRingGroups("mo,io,i") if err != nil { panic(err) } for _, rg := range rgs { fmt.Printf("%s, %s\n", rg.Name(), rg.ShortName()) }
Output: OuterMiddle, om OuterInner, oi Inner, i
Index ¶
Examples ¶
Constants ¶
View Source
const ( Outer RingGroup = 0b100 Middle RingGroup = 0b010 Inner RingGroup = 0b001 OuterMiddle = Outer | Middle OuterInner = Outer | Inner MiddleInner = Middle | Inner )
RingGroup 的合法值
View Source
const SCALES = 6
SCALES 总刻度值
Variables ¶
This section is empty.
Functions ¶
func CheckSolution ¶
CheckSolution 检查罗盘解谜步骤 对穷举的解法试错,尝试捕获最小能够解谜的转动操作方案
Types ¶
type Compass ¶
type Compass struct { OuterRing Ring // 外圈 MiddleRing Ring // 中圈 InnerRing Ring // 内圈 RingGroups []RingGroup // 方案,可以同时旋转的一个或多个圈组成的一个分组 }
Compass 引航罗盘
func ParseCompass ¶
ParseCompass 解析罗盘信息表达式 罗盘信息表达式满足如下格式:
{oLoc}{oSpeed},{mLoc}{mSpeed},{iLoc}{iSpeed}/{rg1},{rg2},{rg3} {oLoc}, {mLoc}, {iLoc}:分别表示外圈、中圈、内圈的初始刻度 {oSpeed}, {mSpeed}, {iSpeed}:分别表示外圈、中圈、内圈的旋转速度 {rg1}, {rg2}, {rg3}:分别表示三种转动方案,可选值如下 o m i om 或 mo oi 或 io im 或 mi
func (*Compass) IsRingGroupSupported ¶
IsRingGroupSupported 判断指定方案是否受当前罗盘支持
func (*Compass) String ¶
String 转为字符串表述
Example ¶
compass := &Compass{ InnerRing: Ring{Location: 0, Speed: 1}, MiddleRing: Ring{Location: 4, Speed: -4}, OuterRing: Ring{Location: 0, Speed: 2}, RingGroups: []RingGroup{ OuterInner, OuterMiddle, MiddleInner, }, } fmt.Println(compass.String())
Output: 0+2,4-4,0+1/mi,oi,om
type Ring ¶
type Ring struct { // 位置 // 指针从罗盘正左方∠0°沿顺时针方向旋转至当前位置所需的刻度 // 刻度以∠60°为一度 // 例如:0 表示正左方∠0°位置,3 表示正右方∠180°位置 // 有效范围是 0-6 Location int // 旋转速度 // 单位为刻度,符号表示旋转方向,正数是顺时针,负数是逆时针 // 旋转速度不会是 0(目前游戏内没有发现不旋转的圈) // 例如:-1 表示每次逆时针旋转 1 个刻度;2 表示每次顺时针旋转 2 个刻度 // 有效范围是 1-4 Speed int }
Ring 定义引航罗盘中的一圈
type Solver ¶
type Solver interface { // Solve 求解引航罗盘 Solve(ctx context.Context, compass Compass) (Steps, error) }
Solver 引航罗盘求解器
func NewHungerSolver ¶
func NewHungerSolver(opts SolverOptions) (Solver, error)
NewHungerSolver 创建穷举求解器
type Steps ¶
type Steps []Step
Steps 引航罗盘解谜步骤组合
func (Steps) String ¶
String 转为字符串表述
Example ¶
steps := Steps{ {RingGroup: Inner, Count: 1}, {RingGroup: OuterMiddle, Count: 3}, {RingGroup: MiddleInner, Count: 2}, {RingGroup: Outer, Count: 1}, {RingGroup: Inner, Count: 1}, {RingGroup: Middle, Count: 0}, } fmt.Println(steps.String())
Output: i2,mi2,o1,om3
Source Files
¶
Click to show internal directories.
Click to hide internal directories.