// 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()); }
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); }
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); }
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); }
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(); }
private static void TestUnit_10_PlayTheGame() { MauMaster.PrintVersion(); String[] names = MauMaster.ReadPlayers(); MauMaster mm = new MauMaster(names); mm.Init(1); mm.Play(); }
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); } }
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(); }
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); } }
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"); }
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); } }