It is currently 16 Apr 2024, 12:36
   
Text Size

Traversable Game State/Engine Code

Post MTG Forge Related Programming Questions Here

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

Re: Traversable Game State/Engine Code

Postby KrazyTheFox » 30 May 2015, 01:16

I've spent the past two days working out some important groundwork for getting combat working as well as fixing some issues. Cost payments are now enforced and you can cancel casting spells. Cards are checked before playing/casting to ensure it's legal to do so. After ensuring all of that worked, I implemented summoning sickness. Next I added in power, toughness, and damage and updated to UI to display all of these. I also started work on state based actions, primarily creature death due to lethal damage and placeholders for a few other important state based actions necessary to implement the starter set.

State based actions are processed in two parts to ensure that complex interactions are correctly accounted for, such as the recent Hurricane + Platinum Angel bug. First, all state based actions are checked to see which ones need processing based on the current game state. These are all added to a list. The list of actions is iterated over after all checks are completed and each action is executed. If any actions were taken, the process is repeated. It's simple, but it seems to do the job quite nicely.

Finally, I've started adding in loading cards from data files. They keep mostly in line with the current format (though that's likely to change significantly when it comes to scripting abilities, etc):
Code: Select all
Name:Bog Imp
ManaCost:1 B
Types:Creature Imp
StaticAbilities:Flying
PT:1/1

I've started working out the details of how I'm going to tackle combat. I'm hoping to have at least attacking completed by tomorrow evening and blocking by Sunday evening. I'm going to have to refactor the way I'm asking for input from players and I'd like to get that right early on.

Since most of the stuff here is under the hood, I'll skip the .gif this time. :P
User avatar
KrazyTheFox
Programmer
 
Posts: 725
Joined: 18 Mar 2014, 23:51
Has thanked: 66 times
Been thanked: 226 times

Re: Traversable Game State/Engine Code

Postby Xitax » 30 May 2015, 19:11

Are you... uh, completely rewriting Forge?
Xitax
 
Posts: 918
Joined: 16 May 2010, 17:19
Has thanked: 183 times
Been thanked: 133 times

Re: Traversable Game State/Engine Code

Postby KrazyTheFox » 30 May 2015, 19:14

Xitax wrote:Are you... uh, completely rewriting Forge?
Yeah, pretty much. :lol:

The fundamental building blocks of the engine need to change to support what I'm trying to do, so instead of trying to re-work it, I'm starting anew.
User avatar
KrazyTheFox
Programmer
 
Posts: 725
Joined: 18 Mar 2014, 23:51
Has thanked: 66 times
Been thanked: 226 times

Re: Traversable Game State/Engine Code

Postby mastroego » 31 May 2015, 06:02

:shock:
Any chance you'll code the 150+ missing cards too along the way? :mrgreen:
mastroego
 
Posts: 236
Joined: 22 Sep 2013, 14:04
Has thanked: 28 times
Been thanked: 16 times

Re: Traversable Game State/Engine Code

Postby KrazyTheFox » 31 May 2015, 17:21

