Ejemplo n.º 1
0
    // private helper methods
    private Card DrawCard()
    {
        // turn over playing deck to serve as new drawing deck
        if (this.drawing.Size == 0)
        {
            MauMaster.Log(">   turn over playing deck to serve as new drawing deck");

            // save topmost card of playing stack
            Card topmostPlayingCard = this.playing.Pop();

            // copy rest of playing deck to drawing deck
            while (!this.playing.IsEmpty)
            {
                Card tmp = this.playing.Pop();
                this.drawing.Push(tmp);
            }

            // shuffle drawing stack
            this.drawing.Shuffle();

            // restore topmost card of playing stack
            this.playing.Push(topmostPlayingCard);
        }

        return(this.drawing.Pop());
    }
Ejemplo n.º 2
0
    public bool PlayCard(CardColor requestedColor)
    {
        for (int i = 0; i < this.hand.Size; i++)
        {
            Card card = this.hand[i];

            // 'Bube' upon 'Bube' not allowed ("Bube auf Bube" stinkt)
            if (card.Picture == CardPicture.Bube)
            {
                continue;
            }

            if (card.Color == requestedColor)
            {
                this.hand.Remove(i);
                this.playing.Push(card);
                String s = String.Format(">   {0} plays {1}", this.name, card);
                MauMaster.Log(s);
                this.PrintMauMauIf();
                return(true);
            }
        }

        return(false);
    }
Ejemplo n.º 3
0
    public bool PlayCard(CardColor requestedColor, CardPicture requestedPicture)
    {
        for (int i = 0; i < this.hand.Size; i++)
        {
            Card card = this.hand[i];
            if (card.Color == requestedColor || card.Picture == requestedPicture)
            {
                this.hand.Remove(i);
                this.playing.Push(card);
                String s = String.Format(">   {0} plays {1}", this.name, card);
                MauMaster.Log(s);
                this.PrintMauMauIf();
                return(true);
            }
        }

        // 'Bube' maybe played upon every card!
        for (int i = 0; i < this.hand.Size; i++)
        {
            Card card = this.hand[i];
            if (card.Picture == CardPicture.Bube)
            {
                this.hand.Remove(i);
                this.playing.Push(card);
                String s = String.Format(">   {0} plays {1}", this.name, card);
                MauMaster.Log(s);
                this.PrintMauMauIf();
                return(true);
            }
        }

        return(false);
    }
Ejemplo n.º 4
0
    private static void TestUnit_12_StressTestMauMaster()
    {
        MauMaster.PrintVersion();
        MauMaster mm = new MauMaster(new String[] { "Hans", "Sepp", "Ulli" });

        int minRounds      = Int32.MaxValue;
        int minRoundsIndex = -1;
        int maxRounds      = -1;
        int maxRoundsIndex = -1;

        for (int i = 1; i < 1000; i++)
        {
            mm.Init(i);
            mm.Play();

            if (mm.Rounds < minRounds)
            {
                minRounds      = mm.Rounds;
                minRoundsIndex = i;
            }

            if (mm.Rounds > maxRounds)
            {
                maxRounds      = mm.Rounds;
                maxRoundsIndex = i;
            }

            Console.WriteLine("Game at {0,5}: {1}", i, mm.Rounds);
        }

        Console.WriteLine("Minumum number of rounds: {0} [Index {1}]", minRounds, minRoundsIndex);
        Console.WriteLine("Maximum number of rounds: {0} [Index {1}]", maxRounds, maxRoundsIndex);
    }
Ejemplo n.º 5
0
    private static void TestUnit_11_SingleTestMauMaster()
    {
        MauMaster.PrintVersion();
        MauMaster mm         = new MauMaster(new String[] { "Hans", "Sepp", "Ulli" });
        int       randomSeed = 188;

        mm.Init(randomSeed);
        mm.Play();
    }
Ejemplo n.º 6
0
    private static void TestUnit_10_PlayTheGame()
    {
        MauMaster.PrintVersion();
        String[]  names = MauMaster.ReadPlayers();
        MauMaster mm    = new MauMaster(names);

        mm.Init(1);
        mm.Play();
    }
Ejemplo n.º 7
0
    public void DrawCards(int number)
    {
        for (int i = 0; i < number; i++)
        {
            Card card = this.DrawCard();
            this.hand.Add(card);

            String msg = String.Format(">   {0} draws {1} from drawing deck!", this.name, card);
            MauMaster.Log(msg);
        }
    }
Ejemplo n.º 8
0
    public void PlayArbitraryCard()
    {
        int  lastIndex = this.hand.Size - 1;
        Card card      = this.hand[lastIndex];

        this.hand.Remove(lastIndex);
        this.playing.Push(card);
        String s = String.Format(">   {0} plays {1}", this.name, card);

        MauMaster.Log(s);
        this.PrintMauMauIf();
    }
Ejemplo n.º 9
0
 private void PrintMauMauIf()
 {
     if (this.hand.Size == 1)
     {
         String s = String.Format("==> {0} says 'Mau'", this.name);
         MauMaster.Log(s);
     }
     else if (this.hand.Size == 0)
     {
         String s = String.Format("##> {0} says 'MAU MAU !!!'", this.name);
         MauMaster.Log(s);
     }
 }
Ejemplo n.º 10
0
    private void PlaySeven()
    {
        for (int i = 0; i < this.hand.Size; i++)
        {
            Card card = this.hand[i];
            if (card.Picture == CardPicture.Sieben)
            {
                this.hand.Remove(i);
                this.playing.Push(card);
                String s = String.Format(">   {0} drops {1} onto deck!", this.name, card);
                MauMaster.Log(s);
                this.PrintMauMauIf();
                return;
            }
        }

        throw new InvalidOperationException("ERROR (PlaySeven): Should never be reached");
    }
Ejemplo n.º 11
0
    public bool CounterSeven(int numCardsToDraw)
    {
        if (this.HasSeven())
        {
            // players holds '7' in his hand
            String msg = String.Format(">   {0} counters '7' with another '7' !", this.name);
            MauMaster.Log(msg);

            this.PlaySeven();
            return(true);
        }
        else
        {
            // players must draw cards
            String msg = String.Format(">   {0} cannot respond to '7', draws {1} card(s)!",
                                       this.name, numCardsToDraw);
            MauMaster.Log(msg);

            this.DrawCards(numCardsToDraw);
            return(false);
        }
    }