On this page you will learn how to set up your first agent. During the tutorial we will quickly summarize the components of the framework and show you how a simple Random Agent is implemented.

Step 1: Important Framework Components

 

Class Description
Program.cs The Program class includes the Main function, which is called when the SabberStoneCoreAi is started. Here, we first setup two agents and a partial observation game handler (POGameHandler.cs). The game can be started using the handler’s PlayGame() function.
POGameHandler.cs The POGameHandler controls the flow of the game and consecutively calls the Agents‘ GetMove function.

The handler assures that each agent can only access the information he should be able to, during a normal game. For this purpose a POGame is created, which consists of a copy of the current game-, in which hand-cards of the opponent are temporarily exchanged by the card „No Way!“, which has no mana cost and no effect.

POGame.cs POGame provides acces to all visible components of the game. hand, board, and deck cards, as well as current information on the game state such as turn-number or mana can be accessed.

The POGame also provides possible moves to the player. An integrated forward model can be used to see the result of the move.

GameStats.cs The GameStats object stores the number of simulated games, winning statistics and average times per turn.
AbstractAgent.cs The AbstractAgent is the base-class for your own Agents.

  • InitializeAgent: load files once at the start of the simulation
  • InitializeGame: initialize data at the start of a game
  • GetMove: return a non-empty list of moves based on the provided POGame
  • FinalizeGame: store the result and update the agent after a game
  • FinalizeGame: store the final model at the end of the simulation
RandomAgent.cs The RandomAgent

 

Step 2: Implementing an Agent

  • Open the src/Agent folder in the SabberStoneCoreAi project
  • Rightlick on the Agent folder and click Add -> New Item to create a new class called MyAgent
  • Add „using SabberStoneCoreAi.Agent;“ to the top of the file and inherit from AbstractAgent
  • Visual Studio will tell you that some implementation of abstract functions are missing. Hover over the red underlined class-name and choose „Show potential fixes“. Click on Implement Abstract Class to automatically add all missing functions.
  • Delete the NotImplementedException in all subclasses. You current Class should look like this:

  • Now lets add some code to the GetMove function. We first create an empty List that will hold all PlayerTasks to return.
  • Using the poGame object we can get all possible moves by calling the function Options() on the current player controller.

  • We add a private Random object to our agent and initialize it in the InitializeAgent function.

  • Back in the GetMove function we choose a random option of all options and add it to our turnList.

  • Hint: We can simulate the result of our chosen Option by calling „poGame.Process(option);“. Keep in mind that some PlayerTasks yield non-deterministic results. For this reason handle this function with care.
  • At the end of the function we return the list to the POGameHandler.

  • The final result should look like this:

  • We can extend this function by returning multiple options. See the following code example: