From 535e2b2dc54e201fa05f21f38bdd365f6895eb12 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sun, 27 Nov 2022 16:20:24 -0800 Subject: [PATCH] Winning2 --- src/dawn/poker/PokerGame.hpp | 2 +- src/dawn/poker/PokerPlayer.cpp | 2 +- src/dawn/poker/PokerPot.cpp | 6 +++--- .../poker/visualnovel/PokerWinnerEvent.hpp | 18 ++++++++++++++++++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/dawn/poker/PokerGame.hpp b/src/dawn/poker/PokerGame.hpp index c884cf50..9311cba2 100644 --- a/src/dawn/poker/PokerGame.hpp +++ b/src/dawn/poker/PokerGame.hpp @@ -22,7 +22,6 @@ namespace Dawn { std::vector deck; std::vector grave; std::vector community; - std::vector pots; uint8_t dealerIndex; uint8_t smallBlindIndex; uint8_t bigBlindIndex; @@ -31,6 +30,7 @@ namespace Dawn { public: std::vector players; + std::vector pots; uint8_t betterIndex; PokerGame(SceneItem *item); diff --git a/src/dawn/poker/PokerPlayer.cpp b/src/dawn/poker/PokerPlayer.cpp index 412d2ced..acb138f8 100644 --- a/src/dawn/poker/PokerPlayer.cpp +++ b/src/dawn/poker/PokerPlayer.cpp @@ -16,7 +16,7 @@ void PokerPlayer::onStart() { SceneItemComponent::onStart(); this->pokerGame = this->getScene()->findComponent(); - assertNotNull(this->pokerGame); + assertNotNull(this->pokerGame); } void PokerPlayer::addChips(int32_t chips) { diff --git a/src/dawn/poker/PokerPot.cpp b/src/dawn/poker/PokerPot.cpp index 92dbf528..415f1c43 100644 --- a/src/dawn/poker/PokerPot.cpp +++ b/src/dawn/poker/PokerPot.cpp @@ -13,7 +13,7 @@ void PokerPotWinning::award() { auto it = this->winners.begin(); while(it != this->winners.end()) { if(it == this->winners.begin()) { - (*it)->addChips(this->chipsOverflow); + (*it)->addChips(this->chipsEach + this->chipsOverflow); } else { (*it)->addChips(this->chipsEach); } @@ -102,9 +102,9 @@ struct PokerPotWinning PokerPot::getWinners(PokerGame *game) { ++it2; } - winning.chipsEach = this->chips / winning.winners.size(); + winning.chipsEach = this->chips / (int32_t)winning.winners.size(); winning.chipsOverflow = this->chips - ( - winning.chipsEach * winning.winners.size() + winning.chipsEach * (int32_t)winning.winners.size() ); return winning; diff --git a/src/dawn/poker/visualnovel/PokerWinnerEvent.hpp b/src/dawn/poker/visualnovel/PokerWinnerEvent.hpp index b727bd71..eec9ecdf 100644 --- a/src/dawn/poker/visualnovel/PokerWinnerEvent.hpp +++ b/src/dawn/poker/visualnovel/PokerWinnerEvent.hpp @@ -5,6 +5,7 @@ #pragma once #include "PokerGameEvent.hpp" +#include "poker/PokerPot.hpp" namespace Dawn { class PokerWinnerEvent : public PokerGameEvent { @@ -12,6 +13,21 @@ namespace Dawn { void onStart(IVisualNovelEvent *previous) override { PokerGameEvent::onStart(previous); std::cout << "Poker Winning" << std::endl; + + // Calculate + auto it = this->pokerGame->pots.begin(); + while(it != this->pokerGame->pots.end()) { + auto pot = &(*it); + this->winnings[pot] = pot->getWinners(this->pokerGame); + ++it; + } + + // Award + auto it2 = this->winnings.begin(); + while(it2 != this->winnings.end()) { + it2->second.award(); + it2++; + } } bool_t onUpdate() override { @@ -22,6 +38,8 @@ namespace Dawn { } public: + std::map winnings; + PokerWinnerEvent(VisualNovelManager *manager) : PokerGameEvent(manager) { } };