From c1d6885970dd614d273cae5121b16a670935d459 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sat, 26 Nov 2022 14:31:06 -0800 Subject: [PATCH] Fixed some bugs with AI --- cmake/hosts/CMakeLists.txt | 2 +- cmake/hosts/build-host-win32/CMakeLists.txt | 6 ++ src/dawn/poker/PokerGame.hpp | 2 +- src/dawn/poker/PokerPlayer.cpp | 16 ++++- src/dawn/poker/PokerPlayer.hpp | 5 ++ src/dawn/poker/PokerTurn.cpp | 28 ++++++++- src/dawn/poker/PokerTurn.hpp | 9 ++- .../poker/visualnovel/PokerAIBetEvent.hpp | 13 ++-- src/dawn/poker/visualnovel/PokerDealEvent.hpp | 5 +- .../visualnovel/PokerDetermineBetterEvent.cpp | 57 ++++++++---------- .../visualnovel/PokerDetermineBetterEvent.hpp | 7 +-- src/dawn/poker/visualnovel/PokerGameEvent.hpp | 2 +- .../poker/visualnovel/PokerNewGameEvent.hpp | 5 +- .../poker/visualnovel/PokerNewRoundEvent.hpp | 5 +- .../visualnovel/PokerTakeBlindsEvent.hpp | 5 +- src/dawn/poker/visualnovel/PokerTurnEvent.hpp | 4 +- src/dawn/ui/UIBorder.cpp | 10 ---- src/dawn/ui/UIBorder.hpp | 2 +- src/dawn/visualnovel/VisualNovelManager.cpp | 28 +++++---- src/dawn/visualnovel/VisualNovelManager.hpp | 18 +++--- .../visualnovel/events/SimpleLoopEvent.hpp | 31 ++++++++++ .../events/VisualNovelTextboxEvent.cpp | 13 +++- .../events/VisualNovelTextboxEvent.hpp | 3 +- src/dawnpokergame/scenes/TestScene.hpp | 29 ++------- .../visualnovel/events/PokerBetLoopEvent.hpp | 59 +++++++++++++++++++ 25 files changed, 245 insertions(+), 119 deletions(-) create mode 100644 cmake/hosts/build-host-win32/CMakeLists.txt create mode 100644 src/dawn/visualnovel/events/SimpleLoopEvent.hpp create mode 100644 src/dawnpokergame/visualnovel/events/PokerBetLoopEvent.hpp diff --git a/cmake/hosts/CMakeLists.txt b/cmake/hosts/CMakeLists.txt index e13990de..3fcc45c7 100644 --- a/cmake/hosts/CMakeLists.txt +++ b/cmake/hosts/CMakeLists.txt @@ -5,7 +5,7 @@ # Check for build target, or default if(WIN32) - set(DAWN_BUILD_HOST "") + set(DAWN_BUILD_HOST "build-host-win32") elseif(UNIX AND NOT APPLE) set(DAWN_BUILD_HOST "build-host-linux64") endif() diff --git a/cmake/hosts/build-host-win32/CMakeLists.txt b/cmake/hosts/build-host-win32/CMakeLists.txt new file mode 100644 index 00000000..11e150c8 --- /dev/null +++ b/cmake/hosts/build-host-win32/CMakeLists.txt @@ -0,0 +1,6 @@ +# Copyright (c) 2022 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +set(DAWN_BUILD_HOST_LIBS "" CACHE INTERNAL ${DAWN_CACHE_TARGET}) \ No newline at end of file diff --git a/src/dawn/poker/PokerGame.hpp b/src/dawn/poker/PokerGame.hpp index b2281866..c884cf50 100644 --- a/src/dawn/poker/PokerGame.hpp +++ b/src/dawn/poker/PokerGame.hpp @@ -26,12 +26,12 @@ namespace Dawn { uint8_t dealerIndex; uint8_t smallBlindIndex; uint8_t bigBlindIndex; - uint8_t betterIndex; int32_t smallBlind = POKER_BLIND_SMALL_DEFAULT; int32_t bigBlind = POKER_BLIND_BIG_DEFAULT; public: std::vector players; + uint8_t betterIndex; PokerGame(SceneItem *item); diff --git a/src/dawn/poker/PokerPlayer.cpp b/src/dawn/poker/PokerPlayer.cpp index 888e012d..cbb4688d 100644 --- a/src/dawn/poker/PokerPlayer.cpp +++ b/src/dawn/poker/PokerPlayer.cpp @@ -42,7 +42,11 @@ void PokerPlayer::bet(struct PokerPot *pot, int32_t chips) { this->chips -= chips; this->currentBet += chips; this->hasBetThisRound = true; - if(chips > 0) this->timesRaised++; + if(chips > 0) { + this->timesRaised++; + } else { + this->timesRaised = 0; + } pot->chips += chips; pot->call = mathMax(pot->call, this ->currentBet); @@ -56,6 +60,12 @@ void PokerPlayer::bet(int32_t chips) { this->bet(&this->pokerGame->pots.back(), chips); } +void PokerPlayer::fold() { + this->isFolded = true; + this->hasBetThisRound = true; + this->timesRaised = 0; +} + bool_t PokerPlayer::canCheck() { return this->pokerGame->getCurrentCallValue() <= this->currentBet; } @@ -96,7 +106,7 @@ struct PokerTurn PokerPlayer::getAITurn() { ); // Get card weight - float_t confidence = (float_t)cardNumber0 + (float_t)cardNumber1; + confidence = (float_t)cardNumber0 + (float_t)cardNumber1; if(cardNumber0 == cardNumber1) {// Pairs confidence += 6; } else if(suitNumber0 == suitNumber1) {// Same suit @@ -214,7 +224,7 @@ struct PokerTurn PokerPlayer::getAITurn() { turn = PokerTurn::bet(this, 0); turn.confidence = 1; } else { - turn = PokerTurn::fold(); + turn = PokerTurn::fold(this); turn.confidence = 1 - confidence; } diff --git a/src/dawn/poker/PokerPlayer.hpp b/src/dawn/poker/PokerPlayer.hpp index eac233c8..a38c9b5c 100644 --- a/src/dawn/poker/PokerPlayer.hpp +++ b/src/dawn/poker/PokerPlayer.hpp @@ -76,6 +76,11 @@ namespace Dawn { */ void bet(int32_t amount); + /** + * Player folds. + */ + void fold(); + /** * Returns the AI result for a turn done by a non human player. * diff --git a/src/dawn/poker/PokerTurn.cpp b/src/dawn/poker/PokerTurn.cpp index c7b1731a..4598aa6e 100644 --- a/src/dawn/poker/PokerTurn.cpp +++ b/src/dawn/poker/PokerTurn.cpp @@ -16,6 +16,7 @@ struct PokerTurn PokerTurn::bet(PokerPlayer *player, int32_t chips) { assertNotNull(player); assertTrue(chips >= 0); + turn.player = player; turn.confidence = 1; if(chips == 0) { @@ -37,10 +38,35 @@ struct PokerTurn PokerTurn::bet(PokerPlayer *player, int32_t chips) { return turn; } -struct PokerTurn PokerTurn::fold() { +struct PokerTurn PokerTurn::fold(PokerPlayer *player) { struct PokerTurn turn; + turn.player = player; turn.chips = 0; turn.confidence = 1; turn.type = POKER_TURN_TYPE_FOLD; return turn; +} + +void PokerTurn::action() { + assertNotNull(this->player); + + switch(this->type) { + case POKER_TURN_TYPE_BET: + case POKER_TURN_TYPE_CALL: + case POKER_TURN_TYPE_ALL_IN: + this->player->bet(this->chips); + break; + + case POKER_TURN_TYPE_CHECK: + player->bet(0); + break; + + case POKER_TURN_TYPE_FOLD: + player->fold(); + break; + + default: + assertUnreachable(); + break; + } } \ No newline at end of file diff --git a/src/dawn/poker/PokerTurn.hpp b/src/dawn/poker/PokerTurn.hpp index 75d4129b..42e9aa95 100644 --- a/src/dawn/poker/PokerTurn.hpp +++ b/src/dawn/poker/PokerTurn.hpp @@ -26,6 +26,8 @@ namespace Dawn { int32_t chips; /** How confident the AI is about their turn. 0 = none, 1 = full */ float_t confidence; + /** Player that this action belongs to */ + PokerPlayer *player; /** * Generate a turn action for betting as a player. @@ -41,6 +43,11 @@ namespace Dawn { * * @return A turn for a fold action. */ - static struct PokerTurn fold(); + static struct PokerTurn fold(PokerPlayer *player); + + /** + * Actions / Performs this turn against the defined player. + */ + void action(); }; } \ No newline at end of file diff --git a/src/dawn/poker/visualnovel/PokerAIBetEvent.hpp b/src/dawn/poker/visualnovel/PokerAIBetEvent.hpp index 1f02023e..59b608a7 100644 --- a/src/dawn/poker/visualnovel/PokerAIBetEvent.hpp +++ b/src/dawn/poker/visualnovel/PokerAIBetEvent.hpp @@ -9,14 +9,16 @@ #define POKER_DEAL_EVENT_CARD_COUNT 2 namespace Dawn { - class PokerDealEvent : public PokerGameEvent { + class PokerAIBetEvent : public PokerGameEvent { protected: - void onStart() override { - PokerGameEvent::onStart(); + void onStart(IVisualNovelEvent *previous) override { + PokerGameEvent::onStart(previous); auto better = this->pokerGame->getNextBetterIndex(); - this->pokerGame->better = better; + this->pokerGame->betterIndex = better; auto player = this->pokerGame->players[better]; + this->turn = player->getAITurn(); + this->turn.action(); } bool_t onUpdate() override { @@ -28,8 +30,9 @@ namespace Dawn { public: uint8_t better; + struct PokerTurn turn; - PokerDealEvent(VisualNovelManager *manager) : PokerGameEvent(manager) { + PokerAIBetEvent(VisualNovelManager *manager) : PokerGameEvent(manager) { } }; } \ No newline at end of file diff --git a/src/dawn/poker/visualnovel/PokerDealEvent.hpp b/src/dawn/poker/visualnovel/PokerDealEvent.hpp index 5c86374a..53011e59 100644 --- a/src/dawn/poker/visualnovel/PokerDealEvent.hpp +++ b/src/dawn/poker/visualnovel/PokerDealEvent.hpp @@ -11,8 +11,9 @@ namespace Dawn { class PokerDealEvent : public PokerGameEvent { protected: - void onStart() override { - PokerGameEvent::onStart(); + void onStart(IVisualNovelEvent *previous) override { + PokerGameEvent::onStart(previous); + std::cout << "Dealing to everyone" << std::endl; this->pokerGame->dealToEveryone(POKER_DEAL_EVENT_CARD_COUNT); } diff --git a/src/dawn/poker/visualnovel/PokerDetermineBetterEvent.cpp b/src/dawn/poker/visualnovel/PokerDetermineBetterEvent.cpp index 88e01be0..391c941a 100644 --- a/src/dawn/poker/visualnovel/PokerDetermineBetterEvent.cpp +++ b/src/dawn/poker/visualnovel/PokerDetermineBetterEvent.cpp @@ -10,32 +10,44 @@ using namespace Dawn; PokerDetermineBetterEvent::PokerDetermineBetterEvent(VisualNovelManager *man) : PokerGameEvent(man) { - + std::cout << "Inited determine better" << std::endl << std::endl; } -void PokerDetermineBetterEvent::onStart() { - PokerGameEvent::onStart(); +void PokerDetermineBetterEvent::onStart(IVisualNovelEvent *previous) { + PokerGameEvent::onStart(previous); + + std::cout << "better evt" << std::endl; if(this->pokerGame->getRemainingPlayersCount() <= 1) { - this->doNext = this->eventEveryoneFolded; + this->then(this->eventEveryoneFolded); + this->eventEveryoneFolded = nullptr; + std::cout << "Everyone folded" << std::endl; return; } uint8_t nextBetterIndex = this->pokerGame->getNextBetterIndex(); if(nextBetterIndex == 0xFF) { if(this->pokerGame->getCountOfCardsToTurn() == 0xFF) { - this->doNext = this->eventBettingFinished; + this->then(this->eventBettingFinished); + this->eventBettingFinished = nullptr; + std::cout << "Betting Finished" << std::endl; } else { - this->doNext = this->eventTurn; + this->then(this->eventTurn); + this->eventTurn = nullptr; + std::cout << "Turn Time?" << std::endl; } return; } auto nextBetter = this->pokerGame->players[nextBetterIndex]; if(nextBetter->isHuman) { - this->doNext = this->eventHumanBet; + this->then(this->eventHumanBet); + this->eventHumanBet = nullptr; + std::cout << "Human Better" << std::endl; } else { - this->doNext = this->eventAiBet; + this->then(this->eventAiBet); + this->eventAiBet = nullptr; + std::cout << "AI Better" << std::endl; } } @@ -47,28 +59,9 @@ void PokerDetermineBetterEvent::onEnd() { } PokerDetermineBetterEvent::~PokerDetermineBetterEvent() { - if( - this->eventEveryoneFolded != nullptr && - this->eventEveryoneFolded != this->doNext - ) delete this->eventEveryoneFolded; - - if( - this->eventBettingFinished != nullptr && - this->eventBettingFinished != this->doNext - ) delete this->eventBettingFinished; - - if( - this->eventTurn != nullptr && - this->eventTurn != this->doNext - ) delete this->eventTurn; - - if( - this->eventAiBet != nullptr && - this->eventAiBet != this->doNext - ) delete this->eventAiBet; - - if( - this->eventHumanBet != nullptr && - this->eventHumanBet != this->doNext - ) delete this->eventHumanBet; + if(this->eventEveryoneFolded != nullptr) delete this->eventEveryoneFolded; + if(this->eventBettingFinished != nullptr) delete this->eventBettingFinished; + if(this->eventTurn != nullptr) delete this->eventTurn; + if(this->eventAiBet != nullptr) delete this->eventAiBet; + if(this->eventHumanBet != nullptr) delete this->eventHumanBet; } \ No newline at end of file diff --git a/src/dawn/poker/visualnovel/PokerDetermineBetterEvent.hpp b/src/dawn/poker/visualnovel/PokerDetermineBetterEvent.hpp index 6a3c1b77..5b2ad227 100644 --- a/src/dawn/poker/visualnovel/PokerDetermineBetterEvent.hpp +++ b/src/dawn/poker/visualnovel/PokerDetermineBetterEvent.hpp @@ -15,7 +15,7 @@ namespace Dawn { IVisualNovelEvent * eventAiBet = nullptr; IVisualNovelEvent * eventHumanBet = nullptr; - void onStart() override; + void onStart(IVisualNovelEvent *previous) override; bool_t onUpdate() override; void onEnd() override; @@ -37,7 +37,6 @@ namespace Dawn { T * whenEveryoneFolded(T *event) { assertNotNull(event); this->eventEveryoneFolded = event; - event->previous = this; return event; } @@ -51,7 +50,6 @@ namespace Dawn { T * whenBettingFinished(T *event) { assertNotNull(event); this->eventBettingFinished = event; - event->previous = this; return event; } @@ -66,7 +64,6 @@ namespace Dawn { T * whenTurn(T *event) { assertNotNull(event); this->eventTurn = event; - event->previous = this; return event; } @@ -80,7 +77,6 @@ namespace Dawn { T * whenAiBet(T *event) { assertNotNull(event); this->eventAiBet = event; - event->previous = this; return event; } @@ -94,7 +90,6 @@ namespace Dawn { T * whenHumanBet(T *event) { assertNotNull(event); this->eventHumanBet = event; - event->previous = this; return event; } diff --git a/src/dawn/poker/visualnovel/PokerGameEvent.hpp b/src/dawn/poker/visualnovel/PokerGameEvent.hpp index 7823e1da..0d5283bd 100644 --- a/src/dawn/poker/visualnovel/PokerGameEvent.hpp +++ b/src/dawn/poker/visualnovel/PokerGameEvent.hpp @@ -12,7 +12,7 @@ namespace Dawn { protected: PokerGame *pokerGame; - void onStart() override { + void onStart(IVisualNovelEvent *previous) override { pokerGame = this->manager->getScene()->findComponent(); assertNotNull(pokerGame); } diff --git a/src/dawn/poker/visualnovel/PokerNewGameEvent.hpp b/src/dawn/poker/visualnovel/PokerNewGameEvent.hpp index 8a0aac25..4cf0893b 100644 --- a/src/dawn/poker/visualnovel/PokerNewGameEvent.hpp +++ b/src/dawn/poker/visualnovel/PokerNewGameEvent.hpp @@ -9,8 +9,9 @@ namespace Dawn { class PokerNewGameEvent : public PokerGameEvent { protected: - void onStart() override { - PokerGameEvent::onStart(); + void onStart(IVisualNovelEvent *previous) override { + PokerGameEvent::onStart(previous); + std::cout << "New Game" << std::endl; this->pokerGame->newGame(); } diff --git a/src/dawn/poker/visualnovel/PokerNewRoundEvent.hpp b/src/dawn/poker/visualnovel/PokerNewRoundEvent.hpp index ee8128ec..bdd6e4ab 100644 --- a/src/dawn/poker/visualnovel/PokerNewRoundEvent.hpp +++ b/src/dawn/poker/visualnovel/PokerNewRoundEvent.hpp @@ -9,8 +9,9 @@ namespace Dawn { class PokerNewRoundEvent : public PokerGameEvent { protected: - void onStart() override { - PokerGameEvent::onStart(); + void onStart(IVisualNovelEvent *previous) override { + PokerGameEvent::onStart(previous); + std::cout << "New Round" << std::endl; this->pokerGame->newRound(); } diff --git a/src/dawn/poker/visualnovel/PokerTakeBlindsEvent.hpp b/src/dawn/poker/visualnovel/PokerTakeBlindsEvent.hpp index b0cc0c07..1828c11d 100644 --- a/src/dawn/poker/visualnovel/PokerTakeBlindsEvent.hpp +++ b/src/dawn/poker/visualnovel/PokerTakeBlindsEvent.hpp @@ -9,8 +9,9 @@ namespace Dawn { class PokerTakeBlindsEvent : public PokerGameEvent { protected: - void onStart() override { - PokerGameEvent::onStart(); + void onStart(IVisualNovelEvent *previous) override { + PokerGameEvent::onStart(previous); + std::cout << "Take Blinds" << std::endl; this->pokerGame->takeBlinds(); } diff --git a/src/dawn/poker/visualnovel/PokerTurnEvent.hpp b/src/dawn/poker/visualnovel/PokerTurnEvent.hpp index 5009eb95..6da5806f 100644 --- a/src/dawn/poker/visualnovel/PokerTurnEvent.hpp +++ b/src/dawn/poker/visualnovel/PokerTurnEvent.hpp @@ -9,8 +9,8 @@ namespace Dawn { class PokerTurnEvent : public PokerGameEvent { protected: - void onStart() override { - PokerGameEvent::onStart(); + void onStart(IVisualNovelEvent *previous) override { + PokerGameEvent::onStart(previous); this->cardsTurned = this->pokerGame->getCountOfCardsToTurn(); assertTrue(this->cardsTurned != 0xFF); diff --git a/src/dawn/ui/UIBorder.cpp b/src/dawn/ui/UIBorder.cpp index 6fe5c3c6..d841c5e2 100644 --- a/src/dawn/ui/UIBorder.cpp +++ b/src/dawn/ui/UIBorder.cpp @@ -10,15 +10,6 @@ using namespace Dawn; UIBorder::UIBorder(UICanvas *canvas) : UIComponent(canvas) { this->mesh.createBuffers(QUAD_VERTICE_COUNT * 9, QUAD_INDICE_COUNT * 9); - this->texture = new Texture(); - this->texture->setSize(3, 3); - struct Color pixels[9] = { - COLOR_WHITE, COLOR_RED, COLOR_BLUE, - COLOR_GREEN, COLOR_MAGENTA, COLOR_BLACK, - COLOR_CORNFLOWER_BLUE, COLOR_WHITE, COLOR_MAGENTA - }; - this->texture->buffer(pixels); - this->updatePositions(); } @@ -134,5 +125,4 @@ glm::vec2 UIBorder::getBorderSize() { } UIBorder::~UIBorder() { - delete this->texture; } \ No newline at end of file diff --git a/src/dawn/ui/UIBorder.hpp b/src/dawn/ui/UIBorder.hpp index 1e3b3ffe..6c1c9d88 100644 --- a/src/dawn/ui/UIBorder.hpp +++ b/src/dawn/ui/UIBorder.hpp @@ -20,7 +20,7 @@ namespace Dawn { void drawSelf(UIShader *shader, glm::mat4 selfTransform) override; public: - Texture *texture; + Texture *texture = nullptr; UIBorder(UICanvas *canvas); diff --git a/src/dawn/visualnovel/VisualNovelManager.cpp b/src/dawn/visualnovel/VisualNovelManager.cpp index 0cf56c7d..29b55065 100644 --- a/src/dawn/visualnovel/VisualNovelManager.cpp +++ b/src/dawn/visualnovel/VisualNovelManager.cpp @@ -29,14 +29,9 @@ void VisualNovelManager::onStart() { void VisualNovelManager::onUnpausedUpdate() { if(this->currentEvent == nullptr) return; - if(!this->currentEvent->hasStarted) { - this->currentEvent->start(); - } - + if(!this->currentEvent->hasStarted) this->currentEvent->start(nullptr); if(this->currentEvent->update()) return; - auto oldCurrent = this->currentEvent; - this->currentEvent = this->currentEvent->end(); - delete oldCurrent; + this->setEvent(this->currentEvent->end()); } VisualNovelManager::~VisualNovelManager() { @@ -46,15 +41,18 @@ VisualNovelManager::~VisualNovelManager() { this->getScene()->eventSceneUnpausedUpdate.removeListener(this, &VisualNovelManager::onUnpausedUpdate); } -// Visual Novel Event + +// // // // // // // // // // // // // // // // // // // // // // // // // // // + + IVisualNovelEvent::IVisualNovelEvent(VisualNovelManager *man) { assertNotNull(man); this->manager = man; } -void IVisualNovelEvent::start() { - this->onStart(); +void IVisualNovelEvent::start(IVisualNovelEvent *previous) { this->hasStarted = true; + this->onStart(previous); } bool_t IVisualNovelEvent::update() { @@ -64,14 +62,18 @@ bool_t IVisualNovelEvent::update() { IVisualNovelEvent * IVisualNovelEvent::end() { this->onEnd(); + std::cout << "End"; + if(this->doNext != nullptr) { + std::cout << " Nexter" << std::endl; auto next = this->doNext; + this->doNext = nullptr; return next; } + std::cout << " No nxt" << std::endl; + return nullptr; } IVisualNovelEvent::~IVisualNovelEvent() { - if(!this->hasStarted && this->doNext != nullptr) { - delete this->doNext; - } + if(this->doNext != nullptr) delete this->doNext; } \ No newline at end of file diff --git a/src/dawn/visualnovel/VisualNovelManager.hpp b/src/dawn/visualnovel/VisualNovelManager.hpp index 74632d79..829df1a3 100644 --- a/src/dawn/visualnovel/VisualNovelManager.hpp +++ b/src/dawn/visualnovel/VisualNovelManager.hpp @@ -15,10 +15,12 @@ namespace Dawn { UICanvas *uiCanvas; IVisualNovelEvent* currentEvent = nullptr; + public: + /** Event listener for unpaused scene updates. */ void onUnpausedUpdate(); - public: + VisualNovelTextbox *textBox; /** * Constructs a visual novel manager, scene item component. @@ -35,8 +37,10 @@ namespace Dawn { */ template T * setEvent(T *event) { - assertNotNull(event); + auto oldCurrent = this->currentEvent; this->currentEvent = event; + if(event != nullptr) this->currentEvent->start(oldCurrent); + delete oldCurrent; return event; } @@ -60,26 +64,22 @@ namespace Dawn { protected: VisualNovelManager *manager; IVisualNovelEvent *doNext = nullptr; - bool_t hasStarted; + bool_t hasStarted = false; - virtual void onStart() = 0; + virtual void onStart(IVisualNovelEvent *previous) = 0; virtual bool_t onUpdate() = 0; virtual void onEnd() = 0; public: - IVisualNovelEvent *previous = nullptr; - IVisualNovelEvent(VisualNovelManager *manager); template T * then(T *next) { - assertNotNull(next); this->doNext = next; - next->previous = this; return next; } - void start(); + void start(IVisualNovelEvent *previous); bool_t update(); IVisualNovelEvent * end(); diff --git a/src/dawn/visualnovel/events/SimpleLoopEvent.hpp b/src/dawn/visualnovel/events/SimpleLoopEvent.hpp new file mode 100644 index 00000000..54a7fbaa --- /dev/null +++ b/src/dawn/visualnovel/events/SimpleLoopEvent.hpp @@ -0,0 +1,31 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "visualnovel/VisualNovelManager.hpp" + +namespace Dawn { + class SimpleLoopEvent : public IVisualNovelEvent { + protected: + std::string text; + + void onStart(IVisualNovelEvent *previous) override { + this->then(new SimpleLoopEvent(this->manager)); + } + + bool_t onUpdate() override { + return false; + } + + void onEnd() override { + + } + + public: + SimpleLoopEvent(VisualNovelManager *man) : IVisualNovelEvent(man) { + + } + }; +} \ No newline at end of file diff --git a/src/dawn/visualnovel/events/VisualNovelTextboxEvent.cpp b/src/dawn/visualnovel/events/VisualNovelTextboxEvent.cpp index 8d199a86..3f3cc04b 100644 --- a/src/dawn/visualnovel/events/VisualNovelTextboxEvent.cpp +++ b/src/dawn/visualnovel/events/VisualNovelTextboxEvent.cpp @@ -14,12 +14,23 @@ VisualNovelTextboxEvent::VisualNovelTextboxEvent( this->text = text; } -void VisualNovelTextboxEvent::onStart() { +void VisualNovelTextboxEvent::onStart(IVisualNovelEvent *previous) { + if(this->manager->textBox == nullptr) return; + this->manager->textBox->setText(this->text); this->manager->textBox->show(); + this->hasSetText = true; } bool_t VisualNovelTextboxEvent::onUpdate() { + if(this->manager->textBox == nullptr) return true; + + if(!this->hasSetText) { + this->manager->textBox->setText(this->text); + this->manager->textBox->show(); + this->hasSetText = true; + } + return this->manager->textBox->isVisible(); } diff --git a/src/dawn/visualnovel/events/VisualNovelTextboxEvent.hpp b/src/dawn/visualnovel/events/VisualNovelTextboxEvent.hpp index 625b1e90..6606674d 100644 --- a/src/dawn/visualnovel/events/VisualNovelTextboxEvent.hpp +++ b/src/dawn/visualnovel/events/VisualNovelTextboxEvent.hpp @@ -10,8 +10,9 @@ namespace Dawn { class VisualNovelTextboxEvent : public IVisualNovelEvent { protected: std::string text; + bool_t hasSetText = false; - void onStart() override; + void onStart(IVisualNovelEvent *previous) override; bool_t onUpdate() override; void onEnd() override; diff --git a/src/dawnpokergame/scenes/TestScene.hpp b/src/dawnpokergame/scenes/TestScene.hpp index 10d89242..77057654 100644 --- a/src/dawnpokergame/scenes/TestScene.hpp +++ b/src/dawnpokergame/scenes/TestScene.hpp @@ -11,18 +11,16 @@ #include "visualnovel/VisualNovelManager.hpp" #include "visualnovel/events/VisualNovelTextboxEvent.hpp" #include "poker/PokerGame.hpp" -#include "poker/visualnovel/PokerNewGameEvent.hpp" -#include "poker/visualnovel/PokerNewRoundEvent.hpp" -#include "poker/visualnovel/PokerTakeBlindsEvent.hpp" -#include "poker/visualnovel/PokerDealEvent.hpp" -#include "poker/visualnovel/PokerTurnEvent.hpp" -#include "poker/visualnovel/PokerDetermineBetterEvent.hpp" +#include "visualnovel/events/PokerBetLoopEvent.hpp" +#include "visualnovel/events/SimpleLoopEvent.hpp" namespace Dawn { class TestScene { public: static Scene * create(DawnGame *game) { - Scene *scene = new Scene(game); + Scene *scene; + + scene = new Scene(game); // Camera auto camera = Camera::create(scene); @@ -55,22 +53,7 @@ namespace Dawn { ->then(new VisualNovelTextboxEvent(vnManager, "Blinds Taken")) ->then(new PokerDealEvent(vnManager)) ->then(new VisualNovelTextboxEvent(vnManager, "Cards Dealt")) - ->then(new PokerDetermineBetterEvent(vnManager)) - ; - betting - ->whenEveryoneFolded(new VisualNovelTextboxEvent(vnManager, "Everyone Folded")) - ; - betting - ->whenBettingFinished(new VisualNovelTextboxEvent(vnManager, "Betting Finished")) - ; - betting - ->whenTurn(new VisualNovelTextboxEvent(vnManager, "Turn Time")) - ; - betting - ->whenAiBet(new VisualNovelTextboxEvent(vnManager, "AI Bet")) - ; - betting - ->whenHumanBet(new VisualNovelTextboxEvent(vnManager, "Human Bet")) + ->then(new PokerBetLoopEvent(vnManager)) ; return scene; diff --git a/src/dawnpokergame/visualnovel/events/PokerBetLoopEvent.hpp b/src/dawnpokergame/visualnovel/events/PokerBetLoopEvent.hpp new file mode 100644 index 00000000..b1d6dc06 --- /dev/null +++ b/src/dawnpokergame/visualnovel/events/PokerBetLoopEvent.hpp @@ -0,0 +1,59 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "poker/visualnovel/PokerNewGameEvent.hpp" +#include "poker/visualnovel/PokerNewRoundEvent.hpp" +#include "poker/visualnovel/PokerTakeBlindsEvent.hpp" +#include "poker/visualnovel/PokerDealEvent.hpp" +#include "poker/visualnovel/PokerTurnEvent.hpp" +#include "poker/visualnovel/PokerDetermineBetterEvent.hpp" +#include "poker/visualnovel/PokerAIBetEvent.hpp" + +#define POKER_DEAL_EVENT_CARD_COUNT 2 + +namespace Dawn { + class PokerBetLoopEvent : public PokerGameEvent { + protected: + void onStart(IVisualNovelEvent *previous) override { + PokerGameEvent::onStart(previous); + std::cout << "Bet Loop, bet" << std::endl; + + auto evt2 = new PokerDetermineBetterEvent(this->manager); + + auto betting = this->then(evt2); + betting + ->whenEveryoneFolded(new VisualNovelTextboxEvent(this->manager, "Everyone Folded")) + ; + betting + ->whenBettingFinished(new VisualNovelTextboxEvent(this->manager, "Betting Finished")) + ; + betting + ->whenTurn(new VisualNovelTextboxEvent(this->manager, "Turn Time")) + ; + betting + ->whenAiBet(new PokerAIBetEvent(this->manager)) + ->then(new VisualNovelTextboxEvent(this->manager, "AI Bet")) + ->then(new PokerBetLoopEvent(this->manager)) + ; + betting + ->whenHumanBet(new VisualNovelTextboxEvent(this->manager, "Human Bet")) + ->then(new PokerBetLoopEvent(this->manager)) + ; + } + + bool_t onUpdate() override { + return false; + } + + void onEnd() override { + std::cout << "Bet lop fin" << std::endl; + } + + public: + PokerBetLoopEvent(VisualNovelManager *manager) : PokerGameEvent(manager) { + } + }; +} \ No newline at end of file