Re: JPortal current status
Posted: 25 Jan 2012, 16:51
Hiho,
I am a bit frustrated. Things keep coming up - like getting a new Laptop (Win 7 on which I am currently mainly developing).
Also bugs/errors and things I missed entirely. I am programming (on and off) for about 1 1/2 year on the next version and I am still not nearly content on releasing it.
Worst thing is - for an outstander it appears to not have changed all that much...
Different things that came up...
I am changing the computer AI for battles. The whole thing with "trying out" all possibly permutations was really bothering me. It might produce good results - but - hell it surely sometimes takes its time.
For testing purposes I have quite large decks and computer players have 100 HP. So huge battle sometimes occur - like 10 attackers and quite as many defenders.
Doing something like that with all possible combination - well - doesn´t really work.
It used to be the way, that the blocking was the "bad one" and the attack calculation the "good one" now (for me) it is the other way arround.
Reason:
Blocking
--------
is a "closed" action. With that I mean, when I block I don´t really have to consider anything that comes after that block round.
I have a nice single input (the attackers) and a nice single output (blockers). Next round the cards a dealt anew I don´t really have to consider what comes next.
Attacking
---------
Is an "open" action. With that I mean I must consider my opponents next turn. If I attack, which cards are
after the attack tapped - and cannot be "used" in any other way? What do I have to keep untapped in order that I may block the opponents attack... etc
There is much more to consider!
Algorithm
---------
For blocking I use following quite simple - but I think very efficient algorythm:
(Scoring must be implemented. I need a score for a permanent on the battlefield - and a scoring for damage a player may take. Both scores must be compareable. For simplicites sake lets assume following scoring:
- a creature has a score of its "toughness + power", player health reduction has score of 2*damage (the scoring in reality should be adapatable in relation how low the health is)
The scoring goes as this, score of one single fight (1 attacker, x blockers, 1 attacked player):
- if attacker is dead: score = score + attackerScore
else: score = score - attackerScore
for each blocker:
- if blocker is dead: score = score - blockerScore
else: score = score + blockerScore
- if player health is reduced: score = score - damageScore
The algorithm than goes:
a) as long as there are attackers and blockers, get (from blockers view) the best scored
attack<-block combination, remove the attacker and blockers, and goto a)
result is the block formation
-> well that was trivial
how to determine the best scored current attack<-blocking:
Built following scorings and compare them:
a) takeDamageScore (determine the fight score if not blocked)
b) noDeadKillers (determine the best score of a blocker, that kills the attacker and does itself not get killed, score of a blocker is determined as above)
c) leastDeadKillers (determines the best score, that can kill the attacker, blockers might get killed to)
d) noDeadBlock (determine the best score of a blocker that can block the attack wihtout getting killed)
e) cheapestDeadBlocker (determine a blocker that gets killed, but the player does not receive damage)
not all scores are allways available. If a score is not available score = -10000 (or something like that)
The best score of above WINS and is taken as the best block for that attacker.
Example:
Attacker
(Overall Attack Score = 20)
Creature 5/5 score = 10
Creature 4/1 score = 5
Creature 4/1 score = 5
Blocker
(Overall Block-Score = 10)
Creature 1/1 score = 2
Creature 1/1 score = 2
Creature 2/2 score = 4
Creature 1/1 score = 2
1) get best scored block of above:
Attacker = 4/1 is dead -> score += 5
Blocker = 1/1 is dead -> score -=2
Player damage 0 -> score += 0
FightScore = 3
Remove attacker/blocker
Attacker
Creature 5/5 score = 10
Creature 4/1 score = 5
Blocker
Creature 1/1 score = 2
Creature 2/2 score = 4
Creature 1/1 score = 2
2) get best scored block of above:
Attacker = 4/1 is dead -> score += 5
Blocker = 1/1 is dead -> score -=2
Player damage 0 -> score += 0
FightScore = 3
Remove attacker/blocker
Attacker
Creature 5/5 score = 10
Blocker
Creature 2/2 score = 4
Creature 1/1 score = 2
3) get best scored block of above:
Attacker = 5/5 is alive -> score -= 10
Blocker = 1/1 is dead -> score -=2
Player damage 0 -> score += 0
FightScore = -12
Remove attacker/blocker
Attacker
Blocker
Creature 2/2 score = 4
Done
In that scoring scheme killing the 5/5 would result in a scoring:
Creature 5/5 score = 10
Creature 4/1 score = 5
Creature 4/1 score = 5
Blocker
Creature 1/1 score = 2
Creature 1/1 score = 2
Creature 2/2 score = 4
Creature 1/1 score = 2
1) get best scored block of above:
Attacker = 5/5 is dead -> score += 10
Blocker = 1/1 is dead -> score -=2
Blocker = 1/1 is dead -> score -=2
Blocker = 1/1 is dead -> score -=2
Blocker = 2/2 is dead -> score -=4
Player damage 0 -> score += 0
FightScore = 0
ATTACKING
---------
This describes the current new implemented attack algorithm of the AI (done today), the reattack algorithm will differ! (and is not done yet)
I differentiate between 3 types of attackers:
a) varAttackers
these are attackers, that upon attacking may e.g. target an enemy
-> these attackers are either attacking "first" or not at all
-> withing the varAttackers, all permutations (also positions related) are played!
-> many variations
b) undangeredAttackers
These attackers are either unblockable, or have so much toughness that they
will not be killed.
These are either played out - or not, all unordered permutations (no order difference is made)
are built (this is only interesting, if opponent can reattack)!
c) all other attackers
These will be extrem "tested", meaning
extreme variations will be built and scored
(Not implemented: ), as long
as scoring is not descending in one way, the extremes will be built
further scoring is done, by locally simulating the match, till next opponents attack/ own block phase (combat resolved)
a) + b) are straight forward.
c) extremes are implemented as:
1) + 2) Order attacker by toughness, build variantions of descending and ascending orders.
3) + 4) Order attacker by power, build variantions of descending and ascending orders.
None
All
-> no doubles
That scheme still produces many variants - but nonetheless is a great reduction to older implementations.
If both attack/ and block algorithms work out -> I will keep them as this.
Regards
Malban
I am a bit frustrated. Things keep coming up - like getting a new Laptop (Win 7 on which I am currently mainly developing).
Also bugs/errors and things I missed entirely. I am programming (on and off) for about 1 1/2 year on the next version and I am still not nearly content on releasing it.
Worst thing is - for an outstander it appears to not have changed all that much...
Different things that came up...
I am changing the computer AI for battles. The whole thing with "trying out" all possibly permutations was really bothering me. It might produce good results - but - hell it surely sometimes takes its time.
For testing purposes I have quite large decks and computer players have 100 HP. So huge battle sometimes occur - like 10 attackers and quite as many defenders.
Doing something like that with all possible combination - well - doesn´t really work.
It used to be the way, that the blocking was the "bad one" and the attack calculation the "good one" now (for me) it is the other way arround.
Reason:
Blocking
--------
is a "closed" action. With that I mean, when I block I don´t really have to consider anything that comes after that block round.
I have a nice single input (the attackers) and a nice single output (blockers). Next round the cards a dealt anew I don´t really have to consider what comes next.
Attacking
---------
Is an "open" action. With that I mean I must consider my opponents next turn. If I attack, which cards are
after the attack tapped - and cannot be "used" in any other way? What do I have to keep untapped in order that I may block the opponents attack... etc
There is much more to consider!
Algorithm
---------
For blocking I use following quite simple - but I think very efficient algorythm:
(Scoring must be implemented. I need a score for a permanent on the battlefield - and a scoring for damage a player may take. Both scores must be compareable. For simplicites sake lets assume following scoring:
- a creature has a score of its "toughness + power", player health reduction has score of 2*damage (the scoring in reality should be adapatable in relation how low the health is)
The scoring goes as this, score of one single fight (1 attacker, x blockers, 1 attacked player):
- if attacker is dead: score = score + attackerScore
else: score = score - attackerScore
for each blocker:
- if blocker is dead: score = score - blockerScore
else: score = score + blockerScore
- if player health is reduced: score = score - damageScore
The algorithm than goes:
a) as long as there are attackers and blockers, get (from blockers view) the best scored
attack<-block combination, remove the attacker and blockers, and goto a)
result is the block formation
-> well that was trivial
how to determine the best scored current attack<-blocking:
Built following scorings and compare them:
a) takeDamageScore (determine the fight score if not blocked)
b) noDeadKillers (determine the best score of a blocker, that kills the attacker and does itself not get killed, score of a blocker is determined as above)
c) leastDeadKillers (determines the best score, that can kill the attacker, blockers might get killed to)
d) noDeadBlock (determine the best score of a blocker that can block the attack wihtout getting killed)
e) cheapestDeadBlocker (determine a blocker that gets killed, but the player does not receive damage)
not all scores are allways available. If a score is not available score = -10000 (or something like that)
The best score of above WINS and is taken as the best block for that attacker.
Example:
Attacker
(Overall Attack Score = 20)
Creature 5/5 score = 10
Creature 4/1 score = 5
Creature 4/1 score = 5
Blocker
(Overall Block-Score = 10)
Creature 1/1 score = 2
Creature 1/1 score = 2
Creature 2/2 score = 4
Creature 1/1 score = 2
1) get best scored block of above:
Attacker = 4/1 is dead -> score += 5
Blocker = 1/1 is dead -> score -=2
Player damage 0 -> score += 0
FightScore = 3
Remove attacker/blocker
Attacker
Creature 5/5 score = 10
Creature 4/1 score = 5
Blocker
Creature 1/1 score = 2
Creature 2/2 score = 4
Creature 1/1 score = 2
2) get best scored block of above:
Attacker = 4/1 is dead -> score += 5
Blocker = 1/1 is dead -> score -=2
Player damage 0 -> score += 0
FightScore = 3
Remove attacker/blocker
Attacker
Creature 5/5 score = 10
Blocker
Creature 2/2 score = 4
Creature 1/1 score = 2
3) get best scored block of above:
Attacker = 5/5 is alive -> score -= 10
Blocker = 1/1 is dead -> score -=2
Player damage 0 -> score += 0
FightScore = -12
Remove attacker/blocker
Attacker
Blocker
Creature 2/2 score = 4
Done
In that scoring scheme killing the 5/5 would result in a scoring:
Creature 5/5 score = 10
Creature 4/1 score = 5
Creature 4/1 score = 5
Blocker
Creature 1/1 score = 2
Creature 1/1 score = 2
Creature 2/2 score = 4
Creature 1/1 score = 2
1) get best scored block of above:
Attacker = 5/5 is dead -> score += 10
Blocker = 1/1 is dead -> score -=2
Blocker = 1/1 is dead -> score -=2
Blocker = 1/1 is dead -> score -=2
Blocker = 2/2 is dead -> score -=4
Player damage 0 -> score += 0
FightScore = 0
ATTACKING
---------
This describes the current new implemented attack algorithm of the AI (done today), the reattack algorithm will differ! (and is not done yet)
I differentiate between 3 types of attackers:
a) varAttackers
these are attackers, that upon attacking may e.g. target an enemy
-> these attackers are either attacking "first" or not at all
-> withing the varAttackers, all permutations (also positions related) are played!
-> many variations
b) undangeredAttackers
These attackers are either unblockable, or have so much toughness that they
will not be killed.
These are either played out - or not, all unordered permutations (no order difference is made)
are built (this is only interesting, if opponent can reattack)!
c) all other attackers
These will be extrem "tested", meaning
extreme variations will be built and scored
(Not implemented: ), as long
as scoring is not descending in one way, the extremes will be built
further scoring is done, by locally simulating the match, till next opponents attack/ own block phase (combat resolved)
a) + b) are straight forward.
c) extremes are implemented as:
1) + 2) Order attacker by toughness, build variantions of descending and ascending orders.
3) + 4) Order attacker by power, build variantions of descending and ascending orders.
None
All
-> no doubles
That scheme still produces many variants - but nonetheless is a great reduction to older implementations.
If both attack/ and block algorithms work out -> I will keep them as this.
Regards
Malban