It is currently 19 Apr 2024, 18:06
   
Text Size

Newbie trying to figure out game structure

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

Newbie trying to figure out game structure

Postby flupo42 » 06 May 2016, 20:15

Downloaded source, was able to compile.

Having a hard time finding where to try plugging in my idea. Could anyone familiar with the game combat/AI classes point out which classes and functions I should be looking at?

I want to

1) Call my class evaluation function at beginning of each turn by AI

2) Within class, I need access to collections of cards in currently playing deck.

3) also need access to collection of cards in each zone.

4) Be able to output stuff to a log file.

Purpose: Want to try writing a game state scoring function that could later be used to allow advance planning for AI. I see there is a simulation folder where someone started that idea and I want to push that along. Currently planning for lands.

Basic Plan:

New Classes:

Class DeckAbilities: will hold a collection of properties about what is possible to do in game to be used for evaluating card weights and game state scores.

Examples of properties CanRetrieveArtifactsFromGraveyard, CanExile, CanDealDirectDamageToCreature, CanDealDirectDamageToPlayer.


Class PlayerProperties( application will maintain an instance of this class representing AI and each other player):

-will hold collection of all cards in deck

-will hold three instances of DeckAbilities class: Potential, Actual, Theoretical.

DeckAbilities Theoretical – populates its ability values based on all the cards known to be left in the library.

DeckAbilities Actual – populates its ability values based on current permanents on board and playable cards in hand

DeckAbilities Potential – populates its ability values based on cards in all zones and known cards in hands.

Example: if Deck contains Cruel Revival, Theoretical instance will have flags such as CanRetrieveCreaturesFromGraveyard and CanDestroyCreatures set to true (or more likely a more complicated value structure will be needed to denote specifics). If player has no Cruel Revival in hand (or other cards that give same potential), the Actual instance will have those same flags set to false.

Example: If AI now has cards in hand or on board that could force opponent to sacrifice a creature, its Actual instance will have CanForceTargetPlayerToSacrifice creature set to false. However if it has a Gravedigger in hand and a Fleshbag Marauder in the graveyard, the Potential instance will have that same value set to true, determined by player having its Actual ability of CanRetrieveCreaturesFromGraveyard and the graveyard having a creature that forces a sacrifice.

The general idea is that when cards or actions are evaluated these properties could be taken into account to adjust weighting.


General usage:

This class will be used by functions calculating Board State to weigh cards in play as well as possible actions.

Sample Use Case:

Proposed weighting algorithm – assigns a score to each card on the board that player controls, total of the score gives an approximation of how desirable the state is. The weighting will be variables taken from a configuration file.

AI has an Island and needs to know how valuable that Island is:

(uses actual numbers, though in reality will be variables like BasePermanentScore, NecessaryManaActualScore, NecessaryTheoreticalScore)

It's a permanent: Score 1 ( BasePermanentScore - there is inherent value in just a permanent as target of potential sacrifice forced by opponent or effects that count number of permanents)

It's a land that gives blue mana. The scoring of that depends on how useful that mana is to the player.
First look at cards in hand and decide how many of cards in hand it needs that blue mana for, each card for which the Mountain is necessary will increase score by 10 ( NecessaryManaActualScore - lands necessary for acting now are highly valuable)

Then look at its CMCCost list based on it the cards it knows it has in library, totaling up number of cards/abilites for which that Island is necessary each of those will be multiplied by 6 (ish.. - NecessaryTheoreticalScore will be lower than for actual, but still pretty high).

Than look at CMC cost again and total up number of those costs it needs that mana for, assuming it already spent an AverageCost for its deck – multiply that by NecManaSecondActionScore, which will be lower still (2 or 3)

Finally repeat the above step assuming it paid 2 average costs, multiply that count by NecManaFlurryOfActionsScore (really low value, 1).

Now the above doesn't fully take into account potential deck properties. But the algorithm can look at certain relevant DeckAbilities values and adjust the weighting of the above cost variables. For example if the deck has a high PotentialCardAdvantage because it runs a dozen cards with Draw a Card effects, than both NecManaSecondActionScore and NecManaFlurryOfActionsScore should be increased because the player will need more mana to make use of the extra cards. Same if there are a lot of mana sink cards, or cards with X in their costs. Lands in hand might check properties like LandfallEffects of the Actual instance of DeckAbilities, or CanTurnLandsIntoCreatures

Using the above algorithm, AI could evaluate how important its lands/mana sources are at the moment.

At each passthrough of evaluation it would assign a very high value to the first Land, and progressively lower values to subsequent lands (doesn't really matter which order it goes through the lands it has) as the game progresses. It would help AI weight decisions like whether it's okay to sacrifice a land – if it's start of the game and it only has 3 in play, each one will have very high scores and result in much worse overall board state score, while if it has 10, the last few will have much lower scores.

Later the above classes can be used for deck-ability referencing in scoring other types of permanents.
flupo42
 
Posts: 6
Joined: 21 Apr 2016, 22:54
Has thanked: 3 times
Been thanked: 0 time

Re: Newbie trying to figure out game structure

Postby excessum » 07 May 2016, 02:13

Nice ideas you have there. I worry that it might be too much to implement until you are more familiar with the nuances of the AI system. Lol I cannot even remember how many grand plans I had over the years that were eventually abandoned because of the effort involved.

The AI decisions usually start from AiController.chooseSpellAbilityToPlay which then calls a long series of various "choose" and "canPlay" methods within AiController. AI responses to prompts such as targeted discard, select card after reveal, etc. are in PlayerControllerAi. Player.getCardsIn is used to access the cards in various zones, including the library.
excessum
 
Posts: 177
Joined: 21 Oct 2013, 02:30
Has thanked: 0 time
Been thanked: 19 times

Re: Newbie trying to figure out game structure

Postby flupo42 » 07 May 2016, 11:43

thank you for the directions.

Right now this plan as more of a test of concept - I won't try to have this affect actual decisions by AI in any way even if this pans out. I just want to start getting it to assign even a partial score to game state to see how heavy the processing will be, focusing just on lands to keep the scope of task smaller at this point.

Meanwhile while digging towards that, found a few small bugs which I will try to use as a learning experience to familiarize myself with how AI is doing things now.
flupo42
 
Posts: 6
Joined: 21 Apr 2016, 22:54
Has thanked: 3 times
Been thanked: 0 time


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 84 guests


Who is online

In total there are 84 users online :: 0 registered, 0 hidden and 84 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 84 guests

Login Form