Moved poker to the games dir

This commit is contained in:
2023-02-26 14:02:31 -08:00
parent 0f9e9f2ccc
commit 451b5b067e
27 changed files with 184 additions and 184 deletions

@ -30,7 +30,6 @@ add_subdirectory(games)
add_subdirectory(input) add_subdirectory(input)
add_subdirectory(locale) add_subdirectory(locale)
add_subdirectory(physics) add_subdirectory(physics)
add_subdirectory(poker)
add_subdirectory(prefab) add_subdirectory(prefab)
add_subdirectory(save) add_subdirectory(save)
add_subdirectory(scene) add_subdirectory(scene)

@ -4,4 +4,5 @@
# https://opensource.org/licenses/MIT # https://opensource.org/licenses/MIT
# Subdirs # Subdirs
add_subdirectory(poker)
add_subdirectory(tictactoe) add_subdirectory(tictactoe)

@ -1,111 +1,111 @@
// Copyright (c) 2022 Dominic Masters // Copyright (c) 2022 Dominic Masters
// //
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#include "PokerPot.hpp" #include "PokerPot.hpp"
#include "PokerGame.hpp" #include "PokerGame.hpp"
#include "PokerPlayer.hpp" #include "PokerPlayer.hpp"
using namespace Dawn; using namespace Dawn;
void PokerPotWinning::award() { void PokerPotWinning::award() {
auto it = this->winners.begin(); auto it = this->winners.begin();
while(it != this->winners.end()) { while(it != this->winners.end()) {
if(it == this->winners.begin()) { if(it == this->winners.begin()) {
(*it)->addChips(this->chipsEach + this->chipsOverflow); (*it)->addChips(this->chipsEach + this->chipsOverflow);
} else { } else {
(*it)->addChips(this->chipsEach); (*it)->addChips(this->chipsEach);
} }
++it; ++it;
} }
} }
struct PokerPotWinning PokerPot::getWinners(PokerGame *game) { struct PokerPotWinning PokerPot::getWinners(PokerGame *game) {
struct PokerPotWinning winning; struct PokerPotWinning winning;
winning.pot = this; winning.pot = this;
// Calculate the winnings first. // Calculate the winnings first.
auto it = this->players.begin(); auto it = this->players.begin();
while(it != this->players.end()) { while(it != this->players.end()) {
auto player = *it; auto player = *it;
if(player->isOut || player->isFolded) { if(player->isOut || player->isFolded) {
++it; ++it;
continue; continue;
} }
winning.participants.push_back(player); winning.participants.push_back(player);
winning.winnings[player] = player->getWinning(); winning.winnings[player] = player->getWinning();
++it; ++it;
} }
// Compare participating players // Compare participating players
auto it2 = winning.participants.begin(); auto it2 = winning.participants.begin();
while(it2 != winning.participants.end()) { while(it2 != winning.participants.end()) {
auto playerLeft = *it2; auto playerLeft = *it2;
auto winnerLeft = &winning.winnings[playerLeft]; auto winnerLeft = &winning.winnings[playerLeft];
bool_t isWinner = true; bool_t isWinner = true;
enum CardValue highNumber = CARD_VALUE_INVALD; enum CardValue highNumber = CARD_VALUE_INVALD;
enum CardValue number = CARD_VALUE_INVALD; enum CardValue number = CARD_VALUE_INVALD;
struct Card highCard(0xFF); struct Card highCard(0xFF);
struct Card card(0xFF); struct Card card(0xFF);
auto it3 = winning.participants.begin(); auto it3 = winning.participants.begin();
while(it3 != winning.participants.end()) { while(it3 != winning.participants.end()) {
if(it2 == it3) { if(it2 == it3) {
++it3; ++it3;
continue; continue;
} }
auto playerRight = *it3; auto playerRight = *it3;
auto winnerRight = &winning.winnings[playerRight]; auto winnerRight = &winning.winnings[playerRight];
// Am I the better hand / Is it the better hand? // Am I the better hand / Is it the better hand?
if(winnerLeft->type < winnerRight->type) { if(winnerLeft->type < winnerRight->type) {
++it3; ++it3;
continue; continue;
} }
if(winnerLeft->type > winnerRight->type) { if(winnerLeft->type > winnerRight->type) {
isWinner = false; isWinner = false;
break; break;
} }
// Equal, compare hands. // Equal, compare hands.
card = PokerWinning::compare(winnerLeft, winnerRight); card = PokerWinning::compare(winnerLeft, winnerRight);
if(card.cardValue == 0xFF) { if(card.cardValue == 0xFF) {
isWinner = false; isWinner = false;
break; break;
} }
// Determine high card. // Determine high card.
number = card.getValue(); number = card.getValue();
if( if(
highNumber == CARD_VALUE_INVALD || highNumber == CARD_VALUE_INVALD ||
number == CARD_ACE || number == CARD_ACE ||
number > highNumber number > highNumber
) { ) {
highCard = card; highCard = card;
highNumber = number; highNumber = number;
} }
++it3; ++it3;
} }
if(!isWinner) { if(!isWinner) {
++it2; ++it2;
continue; continue;
} }
winnerLeft->kicker = highCard; winnerLeft->kicker = highCard;
winning.winners.push_back(playerLeft); winning.winners.push_back(playerLeft);
++it2; ++it2;
} }
winning.chipsEach = this->chips / (int32_t)winning.winners.size(); winning.chipsEach = this->chips / (int32_t)winning.winners.size();
winning.chipsOverflow = this->chips - ( winning.chipsOverflow = this->chips - (
winning.chipsEach * (int32_t)winning.winners.size() winning.chipsEach * (int32_t)winning.winners.size()
); );
return winning; return winning;
} }

