maps

package
v0.0.0-...-989e160 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2012 License: GPL-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Maps has the map data structures and some of the symmetry code

Index

Constants

View Source
const (
	SYMN        = 7  // Neighboorhood size.  needs to be odd and < 8
	SYMMAXCELLS = 32 // maximum number of cells for tranlations...
)
View Source
const (
	SYMTRANS = iota
	SYMMIRRORC
	SYMMIRRORR
	SYMROT90
	SYMROT180
	SYMROT270
	SYMRM1
	SYMRM2
	SYMNONE
	SYMMIRBOTH
	SYMRMBOTH
	SYMMIR8
	SYMROT8
)
View Source
const MAXMAPSIZE = 65536 // this dictated by using uint16 etc for depth
View Source
const MoveMaskPStep = 60
View Source
const MoveMaskPStep2 = 27720

Variables

View Source
var AllMaps = []string{}
View Source
var ByteToDirection [256]Direction
View Source
var DirectionChar = [5]string{"n", "e", "s", "w", "-"}
View Source
var DirectionMap = map[string]Point{"n": {-1, 0}, "e": {0, -1}, "s": {1, 0}, "w": {0, 1}, "-": {0, 0}}
View Source
var DirectionOffset = [5]Point{North: {-1, 0}, East: {0, 1}, South: {1, 0}, West: {0, -1}, NoMovement: {0, 0}}
View Source
var MapRoot string
View Source
var MapSym = map[string]MapSymData{}/* 126 elements not displayed */

The maps from the final

View Source
var MapSymDev = map[string]MapSymData{}/* 310 elements not displayed */

The maps from the development phase

View Source
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},
}
View Source
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.

View Source
var Perm5 = [...][5]Direction{}/* 120 elements not displayed */
View Source
var PermStepD5 [4][6][5]Direction
View Source
var StepableItem [256]bool
View Source
var Steps = [4]Point{North: {-1, 0}, East: {0, 1}, South: {1, 0}, West: {0, -1}} // exclude no move
View Source
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},
}
View Source
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},
}
View Source
var TerminalItem [256]bool

Functions

func ItemColor

func ItemColor(o Item) image.NRGBAColor

func MapFile

func MapFile(name string) string

func MapValidate

func MapValidate(ref *Map, gen *Map) (int, string)

func Permute4

func Permute4(r *rand.Rand) *[4]Direction

Draw from the arrays with rand.Intn(24) for a random permutation of directions.

func Permute4G

func Permute4G(r *rand.Rand) *[5]Direction

Returns a permute4 + guard used in eg NPathIn

func Permute5

func Permute5(r *rand.Rand) *[5]Direction

Draw from the arrays with rand.Intn(120) for a random permutation of directions including NoMovement

func Permute5D

func Permute5D(d Direction, r *rand.Rand) *[5]Direction

Return a set of directions with d first, opposite last an the other 3 permuted.

func VizSymTile

func VizSymTile(pv []Point, valid bool)

Types

type Direction

type Direction uint8

Direction represents the direction concept for issuing orders.

const (
	North Direction = iota
	East
	South
	West
	NoMovement
	InvalidMove
)

func (Direction) String

func (d Direction) String() string

type ImageHelper

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

func (ImageHelper) At

func (ih ImageHelper) At(x, y int) image.Color

func (ImageHelper) Bounds

func (ih ImageHelper) Bounds() image.Rectangle

func (ImageHelper) ColorModel

func (ih ImageHelper) ColorModel() image.ColorModel

type IntSlice

type IntSlice []int

func (IntSlice) Len

func (p IntSlice) Len() int

func (IntSlice) Less

func (p IntSlice) Less(i, j int) bool

func (IntSlice) Swap

func (p IntSlice) Swap(i, j int)

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 ToItem

func ToItem(c byte) Item

Map a character to an Item code

func (Item) IsEnemyAnt

func (o Item) IsEnemyAnt(player int) bool

func (Item) IsEnemyHill

func (o Item) IsEnemyHill(player int) bool

func (Item) IsHill

func (o Item) IsHill() bool

func (Item) String

func (o Item) String() string

func (Item) ToSymbol

func (o Item) ToSymbol() byte

Map an Item code to a character

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 MapLoad

func MapLoad(in *bufio.Reader) (*Map, os.Error)

func MapLoadFile

func MapLoadFile(file string) (m *Map, err os.Error)

func NewMap

func NewMap(rows, cols, players int) *Map

func (*Map) ApplyOffsets

