Skip to content

Prismata AI Executable

Elyot edited this page Mar 20, 2020 · 14 revisions

Replacing the Prismata AI Executable

The Prismata AI system operates completely separately from the rest of the retail game application, with each copy of the game coming with a separate AI executable that is called from within the client to perform AI decision making. With the release of this project, it is possible for you to create your own AI system, make a new AI executable, and distribute this to others to play against within the official Prismata game application.

How the Retail Prismata AI Works

As the Prismata AI is a standalone executable, it must communicate somehow with the Prismata game client, and this is currently done via standard IO channels. Here is what happens whenever the retail Prismata application calls the AI executable:

  1. The AI executable is run and fed a single string in JSON format via std::cin. This string is in JSON format, and contains the following:
    • The CardLibrary data, describing all of the CardType types in the current game
    • The AIParameters configuration file, describing the custom AI parameters used by the client
    • The GameState description, detailing the current game state for the AI to decide a move
  2. The AI executable calls AITools::InitializeAIAndGetAIMove(str) which reads the input string, and
    1. Calls AITools::InitializeAI(str) to initialize the CardType data library
    2. Calls Prismata::InitFromMergedDeckJSON(json) to initialize CardType data values
    3. Calls AIParameters::Instance().parseJSONValue(json) to initialize the AI parameters
    4. Calls AITools::GetAIMove(str) which constructs the game state and returns the AI move
  3. The AI converts the decided move into JSON format, and prints it to std::cout, which is then captured by the Prismata game client, converted into a sequence of actions, and carried out within the game

AI Parameters

The above system uses the AI Parameters configuration file to specify which type of Player should be run to perform the decision making logic. When you choose an AI difficulty in the official Prismata client, this player name is stored. When the AI is called, the AI executable parses that player name and does the appropriate logic. Unfortunately since the Prismata client sends the configuration file to the executable, you are not able to simply modify that file, you can only read it. You can however make whatever changes you want to the parameters manually after reading the configuration into your AI system.

This all sounds quite complicated, and it is, but it was necessary in order to give designers the ability to modify the modular AI system as they see fit, without exposing those modifications to the general public, and possibly wreaking havoc on early versions of the AI system.

The good news for you is that you can bypass all of this by just ignoring the AI config file completely, and returning whatever AI move you want! However if you do want to make use of the AI configuration file, you can do so by reading the sample config file provided for you with this repo.

Modifying the Current AI Executable

Any changes / improvements you make to existing AI Player classes / Partial Player classes / Algorithms will automatically be compiled into the standalone AI executable when you compile it. This is the easiest way to create your own AI modifications, but you will have to work only within the existing classes.

Making Your Own AI Executable

Another to make your own AI system is to modify the sample code that I have provided for you in ExampleAI.cpp. This code shows the necessary steps for performing the logic required to return a move to the client:

  1. Read the JSON input and initialize the AI engine CardType data
  2. Read the JSON input and construct the GameState object for which you will decide a move
  3. Iterate the GameState legal Actions and decide which to perform
  4. Construct a Move object consisting of the sequence of Actions to perform
  5. Convert the Move object into the required JSON syntax for the Prismata game client
  6. Output the JSON syntax to std::cout to be captured by the Prismata game client

The caveat for following this example is that you are no longer reading the AI config file, so this AI move will be performed no matter which AI difficulty was selected in the game client. Also, the rest of the game client AI usage (missions, etc) may not function properly.