witsjson

package
v0.0.0-...-a77d1df Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BonusList_New

func BonusList_New(coord HexCoordJSON) wits.TileDefinition

func FloorList_New

func FloorList_New(coord HexCoordJSON) wits.TileDefinition

func MarshalTerrain

func MarshalTerrain[T ~[]wits.TileDefinition](
	enum string, data *T) ([]byte, error)

Marshaling the types back into a list can also be done in a generic way. The list of tile definitions may contain any terrain type, this method will both filter and encode while keeping to the signature of JSON marshaling. When filtering, it handles common classes (base, spawn, bonus) together.

func NewBase

func NewBase(i, j int, team wits.FriendlyEnum) wits.TileDefinition

func NewSpawn

func NewSpawn(i, j int, team wits.FriendlyEnum) wits.TileDefinition

func NewTile

func NewTile(terrain string, i, j int) wits.TileDefinition

func ParseClass

func ParseClass(name string) wits.UnitClassEnum

func ParseGenericAction

func ParseGenericAction(typename string, encoded []byte) (wits.PlayerAction, error)

func UnmarshalTerrain

func UnmarshalTerrain[T ~[]wits.TileDefinition](
	encoded []byte, enum string, defs *T) error

A generic approach to unmarshaling each list of coordinates into their representative terrain type. This provides the benefit of typed unmarshaling of the JSON representation without the tedium of repetitive code.

func WallList_New

func WallList_New(coord HexCoordJSON) wits.TileDefinition

Types

type ActionNameJSON

type ActionNameJSON string
const (
	PASS_PLAY     ActionNameJSON = "Pass"
	MOVE_UNIT     ActionNameJSON = "MoveUnit"
	HEAL_UNIT     ActionNameJSON = "HealUnit"
	SPAWN_UNIT    ActionNameJSON = "SpawnUnit"
	ATTACK        ActionNameJSON = "Attack"
	CHARM_UNIT    ActionNameJSON = "CharmUnit"
	TOGGLE_ALT    ActionNameJSON = "ToggleAlt"
	TELEPORT_UNIT ActionNameJSON = "Teleport"
)

type AttackAction

type AttackAction struct {
	Agent  wits.HexCoord `json:"agent"`
	Target wits.HexCoord `json:"target"`
}

Some units may attack other units, and their attack strength is dependent on the UnitClass of the attacking unit, the details of which are in the game state. The action itself only needs to mention the attacker's location and the location of the unit's target (only units may attack).

func (AttackAction) ActionName

func (action AttackAction) ActionName() string

func (AttackAction) RelVarEncoding

func (action AttackAction) RelVarEncoding() string

func (AttackAction) Visit

func (action AttackAction) Visit(state *wits.GameState) error

type BaseHealth

type BaseHealth wits.BaseHealth

This value type has hard-coded limits of 0..5 checked when decoding.

func (*BaseHealth) UnmarshalJSON

func (health *BaseHealth) UnmarshalJSON(encoded []byte) error

type BaseList

type BaseList []wits.TileDefinition

Unpacked from a JSON of []HexCoord into a []TileDefinition of TERRAIN_TYPE_BASE.

func (*BaseList) MarshalJSON

func (defs *BaseList) MarshalJSON() ([]byte, error)

func (*BaseList) UnmarshalJSON

func (defs *BaseList) UnmarshalJSON(encoded []byte) error

Unmarshals the list of coordinates for base positions.

type BonusList

type BonusList []wits.TileDefinition

Unpacked from a JSON of []HexCoord into a []TileDefinition of TERRAIN_TYPE_BONUS.

func (*BonusList) MarshalJSON

func (defs *BonusList) MarshalJSON() ([]byte, error)

func (*BonusList) UnmarshalJSON

func (defs *BonusList) UnmarshalJSON(encoded []byte) error

Unmarshals the list of coordinates for bonus positions.

type CharmUnitAction

type CharmUnitAction struct {
	Agent  wits.HexCoord `json:"agent"`
	Target wits.HexCoord `json:"target"`
}

This is a special action for the Scrambler unit class. It converts the unit of an opposing team onto the player's team.

func (CharmUnitAction) ActionName

func (action CharmUnitAction) ActionName() string

func (CharmUnitAction) RelVarEncoding

func (action CharmUnitAction) RelVarEncoding() string

func (CharmUnitAction) Visit

func (action CharmUnitAction) Visit(state *wits.GameState) error

type FloorList

type FloorList []wits.TileDefinition

Unpacked from a JSON of []HexCoord into a []TileDefinition of TERRAIN_TYPE_FLOOR.

