New Testing Facility: Setup Battlefield
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
26 posts
• Page 1 of 2 • 1, 2
New Testing Facility: Setup Battlefield
by Agetian » 31 May 2011, 14:42
UPDATED 01 JUN 2011: New, more intuitive file format, graveyard modification support
UPDATE 2: Setup Battlefield uses a standard file open dialog to open battlefield configurations from custom-named text files.
UPDATE 3: Reflected the modification by keybone in SVN r9251 in this documentation
UPDATE 4: Massive changes to the Setup Battlefield mode, it's now known as Setup Game State and is no longer dependent on order of lines in the text file.
UPDATE 5: Added the ActivePlayer option that allows to define the active player.
UPDATE 6: Added the ActivePhase option that allows to define the current phase.
UPDATE 7: The END tag is no longer required, game state files can contain empty lines and comments preceded by the pound sign (#). Old state setup files are still compatible.
UPDATE 8: Added a possibility to change cards in Exile areas for Human and AI, added an optional ability to specify a specific set for cards spawned through Setup Game State.
UPDATE 9: Made the set info definition for Setup Game State consistent with the deck file format (using the pipe symbol now, e.g. Forest|4ED instead of Forest@4ED).
Hi,
I wanted to inform you that I have successfully coded the initial working implementation of a new testing facility which I'm going to use for my AI improvement experiments and that I believe may be useful to the other developers as well. It's called Setup Game State and may be accessed through the Developer menu when the Forge developer mode is on.
Setup Game State allows you to set up a specific battlefield situation by adding cards onto the battlefield (both human and computer), changing the cards in the human's and computer's hands, and setting up the precise values for the human's and computer's life. Any creatures spawned through Setup Game State will come into play without summoning sickness in order to make the testing of combat situations easier.
Currently the command uses an external text file that is opened through a file open dialog when you click on the Setup Game State menu item. The file structure is simple. It must contain any of the following lines defining what needs to be changed in the current game state:
1) HumanLife=<value> - defines the value to set the human's current life to. Example: HumanLife=6
2) AILife=<value> - defines the value to set the computer opponent's life to. Example: AILife=14
3) HumanCardsInPlay=<card name>; <card name>; <card name>; ... - defines the cards that are to be placed under Human's control on the battlefield. Can be just one card name or a list of card names separated with semicolons. Example: HumanCardsInPlay=Swamp; Swamp; Drudge Skeletons
4) AICardsInPlay=<card name>; <card name>; <card name>; ... - defines the cards that are to be placed under Computer's control on the battlefield. Can be just one card name or a list of card names separated with semicolons. Example: AICardsInPlay=Island
5) HumanCardsInHand=<card name>; <card name>; <card name>; ... - defines the cards that are to replace the Human's current hand. Old cards in the Human's card will be removed. Can be just one card name or a list of card names separated with semicolons, see [3] or [4] for examples.
6) AICardsInHand=<card name>; <card name>; <card name>; ... - defines the cards that are to replace the Computer's current hand. Old cards in the Computer's card will be removed. Can be just one card name or a list of card names separated with semicolons, see [3] or [4] for examples.
7) HumanCardsInGraveyard=<card name>; <card name>; <card name>; ... - defines the cards that are to replace the Human's current graveyard. Old cards in the Human's graveyard will be removed. Can be just one card name or a list of card names separated with semicolons, see [3] or [4] for examples.
8] AICardsInGraveyard=<card name>; <card name>; <card name>; ... - defines the cards that are to replace the Computer's current graveyard. Old cards in the Computer's graveyard will be removed. Can be just one card name or a list of card names separated with semicolons, see [3] or [4] for examples.
9) HumanCardsInLibrary=<card name>; <card name>; <card name>; ... - defines the cards that are to replace the Human's current library. Old cards in the Human's library will be removed. Can be just one card name or a list of card names separated with semicolons, see [3] or [4] for examples.
10) AICardsInLibrary=<card name>; <card name>; <card name>; ... - defines the cards that are to replace the Computer's current library. Old cards in the Computer's library will be removed. Can be just one card name or a list of card names separated with semicolons, see [3] or [4] for examples.
11) HumanCardsInExile=<card name>; <card name>; <card name>; ... - defines the cards that are to replace the Human's current exile area. Old cards in the Human's exile area will be removed. Can be just one card name or a list of card names separated with semicolons, see [3] or [4] for examples.
12) AICardsInExile=<card name>; <card name>; <card name>; ... - defines the cards that are to replace the Computer's current exile area. Old cards in the Computer's exile area will be removed. Can be just one card name or a list of card names separated with semicolons, see [3] or [4] for examples.
13) ActivePlayer=<active_player> - defines the active player that must be given priority when the game state is set up. If this line is absent, the current player is not changed. There are two valid values for this option: Human and AI. Note that this option does not change the current phase, only the current player. Example: ActivePlayer=AI
14) ActivePhase=<current_phase> - changes the current phase of the game to the one specified. The valid values are Untap, Upkeep, Draw, Main1, Declare Attackers, Declare Blockers, Main2, End of Turn, and Cleanup. Note that the phase names are case-sensitive!
SPECIFYING SETS FOR CARDS: When specifying card names, you can optionally add the set code by appending the pipe sign (|) and the three-letter set code to the card name you are spawning. That will allow you to spawn cards from specific sets. For example, HumanCardsInPlay=Mountain; Mountain will just spawn two Mountains on the human battlefield, using the latest possible set for them, while HumanCardsInPlay=Mountain|4ED; Mountain|4ED will spawn two Mountains from the 4th Edition on the human battlefield.
Here are two examples of valid state configuration files:
I hope you'll find this command useful! Currently it's somewhat limited because it doesn't allow you to attach auras and equipments to cards and do other various things like that. Also, note that if the human and/or AI hands, graveyards, exiles, or libraries are replaced with cards through this mode, the cards that were in the respective hands, graveyards, exiles, or libraries before the Setup Game State was called will "disappear" instead of going to the graveyard, exile, or other places. Feel free to expand as necessary.
- Agetian
UPDATE 2: Setup Battlefield uses a standard file open dialog to open battlefield configurations from custom-named text files.
UPDATE 3: Reflected the modification by keybone in SVN r9251 in this documentation
UPDATE 4: Massive changes to the Setup Battlefield mode, it's now known as Setup Game State and is no longer dependent on order of lines in the text file.
UPDATE 5: Added the ActivePlayer option that allows to define the active player.
UPDATE 6: Added the ActivePhase option that allows to define the current phase.
UPDATE 7: The END tag is no longer required, game state files can contain empty lines and comments preceded by the pound sign (#). Old state setup files are still compatible.
UPDATE 8: Added a possibility to change cards in Exile areas for Human and AI, added an optional ability to specify a specific set for cards spawned through Setup Game State.
UPDATE 9: Made the set info definition for Setup Game State consistent with the deck file format (using the pipe symbol now, e.g. Forest|4ED instead of Forest@4ED).
Hi,
I wanted to inform you that I have successfully coded the initial working implementation of a new testing facility which I'm going to use for my AI improvement experiments and that I believe may be useful to the other developers as well. It's called Setup Game State and may be accessed through the Developer menu when the Forge developer mode is on.
Setup Game State allows you to set up a specific battlefield situation by adding cards onto the battlefield (both human and computer), changing the cards in the human's and computer's hands, and setting up the precise values for the human's and computer's life. Any creatures spawned through Setup Game State will come into play without summoning sickness in order to make the testing of combat situations easier.
Currently the command uses an external text file that is opened through a file open dialog when you click on the Setup Game State menu item. The file structure is simple. It must contain any of the following lines defining what needs to be changed in the current game state:
1) HumanLife=<value> - defines the value to set the human's current life to. Example: HumanLife=6
2) AILife=<value> - defines the value to set the computer opponent's life to. Example: AILife=14
3) HumanCardsInPlay=<card name>; <card name>; <card name>; ... - defines the cards that are to be placed under Human's control on the battlefield. Can be just one card name or a list of card names separated with semicolons. Example: HumanCardsInPlay=Swamp; Swamp; Drudge Skeletons
4) AICardsInPlay=<card name>; <card name>; <card name>; ... - defines the cards that are to be placed under Computer's control on the battlefield. Can be just one card name or a list of card names separated with semicolons. Example: AICardsInPlay=Island
5) HumanCardsInHand=<card name>; <card name>; <card name>; ... - defines the cards that are to replace the Human's current hand. Old cards in the Human's card will be removed. Can be just one card name or a list of card names separated with semicolons, see [3] or [4] for examples.
6) AICardsInHand=<card name>; <card name>; <card name>; ... - defines the cards that are to replace the Computer's current hand. Old cards in the Computer's card will be removed. Can be just one card name or a list of card names separated with semicolons, see [3] or [4] for examples.
7) HumanCardsInGraveyard=<card name>; <card name>; <card name>; ... - defines the cards that are to replace the Human's current graveyard. Old cards in the Human's graveyard will be removed. Can be just one card name or a list of card names separated with semicolons, see [3] or [4] for examples.
8] AICardsInGraveyard=<card name>; <card name>; <card name>; ... - defines the cards that are to replace the Computer's current graveyard. Old cards in the Computer's graveyard will be removed. Can be just one card name or a list of card names separated with semicolons, see [3] or [4] for examples.
9) HumanCardsInLibrary=<card name>; <card name>; <card name>; ... - defines the cards that are to replace the Human's current library. Old cards in the Human's library will be removed. Can be just one card name or a list of card names separated with semicolons, see [3] or [4] for examples.
10) AICardsInLibrary=<card name>; <card name>; <card name>; ... - defines the cards that are to replace the Computer's current library. Old cards in the Computer's library will be removed. Can be just one card name or a list of card names separated with semicolons, see [3] or [4] for examples.
11) HumanCardsInExile=<card name>; <card name>; <card name>; ... - defines the cards that are to replace the Human's current exile area. Old cards in the Human's exile area will be removed. Can be just one card name or a list of card names separated with semicolons, see [3] or [4] for examples.
12) AICardsInExile=<card name>; <card name>; <card name>; ... - defines the cards that are to replace the Computer's current exile area. Old cards in the Computer's exile area will be removed. Can be just one card name or a list of card names separated with semicolons, see [3] or [4] for examples.
13) ActivePlayer=<active_player> - defines the active player that must be given priority when the game state is set up. If this line is absent, the current player is not changed. There are two valid values for this option: Human and AI. Note that this option does not change the current phase, only the current player. Example: ActivePlayer=AI
14) ActivePhase=<current_phase> - changes the current phase of the game to the one specified. The valid values are Untap, Upkeep, Draw, Main1, Declare Attackers, Declare Blockers, Main2, End of Turn, and Cleanup. Note that the phase names are case-sensitive!
SPECIFYING SETS FOR CARDS: When specifying card names, you can optionally add the set code by appending the pipe sign (|) and the three-letter set code to the card name you are spawning. That will allow you to spawn cards from specific sets. For example, HumanCardsInPlay=Mountain; Mountain will just spawn two Mountains on the human battlefield, using the latest possible set for them, while HumanCardsInPlay=Mountain|4ED; Mountain|4ED will spawn two Mountains from the 4th Edition on the human battlefield.
Here are two examples of valid state configuration files:
- Code: Select all
HumanLife=5
AILife=6
HumanCardsInPlay=Forest; Forest; Forest; Llanowar Elves
AICardsInPlay=Mountain; Mountain; Mountain
HumanCardsInHand=Island; Raging Goblin
AICardsInHand=Swamp; Swamp; Forest
- Code: Select all
HumanCardsInPlay=Plains|10E
AICardsInPlay=Mountain; Raging Goblin
AICardsInGraveyard=Force of Nature; Raging Goblin; Amulet of Kroog
ActivePlayer=Human
ActivePhase=Main1
I hope you'll find this command useful! Currently it's somewhat limited because it doesn't allow you to attach auras and equipments to cards and do other various things like that. Also, note that if the human and/or AI hands, graveyards, exiles, or libraries are replaced with cards through this mode, the cards that were in the respective hands, graveyards, exiles, or libraries before the Setup Game State was called will "disappear" instead of going to the graveyard, exile, or other places. Feel free to expand as necessary.

