public int PlayCard(int cardChoice) { if (cardChoice < 0) { return(-1); } if (CurrentHand.Any(x => x == cardChoice)) { int res = CurrentHand.First(x => x == cardChoice); if (res <= PlayerStatistics.ActualMana) { CurrentHand.Remove(res); PlayerStatistics.ActualMana -= res; return(res); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Zbyt mało many!"); Console.ResetColor(); return(-2); } } return(-1); }
void HandleFrameEvent(object sender, LMWidgets.EventArg <FrameData> e) { HandModel oldFound = null; // attempt to reconnect to the last good id HandModel[] handList = ReturnPhysicsHand ? e.CurrentValue.PhysicsModels : e.CurrentValue.HandModels; foreach (HandModel handInScene in handList) { if (handInScene.GetLeapHand().Id == lastHandId) { oldFound = handInScene; } } // on failure attempt to find a new good left hand if (!oldFound) { CurrentHand = FirstRightHand(handList); if (CurrentHand) { lastHandId = CurrentHand.GetLeapHand().Id; } } else { CurrentHand = oldFound; } }
// TODO: check if we should apply this function for blinds posting private void PutChipsToPot(Player player, int amount) { Pot potToPutChips = null; foreach (Pot pot in CurrentHand.Pots) { bool hasPlayersAllIn = false; foreach (Player playerInPot in pot.PlayersInPot) { if (playerInPot.IsAllIn) { hasPlayersAllIn = true; break; } } if (!hasPlayersAllIn) { potToPutChips = pot; break; } } if (potToPutChips == null) { Pot newPot = new Pot(); CurrentHand.AddPot(newPot); GameController.Instance.AddPot(); potToPutChips = newPot; } player.PutChipsToPot(potToPutChips, amount); }
protected virtual CardColor PickAColor() { var colorsToChoose = new List <CardColor>(); if (ColorRequest.HasValue) { // we have a pending color request; honor it var color = ColorRequest.Value; StrategyLogger.LogDebug("honoring color request {Color}", color); ColorRequest = null; return(color); } // -> add all four colors once to allow for some chaotic color switching colorsToChoose.Add(CardColor.Red); colorsToChoose.Add(CardColor.Green); colorsToChoose.Add(CardColor.Blue); colorsToChoose.Add(CardColor.Yellow); // -> add all the (non-wild) colors from our hand to increase the chances of a useful pick var handColors = CurrentHand.Select(c => c.Color).Where(c => c != CardColor.Wild).ToList(); for (int i = 0; i < Config.ColorInHandPreference; ++i) { colorsToChoose.AddRange(handColors); } // -> choose at random return(colorsToChoose[Randomizer.Next(colorsToChoose.Count)]); }
public List<Card> DoubleDown(Card card, int amount) { CurrentBet = CurrentBet + amount; Bank -= amount; CurrentHand.Add(card); playerNotify(card, i); return CurrentHand; }
private void SetCallButtonTextIfNeeded() { int uncalledBet = CurrentHand.GetHighestBetNotInPot() - CurrentPlayer.CurrentBet; if (uncalledBet > 0) { GameController.Instance.SetCallButtonText(uncalledBet.ToString()); } }
private void OnPlayerTurnEnded(TurnType turnType, int amount) { Debug.Log("OnPlayerTurnEnded"); if (turnType == TurnType.Invalid) { Debug.Log("OnPlayerTurnEnded: invalid turn type."); return; } if (turnType == TurnType.Fold) { CurrentHand.RemovePlayer(CurrentPlayer); } else if (turnType == TurnType.Call) { PutChipsToPot(CurrentPlayer, amount); GameController.Instance.UpdatePlayerCard(CurrentPlayerIndex, CurrentPlayer); GameController.Instance.UpdatePotSizeTexts(CurrentHand.Pots); } else if (turnType == TurnType.Raise) { PutChipsToPot(CurrentPlayer, amount); GameController.Instance.UpdatePlayerCard(CurrentPlayerIndex, CurrentPlayer); GameController.Instance.UpdatePotSizeTexts(CurrentHand.Pots); } else if (turnType == TurnType.Bet) { PutChipsToPot(CurrentPlayer, amount); GameController.Instance.UpdatePlayerCard(CurrentPlayerIndex, CurrentPlayer); GameController.Instance.UpdatePotSizeTexts(CurrentHand.Pots); } else if (turnType == TurnType.Check) { // TODO } CurrentPlayer.LastTurn = turnType; GameController.Instance.HighlightActivePlayer(false); GameController.Instance.StopTurnTimer(); if (!HandHasWinner(CurrentHand)) { if (NeedToDealNextStreet()) { DealNextStreet(); } else { PlayTurn(); } } else { EndHand(CurrentHand); } }
/// <summary> /// Strategy: weight cards by type. /// </summary> protected StrategyContinuation StrategyWeightByType(List <Card> possibleCards) { // matched only by value, times StandardValueMatchPriority var cardsByValue = CurrentHand.Where(hc => hc.Value == TopCard.Value && hc.Color != TopCard.Color).ToList(); for (int i = 0; i < Config.StandardValueMatchPriority; ++i) { possibleCards.AddRange(cardsByValue); } // matched only by color, times StandardColorMatchPriority var cardsByColor = CurrentHand.Where(hc => hc.Color == TopCard.Color && hc.Value != TopCard.Value).ToList(); for (int i = 0; i < Config.StandardColorMatchPriority; ++i) { possibleCards.AddRange(cardsByColor); } // matched by both color and value, times StandardColorAndValueMatchPriority var identicalCards = CurrentHand.Where(hc => hc.Color == TopCard.Color && hc.Value == TopCard.Value).ToList(); for (int i = 0; i < Config.StandardColorAndValueMatchPriority; ++i) { possibleCards.AddRange(identicalCards); } // color changers (W, WD4), times StandardColorChangePriority var colorChangeCards = CurrentHand.Where(hc => hc.Color == CardColor.Wild).ToList(); for (int i = 0; i < Config.StandardColorChangePriority; ++i) { possibleCards.AddRange(colorChangeCards); } // player sequence reordering cards (R, S, D2, WD4), times StandardReorderPriority var reorderCards = CurrentHand.Where(hc => hc.Value == CardValue.WildDrawFour || ( ( hc.Color == TopCard.Color || hc.Value == TopCard.Value ) && ( hc.Value == CardValue.DrawTwo || hc.Value == CardValue.Reverse || hc.Value == CardValue.Skip ) ) ).ToList(); for (int i = 0; i < Config.StandardReorderPriority; ++i) { possibleCards.AddRange(reorderCards); } return(StrategyContinuation.ContinueToNextStrategy); }
private void SetBetButtonTextIfNeeded() { int uncalledBet = CurrentHand.GetHighestBetNotInPot() - CurrentPlayer.CurrentBet; bool canBet = uncalledBet == 0 && !CurrentHandState.Instance.IsPreflop; if (canBet) { GameController.Instance.SetBetButtonText(_bigBlindSize.ToString()); } }
//Adds card to hand, returns new total public List<Card> Hit(Card card) { CurrentHand.Add(card); if(Hand4 != null) { Hand4.Add(card); } playerNotify(card, i); return CurrentHand; }
public void EndCurrentHand() { CurrentHand.EndHand(); foreach (Player player in ActivePlayers) { player.AddStatistics(CurrentHand.PlayersBets[player]); } dealerIndex++; }
private void SetRaiseButtonTextIfNeeded() { int uncalledBet = CurrentHand.GetHighestBetNotInPot() - CurrentPlayer.CurrentBet; bool canRaise = uncalledBet > 0 && CurrentPlayer.ChipCount > uncalledBet; if (canRaise) { int minRaiseAmount = Math.Min(CurrentHand.GetHighestBetNotInPot() * 2, CurrentPlayer.ChipCount); GameController.Instance.SetRaiseButtonText(minRaiseAmount.ToString()); } }
public void newHand() { numOfHands = (numOfHands + 1) % Players.Count; piles.Clear(); piles.Add(0); lastRasePlayer = 0; currentRaise = 0; deck = shuffle(); cardsOnTable.Clear(); CurrentHand.Clear(); Hand = new Business.DomainModel.Hand(); foreach (KeyValuePair <int, Player> player in Players) { if (player.Value.currentMoney < this.table.BuyInMin) { UserRepository rep = new UserRepository(); User user = rep.ReadByUsername(player.Value.username); if (user.money >= table.BuyInMax) { player.Value.currentMoney += table.BuyInMax; user.money -= table.BuyInMax; rep.UpdateMoney(user.username, user.money); } else if (user.money > table.BuyInMin) { player.Value.currentMoney += table.BuyInMin; user.money -= table.BuyInMin; rep.UpdateMoney(user.username, user.money); } else { continue; } } player.Value.stakesMoney = 0; CurrentHand.Add(player.Key); Hand.username.Add(player.Key.ToString(), player.Value.username); } //for (int j = 0; j < numOfHands; j++) //{ // int tmp = CurrentHand[0]; // for (int i = 0; i < CurrentHand.Count - 1; i++) // CurrentHand[i] = CurrentHand[i + 1]; // CurrentHand[CurrentHand.Count - 1] = tmp; //} }
public void DrawCardFromDeck() { if (!Deck.IsEmpty()) { if (IsOverflow()) { Deck.Draw(); } else { CurrentHand.Add(Deck.Draw()); } } }
// 카드를 뽑는다 public bool DrawCard() { if (CurrentStageDeck.Count == 0 || CurrentHand.Count > 4) { return(false); } int randCardNum = UnityEngine.Random.Range(0, CurrentStageDeck.Count); // 카드 데이터를 기반으로 실제 카드로 바꿈 CurrentHand.Add(CreateCard(CurrentStageDeck[randCardNum])); CurrentStageDeck.RemoveAt(randCardNum); return(true); }
public bool Equals(Player player) { return(IsDealer == player.IsDealer && IsSmallBlind == player.IsSmallBlind && IsBigBlind == player.IsBigBlind && PlayerId == player.PlayerId && PlayerName == player.PlayerName && Chips == player.Chips && (StartingHand != null && StartingHand.Equals(player.StartingHand)) && (CurrentHand != null && CurrentHand.Equals(player.CurrentHand)) && CallSum == player.CallSum && CalledSum == player.CalledSum && Folded == player.Folded && Checked == player.Checked); }
private void BeginShowdown() { // TODO: add muck possibility CurrentHandState.Instance.SetState(HandState.Showdown); List <int> playerIndexes = new List <int>(); for (int playerIndex = 0; playerIndex < _playerCount; playerIndex++) { Player player = _players[playerIndex]; if (CurrentHand.IsPlayerInvolved(player) && !player.IsLocal) { playerIndexes.Add(playerIndex); } } GameController.Instance.ProcessShowdown(playerIndexes); }
public virtual void PlayTurn() { Debug.Log("Game PlayTurn"); //_currentPlayerIndex++; //if (_currentPlayerIndex >= _playerCount) { // _currentPlayerIndex = 0; //} //// TODO: check if this causes some issues //if (!CurrentHand.IsPlayerInvolved(CurrentPlayer) || CurrentPlayer.IsAllIn) { // PlayTurn(); //} IncrementPlayerIndex(); while (!CurrentHand.IsPlayerInvolved(CurrentPlayer) || CurrentPlayer.IsAllIn) { IncrementPlayerIndex(); } }
protected override void PlayACard() { // find a playable card with the lowest malus var cardToPlay = CurrentHand .Where(IsCardPlayable) .OrderBy(c => c.Malus) .Select(c => (Card?)c) .FirstOrDefault(); if (cardToPlay.HasValue) { if (cardToPlay.Value.Color == CardColor.Wild) { // choose the color of which we have the most cards, or red var colorsByCount = CurrentHand .Where(c => c.Color != CardColor.Wild) .GroupBy(c => c.Color) .Select(grp => new { Color = grp.Key, Count = grp.Count() }) .OrderByDescending(cc => cc.Count) .ToList(); var colorToPlay = (colorsByCount.Count > 0) ? colorsByCount[0].Color : CardColor.Red; PlayWildCard(cardToPlay.Value.Value, colorToPlay); } else { PlayColorCard(cardToPlay.Value); } DrewLast = false; } else { if (DrewLast) { PassAfterDrawing(); } else { DrawACard(); } } }
protected override CardColor PickAColor() { if (ColorRequest.HasValue) { // we have a pending color request; honor it var color = ColorRequest.Value; StrategyLogger.LogDebug("honoring color request {Color}", color); ColorRequest = null; return(color); } // choose the color of which we have the most cards, or red var colorsByCount = CurrentHand .Where(c => c.Color != CardColor.Wild) .GroupBy(c => c.Color) .Select(grp => new { Color = grp.Key, Count = grp.Count() }) .OrderByDescending(cc => cc.Count) .ToList(); return((colorsByCount.Count > 0) ? colorsByCount[0].Color : CardColor.Red); }
private void SetPlayerFirstToAct() { int playerFirstToActIndex = CurrentHandState.Instance.IsPreflop ? GetPlayerOnTheBigBlindIndex() + 1 : GetPlayerOnTheButtonIndex() + 1; if (playerFirstToActIndex >= _playerCount) { playerFirstToActIndex = 0; } Player playerFirstToAct = _players[playerFirstToActIndex]; while (!CurrentHand.IsPlayerInvolved(playerFirstToAct)) { playerFirstToActIndex++; if (playerFirstToActIndex >= _playerCount) { playerFirstToActIndex = 0; } playerFirstToAct = _players[playerFirstToActIndex]; } _currentPlayerIndex = playerFirstToActIndex; }
/// <summary> /// Strategy: honor color requests. /// </summary> protected StrategyContinuation StrategyHonorColorRequests(List <Card> possibleCards) { if (!ColorRequest.HasValue) { // no color request to honor return(StrategyContinuation.ContinueToNextStrategy); } // do I have a usable card that matches the target color? possibleCards.AddRange(CurrentHand.Where(hc => hc.Color == ColorRequest.Value && hc.Value == TopCard.Value)); if (possibleCards.Count == 0) { // nope; try changing with a wild card instead possibleCards.AddRange(CurrentHand.Where(hc => hc.Color == CardColor.Wild)); } if (possibleCards.Count > 0) { // alright, no need for the standard pick return(StrategyContinuation.SkipAllOtherStrategiesUnlessFilteredEmpty); } return(StrategyContinuation.ContinueToNextStrategy); }
// 게임 시작되면 현재 덱으로 게임 플레이 public bool OnEvent(IEvent e) { Type eventType = e.GetType(); if (eventType == typeof(BattleStageStartEvent)) { BattleStageStartEvent battleStateStartEvent = e as BattleStageStartEvent; Init(); GameManager.Instance.AddUpdate(this); return(true); } else if (eventType == typeof(BattleStageEndEvent)) { for (int i = 0; i < CurrentHand.Count; i++) { CurrentHand[i].Dispose(); i--; } CurrentHand.Clear(); return(true); } return(false); }
public void DrawOneCard() { var nextCard = Deck.FirstOrDefault(card => !card.InHand && !card.InDiscard); if (nextCard != null) { nextCard.InHand = true; } else { Deck.ForEach(card => card.InDiscard = false); var currentDeck = Deck.Where(card => !card.InHand).ToList(); Shuffle(currentDeck); var currentHand = CurrentHand.ToList(); Deck.Clear(); Deck.AddRange(currentHand); Deck.AddRange(currentDeck); DrawOneCard(); } }
private bool NeedToDealNextStreet() { bool allThePlayersMadeTurn = true; bool noUncalledBets = true; int playerNotAllInCount = 0; foreach (Player player in CurrentHand.PlayersInvolved) { if (player.IsAllIn) { continue; } playerNotAllInCount++; int uncalledBet = CurrentHand.GetHighestBetNotInPot() - player.CurrentBet; if (uncalledBet > 0) { noUncalledBets = false; } if (!player.HasMadeTurn) { allThePlayersMadeTurn = false; } } if (noUncalledBets) { if (allThePlayersMadeTurn || playerNotAllInCount <= 1) { return(true); } } return(false); }
private PlayerState GetActivePlayerState() { if (CurrentPlayer.IsAI) { return(PlayerState.IsAI); } int uncalledBet = CurrentHand.GetHighestBetNotInPot() - CurrentPlayer.CurrentBet; bool canCall = uncalledBet > 0; bool canCheck = uncalledBet == 0; bool canBet = canCheck && !CurrentHandState.Instance.IsPreflop; bool canRaise = uncalledBet >= 0 && CurrentPlayer.ChipCount > uncalledBet; if (CurrentPlayer.IsAllIn) { return(PlayerState.IsAllIn); } else if (canCall && canRaise) { return(PlayerState.CanFoldCallRaise); } else if (canCheck && canBet) { return(PlayerState.CanFoldCheckBet); } else if (canCheck && canRaise) { return(PlayerState.CanFoldCheckRaise); } else if (canCall) { return(PlayerState.CanFoldCall); } return(PlayerState.Invalid); }
protected StrategyContinuation StrategyAnyCard(List <Card> possibleCards) { // just anything possibleCards.AddRange(CurrentHand.Where(IsCardPlayable)); return(StrategyContinuation.ContinueToNextStrategy); }
public string GetChoice() { List <int> smallerChoice = CurrentHand.Where(x => x <= PlayerStatistics.ActualMana).ToList(); if (smallerChoice.Count <= 0) { return(string.Empty); } if (smallerChoice.Contains(0)) { return("0"); } if (smallerChoice.Any(x => x == PlayerStatistics.ActualMana)) { return(smallerChoice.First(x => x == PlayerStatistics.ActualMana).ToString()); } int HigherToLower = 0; int LowerToHigher = 0; int MiddleChoice = 0; int MiddleDefinitiveChoice = 0; int tempMana = PlayerStatistics.ActualMana; List <int> replica = new List <int>(smallerChoice); while (replica.Any() && tempMana >= 0) { if (replica.Max() <= tempMana) { HigherToLower += replica.Max(); tempMana -= replica.Max(); } replica.Remove(replica.Max()); } replica = new List <int>(smallerChoice); tempMana = PlayerStatistics.ActualMana; while (replica.Any() && tempMana >= 0) { if (replica.Min() <= tempMana) { LowerToHigher += replica.Min(); tempMana -= replica.Min(); } replica.Remove(replica.Min()); } replica = new List <int>(smallerChoice); tempMana = PlayerStatistics.ActualMana; while (replica.Any() && tempMana >= 0) { double avg = replica.Average(); replica.Sort(); var higher = replica.FirstOrDefault(x => x >= Math.Ceiling(avg)); var lower = replica.FirstOrDefault(x => x <= Math.Floor(avg)); if (higher != 0 && tempMana >= higher && higher > lower) { MiddleChoice += higher; if (MiddleDefinitiveChoice == 0) { MiddleDefinitiveChoice = higher; } tempMana -= higher; replica.Remove(higher); } else if (lower != 0 && tempMana >= lower && lower > higher) { MiddleChoice += lower; if (MiddleDefinitiveChoice == 0) { MiddleDefinitiveChoice = higher; } tempMana -= lower; replica.Remove(lower); } else { if (tempMana >= 0) { try { var temp = replica.Where(x => x <= tempMana).ToList().Max(); MiddleChoice += temp; replica.Remove(temp); } catch { break; } } } } if (HigherToLower > LowerToHigher && HigherToLower > MiddleChoice) { return(smallerChoice.Max().ToString()); } else if (LowerToHigher > HigherToLower && LowerToHigher > MiddleChoice) { return(smallerChoice.Min().ToString()); } else if (MiddleChoice > HigherToLower && MiddleChoice > LowerToHigher) { return(MiddleDefinitiveChoice.ToString()); } else { return(string.Empty); } }
public void RemoveCard(Card card) { CurrentHand.Remove(card); }
public void ResetRound() { CurrentBet = null; CurrentHand.ClearHand(); }