Page 1 of 3

Who starts the game?

PostPosted: 13 Jun 2010, 10:29
by Beached As
Having the player always starting the game has bugged me for a while. I'm not sure what the official rules are but when my friends played magic we always used to "cut" the deck and see who got the card with the highest converted mana cost. That player would start first. Below is the code which makes that happen but i wasn't sure if i should commit it yet.

Replace the choosewhogoesfirst command in GameAction.java:
Code: Select all
    // Beached
    //decides who goes first when starting another game, used by newGame()
    public void seeWhoPlaysFirst() {

       CardList HLibrary = new CardList(AllZone.getZone(Constant.Zone.Library, Constant.Player.Human).getCards());
        HLibrary = HLibrary.filter(new CardListFilter() {
            public boolean addCard(Card c) {
                return !c.isLand();
            }
        });
       CardList CLibrary = new CardList(AllZone.getZone(Constant.Zone.Library, Constant.Player.Computer).getCards());
        CLibrary = CLibrary.filter(new CardListFilter() {
            public boolean addCard(Card c) {
                return !c.isLand();
            }
        });
        Card HumanCut = null;
        Card ComputerCut = null;
        if(HLibrary.size() > 0) HumanCut = HLibrary.get(MyRandom.random.nextInt(HLibrary.size()));
        else {
           AllZone.Phase.setPhase(Constant.Phase.Untap, Constant.Player.Computer);
           JOptionPane.showMessageDialog(null, "Human has no cards with a converted mana cost in library." + "\r\n" + "Computer Starts", "", JOptionPane.INFORMATION_MESSAGE);
           return;
        }
        if(CLibrary.size() > 0) ComputerCut = CLibrary.get(MyRandom.random.nextInt(CLibrary.size()));
        else {
           JOptionPane.showMessageDialog(null, "Computer has no cards with a converted mana cost in library." + "\r\n" + "Human Starts", "", JOptionPane.INFORMATION_MESSAGE);
           return;
        }
       
        StringBuilder sb = new StringBuilder();
        sb.append("Human cut his / her to deck to : " + HumanCut.getName() + " (" + HumanCut.getManaCost() + ")" + "\r\n");
        sb.append("Computer cut his / her to deck to : " + ComputerCut.getName()  + " (" + ComputerCut.getManaCost() + ")" + "\r\n");
        if(CardUtil.getConvertedManaCost(ComputerCut.getManaCost()) > CardUtil.getConvertedManaCost(HumanCut.getManaCost()))
        {
           AllZone.Phase.setPhase(Constant.Phase.Untap, Constant.Player.Computer);
           JOptionPane.showMessageDialog(null, sb + "\r\n" + "Computer Starts", "", JOptionPane.INFORMATION_MESSAGE);
        } else JOptionPane.showMessageDialog(null, sb + "\r\n" + "Human Starts", "", JOptionPane.INFORMATION_MESSAGE);
           
    }//seeWhoPlaysFirst()
    // Beached
The AI can't play spells without land so i've changed the stacking of AI lands so it happens one card before.
Code: Select all
    private Card[] smoothComputerManaCurve(Card[] in) {
        CardList library = new CardList(in);
        library.shuffle();
       
        //remove all land, keep non-basicland in there, shuffled
        CardList land = library.getType("Land");
        for(int i = 0; i < land.size(); i++)
            if(land.get(i).isLand()) library.remove(land.get(i));
       
        //non-basic lands are removed, because the computer doesn't seem to
        //effectively use them very well
        land = threadLand(land);
       
        try {
            //mana weave, total of 7 land
           // Beached - The Following have all been reduced by 1.
            library.add(6, land.get(0));
            library.add(7, land.get(1));
            library.add(8, land.get(2));
            library.add(9, land.get(3));
            library.add(10, land.get(4));
           
            library.add(12, land.get(5));
            library.add(15, land.get(6));
        } catch(IndexOutOfBoundsException e) {
            System.err.println("Error: cannot smooth mana curve, not enough land");
            return in;
        }
       
        //add the rest of land to the end of the deck
        for(int i = 0; i < land.size(); i++)
            if(!library.contains(land.get(i))) library.add(land.get(i));
       

        //check
        for(int i = 0; i < library.size(); i++)
            System.out.println(library.get(i));
       

        return library.toArray();
    }//smoothComputerManaCurve()
You will also need to call it in the newgame command in GameAction.java also, just before the players draw cards:
Code: Select all
        seeWhoPlaysFirst(); // Beached
        for(int i = 0; i < 7; i++) {
            this.drawCard(Constant.Player.Computer);
            this.drawCard(Constant.Player.Human);
        }
Should we implement this?

EDIT: I've updated the code to solve bugs when there was no card to cut to. The AI also plays cards on the first turn as well.

Re: Who starts the game?

PostPosted: 13 Jun 2010, 11:52
by Hellfish
IIRC, there was some AI reason why the human player always goes first, but for all I know that could be resolved.

Re: Who starts the game?

PostPosted: 13 Jun 2010, 13:36
by Chris H.
Beached As wrote:Having the player always starting the game has bugged me for a while. I'm not sure what the official rules are but when my friends played magic we always used to "cut" the deck and see who got the card with the highest converted mana cost. That player would start first. Below is the code which makes that happen but i wasn't sure if i should commit it yet.
`
Should we implement this?
`
I seem to remember that there might be some code which assumes that the human goes first. It might be best to wait until Rares, Dennis and Rob have had a chance to think about this. :)

Re: Who starts the game?

