// number of opponents public double MyComputeProb(int[] myCards, int[] sharedCards, int NsharedCards, int nplayers, ProbMode mode) { if (myCards.Length < 2) throw new Exception("Necessario pelo menos duas cartas"); Array.Copy(sharedCards, 0, myCards, 2, NsharedCards); int NmyCards= 2+NsharedCards; int p, wins = 0, losses = 0, draws = 0; int myMiss = TAKEN_CARDS - NmyCards; int othersMiss = TAKEN_CARDS - NsharedCards; int[] bufCards = new int[TAKEN_CARDS ]; int[] baseDeck = new int[DECK_CARDS+1]; int[] gameDeck = new int[DECK_CARDS+1]; int permLen = selectDeck(baseDeck, myCards); // IO.Write("AVAILABLE CARDS " + permLen + ":\n" + IO.stringIds(baseDeck, 1, permLen+1) + "\n"); // IO.Write(IO.stringCards(myCards) + ": INITIAL\t\t\tX\t" + IO.stringCards(sharedCards) + ": INITIAL\n"); if (mode == ProbMode.Enumerate) Combinatorics.initCombination(); for (int i = 0; i < TOTAL_SYMS; i++) { bool draw = false; if (mode == ProbMode.Enumerate) Combinatorics.nextCombination(gameDeck); else Combinatorics.selectPermRandom(gameDeck, baseDeck, othersMiss, permLen); const bool PHANDS = false; // IO.Write(IO.stringIds(gameDeck, 0, permLen) + "\n"); // take the needed cards from the deck and distribute it along the players Array.Copy(myCards , 0, bufCards, 0, NmyCards); Array.Copy(gameDeck, 0, bufCards, NmyCards, myMiss); // check Hand. destructive int myHandVal = PokerHand.HandValue(bufCards); if (PHANDS) IO.Write(IO.stringCards(bufCards) + ": " + myHandVal + " " + PokerHand.getHand(myHandVal) + "\tX\t"); for (p = 0; p < nplayers; p++) { Array.Copy(sharedCards, 0, bufCards, 0, NsharedCards); Array.Copy(gameDeck, 0, bufCards, NsharedCards, othersMiss); // check hand int otherHandVal = PokerHand.HandValue(bufCards); if (PHANDS) IO.Write(IO.stringCards(bufCards) + ": " + otherHandVal + " " + PokerHand.getHand(otherHandVal) + "\t"); if (myHandVal == otherHandVal) draw = true; if (myHandVal < otherHandVal) break; } if (p < nplayers) losses++; else if (!draw) wins++; else draws++; if (PHANDS) { if (p < nplayers) IO.Write(" => LOSE\n\n"); else if (!draw) IO.Write(" => WIN\n\n"); else IO.Write(" => DRAW\n\n"); } } return (double) wins / (double) (losses + wins); }
// number of opponents public double MyComputeProb(int[] myCards, int[] sharedCards, int NsharedCards, int nplayers, ProbMode mode) { if (myCards.Length < 2) { throw new Exception("Necessario pelo menos duas cartas"); } Array.Copy(sharedCards, 0, myCards, 2, NsharedCards); int NmyCards = 2 + NsharedCards; int p, wins = 0, losses = 0, draws = 0; int myMiss = TAKEN_CARDS - NmyCards; int othersMiss = TAKEN_CARDS - NsharedCards; int[] bufCards = new int[TAKEN_CARDS]; int[] baseDeck = new int[DECK_CARDS + 1]; int[] gameDeck = new int[DECK_CARDS + 1]; int permLen = selectDeck(baseDeck, myCards); // IO.Write("AVAILABLE CARDS " + permLen + ":\n" + IO.stringIds(baseDeck, 1, permLen+1) + "\n"); // IO.Write(IO.stringCards(myCards) + ": INITIAL\t\t\tX\t" + IO.stringCards(sharedCards) + ": INITIAL\n"); if (mode == ProbMode.Enumerate) { Combinatorics.initCombination(); } for (int i = 0; i < TOTAL_SYMS; i++) { bool draw = false; if (mode == ProbMode.Enumerate) { Combinatorics.nextCombination(gameDeck); } else { Combinatorics.selectPermRandom(gameDeck, baseDeck, othersMiss, permLen); } const bool PHANDS = false; // IO.Write(IO.stringIds(gameDeck, 0, permLen) + "\n"); // take the needed cards from the deck and distribute it along the players Array.Copy(myCards, 0, bufCards, 0, NmyCards); Array.Copy(gameDeck, 0, bufCards, NmyCards, myMiss); // check Hand. destructive int myHandVal = PokerHand.HandValue(bufCards); if (PHANDS) { IO.Write(IO.stringCards(bufCards) + ": " + myHandVal + " " + PokerHand.getHand(myHandVal) + "\tX\t"); } for (p = 0; p < nplayers; p++) { Array.Copy(sharedCards, 0, bufCards, 0, NsharedCards); Array.Copy(gameDeck, 0, bufCards, NsharedCards, othersMiss); // check hand int otherHandVal = PokerHand.HandValue(bufCards); if (PHANDS) { IO.Write(IO.stringCards(bufCards) + ": " + otherHandVal + " " + PokerHand.getHand(otherHandVal) + "\t"); } if (myHandVal == otherHandVal) { draw = true; } if (myHandVal < otherHandVal) { break; } } if (p < nplayers) { losses++; } else if (!draw) { wins++; } else { draws++; } if (PHANDS) { if (p < nplayers) { IO.Write(" => LOSE\n\n"); } else if (!draw) { IO.Write(" => WIN\n\n"); } else { IO.Write(" => DRAW\n\n"); } } } return((double)wins / (double)(losses + wins)); }