jkomoros / boardgame

An in-progress framework in golang to easily build boardgame Progressive Web Apps
Apache License 2.0
31 stars 4 forks source link

Implement notion of AI agents #149

Closed jkomoros closed 7 years ago

jkomoros commented 7 years ago

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.

jkomoros commented 7 years ago

Presumably they shouldn't be on the main server, because they could be pretty expensive

jkomoros commented 7 years ago

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.

jkomoros commented 7 years ago

Actually, no need for a separate config--they'd store that in their own state object

jkomoros commented 7 years ago

The library has no idea what its state looks like--it just passes it a blob, and allows it store back a blob.

jkomoros commented 7 years ago

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.

jkomoros commented 7 years ago

Agents are a separate package off of the main package (how do they get hooked into the main game?)

jkomoros commented 7 years ago

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

jkomoros commented 7 years ago