PostPosted: 13 Jun 2010, 15:58
by Rob Cashwalker
I thought it was a matter of the turn structure is hard-coded as human, computer, human, computer, etc. HOWEVER, there is an "index" pointing to the current point in that turn structure. I don't know why you couldn't jump into the middle... afterall, we have Time Walk figured out....

Re: Who starts the game?

PostPosted: 13 Jun 2010, 17:21
by Beached As
Rob Cashwalker wrote:I thought it was a matter of the turn structure is hard-coded as human, computer, human, computer, etc. HOWEVER, there is an "index" pointing to the current point in that turn structure. I don't know why you couldn't jump into the middle... afterall, we have Time Walk figured out....
Yep thats what the code does, it jumps straight to the computers untap step (i would do main phase1 but the computer doesn't do anything if you jump the phase there) if the computer wins the deck cut. Else it just does what it did previously

Re: Who starts the game?

PostPosted: 13 Jun 2010, 20:46
by DennisBergkamp
I think this should be fine... I know rares said there was some problems with cards like Timewalk, attacking on turn one with Raging Goblin, and also the AI starting on turn one. Timewalk works fine, and also Raging Goblin attacks fine on turn one... I don't see any problems with the AI going first, as long as the turn counter starts at 0.

Re: Who starts the game?

PostPosted: 13 Jun 2010, 21:13
by Beached As
I did a quick test on the turns, everything appears to be normal (i.e. the first turn is one) and i've committed the cutting code. If there are bugs then just delete the entry in the newGame command and reset the AI Stacking code.

Re: Who starts the game?

PostPosted: 13 Jun 2010, 21:23
by DennisBergkamp
Very nice, good job :) I'm sure this is a change a lot of people have been waiting for...

Re: Who starts the game?

PostPosted: 13 Jun 2010, 21:38
by Chris H.
Beached As wrote:I did a quick test on the turns, everything appears to be normal (i.e. the first turn is one) and i've committed the cutting code. If there are bugs then just delete the entry in the newGame command and reset the AI Stacking code.
`
If there are any bugs hidden one of our faithful play testers will notice. :wink:

Re: Who starts the game?

PostPosted: 13 Jun 2010, 21:49
by slowe
This is a nice update I appreciate, but is there any reason not to determine who goes first in a truly random fashion? Cutting is all right when players have nothing else, but a coin flip would be easier and technically fairer.
My two cents. :)

Re: Who starts the game?

PostPosted: 13 Jun 2010, 23:11
by Chris H.
slowe wrote:This is a nice update I appreciate, but is there any reason not to determine who goes first in a truly random fashion? Cutting is all right when players have nothing else, but a coin flip would be easier and technically fairer.
My two cents. :)
`
I just tested this new addition and I like the way it tells us which card we both cut to and it's mana cost. Gives us a slight peek at the deck that we are facing. 8)

Re: Who starts the game?

PostPosted: 14 Jun 2010, 03:13
by Rob Cashwalker
At FNM, we always use a die roll. Most often I see two D6 or D10, some folks use a true D20 (not the Spin-Down life counter, because it's not "random enough").

There are a number of cards that are so iconic of specific decks, that high-level players could make a damn good guess of the rest of the deck based on that one card. (Arcbound Ravager, for example)

So Forge isn't a tournament.... Ahh, but think of how dire the situation is when playing fantasy quests, where every small advantage you can get is necessary. Some of us might know the card-counts of the AI deck so well, that if you know that one of the 1x or 2x cards is definitely at the bottom of the deck (after a physical cut, the cut-to card becomes the bottom card, this should be implemented here if it isn't already) then you may consciously or unconsciously change your game plan to accommodate.

Re: Who starts the game?

PostPosted: 14 Jun 2010, 06:43
by Marek14
The rules state that the turn is to be decided randomly. No peeking allowed :)

Re: Who starts the game?

PostPosted: 14 Jun 2010, 08:49
by Beached As
Rob Cashwalker wrote:At FNM, we always use a die roll. Most often I see two D6 or D10, some folks use a true D20 (not the Spin-Down life counter, because it's not "random enough").

There are a number of cards that are so iconic of specific decks, that high-level players could make a damn good guess of the rest of the deck based on that one card. (Arcbound Ravager, for example)

So Forge isn't a tournament.... Ahh, but think of how dire the situation is when playing fantasy quests, where every small advantage you can get is necessary. Some of us might know the card-counts of the AI deck so well, that if you know that one of the 1x or 2x cards is definitely at the bottom of the deck (after a physical cut, the cut-to card becomes the bottom card, this should be implemented here if it isn't already) then you may consciously or unconsciously change your game plan to accommodate.
Just made it so the cut to card is placed on the bottom.

Marek14 wrote:The rules state that the turn is to be decided randomly. No peeking allowed :)
I thought cutting the deck to decides who goes first has a more magic feel to it as opposed to using hard statistics. But if people agree that using an artificial coin toss is better then i would be more than happy to change it.

Re: Who starts the game?

PostPosted: 14 Jun 2010, 12:15
by slowe
Beached As wrote:
Marek14 wrote:The rules state that the turn is to be decided randomly. No peeking allowed :)
I thought cutting the deck to decides who goes first has a more magic feel to it as opposed to using hard statistics. But if people agree that using an artificial coin toss is better then i would be more than happy to change it.
Having the option for either is nice. Even just making the cut optional works, as we can still essentially go second by passing through the first turn.

Putting the cut-to card on the bottom is strange to me - I always shuffled after doing so to avoid giving additional information, but I can see how it'd be interesting in quest mode.

Regardless of how this update is implemented, I'm pretty happy. 8)