60 lines
1.9 KiB
Go
60 lines
1.9 KiB
Go
package client
|
|
|
|
import "hackerbots.us/server"
|
|
|
|
// Player is the interface that defines a player's behavior.
|
|
//
|
|
// The general case will be to implement a Player type that contains the magic
|
|
// required to slay other robots quickly while staying alive for a long time.
|
|
type Player interface {
|
|
|
|
// GetStats returns a map with an entry for each robot the player will control
|
|
// containing the desired stats for that robot
|
|
GetStats() map[string]server.StatsRequest
|
|
|
|
// SetIDs is called from the client once the server
|
|
// has accepted the robots supplied in GetStats and validated
|
|
// their config, the data passed into SetIDs is a mapping of
|
|
// bot name to server side bot ID that is used in all bot
|
|
// dats sent from the server
|
|
SetIDs(map[string]string)
|
|
|
|
// Update is called on reciept of a board state packet and the response is
|
|
// the instructions for each robot in a map of robot id to instructions
|
|
Update(bs *server.Boardstate) map[string]server.Instruction
|
|
}
|
|
|
|
// MultiPlayer wraps multiple players and calls funcitons in Player in
|
|
// appropriate order.
|
|
//
|
|
// Typically used to add a Spectator to a bot.
|
|
type MultiPlayer []Player
|
|
|
|
// GetStats implements GetStats for a collection of players asking each player
|
|
// for their stats, and returning the configuration of the first player.
|
|
func (mp MultiPlayer) GetStats() map[string]server.StatsRequest {
|
|
var s map[string]server.StatsRequest
|
|
for i := len(mp) - 1; i >= 0; i-- {
|
|
s = mp[i].GetStats()
|
|
}
|
|
return s
|
|
}
|
|
|
|
// SetIDs passes ids to all players.
|
|
func (mp MultiPlayer) SetIDs(ids map[string]string) {
|
|
for _, p := range mp {
|
|
p.SetIDs(ids)
|
|
}
|
|
}
|
|
|
|
// Update implements Update for a collection of players sending board state to
|
|
// each player, and returning the instructions associated with the first
|
|
// player.
|
|
func (mp MultiPlayer) Update(bs *server.Boardstate) map[string]server.Instruction {
|
|
var inst map[string]server.Instruction
|
|
for i := len(mp) - 1; i >= 0; i-- {
|
|
inst = mp[i].Update(bs)
|
|
}
|
|
return inst
|
|
}
|