- Agetian
Last edited by Agetian on 06 Jun 2011, 04:22, edited 18 times in total.
- Agetian
- Programmer
- Posts: 3489
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: New Testing Facility: Setup Battlefield
by jeffwadsworth » 31 May 2011, 16:17
Thanks for this useful tool.
- jeffwadsworth
- Super Tester Elite
- Posts: 1172
- Joined: 20 Oct 2010, 04:47
- Location: USA
- Has thanked: 287 times
- Been thanked: 70 times
Re: New Testing Facility: Setup Battlefield
by Chris H. » 31 May 2011, 17:34
Looks like a good start Agetian. This should help to test changes made to the attacking and blocking code.
-
Chris H. - Forge Moderator
- Posts: 6320
- Joined: 04 Nov 2008, 12:11
- Location: Mac OS X Yosemite
- Has thanked: 644 times
- Been thanked: 643 times
Re: New Testing Facility: Setup Battlefield
by Agetian » 31 May 2011, 17:42
@ jeffwadsworth: It's my pleasure to be of help! Glad you like the idea! 
@ Chris H.: Thanks! That's what I'm hoping for, I'll expand on it as I start working with the AI code as well, and I hope you'll find it useful as well!
- Agetian

@ Chris H.: Thanks! That's what I'm hoping for, I'll expand on it as I start working with the AI code as well, and I hope you'll find it useful as well!

