client

package
v0.0.0-...-5f8b9f5 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2016 License: MIT Imports: 5 Imported by: 2

Documentation

Overview

Client package provides connection to space tyckiting server

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ai Ai, name string) (err error)

Run function creates client for Ai, opens websocket and starts reading from it.

Types

type Action

type Action struct {
	Type     BotActionType `json:"type"`
	BotId    int           `json:"botId"`
	Position Position      `json:"pos"`
}

type ActionsMessage

type ActionsMessage struct {
	Type    ClientMessageType `json:"type"`
	RoundId int               `json:"roundId"`
	Actions []Action          `json:"actions"`
}

type Ai

type Ai interface {
	Move() []Action
	OnStart(msg StartMessage)
	OnConnected(msg ConnectedMessage)
	OnEvents(msg EventsMessage)
	OnEnd(msg EndMessage)
	OnError(msg string)
}

Ai is an interface that custom ai has to implement

type Bot

type Bot struct {
	BotId    int      `json:"botId"`
	Name     string   `json:"name"`
	TeamId   int      `json:"teamId"`
	Hp       int      `json:"hp"`
	Alive    bool     `json:"alive"`
	Position Position `json:"pos"`
}

func (*Bot) GetValidCannons

func (b *Bot) GetValidCannons(r int) []Position

Get valid positios where bot can use cannon

func (*Bot) GetValidMoves

func (b *Bot) GetValidMoves(r int) []Position

Get valid positios where bot can move

func (*Bot) GetValidRadars

func (b *Bot) GetValidRadars(r int) []Position

Get valid positios where bot can use rader

type BotActionType

type BotActionType string
const (
	BOT_MOVE   BotActionType = "move"
	BOT_RADAR  BotActionType = "radar"
	BOT_CANNON BotActionType = "cannon"
)

type Client

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

func (*Client) Log

func (c *Client) Log(s string)

Log funtion prints string to stdout if verbose is set to true

type ClientMessageType

type ClientMessageType string
const (
	CLIENT_JOIN    ClientMessageType = "join"
	CLIENT_ACTIONS ClientMessageType = "actions"
)

type ConnectedMessage

type ConnectedMessage struct {
	TeamId int        `json:"teamId"`
	Config GameConfig `json:"config"`
}

type EndMessage

type EndMessage struct {
	WinnerTeamId int  `json:"winnerTeamId"`
	You          Team `json:"you"`
}

type Event

type Event struct {
	Type     EventType `json:"event"`
	BotId    null.Int  `json:"botId"`
	Source   null.Int  `json:"source"`
	Position Position  `json:"pos"`
	Damage   null.Int  `json:"damage"`
}

type EventType

type EventType string
const (
	EVENT_HIT        EventType = "hit"
	EVENT_DIE        EventType = "die"
	EVENT_RADAR_ECHO EventType = "radarEcho"
	EVENT_SEE        EventType = "see"
	EVENT_DETECTED   EventType = "detected"
	EVENT_DAMAGED    EventType = "damaged"
	EVENT_MOVE       EventType = "move"
	EVENT_NOACTION   EventType = "noaction"
	EVENT_END        EventType = "end"
)

type EventsMessage

type EventsMessage struct {
	RoundId    int        `json:"roundId"`
	You        Team       `json:"you"`
	Config     GameConfig `json:"config"`
	OtherTeams []Team     `json:"otherTeams"`
	Events     []Event    `json:"events"`
}

type GameConfig

type GameConfig struct {
	Bots        int  `json:"bots"`
	FieldRadius int  `json:"fieldRadius"`
	Move        int  `json:"move"`
	StartHp     int  `json:"startHp"`
	Cannon      int  `json:"cannon"`
	Radar       int  `json:"radar"`
	See         int  `json:"see"`
	MaxCount    int  `json:"maxCount"`
	Asteroids   int  `json:"asteroids"`
	LoopTime    int  `json:"loopTime"`
	NoWait      bool `json:"noWait"`
}

type JoinMessage

type JoinMessage struct {
	Type     ClientMessageType `json:"type"`
	TeamName string            `json:"teamName"`
}

type Position

type Position struct {
	X int `json:"x"`
	Y int `json:"y"`
}

type ServerMessage

type ServerMessage struct {
	Type ServerMessageType `json:"type"`
}

type ServerMessageType

type ServerMessageType string
const (
	SERVER_CONNECTED ServerMessageType = "connected"
	SERVER_START     ServerMessageType = "start"
	SERVER_END       ServerMessageType = "end"
	SERVER_EVENTS    ServerMessageType = "events"
	SERVER_ERROR     ServerMessageType = "error"
)

type StartMessage

type StartMessage struct {
	You        Team       `json:"you"`
	Config     GameConfig `json:"config"`
	OtherTeams []Team     `json:"otherTeams"`
}

type Team

type Team struct {
	Name   string `json:"name"`
	TeamId int    `json:"teamId"`
	Bots   []Bot  `json:"bots"`
}

Jump to

Keyboard shortcuts

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