func (m *Map) ApplyOffsets(loc Location, o *Offsets, x func(loc Location))

ApplyOffsets applies a precomputed mask centered on location loc

func (*Map) ApplyOffsetsBreak

func (m *Map) ApplyOffsetsBreak(loc Location, o *Offsets, x func(loc Location) bool)

ApplyOffsetsBreak applies a precomputed mask centered on location loc via function x, if x returns false the apply is aborted.

func (*Map) At

func (m *Map) At(x, y int) image.NRGBAColor

func (*Map) Bounds

func (m *Map) Bounds() image.Rectangle

func (*Map) ColorModel

func (m *Map) ColorModel() image.ColorModel

implement Image for fancy image debugging

func (*Map) DumpMap

func (m *Map) DumpMap() string

func (*Map) FreedomKey

func (m *Map) FreedomKey(loc Location) int

func (*Map) FreedomKeyOff

func (m *Map) FreedomKeyOff(loc Location, o *Offsets) int

func (*Map) FreedomKeyThreat

func (m *Map) FreedomKeyThreat(loc Location, t []int8, nsup [4]int8) int

Compute degrees of freedom taking into account threat, returned value can be used to index into mask.MM

func (*Map) Hills

func (m *Map) Hills(player int) []Location

Return list of Hill Locations, player -1 is all players

func (*Map) MapId

func (m *Map) MapId() string

MapId computes an md5 hash of the string representation of the map data

func (*Map) NewSymData

func (m *Map) NewSymData(minBits uint8) *SymData

func (*Map) OffsetsCachePopulateAll

func (m *Map) OffsetsCachePopulateAll(mask *Mask, cutoff int64)

func (*Map) PointsToPath

func (m *Map) PointsToPath(points []Point) *Path

func (*Map) String

func (m *Map) String() string

func (*Map) TApply

func (m *Map) TApply()

func (*Map) TSet

func (m *Map) TSet(i Item, locs ...Location) bool

Return false if the symmetry mapping gives a result inconsistent with TGrid

func (*Map) Tile

func (m *Map) Tile(minBits uint8) *SymData

Tiles an entire map.

func (*Map) WriteDebugImage

func (m *Map) WriteDebugImage(Desc string, seq int, At func(row, col int) image.NRGBAColor)

type MapSymData

type MapSymData struct {
	Cycle            int
	Equivlen         int
	Gen              int
	Label            string
	Tiles            int
	Rows             int
	Cols             int
	Translate        Point
	RM1, RM2, MR, MC int
	Origin           Point
}

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
}

func MakeMask

func MakeMask(r2, rows, cols int) *Mask

Generate a mask for a circle, including the added/removed list for steps in any directions plus a union of the 1step move There is also the move mask which includes probabilities of a cell falling within the mask given available moves.

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 MakeMoveMask(r2 int, cols int) []*MoveMask

func MakeMoveMask2

func MakeMoveMask2(r2 int, cols int) []*MoveMask

func (*MoveMask) String

func (mm *MoveMask) String() string

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

func LocationsToOffsets(locs []Location, cols int) Offsets

LocationsToOffsets takes a list of location offsets and returns a Points vector

func PointsToOffsets

func PointsToOffsets(pv []Point, cols int) Offsets

PointsToOffsets convert a set of points to location offsets

type Path

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

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

func (s *SymData) SymAnalyze(tile *SymTile) (equivlen int)

Update the analysis of a tile and return the length of the infered equiv set

func (*SymData) SymCompute

func (s *SymData) SymCompute(loc Location) (SymHash, *[8]SymHash, uint8, uint8)

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

func (s *SymData) SymMapValidate(tile *SymTile) ([][]Location, bool)

Takes a tile which has been analyzed and generates a sym map for it and simultaneously validates it.

func (*SymData) Tiling

func (s *SymData) Tiling(tile *SymTile) Torus

func (*SymData) TransMapValidate

func (s *SymData) TransMapValidate(p Point) ([][]Location, bool)

func (*SymData) Update

func (s *SymData) Update(loc Location) (SymHash, bool)

Returns the minhash, true if there is a potential new symmetry

func (*SymData) UpdateSymmetryData

func (s *SymData) UpdateSymmetryData(cutoff int64)

type SymHash

type SymHash int64 // SymHash needs to be int64 if SYMN = 7, int32 otherwise.

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

func (*SymTile) Rotations

func (tile *SymTile) Rotations(t Torus, loc Location, marr []Location) []Location

func (*SymTile) String

func (tile *SymTile) String() string

Jump to

Keyboard shortcuts

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