Closed jkomoros closed 7 years ago
Presumably they shouldn't be on the main server, because they could be pretty expensive
Agents are woken up every time a move has been made to a game they're part of. They get passed a config object representing their own config at time of creation, the game, and their own state blob. If they return a move it will be proposed.
Actually, no need for a separate config--they'd store that in their own state object
The library has no idea what its state looks like--it just passes it a blob, and allows it store back a blob.
Only one copy of an agent will ever run on a given game, so it doesn't have to worry about a race where it's working on a version of the game where its state is out of date.
Agents are a separate package off of the main package (how do they get hooked into the main game?)
type Agent interface {
//Stable, unique name of the agent. How it will be looked up
Name() string
//Called when the game is SetUp with an agent. Their chance to configure a blob of information to be stored.
SetUpForGame(game *Game, player PlayerIndex) (state []byte)
// Called after every move has been made (and its fixups chain has ended). Game can be interrogated for CurrentState() and everything else, although ProposeMove should NOT be called. If there's a move you want to propose, return it. Whatever is returned as NewState will be saved for this agent's state for this game.
ProposeMove(game *Game, player PlayerIndex, agentState []byte) (move Move, newState []byte)
}
//must be called before set up
manager.AddAgent(agent Agent)
manager.Agents() []Agent
manager.AgentByName(name string) Agent
//if agents is not nil, then it should be len(numPlayers). At each index, the agent with that name will be installed (a blank string says no agent)
game.SetUp(numPlayers int, agents []string) error
How do we keep track of games having agents? Is it stored on storage record? Storage obviously needs a layer that stores it
They'd be attached to a specific game, and told which player they play.
After each move they'd see if it was legal for them to play anything.
They'd need a way to store their own state over and above the generic state of the game.