[CODE] Updated Mulligan
Posted: Mon Nov 26, 2012 5:20 am
I tweaked the mulligan code developed by almosthumane to accommodate some issues I was having with the process. You can now take a mulligan during either turn 1 first main or turn 2 upkeep. It also uses the Duel of the Planeswalkers practice of first mulligan free.
GameObserver.cpp
GameStateDuel.cpp
Player.cpp
Player.h
Here are the files I edited: http://www.mediafire.com/?o5i3q3g6vj1dr26
I know that coding classes is better practice than global extern variables but I was going more for proof of concept than efficiency, having not coded for a decade. I've played through multiple games in a row taking various degrees of mulligans in each game and I haven't had an issue yet.
Ideally I'd like to change the mulligan process to a prompt before turn 1 regardless of who goes first, but my coding skills are rusty and I haven't figured out what functions you use for popups yet. I'll give the code another look tomorrow but I'm glad for what I accomplished today.
GameObserver.cpp
Code: Select all
#include "Player.h"
Code: Select all
#include "Player.h"
ResetMullPen(); //Inserted right after game->startGame
if ((cardsinhand != 0) && ((game->turn < 2 && game->currentGamePhase == MTG_PHASE_FIRSTMAIN) || (game->turn < 2 && game->currentGamePhase == MTG_PHASE_UPKEEP)) && game->currentPlayer->game->inPlay->nb_cards == 0 && game->currentPlayer->game->graveyard->nb_cards == 0 && game->currentPlayer->game->exile->nb_cards == 0 && game->currentlyActing() == (Player*)game->currentPlayer) //Modified 1st Play Check
Code: Select all
int MullPen = 0;
void ResetMullPen()
{
for (int n = 7; n != 7 - MullPen; MullPen--); //Simple loop to bring MullPen back to 0
}
Changes to takeMulligan after Shuffle
for (int i = 0; i < (7 - MullPen); i++)
game->drawFromLibrary();
//Draw hand with less cards according to number of mulligans //almhum
MullPen++; //Increase Mulligan Penalty counter
Code: Select all
extern int MullPen;
void ResetMullPen();
I know that coding classes is better practice than global extern variables but I was going more for proof of concept than efficiency, having not coded for a decade. I've played through multiple games in a row taking various degrees of mulligans in each game and I haven't had an issue yet.
Ideally I'd like to change the mulligan process to a prompt before turn 1 regardless of who goes first, but my coding skills are rusty and I haven't figured out what functions you use for popups yet. I'll give the code another look tomorrow but I'm glad for what I accomplished today.