func (*FloorList) MarshalJSON

func (defs *FloorList) MarshalJSON() ([]byte, error)

func (*FloorList) UnmarshalJSON

func (defs *FloorList) UnmarshalJSON(encoded []byte) error

Unmarshals the list of coordinates for floor positions.

type FriendlyEnumJSON

type FriendlyEnumJSON wits.FriendlyEnum

A JSON-compatible representation wrapping the team-association enum.

func ParseTeam

func ParseTeam(color string) FriendlyEnumJSON

func (FriendlyEnumJSON) MarshalJSON

func (team FriendlyEnumJSON) MarshalJSON() ([]byte, error)

func (FriendlyEnumJSON) String

func (team FriendlyEnumJSON) String() string

func (*FriendlyEnumJSON) UnmarshalJSON

func (team *FriendlyEnumJSON) UnmarshalJSON(encoded []byte) error

Read and decode the JSON representation, accepting either integer or string. When reading from JSON, if it is an integer it is interpreted as 1-indexed sequence, and if it is a string then the canonical team coloring is used.

type GameInitJSON

type GameInitJSON struct {
	// Defaults for all these values are defined in the map (see GameMap)
	Units_      []wits.UnitInit `json:"units,omitempty"`
	UsedSpawns_ []wits.HexCoord `json:"used_spawns,omitempty"`
	BonusWits_  []wits.HexCoord `json:"bonus_wits,omitempty"`
	BaseHP_     []BaseHealth    `json:"base_hp,omitempty"` // all bases default 5hp
}

func (GameInitJSON) BonusWits

func (init GameInitJSON) BonusWits() []wits.HexCoordIndex

func (GameInitJSON) Units

func (init GameInitJSON) Units() []wits.UnitInit

func (GameInitJSON) UsedSpawns

func (init GameInitJSON) UsedSpawns() []wits.HexCoordIndex

type GameMapJSON

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

Game maps may be loaded as a complete definition or only referenced by name. The game logic must load the complete map definition in order to simulate the gameplay in its turns.

func (GameMapJSON) IsLoaded

func (m GameMapJSON) IsLoaded() bool

Returns true if the full map definition has been loaded from disk.

func (GameMapJSON) Legacy

func (gamemap GameMapJSON) Legacy() bool

func (GameMapJSON) MapID

func (gamemap GameMapJSON) MapID() wits.GameMapID

Whether the map has been loaded or not, its identifier is known.

func (GameMapJSON) MapName

func (gamemap GameMapJSON) MapName() wits.GameMapName

func (GameMapJSON) MarshalJSON

func (m GameMapJSON) MarshalJSON() ([]byte, error)

We only need to marshal the game's name, its definition is held (once) in a separate file. To marshal the file's content, encode the MapDefinition type.

func (GameMapJSON) Terrain

func (gamemap GameMapJSON) Terrain() wits.TerrainDefinition

func (GameMapJSON) Units

func (gamemap GameMapJSON) Units() []wits.UnitInit

func (*GameMapJSON) UnmarshalJSON

func (m *GameMapJSON) UnmarshalJSON(encoded []byte) error

When unmarshaling, we first attempt to read it as a string (as it would be when found in a game replay encoding). If it is not a string, we unmarshal the map definition (as it appears in the map file representation).

type GameReplayJSON

type GameReplayJSON struct {
	GameID_  OsnGameID        `json:"game_id"`
	GameMap_ wits.GameMapName `json:"map_name"`
	Init_    GameInitJSON     `json:"init,omitempty"`
	Turns_   []PlayerTurnJSON `json:"replay"`

	Players_ []PlayerRoleJSON `json:"players"`
}

func (GameReplayJSON) GameID

func (replay GameReplayJSON) GameID() wits.MatchID

func (GameReplayJSON) MapName

func (replay GameReplayJSON) MapName() wits.GameMapName

func (GameReplayJSON) MatchReplay

func (replay GameReplayJSON) MatchReplay() []wits.PlayerTurn

func (GameReplayJSON) WriteJSON

func (replay GameReplayJSON) WriteJSON(filename string) error

This is not a method offered in wits.GameReplay but perhaps it should be.

type HealUnitAction

type HealUnitAction struct {
	Healer wits.HexCoord `json:"healer"`
	Target wits.HexCoord `json:"target"`
	// contains filtered or unexported fields
}

Heals a friendly unit to their initial HP + 1.

func (HealUnitAction) ActionName

func (action HealUnitAction) ActionName() string

func (HealUnitAction) RelVarEncoding

