smarthome

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2022 License: MIT Imports: 1 Imported by: 1

README

smarthome

Another auto battler.

Documentation

Index

Constants

View Source
const (
	// EventTypeModifyHouseHealth = "modify_house_health"
	EventTypeModifyHealth    = "modify_health"
	EventTypeRelocate        = "relocate"
	EventTypeApplianceBirth  = "appliance_birth"
	EventTypeApplianceDeath  = "appliance_death"
	EventTypeApplianceBought = "appliance_bought"
	EventTypeApplianceSold   = "appliance_sold"
	EventTypeStartGame       = "start_game"
	EventTypeEndGame         = "end_game"
	EventTurnStart           = "turn_start"
	EventTurnEnd             = "turn_end"
	EventTypeHouseDeath      = "house_death"

	EventTypePlayerMovedAppliance  = "player_moved_appliance"
	EventTypePlayerBoughtAppliance = "player_bought_appliance"
	EventTypePlayerSoldAppliance   = "player_sold_appliance"
	EventTypePlayerBoughtItem      = "player_bought_item"
)
View Source
const (
	ResultGoingDown   = int8(-1)
	ResultNotFinished = int8(0)
	ResultGoingUp     = int8(1)
	ResultDraw        = int8(2)
	ResultTimeout     = int8(3)
)
View Source
const (
	SquareWidthBytes  = 15
	SquareHeightLines = 7
)
View Source
const ObjectTypeHouse = "house"

Variables

View Source
var (
	TeamValues = []int8{
		-1,
		1,
	}
)

Functions

func GenerateOptions

func GenerateOptions(turn int) ([]Appliance, []Upgrade)

func GetIndex

func GetIndex(width, x, y int8) int8

func LocationIsHouse

func LocationIsHouse(height, team int8, l Location) bool

func LocationValid

func LocationValid(width, height int8, l Location) bool

func PrintCanvas

func PrintCanvas(canvas [][]string)

func PrintState

func PrintState(width, height int8, state State)

func SameLocation

func SameLocation(loc1, loc2 Location) bool

func ValidatePlayerSelection

func ValidatePlayerSelection(previousState, nextState Selection) bool

players can rearrange their appliances without triggering events. only selection events that trigger other events are: - buy - sell - merge - upgrade for validation, will need a function that confirms all appliances listed in each event match previous known state, even if they've been rearranged

Types

type Appliance

type Appliance interface {
	State() ObjectState
	Type() ObjectType

	// this allows the appliance to be converted to its street location (ie in the two player grid).
	// may decouple location somehow to remove this as a required method....
	MoveToStreet(width, height, team int8) Appliance

	// ReceiveEvent is how the appliance responds to events.
	// The returned appliance object is the next state of the appliance
	// All appliances receive all events in case they have behaviour based on things happening to
	// appliances elsewhere on the board.
	// Receiving events can also trigger more events, for example incoming damage to an ally might trigger a heal event etc
	ReceiveEvents(appliances []Appliance, events []Event, turn uint8) ([]Appliance, []Event)
}

func ApplySelection

func ApplySelection(selection Selection) []Appliance

type ApplianceBirthEvent

type ApplianceBirthEvent struct {
	EventBase
	Appliance Appliance
}

func (ApplianceBirthEvent) Base

func (e ApplianceBirthEvent) Base() EventBase

func (ApplianceBirthEvent) Type

func (e ApplianceBirthEvent) Type() EventType

type ApplianceDeathEvent

type ApplianceDeathEvent struct {
	EventBase
	Appliance Appliance
}

func (ApplianceDeathEvent) Base

func (e ApplianceDeathEvent) Base() EventBase

func (ApplianceDeathEvent) Type

func (e ApplianceDeathEvent) Type() EventType

type BuyApplianceEvent

type BuyApplianceEvent struct {
	EventBase
	NewAppliance Appliance
}

func (BuyApplianceEvent) Base

func (e BuyApplianceEvent) Base() EventBase

func (BuyApplianceEvent) Type

func (e BuyApplianceEvent) Type() EventType

type EndGameEvent

type EndGameEvent struct {
	EventBase
}

func (EndGameEvent) Base

func (e EndGameEvent) Base() EventBase

func (EndGameEvent) Type

func (e EndGameEvent) Type() EventType

type Event

type Event interface {
	// json.Marshaler
	// json.Unmarshaler
	Type() EventType
	Base() EventBase
}

func PushOrAttack

func PushOrAttack(appliance Appliance, appliances []Appliance) []Event

func StandAndAttack

func StandAndAttack(appliance Appliance, appliances []Appliance) []Event

func TurnEndEvents

func TurnEndEvents(appliances []Appliance, turnNumber uint8) []Event

func TurnStartEvents

func TurnStartEvents(appliances []Appliance, turnNumber uint8) []Event

type EventBase

type EventBase struct {
	// Iteration is used for events that occur as a result of another event.
	// For instance the first time someone gets moved they might then get moved back as a result.
	// On the second move any appliance that responds to any move would then try to move them back again
	// creating an infinite loop.
	// By incrementing the iteration on the event we can check for iteration and only act a few times.
	Iteration int8
	// CausedBy is an appliance since team is important
	CausedBy Appliance
	// Target is only a location since it may not be specific to an appliance
	Target Location
}

