diff --git a/src/dawn/CMakeLists.txt b/src/dawn/CMakeLists.txt index 7157d936..48f62f99 100644 --- a/src/dawn/CMakeLists.txt +++ b/src/dawn/CMakeLists.txt @@ -30,7 +30,6 @@ add_subdirectory(games) add_subdirectory(input) add_subdirectory(locale) add_subdirectory(physics) -add_subdirectory(poker) add_subdirectory(prefab) add_subdirectory(save) add_subdirectory(scene) diff --git a/src/dawn/games/CMakeLists.txt b/src/dawn/games/CMakeLists.txt index 05d350a9..f1812e63 100644 --- a/src/dawn/games/CMakeLists.txt +++ b/src/dawn/games/CMakeLists.txt @@ -4,4 +4,5 @@ # https://opensource.org/licenses/MIT # Subdirs +add_subdirectory(poker) add_subdirectory(tictactoe) \ No newline at end of file diff --git a/src/dawn/poker/CMakeLists.txt b/src/dawn/games/poker/CMakeLists.txt similarity index 100% rename from src/dawn/poker/CMakeLists.txt rename to src/dawn/games/poker/CMakeLists.txt diff --git a/src/dawn/poker/Card.cpp b/src/dawn/games/poker/Card.cpp similarity index 100% rename from src/dawn/poker/Card.cpp rename to src/dawn/games/poker/Card.cpp diff --git a/src/dawn/poker/Card.hpp b/src/dawn/games/poker/Card.hpp similarity index 100% rename from src/dawn/poker/Card.hpp rename to src/dawn/games/poker/Card.hpp diff --git a/src/dawn/poker/PokerGame.cpp b/src/dawn/games/poker/PokerGame.cpp similarity index 100% rename from src/dawn/poker/PokerGame.cpp rename to src/dawn/games/poker/PokerGame.cpp diff --git a/src/dawn/poker/PokerGame.hpp b/src/dawn/games/poker/PokerGame.hpp similarity index 100% rename from src/dawn/poker/PokerGame.hpp rename to src/dawn/games/poker/PokerGame.hpp diff --git a/src/dawn/poker/PokerPlayer.cpp b/src/dawn/games/poker/PokerPlayer.cpp similarity index 100% rename from src/dawn/poker/PokerPlayer.cpp rename to src/dawn/games/poker/PokerPlayer.cpp diff --git a/src/dawn/poker/PokerPlayer.hpp b/src/dawn/games/poker/PokerPlayer.hpp similarity index 100% rename from src/dawn/poker/PokerPlayer.hpp rename to src/dawn/games/poker/PokerPlayer.hpp diff --git a/src/dawn/poker/PokerPot.cpp b/src/dawn/games/poker/PokerPot.cpp similarity index 95% rename from src/dawn/poker/PokerPot.cpp rename to src/dawn/games/poker/PokerPot.cpp index 415f1c43..1dbfdea5 100644 --- a/src/dawn/poker/PokerPot.cpp +++ b/src/dawn/games/poker/PokerPot.cpp @@ -1,111 +1,111 @@ -// Copyright (c) 2022 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#include "PokerPot.hpp" -#include "PokerGame.hpp" -#include "PokerPlayer.hpp" - -using namespace Dawn; - -void PokerPotWinning::award() { - auto it = this->winners.begin(); - while(it != this->winners.end()) { - if(it == this->winners.begin()) { - (*it)->addChips(this->chipsEach + this->chipsOverflow); - } else { - (*it)->addChips(this->chipsEach); - } - ++it; - } -} - -struct PokerPotWinning PokerPot::getWinners(PokerGame *game) { - struct PokerPotWinning winning; - - winning.pot = this; - - // Calculate the winnings first. - auto it = this->players.begin(); - while(it != this->players.end()) { - auto player = *it; - - if(player->isOut || player->isFolded) { - ++it; - continue; - } - - winning.participants.push_back(player); - winning.winnings[player] = player->getWinning(); - ++it; - } - - // Compare participating players - auto it2 = winning.participants.begin(); - while(it2 != winning.participants.end()) { - auto playerLeft = *it2; - auto winnerLeft = &winning.winnings[playerLeft]; - bool_t isWinner = true; - enum CardValue highNumber = CARD_VALUE_INVALD; - enum CardValue number = CARD_VALUE_INVALD; - struct Card highCard(0xFF); - struct Card card(0xFF); - - auto it3 = winning.participants.begin(); - while(it3 != winning.participants.end()) { - if(it2 == it3) { - ++it3; - continue; - } - - auto playerRight = *it3; - auto winnerRight = &winning.winnings[playerRight]; - - // Am I the better hand / Is it the better hand? - if(winnerLeft->type < winnerRight->type) { - ++it3; - continue; - } - if(winnerLeft->type > winnerRight->type) { - isWinner = false; - break; - } - - // Equal, compare hands. - card = PokerWinning::compare(winnerLeft, winnerRight); - if(card.cardValue == 0xFF) { - isWinner = false; - break; - } - - // Determine high card. - number = card.getValue(); - if( - highNumber == CARD_VALUE_INVALD || - number == CARD_ACE || - number > highNumber - ) { - highCard = card; - highNumber = number; - } - ++it3; - } - - if(!isWinner) { - ++it2; - continue; - } - - winnerLeft->kicker = highCard; - winning.winners.push_back(playerLeft); - ++it2; - } - - winning.chipsEach = this->chips / (int32_t)winning.winners.size(); - winning.chipsOverflow = this->chips - ( - winning.chipsEach * (int32_t)winning.winners.size() - ); - - return winning; +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "PokerPot.hpp" +#include "PokerGame.hpp" +#include "PokerPlayer.hpp" + +using namespace Dawn; + +void PokerPotWinning::award() { + auto it = this->winners.begin(); + while(it != this->winners.end()) { + if(it == this->winners.begin()) { + (*it)->addChips(this->chipsEach + this->chipsOverflow); + } else { + (*it)->addChips(this->chipsEach); + } + ++it; + } +} + +struct PokerPotWinning PokerPot::getWinners(PokerGame *game) { + struct PokerPotWinning winning; + + winning.pot = this; + + // Calculate the winnings first. + auto it = this->players.begin(); + while(it != this->players.end()) { + auto player = *it; + + if(player->isOut || player->isFolded) { + ++it; + continue; + } + + winning.participants.push_back(player); + winning.winnings[player] = player->getWinning(); + ++it; + } + + // Compare participating players + auto it2 = winning.participants.begin(); + while(it2 != winning.participants.end()) { + auto playerLeft = *it2; + auto winnerLeft = &winning.winnings[playerLeft]; + bool_t isWinner = true; + enum CardValue highNumber = CARD_VALUE_INVALD; + enum CardValue number = CARD_VALUE_INVALD; + struct Card highCard(0xFF); + struct Card card(0xFF); + + auto it3 = winning.participants.begin(); + while(it3 != winning.participants.end()) { + if(it2 == it3) { + ++it3; + continue; + } + + auto playerRight = *it3; + auto winnerRight = &winning.winnings[playerRight]; + + // Am I the better hand / Is it the better hand? + if(winnerLeft->type < winnerRight->type) { + ++it3; + continue; + } + if(winnerLeft->type > winnerRight->type) { + isWinner = false; + break; + } + + // Equal, compare hands. + card = PokerWinning::compare(winnerLeft, winnerRight); + if(card.cardValue == 0xFF) { + isWinner = false; + break; + } + + // Determine high card. + number = card.getValue(); + if( + highNumber == CARD_VALUE_INVALD || + number == CARD_ACE || + number > highNumber + ) { + highCard = card; + highNumber = number; + } + ++it3; + } + + if(!isWinner) { + ++it2; + continue; + } + + winnerLeft->kicker = highCard; + winning.winners.push_back(playerLeft); + ++it2; + } + + winning.chipsEach = this->chips / (int32_t)winning.winners.size(); + winning.chipsOverflow = this->chips - ( + winning.chipsEach * (int32_t)winning.winners.size() + ); + + return winning; } \ No newline at end of file diff --git a/src/dawn/poker/PokerPot.hpp b/src/dawn/games/poker/PokerPot.hpp similarity index 100% rename from src/dawn/poker/PokerPot.hpp rename to src/dawn/games/poker/PokerPot.hpp diff --git a/src/dawn/poker/PokerTurn.cpp b/src/dawn/games/poker/PokerTurn.cpp similarity index 100% rename from src/dawn/poker/PokerTurn.cpp rename to src/dawn/games/poker/PokerTurn.cpp diff --git a/src/dawn/poker/PokerTurn.hpp b/src/dawn/games/poker/PokerTurn.hpp similarity index 100% rename from src/dawn/poker/PokerTurn.hpp rename to src/dawn/games/poker/PokerTurn.hpp diff --git a/src/dawn/poker/PokerWinning.cpp b/src/dawn/games/poker/PokerWinning.cpp similarity index 100% rename from src/dawn/poker/PokerWinning.cpp rename to src/dawn/games/poker/PokerWinning.cpp diff --git a/src/dawn/poker/PokerWinning.hpp b/src/dawn/games/poker/PokerWinning.hpp similarity index 100% rename from src/dawn/poker/PokerWinning.hpp rename to src/dawn/games/poker/PokerWinning.hpp diff --git a/src/dawn/poker/visualnovel/CMakeLists.txt b/src/dawn/games/poker/visualnovel/CMakeLists.txt similarity index 100% rename from src/dawn/poker/visualnovel/CMakeLists.txt rename to src/dawn/games/poker/visualnovel/CMakeLists.txt diff --git a/src/dawn/poker/visualnovel/PokerAIBetEvent.hpp b/src/dawn/games/poker/visualnovel/PokerAIBetEvent.hpp similarity index 100% rename from src/dawn/poker/visualnovel/PokerAIBetEvent.hpp rename to src/dawn/games/poker/visualnovel/PokerAIBetEvent.hpp diff --git a/src/dawn/poker/visualnovel/PokerDealEvent.hpp b/src/dawn/games/poker/visualnovel/PokerDealEvent.hpp similarity index 100% rename from src/dawn/poker/visualnovel/PokerDealEvent.hpp rename to src/dawn/games/poker/visualnovel/PokerDealEvent.hpp diff --git a/src/dawn/poker/visualnovel/PokerDetermineBetterEvent.cpp b/src/dawn/games/poker/visualnovel/PokerDetermineBetterEvent.cpp similarity index 100% rename from src/dawn/poker/visualnovel/PokerDetermineBetterEvent.cpp rename to src/dawn/games/poker/visualnovel/PokerDetermineBetterEvent.cpp diff --git a/src/dawn/poker/visualnovel/PokerDetermineBetterEvent.hpp b/src/dawn/games/poker/visualnovel/PokerDetermineBetterEvent.hpp similarity index 100% rename from src/dawn/poker/visualnovel/PokerDetermineBetterEvent.hpp rename to src/dawn/games/poker/visualnovel/PokerDetermineBetterEvent.hpp diff --git a/src/dawn/poker/visualnovel/PokerGameEvent.hpp b/src/dawn/games/poker/visualnovel/PokerGameEvent.hpp similarity index 100% rename from src/dawn/poker/visualnovel/PokerGameEvent.hpp rename to src/dawn/games/poker/visualnovel/PokerGameEvent.hpp diff --git a/src/dawn/poker/visualnovel/PokerNewBettingRoundEvent.hpp b/src/dawn/games/poker/visualnovel/PokerNewBettingRoundEvent.hpp similarity index 96% rename from src/dawn/poker/visualnovel/PokerNewBettingRoundEvent.hpp rename to src/dawn/games/poker/visualnovel/PokerNewBettingRoundEvent.hpp index 00eb289f..5e9d846d 100644 --- a/src/dawn/poker/visualnovel/PokerNewBettingRoundEvent.hpp +++ b/src/dawn/games/poker/visualnovel/PokerNewBettingRoundEvent.hpp @@ -1,29 +1,29 @@ -// Copyright (c) 2022 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#pragma once -#include "PokerGameEvent.hpp" - -namespace Dawn { - class PokerNewBettingRoundEvent : public PokerGameEvent { - protected: - void onStart(IVisualNovelEvent *previous) override { - PokerGameEvent::onStart(previous); - std::cout << "New Betting Round" << std::endl; - this->pokerGame->newBettingRound(); - } - - bool_t onUpdate() override { - return false; - } - - void onEnd() override { - } - - public: - PokerNewBettingRoundEvent(VisualNovelManager *manager) : PokerGameEvent(manager) { - } - }; +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "PokerGameEvent.hpp" + +namespace Dawn { + class PokerNewBettingRoundEvent : public PokerGameEvent { + protected: + void onStart(IVisualNovelEvent *previous) override { + PokerGameEvent::onStart(previous); + std::cout << "New Betting Round" << std::endl; + this->pokerGame->newBettingRound(); + } + + bool_t onUpdate() override { + return false; + } + + void onEnd() override { + } + + public: + PokerNewBettingRoundEvent(VisualNovelManager *manager) : PokerGameEvent(manager) { + } + }; } \ No newline at end of file diff --git a/src/dawn/poker/visualnovel/PokerNewGameEvent.hpp b/src/dawn/games/poker/visualnovel/PokerNewGameEvent.hpp similarity index 100% rename from src/dawn/poker/visualnovel/PokerNewGameEvent.hpp rename to src/dawn/games/poker/visualnovel/PokerNewGameEvent.hpp diff --git a/src/dawn/poker/visualnovel/PokerNewRoundEvent.hpp b/src/dawn/games/poker/visualnovel/PokerNewRoundEvent.hpp similarity index 100% rename from src/dawn/poker/visualnovel/PokerNewRoundEvent.hpp rename to src/dawn/games/poker/visualnovel/PokerNewRoundEvent.hpp diff --git a/src/dawn/poker/visualnovel/PokerTakeBlindsEvent.hpp b/src/dawn/games/poker/visualnovel/PokerTakeBlindsEvent.hpp similarity index 100% rename from src/dawn/poker/visualnovel/PokerTakeBlindsEvent.hpp rename to src/dawn/games/poker/visualnovel/PokerTakeBlindsEvent.hpp diff --git a/src/dawn/poker/visualnovel/PokerTurnEvent.hpp b/src/dawn/games/poker/visualnovel/PokerTurnEvent.hpp similarity index 100% rename from src/dawn/poker/visualnovel/PokerTurnEvent.hpp rename to src/dawn/games/poker/visualnovel/PokerTurnEvent.hpp diff --git a/src/dawn/poker/visualnovel/PokerWinnerEvent.hpp b/src/dawn/games/poker/visualnovel/PokerWinnerEvent.hpp similarity index 96% rename from src/dawn/poker/visualnovel/PokerWinnerEvent.hpp rename to src/dawn/games/poker/visualnovel/PokerWinnerEvent.hpp index eec9ecdf..9dd43c53 100644 --- a/src/dawn/poker/visualnovel/PokerWinnerEvent.hpp +++ b/src/dawn/games/poker/visualnovel/PokerWinnerEvent.hpp @@ -1,46 +1,46 @@ -// Copyright (c) 2022 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#pragma once -#include "PokerGameEvent.hpp" -#include "poker/PokerPot.hpp" - -namespace Dawn { - class PokerWinnerEvent : public PokerGameEvent { - protected: - 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 { - return false; - } - - void onEnd() override { - } - - public: - std::map winnings; - - PokerWinnerEvent(VisualNovelManager *manager) : PokerGameEvent(manager) { - } - }; +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "PokerGameEvent.hpp" +#include "poker/PokerPot.hpp" + +namespace Dawn { + class PokerWinnerEvent : public PokerGameEvent { + protected: + 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 { + return false; + } + + void onEnd() override { + } + + public: + std::map winnings; + + PokerWinnerEvent(VisualNovelManager *manager) : PokerGameEvent(manager) { + } + }; } \ No newline at end of file