Here, there and back again.
Status update. For folks who watch my svn activities it is obvious, that work is still ongoing. For allother a small update.
I know it has been a long time since a last official release. But doing the new AI is quite more work than I originally anticipated. Nonetheless - work is ongoing and AI is getting better and bugs are removed as I make progress.
What I am actually doing is a mixture between "BugFix" and "Opimization".
As befor - the skeletton of the new AI is finished - and I am fleshing it out.
Main challenge 1 for the new AI is still the sheer multitude of possible choices that can be made.
----------------
The challenge is:
- the new AI tries all possible variations of cards that can be played, cards that can be activated and attack variations that are possible etc.
- instants that can be played in all round -> choices are generated for all rounds
- the AI (default) will look ahead till the end of the opponents player combat phase, thus it will be estimated all possible actions for:
1. PHASE_BEGINNING_UNTAP
2. PHASE_BEGINNING_UPKEEP
3. PHASE_BEGINNING_DRAW
4. PHASE_MAIN1
5. PHASE_COMBAT_BEGIN
6. PHASE_COMBAT_DECLARE_ATTACKERS
7. PHASE_COMBAT_DECLARE_BLOCKERS
8. PHASE_COMBAT_DAMAGE
9. PHASE_COMBAT_END
10. PHASE_MAIN2
11. PHASE_END_END
12. PHASE_END_CLEANUP
13. PHASE_BEGINNING_UNTAP
14. PHASE_BEGINNING_UPKEEP
15. PHASE_BEGINNING_DRAW
16. PHASE_MAIN1
17. PHASE_COMBAT_BEGIN
18. PHASE_COMBAT_DECLARE_ATTACKERS
19. PHASE_COMBAT_DECLARE_BLOCKERS
20. PHASE_COMBAT_DAMAGE
21. PHASE_COMBAT_END
-> depth of 21 phases (but the depth looked at will be configurable)
This can be very fast VERY challenging.
If there are only TWO choices per phase to evaluate, that means we have 2 ^ 21 choices -> 2.097.152! This is the main challange. Reduce the volume of choices that can be made, and reduce them in a way that no "GOOD" choices are eleminated.
Here I will shortly sketch the means implemented to reduce. Some of them are configureable, some are "hardwired". In no particular relevant order:
- "Recuce library chosing to:" a number Cards that "open" the library and allow chosing any card... generate sheer multitudes of options.
Chosing a "I try them all out" strategie is virtually impossible with current computers. Thus
I reduce the cards that are evaluated to a maximum. The cards that are evaluated are chosen using a scheme like the one used in the old AI, "chose_good_card();" - default value here is 5
- "If land can be played, force Main1, played first"
A number of lands on hand, which can be played in Main1 and Main2 generate a lot of not needed choices.
If AI decides beforhand:
a) Do I want to play a land
b) what color do I want to play
c) I play in Main1
I reduce the amount of choices generated considerably.
(If I have no land, draw land and have it available only in Main2 -> it nonetheless will be played out correctly)
- Try to decide between good/bad
Allways from the players point of view.
Bad cards are damaging cards, moving to graveyard etc...
Good cards are healing of any kind, moving from graveyard etc...
For "bad" cards -> prefer choices using opponent cards
For "good" cards -> prefer choices using own cards
(Todo: make a choice of "perhaps" cards, like move creature to hand -> if we gain needed heal from playing it out again,
in that situation it will be a good card...)
- Maximize target selection
Meaning cards which have a varying number of targets (Tap 1, 2 or 3 creatures...) allways try to maximize targets, do
not try to evaluate all coices (if not enough targets are present -> try the ones available)
- Do forcable attack on no blockers
if opponent has no blockers, try to attack with all attackers, rather than try all possible variations
of attackers that are possible
(Still might not attack with all, since if low on health AI may decide to keep a blocker for safety reasons)
- Try simple block
Try an algorithmic approach to blocking. Like Block all Attackers, without losing a blocker... etc
If no definite stragtegy can be found -> try them all out.
(surpisingly often a "simple strategy" can be found which is "optimal")
- Try simple attack
if there are more attackers than blockers, one can usually reduce
the attack->block combination that a number of attackers do not have any blockers (algorithmic apporach, attacker blocker
combination which "make sense")
After reduction "Do forcable attack on no blockers" can be applied.
- Try extreme testing
Upon attacking very often "extremes" are the best, meaning either an "all out attack" or "do not attack at all".
Scoring for the below cases are made in advance:
- attack with all
- attack with all minus most powerfull attacker
- attack with none
- attack with only the most powerfull attacker
- attack with only attackers, that can not be blocked
if any of the scores (NON, ALL, NOTBLOCKABLE) (SCORING!) is higher (or equal) than all other scores
-> that one will be taken as planned attack combination
There might be very rare cases, where other attack strategies might be more successfull, but I find them
very hard to find...
- Reduced activation evaluation
If a creature / artifact can be activated in ALL phases, only test them in Main1 or Main2 (or opponents turn) phase, not in
any other "own" turns
I don´t see any difference in the outcome. Is there any?
- reduced instant evaluation
If an instant is either a Buf (of own creatures) or a debuf (of opponent creatures)
- only evaluate them in attack / block phase, not in Main1 or Main 2
- Don´t evalutae (1 Round) Buf / Debufs in Main2
do not buf / debuf creatures in Main 2 -> because it will never do any good
(scoring would prevent playing anyway)
- Double check attacker instants
choices generate for attacking which include Buffing of creatures which do NOT attack are elimitated
- Blocking:
- also elemitation of combinations, see here old posts.
TODO:
- Do quick reblock analyze
Not implemented yet
- Use scoring in block evaluation
Not implemented yet
- kicker extremes
Kickers can explode choices. I still have to think about that
- twins
Quite often players have Twin-Options, like two of the same cards on the hand.
Still have to elimtate exactly the same combinations with equal cards
Main challenge 2 are the new hints and the support for the hints in the new match simulation.
----------------
In JPortal AI and the actual game are still two different stories. And I intend to keep it this way.
This means "The Game" does not know whether a player is human or a computer player.
From the Match (that is the name of the main game class) point of view both human and computer players
are interfaced in exactly the same way.
This also means I do not reuse any of the Match to implement the AI.
The choices generated are not tested using the "Match" - all choices are tested internally by the AI.
For that reason "within" the AI package the AI has its own independend implementation of a different Match.
This one is called "VirtualMatch".
This the real match is called "Match", the AI evaluation match is called "VirtualMatch".
Match
Enforces all MTG rules. Cards are evalutaed by the scripting of the cards. Players are questioned when needed.
VirtualMatch
Does not really enforce rules, but rather implements needed routines that can be used by AI.
Cards are evaluated by using the hints found for cards (EnhancedHints).
EnhancedAI interfaces both the Match (indirectily) and VirtualMatch by EAIActions.
Thus the challange is to implement VirtualMatch to enable it to evaluate all cards in a way that is as similar as possible
to the actual real thing in "Match".
I discovered that this is slow going. Once all is done it will be easy to keep it up to date. But I made knots in my brain
to implement e.g. triggers of any kind in VirtualMatch. I have already come a good far way - but there is still
much left todo.
Main challenge 3 are correctly implementing Hints for all supported cards -> test cards
---------------
This is directly related to challange 2.
All supported cards must have the correct EnhancedHints.
1/2 a year ago I said "finished" - but as testing continues, again and again I discover cards where not
all hints are in place. This will require quite a lot of playing and focused attantion on details to discover
cards where hints are not complete.
To make a long post even longer...
Debug Window for new AI.
It is cool
And more than helpfull. You can evaluate all choices, look at the damage cards took, which are tapped, health of players and so on. Nice!
Conclusion:
----------
I still want a release this year.
Perhaps it will be a beta with known unfinished lose ends.
Regards...
Malban