Who starts the game?

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:
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.
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
- 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()
- Code: Select all
seeWhoPlaysFirst(); // Beached
for(int i = 0; i < 7; i++) {
this.drawCard(Constant.Player.Computer);
this.drawCard(Constant.Player.Human);
}
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.