mastroego wrote::shock:
Any chance you'll code the 150+ missing cards too along the way? :mrgreen:
I can say with certainty that some of the cards will probably never, ever be implemented (I'm looking at you, Chaos Orb). However, I'm making every attempt to keep things extremely flexible, so it's possible that at least some of those cards could be implemented without problems. Looking over the unimplemented card list, many of them should be doable. It's good that you reminded me to look at that list to see what kind of weird things I'll need to code the new engine for.
User avatar
KrazyTheFox
Programmer
 
Posts: 725
Joined: 18 Mar 2014, 23:51
Has thanked: 66 times
Been thanked: 226 times

Re: Traversable Game State/Engine Code

Postby friarsol » 31 May 2015, 17:35

A lot of them care about looking back in time at a certain event, so having a traversable game state will allow those to be implemented immediately.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Traversable Game State/Engine Code

Postby mastroego » 01 Jun 2015, 18:14

=D>

Well, I certainly don't mean to sound alarmed or anything, I'm just sincerely curious.
What will happen with the coded cards? I mean I can understand rewriting the engine [ :shock: ] but 15000 cards?
Ok, I know there are lands and simple cards too, still, such an undertaking seems almost too much to be believed.
Or will cards code be salvaged?

And don't worry, I think we can safely live without Chaos Orb and other meta-cards :wink:
mastroego
 
Posts: 236
Joined: 22 Sep 2013, 14:04
Has thanked: 28 times
Been thanked: 16 times

Re: Traversable Game State/Engine Code

Postby KrazyTheFox » 01 Jun 2015, 18:55

mastroego wrote:15000 cards?
It is a tall order, certainly. However, the system I'm building should also make scripting cards far more simple. Each ability, effect, etc. will be composed of a series of actions that, together, create a much more complex ability. In fact, the entire game is composed of these actions and that's how I'm making everything reversible. Each action does one thing and can undo that one thing. For example, the current Untap step goes like this:

Code: Select all
for each player, do a ClearManaPoolAction
for each creature the current player controls, if it has summoning sickness, do a RemoveSummoningSicknessAction
do an AdvancePhaseAction (advancing to the Untap step)
for each card the current player controls, if it's tapped, do an UntapCardAction

It's still going to be a lot of work to support the huge amount of cards we currently have implemented again, but now that we have existing cards as a reference, a lot of things should be find/replace and those that aren't won't be too hard to convert.

As with the rest of this project, I won't be surprised if it ends up taking years to being this up to the completeness level that Forge supports now. If I were able to work on this full time, it might take just a year. :lol:
User avatar
KrazyTheFox
Programmer
 
Posts: 725
Joined: 18 Mar 2014, 23:51
Has thanked: 66 times
Been thanked: 226 times

Re: Traversable Game State/Engine Code

Postby mastroego » 01 Jun 2015, 20:53

Krazy, I'm amazed and thankful that you're even willing to contemplate such a plan.
At the same time, I'd advise to consider carefully if it really is the right way to go about it.
Forge already has taken years to get where it is, and it gets SO MANY things right.
Not perfect, of course, nothing is.
And it's a miracle already, almost the entirety of non profit projects such as this end up as vaporware. Forge defied any reasonable expectation in this regard.
But starting from scratch, with a project that will require coding all the cards again?
You might risk losing the steam for the current iteration of this amazing project, and not having enough for the next one.

Not trying to sound negative, just prompting some additional thought, maybe from a different perspective.
I'll be here giving the feedback I can regardless :)
In any case, thanks for devoting your skills to this and may your plans see completion :)
mastroego
 
Posts: 236
Joined: 22 Sep 2013, 14:04
Has thanked: 28 times
Been thanked: 16 times

Re: Traversable Game State/Engine Code

Postby KrazyTheFox » 01 Jun 2015, 22:11

mastroego wrote:Not trying to sound negative, just prompting some additional thought, maybe from a different perspective.
I totally get where you're coming from and there's a definite possibility that I'll never actually finish this. That said, it's a fun project to work on right now and that's the most important part to me. While I may run out of steam (and probably will), there's a very good chance I'll come back to Forge (it's happened a couple times already). I tend to jump between a few projects at any given time. Additionally, once I have the core game together and the kinks worked out, I'll create a new branch on our SVN repo and hopefully some others will jump in and help out with it. If nothing else, it'll be there for someone else to pick up.

mastroego wrote:I'd advise to consider carefully if it really is the right way to go about it.
I'm not sure how else I'd get better AI into Forge, really. :P I would absolutely take the easier route if there was one.

mastroego wrote:I'll be here giving the feedback I can regardless :)
In any case, thanks for devoting your skills to this and may your plans see completion :)
Thanks! It's stuff like this that makes it all super satisfying. Getting to share cool things with people is half the reason I program stuff.
User avatar
KrazyTheFox
Programmer
 
Posts: 725
Joined: 18 Mar 2014, 23:51
Has thanked: 66 times
Been thanked: 226 times

Re: Traversable Game State/Engine Code

Postby mastroego » 02 Jun 2015, 15:52

Well, if I EVER get to a point in my life where I have more free time (something I'm actively striving for, but might not ever happen) I might try and pick up coding myself to help.
Life led me elsewhere, but I looked like I could become a good programmer in my youth :)

I'd have to start basically from scratch and all, but I think I might be able to code a bunch of cards from the basic building blocks.
So again, best of luck :)
mastroego
 
Posts: 236
Joined: 22 Sep 2013, 14:04
Has thanked: 28 times
Been thanked: 16 times