@ -1,29 +1,29 @@
// Copyright (c) 2022 Dominic Masters // Copyright (c) 2022 Dominic Masters
// //
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#pragma once #pragma once
#include "PokerGameEvent.hpp" #include "PokerGameEvent.hpp"
namespace Dawn { namespace Dawn {
class PokerNewBettingRoundEvent : public PokerGameEvent { class PokerNewBettingRoundEvent : public PokerGameEvent {
protected: protected:
void onStart(IVisualNovelEvent *previous) override { void onStart(IVisualNovelEvent *previous) override {
PokerGameEvent::onStart(previous); PokerGameEvent::onStart(previous);
std::cout << "New Betting Round" << std::endl; std::cout << "New Betting Round" << std::endl;
this->pokerGame->newBettingRound(); this->pokerGame->newBettingRound();
} }
bool_t onUpdate() override { bool_t onUpdate() override {
return false; return false;
} }
void onEnd() override { void onEnd() override {
} }
public: public:
PokerNewBettingRoundEvent(VisualNovelManager *manager) : PokerGameEvent(manager) { PokerNewBettingRoundEvent(VisualNovelManager *manager) : PokerGameEvent(manager) {
} }
}; };
} }

@ -1,46 +1,46 @@
// Copyright (c) 2022 Dominic Masters // Copyright (c) 2022 Dominic Masters
// //
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#pragma once #pragma once
#include "PokerGameEvent.hpp" #include "PokerGameEvent.hpp"
#include "poker/PokerPot.hpp" #include "poker/PokerPot.hpp"
namespace Dawn { namespace Dawn {
class PokerWinnerEvent : public PokerGameEvent { class PokerWinnerEvent : public PokerGameEvent {
protected: protected:
void onStart(IVisualNovelEvent *previous) override { void onStart(IVisualNovelEvent *previous) override {
PokerGameEvent::onStart(previous); PokerGameEvent::onStart(previous);
std::cout << "Poker Winning" << std::endl; std::cout << "Poker Winning" << std::endl;
// Calculate // Calculate
auto it = this->pokerGame->pots.begin(); auto it = this->pokerGame->pots.begin();
while(it != this->pokerGame->pots.end()) { while(it != this->pokerGame->pots.end()) {
auto pot = &(*it); auto pot = &(*it);
this->winnings[pot] = pot->getWinners(this->pokerGame); this->winnings[pot] = pot->getWinners(this->pokerGame);
++it; ++it;
} }
// Award // Award
auto it2 = this->winnings.begin(); auto it2 = this->winnings.begin();
while(it2 != this->winnings.end()) { while(it2 != this->winnings.end()) {
it2->second.award(); it2->second.award();
it2++; it2++;
} }
} }
bool_t onUpdate() override { bool_t onUpdate() override {
return false; return false;
} }
void onEnd() override { void onEnd() override {
} }
public: public:
std::map<struct PokerPot*, struct PokerPotWinning> winnings; std::map<struct PokerPot*, struct PokerPotWinning> winnings;
PokerWinnerEvent(VisualNovelManager *manager) : PokerGameEvent(manager) { PokerWinnerEvent(VisualNovelManager *manager) : PokerGameEvent(manager) {
} }
}; };
} }