func (action HealUnitAction) RelVarEncoding() string

func (HealUnitAction) Visit

func (action HealUnitAction) Visit(state *wits.GameState) error

type HexCoordJSON

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

Satisfies schema.HexCoord and serializes to a 2D-array. When deseriailzing, asserts that the list/slice has exactly two elements, returning an error.

func NewHexCoord

func NewHexCoord(i, j int) HexCoordJSON

Trivial constructor function, exposes a one-time setter for the coordinates.

func (HexCoordJSON) I

func (coord HexCoordJSON) I() int

func (HexCoordJSON) J

func (coord HexCoordJSON) J() int

func (HexCoordJSON) MarshalJSON

func (coord HexCoordJSON) MarshalJSON() ([]byte, error)

Marshals the coordinate as its 2D list representation.

func (HexCoordJSON) String

func (coord HexCoordJSON) String() string

Simple string representation that formats it like a vector. Not meant to be its parseable form.

func (*HexCoordJSON) UnmarshalJSON

func (coord *HexCoordJSON) UnmarshalJSON(encoded []byte) error

The deserialization process first tries to parse it as an int array, checking that it fits the dimension types. Failing that, it will read the value as an (i, j)-keyed jsondict representation. Otherwise returns an error.

type LeagueTierJSON

type LeagueTierJSON wits.LeagueTier

type MapDefinition

type MapDefinition struct {
	MapID   string            `json:"map_id"`
	Name    string            `json:"name"`
	Terrain TerrainDefinition `json:"terrain"`
	Init    MapInit           `json:"init"`
	Rotate  *Rotation         `json:"rotate,omitempty"`
	Mirror  *Reflection       `json:"mirror,omitempty"`
	Legacy  *bool             `json:"legacy,omitempty"`
}

type MapInit

type MapInit struct {
	Units []UnitInitJSON `json:"units"`
}

Initialization of map-related game state that is not terrain related.

type MoveUnitAction

type MoveUnitAction struct {
	From wits.HexCoord `json:"from"`
	To   wits.HexCoord `json:"to"`
	// contains filtered or unexported fields
}

Moves a unit from a HexCoord position to a (different) HexCoord position.

func (MoveUnitAction) ActionName

func (action MoveUnitAction) ActionName() string

func (MoveUnitAction) RelVarEncoding

func (action MoveUnitAction) RelVarEncoding() string

func (MoveUnitAction) Visit

func (action MoveUnitAction) Visit(state *wits.GameState) error

type OsnGameID

type OsnGameID string

Game IDs read in by JSON Unmarshaling will have already been shortened.

func (OsnGameID) MarshalJSON

func (gameID OsnGameID) MarshalJSON() ([]byte, error)

func (OsnGameID) ShortID

func (gameID OsnGameID) ShortID() string

type PlayerID

type PlayerID struct {
	GCID_ wits.GCID `json:"gcID"`
}

May be inlined by other structs (see PlayerRoleJSON and player standings).

func (PlayerID) GCID

func (id PlayerID) GCID() wits.GCID

type PlayerRoleJSON

type PlayerRoleJSON struct {
	PlayerID
	Name_   string               `json:"name"`
	Race_   UnitRaceJSON         `json:"race"`
	Team_   FriendlyEnumJSON     `json:"team"`
	Result_ TerminalStatusJSON   `json:"result"`
	Before_ wits.PlayerStandings `json:"before"`
	After_  wits.PlayerUpdate    `json:"after"`
	BaseHP_ BaseHealth           `json:"base_hp"`
	Wits_   int                  `json:"wits"`
}

Compatible with wits.PlayerRole interface, from a JSON-formatted replay.

func (PlayerRoleJSON) After

func (role PlayerRoleJSON) After() wits.PlayerUpdate

func (PlayerRoleJSON) BaseHP

func (role PlayerRoleJSON) BaseHP() wits.BaseHealth

func (PlayerRoleJSON) Before

func (role PlayerRoleJSON) Before() wits.PlayerStandings

func (PlayerRoleJSON) Name

func (role PlayerRoleJSON) Name() wits.PlayerName

func (PlayerRoleJSON) Race

func (role PlayerRoleJSON) Race() wits.UnitRaceEnum

func (PlayerRoleJSON) Result

func (role PlayerRoleJSON) Result() wits.TerminalStatus

func (PlayerRoleJSON) Team

func (role PlayerRoleJSON) Team() wits.FriendlyEnum

func (PlayerRoleJSON) Wits

func (role PlayerRoleJSON) Wits() wits.ActionPoints

type PlayerStandingsJSON

