public int TakeAction(ITable table, ActionInfo actionInfo) { UpdateParams(); return(MakeDecision(table, actionInfo)); }
public abstract int MakeDecision(ITable table, ActionInfo actionInfo);
public IGameAction TakeAction(ITable table) { playerAi.HoleCards = new List <ICard> { HoleCards[0], HoleCards[1] }; playerAi.Chips = Chips; playerAi.CurrentBet = Bet; playerAi.TablePosition = TablePosition; int biggestBet = table.PlayerBets.Values.Max(); int biggestChips = table.PlayerChips.Where(x => x.Key != Name).Select(x => x.Value).Max(); bool isFoldPossible = true; int betToCall = biggestBet; int minRaise; int maxRaise = Chips + Bet; if (maxRaise > biggestChips) { maxRaise = biggestChips; } if (table.GameStage == GameStage.Preflop || table.GameStage == GameStage.Flop) { minRaise = biggestBet + table.BigBlind; } else { minRaise = biggestBet + 2 * table.BigBlind; } if (biggestBet == Bet) { isFoldPossible = false; betToCall = 0; } if (minRaise >= maxRaise) { maxRaise = minRaise; } if (betToCall > Chips + Bet) { betToCall = -1; } ActionInfo actionInfo = new ActionInfo(isFoldPossible, betToCall, minRaise, maxRaise); int choice = playerAi.TakeAction(table, actionInfo); if (!isFoldPossible && choice == -1) { throw new InvalidOperationException("Fold is impossible right now for this player."); } if (choice > maxRaise) { throw new InvalidOperationException("Cannot raise more than maximum possible."); } if (choice < minRaise && betToCall != 0 && betToCall != choice && choice != -1) { throw new InvalidOperationException("Cannot raise less than minimum possible."); } if (choice < -1) { throw new InvalidOperationException($"Invalid bet. Choice {choice} is less than -1."); } if (choice == -1) { return(new GameActionFold(this, table)); } else if (choice == Bet) { return(new GameActionCheck(this, table)); } else { return(new GameActionBet(this, table, choice)); } }