private Card GetCardToPlay(PlayerTurnContext context) { foreach (var card in this.Cards) { if (!this.CardsNotInDeck.Contains(card)) { this.CardsNotInDeck.Add(card); } } if (context.FirstPlayedCard != null) { this.CardsNotInDeck.Add(context.FirstPlayedCard); } if (context.SecondPlayedCard != null) { this.CardsNotInDeck.Add(context.SecondPlayedCard); } var validCards = this.GetValidCards(context); var hashedHand = this.GetHash(this.Cards, this.CardsNotInDeck); if (this.MonteCarlo.ContainsKey(hashedHand)) { for (int i = 0; i < validCards.Count; i++) { var cardHash = this.GetTwoNumberHash((uint)validCards[i].Type, (uint)validCards[i].Suit); if (validCards[i] == this.MonteCarlo[hashedHand]) { return(validCards[i]); } } } float bestActionProbability = float.MinValue; int bestActionIndex = 0; var currentContext = GetCurrentContext(context); var helper = new SantiagoHelper(this.Cards); for (int i = 0; i < validCards.Count; i++) { var probability = helper.GetProbability(currentContext, validCards[i], this.CardsNotInDeck, this.Cards); if (probability >= bestActionProbability) { bestActionProbability = probability; bestActionIndex = i; } } this.MonteCarlo[hashedHand] = validCards[bestActionIndex]; return(validCards[bestActionIndex]); }
private Card GetCardToPlay(PlayerTurnContext context) { foreach (var card in this.Cards) { if (!this.CardsNotInDeck.Contains(card)) { this.CardsNotInDeck.Add(card); } } if (context.FirstPlayedCard != null) { this.CardsNotInDeck.Add(context.FirstPlayedCard); } if (context.SecondPlayedCard != null) { this.CardsNotInDeck.Add(context.SecondPlayedCard); } var validCards = this.GetValidCards(context); var hashedHand = this.GetHash(this.Cards, this.CardsNotInDeck); if (this.MonteCarlo.ContainsKey(hashedHand)) { for (int i = 0; i < validCards.Count; i++) { var cardHash = this.GetTwoNumberHash((uint)validCards[i].Type, (uint)validCards[i].Suit); if (validCards[i] == this.MonteCarlo[hashedHand]) { return validCards[i]; } } } float bestActionProbability = float.MinValue; int bestActionIndex = 0; var currentContext = GetCurrentContext(context); var helper = new SantiagoHelper(this.Cards); for (int i = 0; i < validCards.Count; i++) { var probability = helper.GetProbability(currentContext, validCards[i], this.CardsNotInDeck, this.Cards); if (probability >= bestActionProbability) { bestActionProbability = probability; bestActionIndex = i; } } this.MonteCarlo[hashedHand] = validCards[bestActionIndex]; return validCards[bestActionIndex]; }