type PlayerStandingsJSON struct {
	Tier_ wits.LeagueTier `json:"tier"`
	Rank_ wits.LeagueRank `json:"rank"`
}

Player standings is the tier/rank of the player before or after the match.

func (PlayerStandingsJSON) Rank

func (standings PlayerStandingsJSON) Rank() wits.LeagueRank

func (PlayerStandingsJSON) Tier

func (standings PlayerStandingsJSON) Tier() wits.LeagueTier

type PlayerTurnJSON

type PlayerTurnJSON struct {
	Turn_    uint                `json:"turn"`
	Actions_ []wits.PlayerAction `json:"actions"`

	// Temporarily here so that we can validate the simulation against the intermediate states.
	State_ wits.GameState `json:"state"`
}

func (PlayerTurnJSON) Actions

func (turn PlayerTurnJSON) Actions() []wits.PlayerAction

Give the list of actions performed for the current turn.

func (PlayerTurnJSON) Opponent

func (turn PlayerTurnJSON) Opponent() wits.FriendlyEnum

Works for both 1v1 and multiplayer.

func (PlayerTurnJSON) State

func (turn PlayerTurnJSON) State() wits.GameState

DEPRECATED: included for sanity checks over existing replays until proper testing is in place.

func (PlayerTurnJSON) Team

func (turn PlayerTurnJSON) Team() wits.FriendlyEnum

On odd turns it is team 1's turn, on even turns it is team 2's turn.

func (PlayerTurnJSON) TurnCount

func (turn PlayerTurnJSON) TurnCount() uint

type Reflection

type Reflection struct {
	Axis   int            `json:"axis"`
	Flip   ReflectionType `json:"flip"`
	Cetner bool           `json:"center"`
}

type ReflectionType

type ReflectionType string

type Rotation

type Rotation struct {
	Position HexCoordJSON `json:"position"`
	Center   bool         `json:"center"`
}

type SpawnList

type SpawnList []wits.TileDefinition

Unpacked from a JSON of []HexCoord into a []TileDefinition of TERRAIN_TYPE_SPAWN.

func (*SpawnList) MarshalJSON

func (defs *SpawnList) MarshalJSON() ([]byte, error)

func (*SpawnList) UnmarshalJSON

func (defs *SpawnList) UnmarshalJSON(encoded []byte) error

Unmarshals the list of coordinates for spawn positions.

type SpawnUnitAction

type SpawnUnitAction struct {
	Spawn wits.HexCoord `json:"spawn"`
	Class UnitClassJSON `json:"class"`
	// contains filtered or unexported fields
}

Units may be spawned only from specific locations on the map.

func (SpawnUnitAction) ActionName

func (action SpawnUnitAction) ActionName() string

func (SpawnUnitAction) RelVarEncoding

func (action SpawnUnitAction) RelVarEncoding() string

func (SpawnUnitAction) Visit

func (action SpawnUnitAction) Visit(state *wits.GameState) error

Parentage is determined by this action but the parent/spawned-from state is not stored as part of the unit -- it is instead determined at the game state (via turn reconstruction and a specialized game state). This allows for a unified implementation here, whether it was a SpawnTile or a Bramble.

type StandingsAfterJSON

type StandingsAfterJSON struct {
	Tier_  LeagueTierJSON  `json:"tier"`
	Rank_  wits.LeagueRank `json:"rank"`
	Delta_ int             `json:"delta"`
}

func (StandingsAfterJSON) Delta

func (standings StandingsAfterJSON) Delta() int

func (StandingsAfterJSON) Rank

func (standings StandingsAfterJSON) Rank() wits.LeagueRank

func (StandingsAfterJSON) Tier

func (standings StandingsAfterJSON) Tier() wits.LeagueTier

type TeleportUnitAction

type TeleportUnitAction struct {
	wits.HexCoord `json:"mobi"`
	From          wits.HexCoord `json:"from"`
	To            wits.HexCoord `json:"to"`
}

func (TeleportUnitAction) ActionName

func (action TeleportUnitAction) ActionName() string

func (TeleportUnitAction) RelVarEncoding

func (action TeleportUnitAction) RelVarEncoding() string

func (TeleportUnitAction) Visit

func (action TeleportUnitAction) Visit(state *wits.GameState) error

type TerminalStatusJSON

type TerminalStatusJSON wits.TerminalStatus

type TerrainDefinition

type TerrainDefinition struct {
	Floor_ FloorList `json:"floor"`
	Wall_  WallList  `json:"wall"`
	Bonus_ BonusList `json:"bonus"`
	Spawn_ SpawnList `json:"spawn"`
	Base_  BaseList  `json:"base"`
}

