Documentation
¶
Overview ¶
Package cell implements CELL (Coordinate Encoding for Layered Locations) for Go.
CELL is a standardized format for representing coordinates on multi-dimensional game boards using a cyclical ASCII character system.
Format ¶
CELL uses a cyclical three-character-set system:
| Dimension | Condition | Character Set | |-----------------|-----------|----------------------------| | 1st, 4th, 7th… | n % 3 = 1 | Latin lowercase (`a`–`z`) | | 2nd, 5th, 8th… | n % 3 = 2 | Positive integers | | 3rd, 6th, 9th… | n % 3 = 0 | Latin uppercase (`A`–`Z`) |
Examples ¶
cell.Valid("a1") // true
cell.Valid("a1A") // true
cell.MustParse("e4") // []string{"e", "4"}
cell.MustToIndices("e4") // []int{4, 3}
cell.MustFromIndices([]int{4, 3}) // "e4"
See the CELL Specification for details.
Index ¶
- func Dimensions(s string) int
- func FromIndices(indices ...int) (string, error)
- func MustFromIndices(indices ...int) string
- func MustParse(s string) []string
- func MustToIndices(s string) []int
- func Parse(s string) ([]string, error)
- func Regex() *regexp.Regexp
- func ToIndices(s string) ([]int, error)
- func Valid(s string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dimensions ¶
Dimensions returns the number of dimensions in a CELL coordinate.
Returns 0 for invalid coordinates.
Examples:
cell.Dimensions("a") // 1
cell.Dimensions("a1") // 2
cell.Dimensions("a1A") // 3
cell.Dimensions("h8Hh8") // 5
cell.Dimensions("1nvalid") // 0
func FromIndices ¶
FromIndices converts 0-indexed integers to a CELL coordinate.
Examples:
cell.FromIndices(0, 0) // "a1", nil cell.FromIndices(4, 3) // "e4", nil cell.FromIndices(0, 0, 0) // "a1A", nil cell.FromIndices(25, 25, 25) // "z26Z", nil cell.FromIndices(26, 0, 26) // "aa1AA", nil cell.FromIndices() // "", error cell.FromIndices(-1, 0) // "", error
func MustFromIndices ¶
MustFromIndices converts 0-indexed integers to a CELL coordinate.
Returns the coordinate on success, panics on failure.
Examples:
cell.MustFromIndices(4, 3) // "e4" cell.MustFromIndices(0, 0, 0) // "a1A" cell.MustFromIndices() // panics
func MustParse ¶
MustParse parses a CELL coordinate string into dimensional components.
Returns the components on success, panics on failure.
Examples:
cell.MustParse("a1A") // []string{"a", "1", "A"}
cell.MustParse("1nvalid") // panics
func MustToIndices ¶
MustToIndices converts a CELL coordinate to a slice of 0-indexed integers.
Returns the indices on success, panics on failure.
Examples:
cell.MustToIndices("e4") // []int{4, 3}
cell.MustToIndices("a1A") // []int{0, 0, 0}
cell.MustToIndices("1nvalid") // panics
func Parse ¶
Parse parses a CELL coordinate string into dimensional components.
Returns the components on success, or an error on failure.
Examples:
cell.Parse("a1") // []string{"a", "1"}, nil
cell.Parse("a1A") // []string{"a", "1", "A"}, nil
cell.Parse("h8Hh8") // []string{"h", "8", "H", "h", "8"}, nil
cell.Parse("foobar") // []string{"foobar"}, nil
cell.Parse("invalid!") // nil, error
func Regex ¶
Regex returns the validation regular expression from CELL specification v1.0.0.
Note: This regex alone does not guarantee full compliance. The Valid function additionally rejects strings containing line breaks, as required by the specification's anchoring requirements.
func ToIndices ¶
ToIndices converts a CELL coordinate to a slice of 0-indexed integers.
Examples:
cell.ToIndices("a1") // []int{0, 0}, nil
cell.ToIndices("e4") // []int{4, 3}, nil
cell.ToIndices("a1A") // []int{0, 0, 0}, nil
cell.ToIndices("z26Z") // []int{25, 25, 25}, nil
cell.ToIndices("aa1AA") // []int{26, 0, 26}, nil
cell.ToIndices("1nvalid") // nil, error
func Valid ¶
Valid checks if a string represents a valid CELL coordinate.
Implements full-string matching as required by the CELL specification. Rejects any input containing line breaks (\r or \n).
Examples:
cell.Valid("a1") // true
cell.Valid("a1A") // true
cell.Valid("e4") // true
cell.Valid("a0") // false
cell.Valid("") // false
cell.Valid("1a") // false
cell.Valid("a1\n") // false
Types ¶
This section is empty.