Moved poker to the games dir
This commit is contained in:
1 parent
0f9e9f2ccc
commit
451b5b067e
27 files changed
+184
-184
No files matched your search
@@ -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)
|
||||
|
||||
@@ -4,4 +4,5 @@
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(poker)
|
||||
add_subdirectory(tictactoe)
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -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;
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+28
-28
@@ -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) {
|
||||
}
|
||||
};
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+45
-45
@@ -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<struct PokerPot*, struct PokerPotWinning> 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<struct PokerPot*, struct PokerPotWinning> winnings;
|
||||
|
||||
PokerWinnerEvent(VisualNovelManager *manager) : PokerGameEvent(manager) {
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user