Documentation
¶
Index ¶
- func CalculateSoftmax(scores []float64) []float64
- func CalculateTreeFitness(tree *individual.TreeNode, targetResults []float64, ...) float64
- func ExtractGameScore(observation map[string]interface{}) float64
- func Round(x float64, places int) float64
- func SampleAction(probabilties []float64) int
- func SetupEvalFunction(evalFunction string, variableSet []string, testCaseCount int) ([]map[string]float64, []float64)
- type ActionExecutor
- type ActionRequest
- type ActionTreeFitnessCalculator
- type ActionValidator
- func (av *ActionValidator) DirectionActionMask(x, y int) ([]float64, error)
- func (av *ActionValidator) SelectValidAction(actionOutputs [][]float64, owned_cells [][]bool) ([]int, error)
- func (av *ActionValidator) SetMountains(mountain_array [][]bool)
- func (av *ActionValidator) ValidXActionMask(owned_cells [][]bool) ([]float64, error)
- func (av *ActionValidator) ValidYActionMask(x int, owned_cells [][]bool) ([]float64, error)
- type BinaryFitnessCalculator
- type Client
- type ConnectRequest
- type ConnectedResponse
- type ErrorResponse
- type FitnessCalculator
- type FitnessSetupInformation
- type GameOverResponse
- type GrammarTreeFitnessCalculator
- type MessageType
- type ObservationResponse
- type SaveReplayRequest
- type ServerHealthChecker
- type TCPClient
- func (tc *TCPClient) Connect() error
- func (tc *TCPClient) ConnectToGame(clientId string, opponentType string) (*ConnectedResponse, error)
- func (tc *TCPClient) Disconnect() error
- func (tc *TCPClient) ReceiveMessage() (map[string]interface{}, error)
- func (tc *TCPClient) ReceiveObservation() (*ObservationResponse, error)
- func (tc *TCPClient) SendAction(action interface{}) error
- func (tc *TCPClient) SendDisconnect() error
- func (tc *TCPClient) SendMessage(message interface{}) error
- func (tc *TCPClient) WaitForGameOver() (*GameOverResponse, error)
- type TCPConnectionPool
- type TreeFitnessCalculator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateSoftmax ¶ added in v1.15.0
calculateSoftmax converts scores to probabilities using numerically stable softmax
func CalculateTreeFitness ¶
func ExtractGameScore ¶ added in v1.11.0
ExtractGameScore extracts a numeric score from observation data
func SampleAction ¶ added in v1.15.0
Types ¶
type ActionExecutor ¶ added in v1.11.0
type ActionExecutor struct {
// contains filtered or unexported fields
}
ActionExecutor evaluates action trees and converts outputs to game actions
func NewActionExecutor ¶ added in v1.11.0
func NewActionExecutor(actions []individual.ActionTuple) *ActionExecutor
NewActionExecutor creates a new action executor
func (*ActionExecutor) ExecuteActionTreesWithSoftmax ¶ added in v1.11.0
func (ae *ActionExecutor) ExecuteActionTreesWithSoftmax(actionTreeIndividual *individual.ActionTreeIndividual, weights *individual.WeightsIndividual, inputs map[string]float64, owned_cells [][]bool) ([]int, error)
ExecuteActionTreesWithSoftmax evaluates all action trees with given inputs and returns selected action using softmax
type ActionRequest ¶ added in v1.11.0
type ActionRequest struct {
Type string `json:"type"`
Action interface{} `json:"action"`
}
type ActionTreeFitnessCalculator ¶ added in v1.11.0
type ActionTreeFitnessCalculator struct {
// contains filtered or unexported fields
}
ActionTreeFitnessCalculator implements fitness calculation for ActionTree individuals
func NewActionTreeFitnessCalculator ¶ added in v1.11.0
func NewActionTreeFitnessCalculator(serverAddr string, opponentType string, actions []individual.ActionTuple, maxSteps int, populations []*[]individual.Evolvable, selectionPercentage float64, poolSize int, testCaseCount int, timeout time.Duration) *ActionTreeFitnessCalculator
NewActionTreeFitnessCalculator creates a new action tree fitness calculator
func (*ActionTreeFitnessCalculator) CalculateFitness ¶ added in v1.11.0
func (atfc *ActionTreeFitnessCalculator) CalculateFitness(evolvable individual.Evolvable)
CalculateFitness evaluates the fitness of an ActionTree individual
func (*ActionTreeFitnessCalculator) Close ¶ added in v1.14.0
func (atfc *ActionTreeFitnessCalculator) Close() error
Close closes the connection pool and cleans up resources
func (*ActionTreeFitnessCalculator) SetupGameAndRun ¶ added in v1.12.0
func (atfc *ActionTreeFitnessCalculator) SetupGameAndRun(weightsInd *individual.WeightsIndividual, actionTreeInd *individual.ActionTreeIndividual) (float64, string, error)
type ActionValidator ¶ added in v1.14.0
type ActionValidator struct {
// contains filtered or unexported fields
}
ActionValidator validates actions based on game observations
func NewActionValidator ¶ added in v1.14.0
func NewActionValidator() *ActionValidator
NewActionValidator creates a new action validator
func (*ActionValidator) DirectionActionMask ¶ added in v1.15.0
func (av *ActionValidator) DirectionActionMask(x, y int) ([]float64, error)
func (*ActionValidator) SelectValidAction ¶ added in v1.15.0
func (av *ActionValidator) SelectValidAction(actionOutputs [][]float64, owned_cells [][]bool) ([]int, error)
func (*ActionValidator) SetMountains ¶ added in v1.15.0
func (av *ActionValidator) SetMountains(mountain_array [][]bool)
func (*ActionValidator) ValidXActionMask ¶ added in v1.15.0
func (av *ActionValidator) ValidXActionMask(owned_cells [][]bool) ([]float64, error)
ValidXActionMask Returns all x values that have a potential y value
func (*ActionValidator) ValidYActionMask ¶ added in v1.15.0
func (av *ActionValidator) ValidYActionMask(x int, owned_cells [][]bool) ([]float64, error)
ValidYActionMask Returns all x values that have a potential y value
type BinaryFitnessCalculator ¶
type BinaryFitnessCalculator struct{}
func (*BinaryFitnessCalculator) CalculateFitness ¶
func (binaryFitness *BinaryFitnessCalculator) CalculateFitness(evolvable individual.Evolvable)
type ConnectRequest ¶ added in v1.11.0
type ConnectRequest struct {
Type string `json:"type"`
ClientId string `json:"client_id"`
AgentType string `json:"agent_type"`
OpponentType string `json:"opponent_type"`
}
Message structures matching Python payloads
type ConnectedResponse ¶ added in v1.11.0
type ErrorResponse ¶ added in v1.11.0
type FitnessCalculator ¶
type FitnessCalculator interface {
CalculateFitness(evolvable individual.Evolvable)
}
func FitnessCalculatorFactory ¶
func FitnessCalculatorFactory(info FitnessSetupInformation) FitnessCalculator
func FitnessCalculatorFactoryWithConfig ¶ added in v1.14.0
func FitnessCalculatorFactoryWithConfig(info FitnessSetupInformation, config *cfg.Config) FitnessCalculator
type FitnessSetupInformation ¶
type FitnessSetupInformation struct {
EvalFunction string
VariableSet []string
GenomeType individual.GenomeType
TestCaseCount int
Grammar map[string]individual.Node
ServerAddr string
OpponentType string
MaxSteps int
Actions []individual.ActionTuple
Population []*[]individual.Evolvable
ActionTreeSelectionPercentage float64
}
func GenerateFitnessInfoFromConfig ¶
func GenerateFitnessInfoFromConfig(config *cfg.Config, genomeType individual.GenomeType, grammar map[string]individual.Node, populations []*[]individual.Evolvable) FitnessSetupInformation
type GameOverResponse ¶ added in v1.11.0
type GrammarTreeFitnessCalculator ¶
type GrammarTreeFitnessCalculator struct {
TestCases []map[string]float64
TargetResults []float64
Grammar map[string]individual.Node
}
func (*GrammarTreeFitnessCalculator) CalculateFitness ¶
func (gtreeCalculator *GrammarTreeFitnessCalculator) CalculateFitness(evolvable individual.Evolvable)
func (*GrammarTreeFitnessCalculator) SetupEvalFunction ¶
func (fitnessCalc *GrammarTreeFitnessCalculator) SetupEvalFunction(evalFunction string, variableSet []string, testCaseCount int)
type MessageType ¶ added in v1.11.0
type MessageType string
MessageType constants matching the Python server
const ( Connect MessageType = "connect" Action MessageType = "action" Reset MessageType = "reset" Connected MessageType = "connected" Observation MessageType = "observation" Error MessageType = "error" GameOver MessageType = "game_over" SaveReplay MessageType = "save_replay" )
type ObservationResponse ¶ added in v1.11.0
type SaveReplayRequest ¶ added in v1.19.0
type SaveReplayRequest struct {
Type string `json:"type"`
}
type ServerHealthChecker ¶ added in v1.14.0
type ServerHealthChecker struct {
// contains filtered or unexported fields
}
ServerHealthChecker performs health checks on game server
func NewServerHealthChecker ¶ added in v1.14.0
func NewServerHealthChecker(serverAddr string, timeout time.Duration) *ServerHealthChecker
NewServerHealthChecker creates a new health checker
func (*ServerHealthChecker) CheckServerHealth ¶ added in v1.14.0
func (shc *ServerHealthChecker) CheckServerHealth() error
CheckServerHealth performs a basic health check on the game server
func (*ServerHealthChecker) CheckServerHealthWithRetry ¶ added in v1.14.0
func (shc *ServerHealthChecker) CheckServerHealthWithRetry() error
CheckServerHealthWithRetry performs health check with a single retry
type TCPClient ¶ added in v1.11.0
type TCPClient struct {
// contains filtered or unexported fields
}
TCPClient handles communication with the game server
func NewTCPClient ¶ added in v1.11.0
NewTCPClient creates a new TCP client
func (*TCPClient) ConnectToGame ¶ added in v1.11.0
func (tc *TCPClient) ConnectToGame(clientId string, opponentType string) (*ConnectedResponse, error)
ConnectToGame sends connect request and waits for connected response
func (*TCPClient) Disconnect ¶ added in v1.11.0
Disconnect closes the connection
func (*TCPClient) ReceiveMessage ¶ added in v1.11.0
ReceiveMessage receives a JSON message from the server
func (*TCPClient) ReceiveObservation ¶ added in v1.11.0
func (tc *TCPClient) ReceiveObservation() (*ObservationResponse, error)
ReceiveObservation waits for an observation response
func (*TCPClient) SendAction ¶ added in v1.11.0
SendAction sends an action to the server
func (*TCPClient) SendDisconnect ¶ added in v1.19.0
SendAction sends an action to the server
func (*TCPClient) SendMessage ¶ added in v1.11.0
SendMessage sends a JSON message to the server
func (*TCPClient) WaitForGameOver ¶ added in v1.11.0
func (tc *TCPClient) WaitForGameOver() (*GameOverResponse, error)
WaitForGameOver waits specifically for a game over message
type TCPConnectionPool ¶ added in v1.14.0
type TCPConnectionPool struct {
// contains filtered or unexported fields
}
func NewTCPConnectionPool ¶ added in v1.14.0
func NewTCPConnectionPool(serverAddr string, maxConnections int, timeout time.Duration) *TCPConnectionPool
func (*TCPConnectionPool) Close ¶ added in v1.14.0
func (p *TCPConnectionPool) Close() error
─────────────────────────────
Close()
─────────────────────────────
func (*TCPConnectionPool) GetConnection ¶ added in v1.14.0
func (p *TCPConnectionPool) GetConnection() (*TCPClient, error)
─────────────────────────────
BLOCKING GetConnection()
─────────────────────────────
func (*TCPConnectionPool) GetStats ¶ added in v1.14.0
func (p *TCPConnectionPool) GetStats() map[string]interface{}
─────────────────────────────
Stats
─────────────────────────────
func (*TCPConnectionPool) HealthCheck ¶ added in v1.14.0
func (p *TCPConnectionPool) HealthCheck() error
─────────────────────────────
HealthCheck() external API
─────────────────────────────
func (*TCPConnectionPool) ReturnConnection ¶ added in v1.14.0
func (p *TCPConnectionPool) ReturnConnection(client *TCPClient) error
─────────────────────────────
ReturnConnection
─────────────────────────────
type TreeFitnessCalculator ¶
func (*TreeFitnessCalculator) CalculateFitness ¶
func (fitnessCalc *TreeFitnessCalculator) CalculateFitness(evolvable individual.Evolvable)
func (*TreeFitnessCalculator) SetupEvalFunction ¶
func (fitnessCalc *TreeFitnessCalculator) SetupEvalFunction(evalFunction string, variableSet []string, testCaseCount int)