Skip to content

Computer Opponents

Create an AI Profile (Create > TCG Kit > AI Profile) and assign it to the MatchBootstrap’s AI Profile, with Mode set to Versus Computer. The human takes the first seat and the computer plays the others.

A profile says how the computer values a position:

  • Player Stats: what each point of the computer’s own stats is worth, such as Life 10.
  • Zones: what cards are worth by where they are, for example 10 per creature on the board plus 10 per point of attack and 8 per point of health, and 3 per card in hand.
  • Random Move Percent: how often it plays a random legal move instead of the best one it found. 0 is the strongest; raise it for easier difficulty levels.

The numbers are relative. The opponent subtracts its opponents’ value from its own.

HeuristicAgent tries each legal command on a copy of the match, scores the position it leads to, and plays the best. It ends its phase when nothing beats standing still. If a command leads to a choice, it tries the answers too.

To stay fair, every copy has the zones the computer cannot see reshuffled and its random numbers reseeded first, so it cannot know what it will draw or how a random effect will land. The evaluator only counts the cards in hidden zones; it never reads them.

It looks one move ahead. It will not plan a combination over several cards, or anticipate the opponent’s reply.

Computer players run on the host. MatchHost.AddAgent seats one; after every update the host plays computer seats until a human must act. Turn off AutoRunAgents and call StepAgent to pace them yourself, for example to add a pause between moves. A computer player that gives no command, an illegal one, or throws ends its phase instead, so a faulty opponent cannot stall a match.

Implement IPlayerAgent:

public class AggressiveAgent : IPlayerAgent
{
public GameCommand ChooseCommand(Match match, int playerId)
{
var legal = match.GetLegalCommands(playerId);
return legal.FirstOrDefault(c => c is SubmitChoiceCommand)
?? legal.FirstOrDefault(c => c is AttackCommand)
?? legal.FirstOrDefault(c => c is PlayCardCommand)
?? legal.First(c => c is EndPhaseCommand);
}
}

Use it from an AI Profile subclass:

[CreateAssetMenu(menuName = "My Game/Aggressive AI")]
public class AggressiveProfile : AIProfile
{
public override IPlayerAgent CreateAgent(ulong seed) => new AggressiveAgent();
}

To keep the built-in search but score positions differently, override CreateEvaluator and return your own IStateEvaluator. Use match.Fork() to try commands on a copy, never on the match you were given.