- Agetian
- Agetian
- Programmer
- Posts: 3489
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: New Testing Facility: Setup Battlefield
by Agetian » 01 Jun 2011, 04:47
UPDATED 01 JUN 2011:
- New, more intuitive dev_battle.txt format
- Graveyard modification support for both human and AI
- Agetian
- New, more intuitive dev_battle.txt format
- Graveyard modification support for both human and AI
- Agetian
- Agetian
- Programmer
- Posts: 3489
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: New Testing Facility: Setup Battlefield
by Sloth » 01 Jun 2011, 07:06
Good work Agetian! Thanks.
-
Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: New Testing Facility: Setup Battlefield
by Agetian » 01 Jun 2011, 07:18
Thanks for your support, I'm glad you like the idea!Sloth wrote:Good work Agetian! Thanks.

- Agetian
- Agetian
- Programmer
- Posts: 3489
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: New Testing Facility: Setup Battlefield
by Agetian » 01 Jun 2011, 11:39
UPDATE 2:
- The Setup Battlefield facility is no longer limited to the file name dev_battle.txt and allows to open a custom-named text file through a standard file open dialog.
- Agetian
- The Setup Battlefield facility is no longer limited to the file name dev_battle.txt and allows to open a custom-named text file through a standard file open dialog.
- Agetian
- Agetian
- Programmer
- Posts: 3489
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: New Testing Facility: Setup Battlefield
by friarsol » 01 Jun 2011, 12:04
Agetian, I would love to see this code moved out of the GuiDisplay*.java and into a Utility file. (GuiDisplayUtil.java might make the most sense) That way you aren't updating two bits of codes for each update. This is something we should probably do for any other game logic that exists in the UI code.
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: New Testing Facility: Setup Battlefield
by Agetian » 01 Jun 2011, 13:52
Awesome, I was thinking about where it could belong actually.friarsol wrote:Agetian, I would love to see this code moved out of the GuiDisplay*.java and into a Utility file. (GuiDisplayUtil.java might make the most sense) That way you aren't updating two bits of codes for each update. This is something we should probably do for any other game logic that exists in the UI code.


