It is currently 04 Sep 2025, 23:29
   
Text Size

Who starts the game?

Post MTG Forge Related Programming Questions Here

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

Who starts the game?

Postby Beached As » 13 Jun 2010, 10:29

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.
Last edited by Beached As on 13 Jun 2010, 13:50, edited 1 time in total.
Beached As
Programmer
 
Posts: 110
Joined: 23 Feb 2010, 07:48
Has thanked: 0 time
Been thanked: 0 time

Re: Who starts the game?

Postby Hellfish » 13 Jun 2010, 11:52

IIRC, there was some AI reason why the human player always goes first, but for all I know that could be resolved.
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
User avatar
Hellfish
Programmer
 
Posts: 1297
Joined: 07 Jun 2009, 10:41
Location: South of the Pumphouse
Has thanked: 110 times
Been thanked: 169 times

Re: Who starts the game?

Postby Chris H. » 13 Jun 2010, 13:36

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. :)
User avatar
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: Who starts the game?

Postby Rob Cashwalker » 13 Jun 2010, 15:58

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....
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

Re: Who starts the game?

Postby Beached As » 13 Jun 2010, 17:21

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
Beached As
Programmer
 
Posts: 110
Joined: 23 Feb 2010, 07:48
Has thanked: 0 time
Been thanked: 0 time

Re: Who starts the game?

Postby DennisBergkamp » 13 Jun 2010, 20:46

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.
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Who starts the game?

Postby Beached As » 13 Jun 2010, 21:13

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.
Beached As
Programmer
 
Posts: 110
Joined: 23 Feb 2010, 07:48
Has thanked: 0 time
Been thanked: 0 time

Re: Who starts the game?

Postby DennisBergkamp » 13 Jun 2010, 21:23

Very nice, good job :) I'm sure this is a change a lot of people have been waiting for...
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Who starts the game?

Postby Chris H. » 13 Jun 2010, 21:38

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:
User avatar
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: Who starts the game?

Postby slowe » 13 Jun 2010, 21:49

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. :)
slowe
 
Posts: 127
Joined: 05 Jan 2010, 14:04
Has thanked: 6 times
Been thanked: 10 times

Re: Who starts the game?

Postby Chris H. » 13 Jun 2010, 23:11

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)
User avatar
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: Who starts the game?

Postby Rob Cashwalker » 14 Jun 2010, 03:13

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.
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

Re: Who starts the game?

Postby Marek14 » 14 Jun 2010, 06:43

The rules state that the turn is to be decided randomly. No peeking allowed :)
Marek14
Tester
 
Posts: 2773
Joined: 07 Jun 2008, 07:54
Has thanked: 0 time
Been thanked: 303 times

Re: Who starts the game?

Postby Beached As » 14 Jun 2010, 08:49

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.
Beached As
Programmer
 
Posts: 110
Joined: 23 Feb 2010, 07:48
Has thanked: 0 time
Been thanked: 0 time

Re: Who starts the game?

Postby slowe » 14 Jun 2010, 12:15

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)
slowe
 
Posts: 127
Joined: 05 Jan 2010, 14:04
Has thanked: 6 times
Been thanked: 10 times

Next

Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 27 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 27 users online :: 0 registered, 0 hidden and 27 guests (based on users active over the past 10 minutes)
Most users ever online was 7303 on 15 Jul 2025, 20:46

Users browsing this forum: No registered users and 27 guests

Login Form