diff --git a/src/NPokerEngine.Tests/Engine/MessageBuilderTests.cs b/src/NPokerEngine.Tests/Engine/MessageBuilderTests.cs index fd7e88f..ac9b219 100644 --- a/src/NPokerEngine.Tests/Engine/MessageBuilderTests.cs +++ b/src/NPokerEngine.Tests/Engine/MessageBuilderTests.cs @@ -93,7 +93,7 @@ public void RoundResultMessageTest() var winners = state.Table.Seats.Players.Skip(1).Take(1); var handInfo = new string[] { "dummy", "info" }; - var message = MessageBuilder.Instance.BuildRoundResultMessage(7, winners, handInfo, state); + var message = MessageBuilder.Instance.BuildRoundResultMessage(7, winners, handInfo, state, null); using (new AssertionScope()) { diff --git a/src/NPokerEngine/Emulator.cs b/src/NPokerEngine/Emulator.cs index a68309b..b578403 100644 --- a/src/NPokerEngine/Emulator.cs +++ b/src/NPokerEngine/Emulator.cs @@ -61,6 +61,12 @@ public void RegisterPlayer(PokerPlayer player) } public (GameState gameState, List messages) ApplyAction(GameState gameState, ActionType actionType, float betAmount = 0) + { + ActionHistoryEntry actionHistoryEntry; + return ApplyAction(gameState, actionType, out actionHistoryEntry, betAmount); + } + + public (GameState gameState, List messages) ApplyAction(GameState gameState, ActionType actionType, out ActionHistoryEntry actionHistoryEntry, float betAmount = 0) { var messages = new List(); if (gameState.Street == StreetType.FINISHED) @@ -68,7 +74,7 @@ public void RegisterPlayer(PokerPlayer player) (gameState, messages) = StartNextRound(gameState); } - var (updatedState, msgs) = RoundManager.Instance.ApplyAction(gameState, actionType, betAmount); + var (updatedState, msgs) = RoundManager.Instance.ApplyAction(gameState, actionType, betAmount, out actionHistoryEntry); gameState = updatedState; messages.AddRange(msgs); diff --git a/src/NPokerEngine/Engine/MessageBuilder.cs b/src/NPokerEngine/Engine/MessageBuilder.cs index 3dabce5..42a8504 100644 --- a/src/NPokerEngine/Engine/MessageBuilder.cs +++ b/src/NPokerEngine/Engine/MessageBuilder.cs @@ -117,34 +117,15 @@ public virtual GameUpdateMessage BuildGameUpdateMessage(int playerPos, ActionTyp }; } - public virtual RoundResultMessage BuildRoundResultMessage(int round_count, IEnumerable winners, object hand_info, GameState state) + public virtual RoundResultMessage BuildRoundResultMessage(int round_count, IEnumerable winners, object hand_info, GameState state, Dictionary prizeMap) { return new RoundResultMessage { RoundCount = round_count, Winners = winners.ToList(), - State = state + State = state, + PrizeMap = prizeMap }; - //var message = new Dictionary { - // { - // "message_type", - // ROUND_RESULT_MESSAGE}, - // { - // "round_count", - // round_count}, - // { - // "hand_info", - // hand_info}, - // { - // "round_state", - // DataEncoder.Instance.EncodeRoundState(state)}}; - - //foreach (var item in DataEncoder.Instance.EncodeWinners(winners)) - //{ - // message[item.Key] = item.Value; - //} - - //return this.BuildNotificationMessage(message); } public GameResultMessage BuildGameResultMessage(GameConfig config, Seats seats) diff --git a/src/NPokerEngine/Engine/RoundManager.cs b/src/NPokerEngine/Engine/RoundManager.cs index df13db8..39d042c 100644 --- a/src/NPokerEngine/Engine/RoundManager.cs +++ b/src/NPokerEngine/Engine/RoundManager.cs @@ -27,10 +27,16 @@ internal class RoundManager : Singleton } public Tuple> ApplyAction(GameState original_state, ActionType action, float bet_amount) + { + ActionHistoryEntry appliedActionHistoryEntry; + return ApplyAction(original_state, action, bet_amount, out appliedActionHistoryEntry); + } + + public Tuple> ApplyAction(GameState original_state, ActionType action, float bet_amount, out ActionHistoryEntry appliedActionHistoryEntry) { var state = this.DeepCopyState(original_state); - state = this.UpdateStateByAction(state, action, bet_amount); + state = this.UpdateStateByAction(state, action, bet_amount, out appliedActionHistoryEntry); var table = state.Table; var update_msg = this.UpdateMessage(state, action, bet_amount); if (this.IsEveryoneAgreed(state)) @@ -174,7 +180,7 @@ private void DealHolecard(Deck deck, IEnumerable players) { var (winners, hand_info, prize_map) = GameEvaluator.Instance.Judge((Table)state.Table); this.PrizeToWinners(state.Table.Seats.Players, prize_map); - var result_message = MessageBuilder.Instance.BuildRoundResultMessage(state.RoundCount, winners, hand_info, state); + var result_message = MessageBuilder.Instance.BuildRoundResultMessage(state.RoundCount, winners, hand_info, state, prize_map); state.Table.Reset(); state.Street = (StreetType)(Convert.ToByte(state.Street) + 1); return (state, new List() { result_message }); @@ -224,7 +230,7 @@ private List RoundStartMessage(int round_count, Table table) } } - private GameState UpdateStateByAction(GameState state, ActionType action, float bet_amount) + private GameState UpdateStateByAction(GameState state, ActionType action, float bet_amount, out ActionHistoryEntry actionHistoryEntry) { (action, bet_amount) = ActionChecker.Instance.CorrectAction(state.Table.Seats.Players, state.NextPlayerIx, state.SmallBlindAmount, action, bet_amount); var next_player = state.Table.Seats.Players[state.NextPlayerIx]; @@ -232,26 +238,26 @@ private GameState UpdateStateByAction(GameState state, ActionType action, float { next_player.PayInfo.UpdateToAllin(); } - return this.AcceptAction(state, action, bet_amount); + return this.AcceptAction(state, action, bet_amount, out actionHistoryEntry); } - private GameState AcceptAction(GameState state, ActionType action, float bet_amount) + private GameState AcceptAction(GameState state, ActionType action, float bet_amount, out ActionHistoryEntry actionHistoryEntry) { var player = state.Table.Seats.Players[state.NextPlayerIx]; if (action == ActionType.CALL) { this.ChipTransaction(player, bet_amount); - player.AddActionHistory(ActionType.CALL, bet_amount); + actionHistoryEntry = player.AddActionHistory(ActionType.CALL, bet_amount); } else if (action == ActionType.RAISE) { this.ChipTransaction(player, bet_amount); var add_amount = bet_amount - ActionChecker.Instance.AgreeAmount(state.Table.Seats.Players); - player.AddActionHistory(ActionType.RAISE, bet_amount, add_amount); + actionHistoryEntry = player.AddActionHistory(ActionType.RAISE, bet_amount, add_amount); } else if (action == ActionType.FOLD) { - player.AddActionHistory(ActionType.FOLD); + actionHistoryEntry = player.AddActionHistory(ActionType.FOLD); player.PayInfo.UpdateToFold(); } else diff --git a/src/NPokerEngine/Messages/RoundResultMessage.cs b/src/NPokerEngine/Messages/RoundResultMessage.cs index 60201f4..73ec18e 100644 --- a/src/NPokerEngine/Messages/RoundResultMessage.cs +++ b/src/NPokerEngine/Messages/RoundResultMessage.cs @@ -8,6 +8,7 @@ public class RoundResultMessage : IMessage public int RoundCount { get; set; } public GameState State { get; set; } public List Winners { get; set; } + public Dictionary PrizeMap { get; set; } public MessageType MessageType => MessageType.ROUND_RESULT_MESSAGE; } diff --git a/src/NPokerEngine/Types/Player.cs b/src/NPokerEngine/Types/Player.cs index bba58da..ff36154 100644 --- a/src/NPokerEngine/Types/Player.cs +++ b/src/NPokerEngine/Types/Player.cs @@ -84,7 +84,7 @@ public bool IsWaitingAsk() return this._payInfo.Status == PayInfoStatus.PAY_TILL_END; } - public void AddActionHistory(ActionType kind, float chipAmount = 0, float addAmount = 0, float sbAmount = 0) + public ActionHistoryEntry AddActionHistory(ActionType kind, float chipAmount = 0, float addAmount = 0, float sbAmount = 0) { ActionHistoryEntry history = null; if (kind == ActionType.FOLD) @@ -117,6 +117,7 @@ public void AddActionHistory(ActionType kind, float chipAmount = 0, float addAmo } history.Uuid = this._uuid; this._actionHistories.Add(history); + return history; } public void SaveStreetActionHistories(StreetType street)