- Agetian
- Agetian
- Programmer
- Posts: 3489
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: New Testing Facility: Setup Battlefield
by Agetian » 04 Jun 2011, 10:50
UPDATE 3 JUN 2011: Reflected the modification by keybone in SVN r9251 in the original post (thanks to keybone for expanding the mode!)
- Agetian
- Agetian
- Agetian
- Programmer
- Posts: 3489
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: New Testing Facility: Setup Battlefield
by Hellfish » 04 Jun 2011, 10:57
No problem. I gotta say, this is immensely helpful, I am surprised we didn't have this already 

So now you're
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
-
Hellfish - Programmer
- Posts: 1297
- Joined: 07 Jun 2009, 10:41
- Location: South of the Pumphouse
- Has thanked: 110 times
- Been thanked: 169 times
Re: New Testing Facility: Setup Battlefield
by friarsol » 04 Jun 2011, 14:59
This is extraordinarily helpful, and should pave the way to Puzzle Mode: http://code.google.com/p/cardforge/issues/detail?id=79
Setup Battlefield might need a rename to "Setup Game State" as it grows and grows. I'm adding it into the Wiki where it'll be more conveniently editable. Feel free to Edit things if I misunderstood how it works, or anything I might not have mentioned that probably is worth repeating.
http://www.slightlymagic.net/wiki/Forge_DevMode
The main thing I'd like to see from this feature is:
Actual Parsing/No Required Order/Missing Parameters use Default (-1 or NONE as appropriate). It would be great if the Parsing would allow me to just have a file that says:
HumanBattlefield
AIHand
etc
(Edit: It looks like your second example uses names in this structure already, which is the way to go)
Keep up the good work, I'm sure in a month we'll all be wondering how we tested cards before this came along.
Setup Battlefield might need a rename to "Setup Game State" as it grows and grows. I'm adding it into the Wiki where it'll be more conveniently editable. Feel free to Edit things if I misunderstood how it works, or anything I might not have mentioned that probably is worth repeating.
http://www.slightlymagic.net/wiki/Forge_DevMode
The main thing I'd like to see from this feature is:
Actual Parsing/No Required Order/Missing Parameters use Default (-1 or NONE as appropriate). It would be great if the Parsing would allow me to just have a file that says:
- Code: Select all
HumanCardsInPlay=Gorilla Shaman; Mox Jet; Mox Ruby
END
HumanBattlefield
AIHand
etc
(Edit: It looks like your second example uses names in this structure already, which is the way to go)
Keep up the good work, I'm sure in a month we'll all be wondering how we tested cards before this came along.
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: New Testing Facility: Setup Battlefield
by Agetian » 04 Jun 2011, 15:23
Hehe thanks guys, glad you're finding it useful. I'll be working on the line name parsing (instead of the line order-based reading) next. 
- Agetian

