Page 1 of 2

New Testing Facility: Setup Battlefield

PostPosted: 31 May 2011, 14:42
by Agetian
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:

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
Sets human's life to 5, AI life to 6, puts 3 Forests and Llanowar Elves on the human battlefield, puts 3 Mountains on the computer battlefield, replaces the human hand with Island and Raging Goblin, replaces the AI hand with 2 Swamps and a Forest. Does not add any cards to either graveyard and does not replace either library.

Code: Select all
HumanCardsInPlay=Plains|10E
AICardsInPlay=Mountain; Raging Goblin
AICardsInGraveyard=Force of Nature; Raging Goblin; Amulet of Kroog
ActivePlayer=Human
ActivePhase=Main1
Does not change the human's life and the AI life, puts a Plains from the 10th Edition on the human battlefield, puts a Mountain and a Raging Goblin on the opponent's battlefield, does not replace the human and the AI hands and leaves them intact, and adds Force of Nature, Raging Goblin, and Amulet of Kroog to the computer's graveyard. Does not replace either library. Sets the current player to Human and the current phase to Main 1.

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

Re: New Testing Facility: Setup Battlefield

PostPosted: 31 May 2011, 16:17
by jeffwadsworth
Thanks for this useful tool.

Re: New Testing Facility: Setup Battlefield

PostPosted: 31 May 2011, 17:34
by Chris H.
Looks like a good start Agetian. This should help to test changes made to the attacking and blocking code.

Re: New Testing Facility: Setup Battlefield

PostPosted: 31 May 2011, 17:42
by Agetian
@ 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

Re: New Testing Facility: Setup Battlefield

PostPosted: 01 Jun 2011, 04:47
by Agetian
UPDATED 01 JUN 2011:
- New, more intuitive dev_battle.txt format
- Graveyard modification support for both human and AI

- Agetian

Re: New Testing Facility: Setup Battlefield

PostPosted: 01 Jun 2011, 07:06
by Sloth
Good work Agetian! Thanks.

Re: New Testing Facility: Setup Battlefield

PostPosted: 01 Jun 2011, 07:18
by Agetian
Sloth wrote:Good work Agetian! Thanks.
Thanks for your support, I'm glad you like the idea! :)

- Agetian

Re: New Testing Facility: Setup Battlefield

PostPosted: 01 Jun 2011, 11:39
by Agetian
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

Re: New Testing Facility: Setup Battlefield

PostPosted: 01 Jun 2011, 12:04
by friarsol
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.

Re: New Testing Facility: Setup Battlefield

PostPosted: 01 Jun 2011, 13:52
by Agetian
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.
Awesome, I was thinking about where it could belong actually. :) I moved it to GuiDisplayUtil.java as suggested, hope this will allow us to keep the code cleaner. Thanks! :)

- Agetian

Re: New Testing Facility: Setup Battlefield

PostPosted: 04 Jun 2011, 10:50
by Agetian
UPDATE 3 JUN 2011: Reflected the modification by keybone in SVN r9251 in the original post (thanks to keybone for expanding the mode!)

- Agetian

Re: New Testing Facility: Setup Battlefield

PostPosted: 04 Jun 2011, 10:57
by Hellfish
No problem. I gotta say, this is immensely helpful, I am surprised we didn't have this already :lol:

Re: New Testing Facility: Setup Battlefield

PostPosted: 04 Jun 2011, 14:59
by friarsol
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:

Code: Select all
HumanCardsInPlay=Gorilla Shaman; Mox Jet; Mox Ruby
END
On the Same lines, if we would move to a Name Parser (instead of a Line # parser), I'd like to simplify the names to match what they are in the codebase:
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.

Re: New Testing Facility: Setup Battlefield

PostPosted: 04 Jun 2011, 15:23
by Agetian
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

Re: New Testing Facility: Setup Battlefield

PostPosted: 04 Jun 2011, 16:07
by Agetian
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