type EventType

type EventType string

type GameSquare

type GameSquare struct {
	Appliance Appliance
	Events    []Event
}

func (GameSquare) Print

func (g GameSquare) Print(x, y int8, canvas [][]string)

puts all the rows for one square into the right string in the canvas

type House

type House struct {
	Appliances []Appliance
}

type HouseDeathEvent

type HouseDeathEvent struct {
	EventBase
}

func (HouseDeathEvent) Base

func (e HouseDeathEvent) Base() EventBase

func (HouseDeathEvent) Type

func (e HouseDeathEvent) Type() EventType

type HouseState

type HouseState struct {
	// May rethink the appliancestate interface
	ObjectState
}

HouseState implements Appliance since it can be responsible for events, and receive damage

func (HouseState) MoveToStreet

func (h HouseState) MoveToStreet(width, height, team int8) Appliance

func (HouseState) ReceiveEvents

func (h HouseState) ReceiveEvents(appliances []Appliance, events []Event, turn uint8) ([]Appliance, []Event)

func (HouseState) Type

func (h HouseState) Type() ObjectType

type Location

type Location struct {
	X int8
	Y int8
}

func (Location) MoveToStreet

func (l Location) MoveToStreet(width, height, team int8) Location

team is either -1 or 1 team 1 gets moved to top and inverted on both axis

type ModifyHealthEvent

type ModifyHealthEvent struct {
	EventBase
	Value int8
}

func (ModifyHealthEvent) Base

func (e ModifyHealthEvent) Base() EventBase

func (ModifyHealthEvent) Type

func (e ModifyHealthEvent) Type() EventType

type ObjectState

type ObjectState struct {
	Location Location
	Upgrade  Upgrade

	// -1 = going down
	// 0 = not set (default when viewing your own team)
	// 1 = going up
	Team int8

	Health   int8
	Strength int8

	// TODO
	Repair int8
	Model  int8
}

func (ObjectState) State

func (s ObjectState) State() ObjectState

this make any object that contains an object state implement the state method

type ObjectType

type ObjectType string

type RelocationEvent

type RelocationEvent struct {
	EventBase
	NewLocation Location
}

func (RelocationEvent) Base

func (e RelocationEvent) Base() EventBase

func (RelocationEvent) Type

func (e RelocationEvent) Type() EventType

type Rumba

type Rumba struct {
	ObjectState
}

want him to path towards home currently just a copy of toaster

func (Rumba) MoveToStreet

func (t Rumba) MoveToStreet(width, height, team int8) Appliance

func (Rumba) ReceiveEvents

func (t Rumba) ReceiveEvents(appliances []Appliance, events []Event, turn uint8) ([]Appliance, []Event)

func (Rumba) Type

func (t Rumba) Type() ObjectType

type Selection

type Selection struct {
	Objects     []Appliance
	PlayerEvent Event
}

type StartGameEvent

type StartGameEvent struct {
	EventBase
}

func (StartGameEvent) Base

func (e StartGameEvent) Base() EventBase

func (StartGameEvent) Type

func (e StartGameEvent) Type() EventType

type State

type State struct {
	Appliances []Appliance
	// HouseStates [2]HouseState
	Events []Event
}

func DoTurn

func DoTurn(startingState State, turnNumber uint8) []State

func GetFirstState

func GetFirstState(houses [2]House) State

func LoopUntilNoEventsRemaining

func LoopUntilNoEventsRemaining(startingState State, turnNumber uint8) []State

func PlayGame

func PlayGame(startingState State) ([]State, int8)

type Sticky

type Sticky struct {
	ObjectState
}

func (Sticky) MoveToStreet

func (t Sticky) MoveToStreet(width, height, team int8) Appliance

func (Sticky) ReceiveEvents

func (t Sticky) ReceiveEvents(appliances []Appliance, events []Event, turn uint8) ([]Appliance, []Event)

func (Sticky) Type

func (t Sticky) Type() ObjectType

type Team

type Team struct {
	Appliances []Appliance
}

type Toaster

type Toaster struct {
	ObjectState
}

func (Toaster) MoveToStreet

func (t Toaster) MoveToStreet(width, height, team int8) Appliance

func (Toaster) ReceiveEvents

func (t Toaster) ReceiveEvents(appliances []Appliance, events []Event, turn uint8) ([]Appliance, []Event)

func (Toaster) Type

func (t Toaster) Type() ObjectType

type TurnEndEvent

type TurnEndEvent struct {
	EventBase
	Turn uint8
}

func (TurnEndEvent) Base

func (e TurnEndEvent) Base() EventBase

func (TurnEndEvent) Type

func (e TurnEndEvent) Type() EventType

type TurnStartEvent

type TurnStartEvent struct {
	EventBase
	Turn uint8
}

func (TurnStartEvent) Base

func (e TurnStartEvent) Base() EventBase

func (TurnStartEvent) Type

func (e TurnStartEvent) Type() EventType

type Upgrade

type Upgrade interface {
	ReceiveEvents(appliances []Appliance, events []Event, turn uint8) []Event
}

Upgrade is something that can be added to appliances to give them boosts etc

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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