Documentation ¶
Overview ¶
Maps has the map data structures and some of the symmetry code
Index ¶
- Constants
- Variables
- func ItemColor(o Item) image.NRGBAColor
- func MapFile(name string) string
- func MapValidate(ref *Map, gen *Map) (int, string)
- func Permute4(r *rand.Rand) *[4]Direction
- func Permute4G(r *rand.Rand) *[5]Direction
- func Permute5(r *rand.Rand) *[5]Direction
- func Permute5D(d Direction, r *rand.Rand) *[5]Direction
- func VizSymTile(pv []Point, valid bool)
- type Direction
- type ImageHelper
- type IntSlice
- type Item
- type Map
- func (m *Map) ApplyOffsets(loc Location, o *Offsets, x func(loc Location))
- func (m *Map) ApplyOffsetsBreak(loc Location, o *Offsets, x func(loc Location) bool)
- func (m *Map) At(x, y int) image.NRGBAColor
- func (m *Map) Bounds() image.Rectangle
- func (m *Map) ColorModel() image.ColorModel
- func (m *Map) DumpMap() string
- func (m *Map) FreedomKey(loc Location) int
- func (m *Map) FreedomKeyOff(loc Location, o *Offsets) int
- func (m *Map) FreedomKeyThreat(loc Location, t []int8, nsup [4]int8) int
- func (m *Map) Hills(player int) []Location
- func (m *Map) MapId() string
- func (m *Map) NewSymData(minBits uint8) *SymData
- func (m *Map) OffsetsCachePopulateAll(mask *Mask, cutoff int64)
- func (m *Map) PointsToPath(points []Point) *Path
- func (m *Map) String() string
- func (m *Map) TApply()
- func (m *Map) TSet(i Item, locs ...Location) bool
- func (m *Map) Tile(minBits uint8) *SymData
- func (m *Map) WriteDebugImage(Desc string, seq int, At func(row, col int) image.NRGBAColor)
- type MapSymData
- type Mask
- type MoveMask
- type OffsetSlice
- type Offsets
- type Path
- type SymData
- func (s *SymData) SymAnalyze(tile *SymTile) (equivlen int)
- func (s *SymData) SymCompute(loc Location) (SymHash, *[8]SymHash, uint8, uint8)
- func (s *SymData) SymMapValidate(tile *SymTile) ([][]Location, bool)
- func (s *SymData) Tiling(tile *SymTile) Torus
- func (s *SymData) TransMapValidate(p Point) ([][]Location, bool)
- func (s *SymData) Update(loc Location) (SymHash, bool)
- func (s *SymData) UpdateSymmetryData(cutoff int64)
- type SymHash
- type SymTile
- func (tile *SymTile) Diagonals(t Torus, loc Location, marr []Location) []Location
- func (tile *SymTile) Generate(t Torus, loc Location, marr []Location) []Location
- func (tile *SymTile) Mirrors(t Torus, loc Location, marr []Location) []Location
- func (tile *SymTile) Rot180(t Torus, loc Location, marr []Location) []Location
- func (tile *SymTile) Rotations(t Torus, loc Location, marr []Location) []Location
- func (tile *SymTile) String() string
Constants ¶
const ( SYMN = 7 // Neighboorhood size. needs to be odd and < 8 SYMMAXCELLS = 32 // maximum number of cells for tranlations... )
const ( SYMTRANS = iota SYMMIRRORC SYMMIRRORR SYMROT90 SYMROT180 SYMROT270 SYMRM1 SYMRM2 SYMNONE SYMMIRBOTH SYMRMBOTH SYMMIR8 SYMROT8 )
const MAXMAPSIZE = 65536 // this dictated by using uint16 etc for depth
const MoveMaskPStep = 60
const MoveMaskPStep2 = 27720
Variables ¶
var AllMaps = []string{}
var ByteToDirection [256]Direction
var DirectionChar = [5]string{"n", "e", "s", "w", "-"}
var DirectionMap = map[string]Point{"n": {-1, 0}, "e": {0, -1}, "s": {1, 0}, "w": {0, 1}, "-": {0, 0}}
var DirectionOffset = [5]Point{North: {-1, 0}, East: {0, 1}, South: {1, 0}, West: {0, -1}, NoMovement: {0, 0}}
var MapRoot string
var MapSym = map[string]MapSymData{}/* 126 elements not displayed */
The maps from the final
var MapSymDev = map[string]MapSymData{}/* 310 elements not displayed */
The maps from the development phase
var Perm4 = [...][4]Direction{
{0, 1, 2, 3},
{0, 1, 3, 2},
{0, 2, 1, 3},
{0, 2, 3, 1},
{0, 3, 1, 2},
{0, 3, 2, 1},
{1, 0, 2, 3},
{1, 0, 3, 2},
{1, 2, 0, 3},
{1, 2, 3, 0},
{1, 3, 0, 2},
{1, 3, 2, 0},
{2, 0, 1, 3},
{2, 0, 3, 1},
{2, 1, 0, 3},
{2, 1, 3, 0},
{2, 3, 0, 1},
{2, 3, 1, 0},
{3, 0, 1, 2},
{3, 0, 2, 1},
{3, 1, 0, 2},
{3, 1, 2, 0},
{3, 2, 0, 1},
{3, 2, 1, 0},
}
var Perm4G = [...][5]Direction{
{0, 1, 2, 3, 4},
{3, 2, 1, 0, 4},
{0, 1, 3, 2, 4},
{0, 2, 1, 3, 4},
{0, 2, 3, 1, 4},
{0, 3, 1, 2, 4},
{0, 3, 2, 1, 4},
{1, 0, 2, 3, 4},
{1, 0, 3, 2, 4},
{1, 2, 0, 3, 4},
{1, 2, 3, 0, 4},
{1, 3, 0, 2, 4},
{1, 3, 2, 0, 4},
{2, 0, 1, 3, 4},
{2, 0, 3, 1, 4},
{2, 1, 0, 3, 4},
{2, 1, 3, 0, 4},
{2, 3, 0, 1, 4},
{2, 3, 1, 0, 4},
{3, 0, 1, 2, 4},
{3, 0, 2, 1, 4},
{3, 1, 0, 2, 4},
{3, 1, 2, 0, 4},
{3, 2, 0, 1, 4},
}
Perm4G is the directions permuted with the NoMovement guard. The ordering here is relevant since NPathInString uses the perm flag to index into this in order to generate bounding paths.
var Perm5 = [...][5]Direction{}/* 120 elements not displayed */
var PermStepD5 [4][6][5]Direction
var StepableItem [256]bool
var Steps = [4]Point{North: {-1, 0}, East: {0, 1}, South: {1, 0}, West: {0, -1}} // exclude no move
var Steps2 = []Point{{-1, 0}, {0, 1}, {1, 0}, {0, -1},
{-2, 0}, {-1, 1}, {0, 2}, {1, 1}, {2, 0}, {1, -1}, {0, -2}, {-1, -1},
}
var Steps3 = []Point{{-1, 0}, {0, 1}, {1, 0}, {0, -1},
{-2, 0}, {-1, 1}, {0, 2}, {1, 1}, {2, 0}, {1, -1}, {0, -2}, {-1, -1},
{-3, 0}, {-2, 1}, {-1, 2}, {0, 3}, {1, 2}, {2, 1},
{3, 0}, {2, -1}, {1, -2}, {0, -3}, {-1, -2}, {-2, -1},
}
var TerminalItem [256]bool
Functions ¶
func ItemColor ¶
func ItemColor(o Item) image.NRGBAColor
func Permute5 ¶
Draw from the arrays with rand.Intn(120) for a random permutation of directions including NoMovement
func VizSymTile ¶
func VizSymTile(pv []Point, valid bool)
Types ¶
type Direction ¶
type Direction uint8
Direction represents the direction concept for issuing orders.
type ImageHelper ¶
type ImageHelper struct {
// contains filtered or unexported fields
}
func (ImageHelper) Bounds ¶
func (ih ImageHelper) Bounds() image.Rectangle
func (ImageHelper) ColorModel ¶
func (ih ImageHelper) ColorModel() image.ColorModel
type Item ¶
type Item byte
Item codes from parsing turns
const ( UNKNOWN Item = iota WATER FOOD LAND MY_ANT PLAYER1 PLAYER2 PLAYER3 PLAYER4 PLAYER5 PLAYER6 PLAYER7 PLAYER8 PLAYER9 PLAYERGUESS MY_HILL HILL1 HILL2 HILL3 HILL4 HILL5 HILL6 HILL7 HILL8 HILL9 HILLGUESS // Not a real hill - our guess MY_DEAD DEAD1 DEAD2 DEAD3 DEAD4 DEAD5 DEAD6 DEAD7 DEAD8 DEAD9 MY_HILLANT HILLANT1 HILLANT2 HILLANT3 HILLANT4 HILLANT5 HILLANT6 HILLANT7 HILLANT8 HILLANT9 EXPLORE // An explore goal - terminal DEFEND // A defense spot - terminal RALLY // rally point for future attack - terminal WAYPOINT // a place to go on the way somewhere - terminal BLOCK // A moved ant or something else preventing stepping in OCCUPIED // An ant has moved here so it can't be moved into MAX_ITEM INVALID_ITEM Item = 255 )
func (Item) IsEnemyAnt ¶
func (Item) IsEnemyHill ¶
type Map ¶
type Map struct { Torus // Defines the geometry of the map Players int // This is stored in the map file Grid []Item // The map data possibly run through the symmetry mapper TGrid []Item // The true map data - updated via ProcessTurn *SymData // Symmetry data SID int // The integer id for symmetry so we can invalidate hill guesses etc. SMap [][]Location // Symmetry map // internal cache data BorderDist []uint8 // border distance LocStep [][5]Location // adjecent tile pointer }
func (*Map) ApplyOffsets ¶
ApplyOffsets applies a precomputed mask centered on location loc
func (*Map) ApplyOffsetsBreak ¶
ApplyOffsetsBreak applies a precomputed mask centered on location loc via function x, if x returns false the apply is aborted.
func (*Map) ColorModel ¶
func (m *Map) ColorModel() image.ColorModel
implement Image for fancy image debugging
func (*Map) FreedomKey ¶
func (*Map) FreedomKeyOff ¶
func (*Map) FreedomKeyThreat ¶
Compute degrees of freedom taking into account threat, returned value can be used to index into mask.MM
func (*Map) NewSymData ¶
func (*Map) OffsetsCachePopulateAll ¶
func (*Map) PointsToPath ¶
func (*Map) WriteDebugImage ¶
type MapSymData ¶
type Mask ¶
type Mask struct { Stride int // Cols Offsets // Locations added or removed for a step in each direction Union Offsets // Union is the one step out in any direction Add []Offsets // Points added for step in dir d Remove []Offsets // Points removed for step in dir d MM []*MoveMask // See FreedomKey for how to index into this MM2O Offsets }
type MoveMask ¶
type MoveMask struct { Offsets Add Offsets // Points added on the step. NFree int // Degrees of freedom PStep int // Probability denom PTot int // Probability denom Stride int // Cols used to generate loc offsets. MinPr []int // Pr numerator, matches Offsets order MaxPr []int // Pr numerator, matches Offsets order }
MoveMask is generated for a given number of degrees of freedom
func MakeMoveMask ¶
func MakeMoveMask2 ¶
type OffsetSlice ¶
type OffsetSlice []Point
Utility to implement manhattan distance sorting on a slice of Point Offsets TODO think about how to do this in context of torus. Assumes Offset < side/2
func (OffsetSlice) Len ¶
func (p OffsetSlice) Len() int
func (OffsetSlice) Less ¶
func (p OffsetSlice) Less(i, j int) bool
Sort metric is Manhattan distance from origin.
func (OffsetSlice) Swap ¶
func (p OffsetSlice) Swap(i, j int)
type Offsets ¶
type Offsets struct { R uint8 // Bounding Radius P []Point L []Location // contains filtered or unexported fields }
func LocationsToOffsets ¶
LocationsToOffsets takes a list of location offsets and returns a Points vector
func PointsToOffsets ¶
PointsToOffsets convert a set of points to location offsets
type SymData ¶
type SymData struct { *Map // The associated map for the Symmetry data. Offsets // The offsets cache MinBits uint8 // Ignore hashes with less than MinBits bits of different info NLen [16]int // Number of equiv group for a given N MinHash []SymHash // Sym data for a given point. Hashes []*[8]SymHash // Map from the location to all rotations of the given location Tiles map[SymHash]*SymTile // Map from minhash to location list. Fails int Check map[SymHash]bool // list of pending tiles to check. possibly carried over from a previous turn. }
func (*SymData) SymAnalyze ¶
Update the analysis of a tile and return the length of the infered equiv set
func (*SymData) SymCompute ¶
Compute the minhash for a given location, returning the bits of data, the minHash and all 8 hashes. It returns (0, -1, nil) in the event it encounters an unknown tile...
func (*SymData) SymMapValidate ¶
Takes a tile which has been analyzed and generates a sym map for it and simultaneously validates it.
func (*SymData) TransMapValidate ¶
func (*SymData) UpdateSymmetryData ¶
type SymTile ¶
type SymTile struct { Hash SymHash // the minhash Locs []Location // encountered tiles with this minhash Bits uint8 // bits of info Min(SYMN*SYMN - N*Water, N*Water) Self uint8 // number of matching self rotations Ignore bool // Ignore this tile for symmetry stuff. Subtile Torus // The dimensions for the subtile == the map dim if none Gen int // the generator for the origin Origin Point // Origin for discovered symmetries RM1 int RM2 int MR int MC int Translate Point // The offset for translation symmetry {0,0} for non translation EquivSet []Location // the location list for the identified symmetry of this tile. }
func (*SymTile) Diagonals ¶
func (tile *SymTile) Diagonals(t Torus, loc Location, marr []Location) []Location
func (*SymTile) Generate ¶
func (tile *SymTile) Generate(t Torus, loc Location, marr []Location) []Location
Given an analyzed tile generate the map for loc, appending map to marr t is the Main map.
func (*SymTile) Mirrors ¶
func (tile *SymTile) Mirrors(t Torus, loc Location, marr []Location) []Location
func (*SymTile) Rot180 ¶
func (tile *SymTile) Rot180(t Torus, loc Location, marr []Location) []Location