Re: Traversable Game State/Engine Code

Postby KrazyTheFox » 04 Jun 2015, 01:21

As it turns out, MtG combat is really complex. :lol:

I've been chipping away at it and some rudimentary AI. Right now I have most of the actual combat basics in place: declaring attackers, declaring blockers (including multi-blocking), assigning damage (rules not enforced), dealing damage to both players and creatures, and a state based action to kill creatures when their damage is lethal. Combat steps are removed and added as necessary. The AI attacks and blocks, but doesn't assign damage. The player can only attack so far. The AI also casts creatures and plays lands and is capable of making mana payments with mana abilities.

Hopefully I'll be able to implement the missing pieces for player input to get combat completely working within the next couple of days. There's also a couple undo/redo bugs I need to tackle.
User avatar
KrazyTheFox
Programmer
 
Posts: 725
Joined: 18 Mar 2014, 23:51
Has thanked: 66 times
Been thanked: 226 times

Re: Traversable Game State/Engine Code

Postby mastroego » 04 Jun 2015, 07:05

Hi again Krazy, do you remember this thread about Combat refactoring?
(I mean you might have been in hiatus)

viewtopic.php?f=52&t=15836
An entirely new (and, by the looks of it, quite complicated) algorithm was created by elcnesh in order to code a few more of the missing cards, like Viashino Bey.

I seem to remember that the blocking part could not be solved even then though.
Sorry if the information is redundant :)
mastroego
 
Posts: 236
Joined: 22 Sep 2013, 14:04
Has thanked: 28 times
Been thanked: 16 times

Re: Traversable Game State/Engine Code

Postby KrazyTheFox » 04 Jun 2015, 17:36

mastroego wrote:Hi again Krazy, do you remember this thread about Combat refactoring?
(I mean you might have been in hiatus)

viewtopic.php?f=52&t=15836
An entirely new (and, by the looks of it, quite complicated) algorithm was created by elcnesh in order to code a few more of the missing cards, like Viashino Bey.

I seem to remember that the blocking part could not be solved even then though.
Sorry if the information is redundant :)
That's good to know for future use. Right now I'm just focused on giving players the ability to declare attackers and blockers in the first place. I've got a few ideas to speed up blocking, but those will have to wait for the actual AI to be programmed in. The current "AI" is just here to demonstrate that these things work. It's very bad at actually playing the game and will remain that way for a while. :P
User avatar
KrazyTheFox
Programmer
 
Posts: 725
Joined: 18 Mar 2014, 23:51
Has thanked: 66 times
Been thanked: 226 times

Re: Traversable Game State/Engine Code

Postby verdealex79 » 21 Oct 2018, 10:55

Hi! Let me say at the beginning: THANKS to you and all the devs for creating this piece of software, that is simply amazing.

By now I think Forge is a gem of software, and what I consider "nearest" to a full "Magic the Gathering in a box". This "simulating future moves AI" would be - imho - the next BIG step to have Forge be a dream come true, because - while fun and entertaining (and I like that it is available with different moods) - the current AI is the only thing that - sometimes - I still find lacking.

Is this AI enhancement is still in the plans? maybe is being actively developed? Please update us on what (and if) you plan to do / are doing!!

KrazyTheFox wrote:A lot of the current issues with the AI is something I'm attempting to tackle in my Traversable Game State topic. These problems are due to the fact that in Forge we can't really do proper look-aheads and can't rewind the game. There's a tremendous amount of work to do to get a traversable game state into Forge, but the goal is to eventually have AI that simulates future moves and picks the most beneficial ones, likely behaving very similarly to how you describe in this topic.
Apart from this, Forge has almost everything:

- only 139 cards missing in all the MTG history
- single player quest mode (I consider that as a "MTC collecting life simulation")
- single player Constructed with almost every variant (only Two Headed Giant is missing)
- single player Sealed and Limited
- Tournaments
- Multiplayer mode for human opponents (coming - when it will be possible - with all the modes present for the single player)
- TONZ of decks ready to be played (and I mean it, TONZ)
- playable with an AI that is already a lot of fun

You guys rock!!!
verdealex79
 
Posts: 44
Joined: 01 Apr 2013, 18:19
Has thanked: 14 times
Been thanked: 7 times

Previous

Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 46 guests


Who is online

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

Login Form