It is currently 19 Apr 2024, 19:46
   
Text Size

Combat Refactoring

Post MTG Forge Related Programming Questions Here

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

Re: Combat Refactoring

Postby Marek14 » 23 Oct 2014, 17:37

elcnesh wrote:I've got it working!!!! :D

I implemented it in the "new" way, and it works like a charm. I've resolved some of the possible issues mentioned by Marek14 (thanks, most of them were indeed an issue) and changed it to use minimum breaking restriction rather than most fulfilling (IMO the comp rules should be updated in that way also), and it seems to work, at least with the stuff I've tested, including Ekundu Cyclops, Viashino Bey, War's Toll, Scarred Puma, Okk. The only thing that really needs to be done is AI, but I'm a complete noob when it comes to the AI code... Maybe I'll just add a safeguard for now, so that the AI always has a legal way of attacking, and other people can optimise that later.
Minimum breaking restriction and most fulfilling are basically equivalent IF the number of restrictions is kept constant -- the problem is that the logic might not feel very intuitive in that case. Minimum breaking is easier to understand correctly.

Did you use the "negative requirement" approach? :)
Marek14
Tester
 
Posts: 2759
Joined: 07 Jun 2008, 07:54
Has thanked: 0 time
Been thanked: 296 times

Re: Combat Refactoring

Postby elcnesh » 24 Oct 2014, 14:25

lujo wrote:Huge salute for this! One important bit - how does this all reflect on banding? Banding is possibly the biggest white ability, and probably the biggest ever non-evasion combat ability there's ever been in the game and having it work or grounds to even develop decent AI for it would be huge for getting older sets to play right?
It would be, but as I mentioned I know next-to-nothing about AI programming (be it Forge or otherwise), so I'm afraid I can't do that. What I did was only rules-based, that is, getting Forge to work consistently with the rules. Of course, if someone else is going to make the AI work with my code, they could also do some work on banding, but that's not up to me.

Marek14 wrote:Minimum breaking restriction and most fulfilling are basically equivalent IF the number of restrictions is kept constant -- the problem is that the logic might not feel very intuitive in that case. Minimum breaking is easier to understand correctly.

Did you use the "negative requirement" approach? :)
IF it is, but that depends on how you read the cards :P
In the end I didn't use it. I'll reread it to see if it can be an improvement to the current code ;)
elcnesh
 
Posts: 290
Joined: 16 May 2014, 15:11
Location: Netherlands
Has thanked: 34 times
Been thanked: 92 times

Re: Combat Refactoring

Postby friarsol » 17 Nov 2014, 04:39

I'm not sure what part of the refactoring caused this, but there's a bug that was added as part of this code (or maybe other similar changes in the last month).

Basically in PhaseHandler.py this block of code exists:

Code: Select all
                case COMBAT_END:
                    // End Combat always happens
                    game.getEndOfCombat().executeUntil();
                    game.getEndOfCombat().executeAt();

                    if (combat != null) {
                        combat.endCombat();
                    }
                    //SDisplayUtil.showTab(EDocID.REPORT_STACK.getDoc());
                    break;
But "combat.endCombat()" seems to clear out attackers and blockers and things like that. But that's completely wrong. Creatures are still attacking and blocking until the Combat Phase ends, and the EndCombat step is part of the Combat Phase. Maybe this was added in an attempt to fix combat icons not being removed, but this is the wrong course of action. If you look later in this file, in "phaseEnd" there's a combat.endCombat() call to handle all of the clear out combatants at the right time.

With this code, the card Desert is completely unplayable, along with other tricks that happen during this step. (Like Reconnaissance)
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Combat Refactoring

Postby elcnesh » 17 Nov 2014, 13:15

I don't think I edited that part of the code... I only changed the attack declaration, not any other parts of combat.

Edit: isn't the solution as simple as just removing those lines?
elcnesh
 
Posts: 290
Joined: 16 May 2014, 15:11
Location: Netherlands
Has thanked: 34 times
Been thanked: 92 times

Re: Combat Refactoring

Postby friarsol » 17 Nov 2014, 15:11

elcnesh wrote:Edit: isn't the solution as simple as just removing those lines?
I tried that last night, but the UI wasn't updating the Icons when combat was actually ending.

Ahh.. it looks like it was actually added by DrDev in r27875, http://svn.slightlymagic.net/websvn/rev ... &peg=27875

Didn't realize there was multiple things happening to Combat at the same time.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Combat Refactoring

Postby drdev » 17 Nov 2014, 20:11

friarsol wrote:
elcnesh wrote:Edit: isn't the solution as simple as just removing those lines?
I tried that last night, but the UI wasn't updating the Icons when combat was actually ending.

Ahh.. it looks like it was actually added by DrDev in r27875, http://svn.slightlymagic.net/websvn/rev ... &peg=27875

Didn't realize there was multiple things happening to Combat at the same time.
Yeah, now that you mention I do remember making that change, and it had to do with the combat icons. I'm certainly not attached to my implementation if there's a better one that aligns with the way the combat phase should work rules-wise.
drdev
Programmer
 
Posts: 1958
Joined: 27 Jul 2013, 02:07
Has thanked: 189 times
Been thanked: 565 times

Re: Combat Refactoring

Postby elcnesh » 21 Nov 2014, 09:07

Hi everyone,

So I'm nearly there with block refactoring, there's just one part that I can't seem to get a grip on. Maybe someone else has an idea?

When a creature "must be blocked" by anything, I have trouble determining which creature should block it. If I choose a creature right away, it might be the wrong one, ie. one we need for another attacker. I can postpone this choice, but now suppose there's a few of these choices, each featuring a unique set of legal blockers. How can we determine if such a set can still be fulfilled?
Put differently: suppose X has to be blocked, and its legal blockers are A and B. Now Y also has to be blocked, and can be by C and D. All is fine up until this point. Now Z comes along, who can be blocked by B and C. How do we (quickly/efficiently) determine if Z can still be blocked? (Of course, this can become much more complex with many attackers and blockers!)

Other than this, everything is finished :)
elcnesh
 
Posts: 290
Joined: 16 May 2014, 15:11
Location: Netherlands
Has thanked: 34 times
Been thanked: 92 times

Re: Combat Refactoring

Postby Marek14 » 21 Nov 2014, 14:02

If you block X by B and Y by C, then the number of broken requirements will stay if we add another blocker or if we switch one blocker to another attacker, so we reach a plateau. So is it necessary to add an operation "switch one blocker while simultaneously adding another"?

Not sure how to resolve this issue. Maybe to try, for each unblocked "must be blocked" creature, to grab a blocker from elsewhere in a way that wouldn't break requirements on the blocking creature, and then see if any broken requirements on the attacking creatures can be satisfied by a "free" blocker?
Marek14
Tester
 
Posts: 2759
Joined: 07 Jun 2008, 07:54
Has thanked: 0 time
Been thanked: 296 times

Previous

Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 100 guests


Who is online

In total there are 100 users online :: 0 registered, 0 hidden and 100 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 100 guests

Login Form