func (TerrainDefinition) Base

func (terrain TerrainDefinition) Base() []wits.TileDefinition

func (TerrainDefinition) Bonus

func (terrain TerrainDefinition) Bonus() []wits.TileDefinition

func (TerrainDefinition) Floor

func (terrain TerrainDefinition) Floor() []wits.TileDefinition

func (TerrainDefinition) Spawn

func (terrain TerrainDefinition) Spawn() []wits.TileDefinition

func (TerrainDefinition) Wall

func (terrain TerrainDefinition) Wall() []wits.TileDefinition

type TerrainType

type TerrainType func(HexCoordJSON) wits.TileDefinition

Functor for a curried constructor of a specific tile type.

type TileDistance

type TileDistance int

type ToggleAltAction

type ToggleAltAction struct {
	wits.HexCoord `json:"position"`
}

func (ToggleAltAction) ActionName

func (action ToggleAltAction) ActionName() string

func (ToggleAltAction) RelVarEncoding

func (action ToggleAltAction) RelVarEncoding() string

func (ToggleAltAction) Visit

func (action ToggleAltAction) Visit(state *wits.GameState) error

type UnitClassJSON

type UnitClassJSON wits.UnitClassEnum

func (UnitClassJSON) MarshalJSON

func (class UnitClassJSON) MarshalJSON() ([]byte, error)

func (*UnitClassJSON) UnmarshalJSON

func (class *UnitClassJSON) UnmarshalJSON(encoded []byte) error

type UnitInitJSON

type UnitInitJSON struct {
	Coord  HexCoordJSON     `json:"coord"`
	Team_  FriendlyEnumJSON `json:"team"`
	Class_ UnitClassJSON    `json:"class"`
}

Initial unit description, satisfies both Unit and UnitInit interfaces.

This format is suitable for storing in the map definition and replay init. Typically, however, the coordinate is part of the tile (not unit) position. This will also be missing the race association because map definitions are player-race agnostic -- the race isn't chosen until match start.

{"i": 4, "j": 2, "team": 1, "class": 1}

When marshaled as JSON it is always as the dict/object representation. The shorthand can be obtained via GdlEncoding. It isn't enough context to make a Unit directly, or to implement Unit, because specials are determined by race and race hasn't been chosen yet. But it is enough for GameMatch initialization to construct the equivalent via NewUnit and into a TileState, after a game match has begun.

func (UnitInitJSON) Class

func (init UnitInitJSON) Class() wits.UnitClassEnum

func (UnitInitJSON) Cost

func (init UnitInitJSON) Cost() wits.ActionPoints

func (UnitInitJSON) Distance

func (init UnitInitJSON) Distance() wits.TileDistance

func (UnitInitJSON) GdlEncoding

func (unit UnitInitJSON) GdlEncoding() string

An s-expression compatible relation defining the unit, serialized as a string.

func (UnitInitJSON) Health

func (init UnitInitJSON) Health() wits.UnitHealth

func (UnitInitJSON) IsSpecial

func (init UnitInitJSON) IsSpecial() bool

func (UnitInitJSON) Position

func (init UnitInitJSON) Position() wits.HexCoord

func (UnitInitJSON) Race

func (init UnitInitJSON) Race() wits.UnitRaceEnum

func (UnitInitJSON) Strength

func (init UnitInitJSON) Strength() wits.UnitHealth

func (UnitInitJSON) Team

func (init UnitInitJSON) Team() wits.FriendlyEnum

func (*UnitInitJSON) UnmarshalJSON

func (unit *UnitInitJSON) UnmarshalJSON(encoded []byte) error

type UnitRaceJSON

type UnitRaceJSON wits.UnitRaceEnum

func ParseRace

func ParseRace(name string) UnitRaceJSON

func (UnitRaceJSON) MarshalJSON

func (race UnitRaceJSON) MarshalJSON() ([]byte, error)

func (*UnitRaceJSON) UnmarshalJSON

func (race *UnitRaceJSON) UnmarshalJSON(encoded []byte) error

type WallList

type WallList []wits.TileDefinition

Unpacked from a JSON of []HexCoord into a []TileDefinition of TERRAIN_TYPE_WALL.

func (*WallList) MarshalJSON

func (defs *WallList) MarshalJSON() ([]byte, error)

func (*WallList) UnmarshalJSON

func (defs *WallList) UnmarshalJSON(encoded []byte) error

Unmarshals the list of coordinates for wall positions.

Jump to

Keyboard shortcuts

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