- Agetian
- Agetian
- Programmer
- Posts: 3489
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: New Testing Facility: Setup Battlefield
by Agetian » 04 Jun 2011, 16:07
UPDATE 3 JUN 2011:
- Made the Setup Game State text file format not dependent on the line order,
now the format is more free and allows only certain lines to be present in the
file. The lines that are absent in the file will be set to the default value
that makes no changes.
- Renamed Setup Battlefield to Setup Game State as the function slowly outgrows
its initial usage.
- Fixed a bug in the graveyard and library processing in Setup Game State that
caused the cards added to human library and graveyard be registered as AI cards
that caused a number of weird side effects.
- Made the way Setup Game State modifies the graveyard consistent with that of
the hand and the library (now the graveyard gets replaced with the cards
specified in the game state setup file).
- Added the ActivePlayer option that allows to define the current player which
must take priority when the game state is set.
- Modified the first post of this thread to reflect these changes.
Enjoy!
- Agetian
- Made the Setup Game State text file format not dependent on the line order,
now the format is more free and allows only certain lines to be present in the
file. The lines that are absent in the file will be set to the default value
that makes no changes.
- Renamed Setup Battlefield to Setup Game State as the function slowly outgrows
its initial usage.
- Fixed a bug in the graveyard and library processing in Setup Game State that
caused the cards added to human library and graveyard be registered as AI cards
that caused a number of weird side effects.
- Made the way Setup Game State modifies the graveyard consistent with that of
the hand and the library (now the graveyard gets replaced with the cards
specified in the game state setup file).
- Added the ActivePlayer option that allows to define the current player which
must take priority when the game state is set.
- Modified the first post of this thread to reflect these changes.
Enjoy!
- Agetian
- Agetian
- Programmer
- Posts: 3489
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
26 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 47 guests