-
Notifications
You must be signed in to change notification settings - Fork 10
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.
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:
- 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 theCardType
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
- The
- The AI executable calls
AITools::InitializeAIAndGetAIMove(str)
which reads the input string, and- Calls
AITools::InitializeAI(str)
to initialize the CardType data library - Calls
Prismata::InitFromMergedDeckJSON(json)
to initialize CardType data values - Calls
AIParameters::Instance().parseJSONValue(json)
to initialize the AI parameters - Calls
AITools::GetAIMove(str)
which constructs the game state and returns the AI move
- Calls
- 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
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.
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.
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:
- Read the JSON input and initialize the AI engine CardType data
- Read the JSON input and construct the GameState object for which you will decide a move
- Iterate the
GameState
legalAction
s and decide which to perform - Construct a
Move
object consisting of the sequence ofAction
s to perform - Convert the
Move
object into the required JSON syntax for the Prismata game client - 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.