Progress has been made.

This commit is contained in:
2022-05-15 01:08:03 -07:00
parent d6a06d851a
commit 9756b4eb7d
12 changed files with 338 additions and 219 deletions

View File

@@ -0,0 +1,120 @@
/**
* Copyright (c) 2022 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "better.h"
#include "../../poker/poker.h"
#include "../textbox.h"
void conversationQueueBeginBetting() {
pokerturn_t turn;
turn.chips = 0;
// Begin the betting process. First we need to decide if the player or the
// AI is betting, then based on that we decide what to do next.
// TODO: Actually bet.
if(POKER_PLAYER_BETTER == POKER_HUMAN_INDEX) {
// This is the human player.
BGB_MESSAGE("Player folding.");
conversationTextboxSetText(STR_DEBUG_PLAYER);
POKER_PLAYERS[POKER_PLAYER_BETTER].state |= POKER_PLAYER_STATE_FOLDED;
} else {
// This is an AI player, get their turn.
BGB_MESSAGE("AI turn to bet");
pokerAi(POKER_PLAYER_BETTER, &turn);
BGB_printf("AI Decided to %u, with %u chips and %u confidence, bluffin: %u", turn.type, turn.chips, turn.confidence, turn.bluff);
switch(turn.type) {
case POKER_TURN_TYPE_FOLD:
POKER_PLAYERS[POKER_PLAYER_BETTER].state |= POKER_PLAYER_STATE_FOLDED;
conversationTextboxSetText(STR_POKER_GAME_AI_FOLD);
break;
case POKER_TURN_TYPE_BET:
if(turn.bluff) {
conversationTextboxSetText(STR_POKER_GAME_AI_RAISE_BLUFF);
} else {
conversationTextboxSetText(STR_POKER_GAME_AI_RAISE);
}
break;
case POKER_TURN_TYPE_CALL:
if(turn.bluff) {
conversationTextboxSetText(STR_POKER_GAME_AI_CALL_BLUFF);
} else {
conversationTextboxSetText(STR_POKER_GAME_AI_CALL);
}
break;
case POKER_TURN_TYPE_ALL_IN:
if(turn.bluff) {
conversationTextboxSetText(STR_POKER_GAME_AI_ALL_IN_BLUFF);
} else {
conversationTextboxSetText(STR_POKER_GAME_AI_ALL_IN);
}
break;
case POKER_TURN_TYPE_CHECK:
if(turn.bluff) {
conversationTextboxSetText(STR_POKER_GAME_AI_CHECK_BLUFF);
} else {
conversationTextboxSetText(STR_POKER_GAME_AI_CHECK);
}
break;
}
// Now we have their turn, decide what to say based on that.
}
// Update bet state
POKER_PLAYERS[POKER_PLAYER_BETTER].state |= (
POKER_PLAYER_STATE_HAS_BET_THIS_ROUND
);
if(turn.chips > 0) {
pokerBet(POKER_PLAYER_BETTER, turn.chips);
}
QUEUE_ITEM = QUEUE_NEXT_BETTER;
}
void conversationQueueNextBetter() {
uint8_t i, j, countStillInGame;
// Now we decide the next better.
countStillInGame = 0;
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
//In theory I don't think the current better can ever be selected again.
// if(i == POKER_PLAYER_BETTER) continue; // Commented because we now count
// Next better is the better to the right of the current better.
j = (POKER_PLAYER_BETTER + i) % POKER_PLAYER_COUNT;
if(!pokerDoesPlayerNeedToBet(j)) {
if((POKER_PLAYERS[j].state & (POKER_PLAYER_STATE_FOLDED | POKER_PLAYER_STATE_OUT)) == 0) {
countStillInGame++;
}
continue;
}
// They haven't bet yet, make them the "next better"
POKER_PLAYER_BETTER = j;
QUEUE_ITEM = QUEUE_BEGIN_BETTING;
conversationQueueNext();
return;
}
// If we reach this point then we either need to begin the betting round, or
// we are going to move to the winning decider.
if(POKER_COMMUNITY_SIZE_MAX == POKER_COMMUNITY_SIZE || countStillInGame == 1) {
QUEUE_ITEM = QUEUE_WINNER_DECIDE;
conversationQueueNext();
return;
}
QUEUE_ITEM = QUEUE_FLOP;
conversationQueueNext();
}

View File

@@ -0,0 +1,13 @@
/**
* Copyright (c) 2022 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../../libs.h"
#include "../queue.h"
void conversationQueueBeginBetting();
void conversationQueueNextBetter();

View File

@@ -0,0 +1,57 @@
/**
* Copyright (c) 2022 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "flop.h"
#include "../queue.h"
void conversationQueueFlopTurnRiver() {
uint8_t i, count;
pokerplayer_t *player;
switch(POKER_COMMUNITY_SIZE) {
case 0:
count = POKER_COUNT_FLOP;
conversationTextboxSetText(STR_POKER_GAME_CARDS_FLOPPED);
break;
case POKER_COUNT_FLOP:
count = POKER_COUNT_TURN;
conversationTextboxSetText(STR_POKER_GAME_CARDS_TURNED);
break;
default:
count = POKER_COUNT_RIVER;
conversationTextboxSetText(STR_POKER_GAME_CARDS_RIVERED);
break;
}
// Reset each players required to bet state
do {
player = POKER_PLAYERS + i;
player->state &= ~POKER_PLAYER_STATE_HAS_BET_THIS_ROUND;
player->timesRaised = 0;
} while(++i < POKER_PLAYER_COUNT);
// In reality we'd burn the top card but that would waste some CPU I need.
// Deal the top cards.
for(i = 0; i < count; i++) {
POKER_COMMUNITY[POKER_COMMUNITY_SIZE++] = POKER_DECK[--POKER_DECK_SIZE];
}
// Check how many players need to bet, if it's zero then all players are
// either folded or all-in
if(pokerGetRemainingBetterCount() == 0x00) {
if(POKER_COMMUNITY_SIZE == POKER_COMMUNITY_SIZE_MAX) {
QUEUE_ITEM = QUEUE_WINNER_DECIDE;
} else {
QUEUE_ITEM = QUEUE_FLOP;
}
} else {
QUEUE_ITEM = QUEUE_BEGIN_BETTING;
}
}

View File

@@ -0,0 +1,13 @@
/**
* Copyright (c) 2022 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../../libs.h"
#include "../../poker/poker.h"
#include "../textbox.h"
void conversationQueueFlopTurnRiver();

View File

@@ -0,0 +1,15 @@
/**
* Copyright (c) 2022 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "gameintro.h"
#include "../queue.h"
void conversationQueueGameBegin() {
char buffer[TEXTBOX_BUFFER_MAX];
sprintf(STR_GAME_BEGIN, POKER_GAME_BLINDS_CURRENT * 2, POKER_GAME_BLINDS_CURRENT);
conversationTextboxSetText(buffer);
}

View File

@@ -0,0 +1,14 @@
/**
* Copyright (c) 2022 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../../libs.h"
#include "../../poker/poker.h"
#include "../textbox.h"
#include "../../strings.h"
void conversationQueueGameBegin();

View File

@@ -0,0 +1,56 @@
/**
* Copyright (c) 2022 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "winner.h"
#include "../../poker/poker.h"
#include "../textbox.h"
void conversationQueueWinnerDecide() {
pokerpot_t *pot;
uint8_t i, j, countOfPotsWithChips, chipsEach;
QUEUE_ITEM = QUEUE_START;
countOfPotsWithChips = 0;
for(i = 0; i < POKER_POT_COUNT; i++) {
pot = POKER_POTS + i;
if(pot->chips == 0) break;
countOfPotsWithChips++;
}
// TODO: Messages
if(countOfPotsWithChips == 1) {
} else {
}
// Pots.
for(i = 0; i < countOfPotsWithChips; i++) {
pot = POKER_POTS + i;
pokerWinnerDetermineForPot(
pot,
POKER_WINNERS,
POKER_WINNER_PLAYERS,
&POKER_WINNER_COUNT,
POKER_WINNER_PARTICIPANTS,
&POKER_WINNER_PARTICIPANT_COUNT
);
chipsEach = pot->chips / POKER_WINNER_COUNT;
for(j = 0; j < POKER_WINNER_COUNT; j++) {
POKER_PLAYERS[POKER_WINNER_PLAYERS[j]].chips += chipsEach;
// TODO: I can determine rounding error here if I need to, just sub the
// taken chips for each player and when I get to chips remaining less than
// the chipsEach, then reward the rounding offset.
}
}
// TODO: Decide on a winner for real.
conversationTextboxSetText(STR_DEBUG_WINNER_DECIDED);
// New Round
pokerNewRound();
}

View File

@@ -0,0 +1,11 @@
/**
* Copyright (c) 2022 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../../libs.h"
void conversationQueueWinnerDecide();

View File

@@ -10,6 +10,10 @@
#include "textbox.h"
#include "fade.h"
#include "../poker/poker.h"
#include "items/flop.h"
#include "items/winner.h"
#include "items/better.h"
#include "items/gameintro.h"
uint16_t QUEUE_ITEM;
@@ -17,225 +21,16 @@ void conversationQueueDebug() {
conversationTextboxSetText(STR_ERROR);
}
void conversationQueueBegin() {
QUEUE_ITEM = QUEUE_TAKE_BLINDS;
conversationTextboxSetText(STR_POKER_GAME_START);
}
void conversationQueueTakeBlinds() {
QUEUE_ITEM = QUEUE_DEAL_CARDS;
conversationTextboxSetText(STR_POKER_GAME_TAKING_BLINDS);
}
void conversationQueueDealCards() {
QUEUE_ITEM = QUEUE_BEGIN_BETTING;
conversationTextboxSetText(STR_POKER_GAME_CARDS_DEALT);
}
void conversationQueueBeginBetting() {
pokerturn_t turn;
turn.chips = 0;
// Begin the betting process. First we need to decide if the player or the
// AI is betting, then based on that we decide what to do next.
// TODO: Actually bet.
if(POKER_PLAYER_BETTER == POKER_HUMAN_INDEX) {
// This is the human player.
BGB_MESSAGE("Player folding.");
conversationTextboxSetText(STR_DEBUG_PLAYER);
POKER_PLAYERS[POKER_PLAYER_BETTER].state |= POKER_PLAYER_STATE_FOLDED;
} else {
// This is an AI player, get their turn.
BGB_MESSAGE("AI turn to bet");
pokerAi(POKER_PLAYER_BETTER, &turn);
BGB_printf("AI Decided to %u, with %u chips and %u confidence, bluffin: %u", turn.type, turn.chips, turn.confidence, turn.bluff);
switch(turn.type) {
case POKER_TURN_TYPE_FOLD:
POKER_PLAYERS[POKER_PLAYER_BETTER].state |= POKER_PLAYER_STATE_FOLDED;
conversationTextboxSetText(STR_POKER_GAME_AI_FOLD);
break;
case POKER_TURN_TYPE_BET:
if(turn.bluff) {
conversationTextboxSetText(STR_POKER_GAME_AI_RAISE_BLUFF);
} else {
conversationTextboxSetText(STR_POKER_GAME_AI_RAISE);
}
break;
case POKER_TURN_TYPE_CALL:
if(turn.bluff) {
conversationTextboxSetText(STR_POKER_GAME_AI_CALL_BLUFF);
} else {
conversationTextboxSetText(STR_POKER_GAME_AI_CALL);
}
break;
case POKER_TURN_TYPE_ALL_IN:
if(turn.bluff) {
conversationTextboxSetText(STR_POKER_GAME_AI_ALL_IN_BLUFF);
} else {
conversationTextboxSetText(STR_POKER_GAME_AI_ALL_IN);
}
break;
case POKER_TURN_TYPE_CHECK:
if(turn.bluff) {
conversationTextboxSetText(STR_POKER_GAME_AI_CHECK_BLUFF);
} else {
conversationTextboxSetText(STR_POKER_GAME_AI_CHECK);
}
break;
}
// Now we have their turn, decide what to say based on that.
}
// Update bet state
POKER_PLAYERS[POKER_PLAYER_BETTER].state |= (
POKER_PLAYER_STATE_HAS_BET_THIS_ROUND
);
if(turn.chips > 0) {
pokerBet(POKER_PLAYER_BETTER, turn.chips);
}
QUEUE_ITEM = QUEUE_NEXT_BETTER;
}
void conversationQueueNextBetter() {
uint8_t i, j, countStillInGame;
// Now we decide the next better.
countStillInGame = 0;
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
//In theory I don't think the current better can ever be selected again.
// if(i == POKER_PLAYER_BETTER) continue; // Commented because we now count
// Next better is the better to the right of the current better.
j = (POKER_PLAYER_BETTER + i) % POKER_PLAYER_COUNT;
if(!pokerDoesPlayerNeedToBet(j)) {
if((POKER_PLAYERS[j].state & (POKER_PLAYER_STATE_FOLDED | POKER_PLAYER_STATE_OUT)) == 0) {
countStillInGame++;
}
continue;
}
// They haven't bet yet, make them the "next better"
POKER_PLAYER_BETTER = j;
QUEUE_ITEM = QUEUE_BEGIN_BETTING;
conversationQueueNext();
return;
}
// If we reach this point then we either need to begin the betting round, or
// we are going to move to the winning decider.
if(POKER_COMMUNITY_SIZE_MAX == POKER_COMMUNITY_SIZE || countStillInGame == 1) {
QUEUE_ITEM = QUEUE_WINNER_DECIDE;
conversationQueueNext();
return;
}
QUEUE_ITEM = QUEUE_FLOP;
void conversationQueueStart() {
QUEUE_ITEM = QUEUE_GAME_BEGIN;
conversationQueueNext();
}
void conversationQueueFlopTurnRiver() {
uint8_t i, count;
pokerplayer_t *player;
switch(POKER_COMMUNITY_SIZE) {
case 0:
count = POKER_COUNT_FLOP;
conversationTextboxSetText(STR_POKER_GAME_CARDS_FLOPPED);
break;
case POKER_COUNT_FLOP:
count = POKER_COUNT_TURN;
conversationTextboxSetText(STR_POKER_GAME_CARDS_TURNED);
break;
default:
count = POKER_COUNT_RIVER;
conversationTextboxSetText(STR_POKER_GAME_CARDS_RIVERED);
break;
}
// Reset each players required to bet state
do {
player = POKER_PLAYERS + i;
player->state &= ~POKER_PLAYER_STATE_HAS_BET_THIS_ROUND;
player->timesRaised = 0;
} while(++i < POKER_PLAYER_COUNT);
// In reality we'd burn the top card but that would waste some CPU I need.
// Deal the top cards.
for(i = 0; i < count; i++) {
POKER_COMMUNITY[POKER_COMMUNITY_SIZE++] = POKER_DECK[--POKER_DECK_SIZE];
}
// Check how many players need to bet, if it's zero then all players are
// either folded or all-in
if(pokerGetRemainingBetterCount() == 0x00) {
if(POKER_COMMUNITY_SIZE == POKER_COMMUNITY_SIZE_MAX) {
QUEUE_ITEM = QUEUE_WINNER_DECIDE;
} else {
QUEUE_ITEM = QUEUE_FLOP;
}
} else {
QUEUE_ITEM = QUEUE_BEGIN_BETTING;
}
}
void conversationQueueWinnerDecide() {
pokerpot_t *pot;
uint8_t i, j, countOfPotsWithChips, chipsEach;
QUEUE_ITEM = QUEUE_BEGIN;
countOfPotsWithChips = 0;
for(i = 0; i < POKER_POT_COUNT; i++) {
pot = POKER_POTS + i;
if(pot->chips == 0) break;
countOfPotsWithChips++;
}
// TODO: Messages
if(countOfPotsWithChips == 1) {
} else {
}
// Pots.
for(i = 0; i < countOfPotsWithChips; i++) {
pot = POKER_POTS + i;
pokerWinnerDetermineForPot(
pot,
POKER_WINNERS,
POKER_WINNER_PLAYERS,
&POKER_WINNER_COUNT,
POKER_WINNER_PARTICIPANTS,
&POKER_WINNER_PARTICIPANT_COUNT
);
chipsEach = pot->chips / POKER_WINNER_COUNT;
for(j = 0; j < POKER_WINNER_COUNT; j++) {
POKER_PLAYERS[POKER_WINNER_PLAYERS[j]].chips += chipsEach;
// TODO: I can determine rounding error here if I need to, just sub the
// taken chips for each player and when I get to chips remaining less than
// the chipsEach, then reward the rounding offset.
}
}
// TODO: Decide on a winner for real.
conversationTextboxSetText(STR_DEBUG_WINNER_DECIDED);
// New Round
pokerNewRound();
}
////////////////////////////////////////////////////////////////////////////////
queuecallback_t *QUEUE_CALLBACKS[] = {
@@ -247,14 +42,14 @@ queuecallback_t *QUEUE_CALLBACKS[] = {
NULL,
// 5
&conversationQueueBegin,
&conversationQueueStart,
NULL,
NULL,
NULL,
NULL,
// 10
&conversationQueueTakeBlinds,
&conversationQueueGameBegin,
NULL,
NULL,
NULL,
@@ -304,7 +99,7 @@ queuecallback_t *QUEUE_CALLBACKS[] = {
};
inline void conversationQueueInit() {
QUEUE_ITEM = QUEUE_BEGIN;
QUEUE_ITEM = QUEUE_START;
}
inline void conversationQueueNext() {

View File

@@ -15,13 +15,14 @@ extern uint16_t QUEUE_ITEM;
extern queuecallback_t *QUEUE_CALLBACKS[];
#define QUEUE_DEBUG 1
#define QUEUE_BEGIN 5
#define QUEUE_TAKE_BLINDS 10
#define QUEUE_START 5
#define QUEUE_GAME_BEGIN 10
#define QUEUE_DEAL_CARDS 15
#define QUEUE_BEGIN_BETTING 20
#define QUEUE_NEXT_BETTER 25
#define QUEUE_FLOP 30
#define QUEUE_WINNER_DECIDE 40
void conversationQueueStart();
inline void conversationQueueInit();
inline void conversationQueueNext();

View File

@@ -7,11 +7,19 @@
#include "strings.h"
const char STR_GAME_BEGIN[] = "The blinds are set %u for the big, and %u for the small blinds.";
const char STR_ERROR[] = "An error\nhas occured";
const char STR_HELLO[] = "Hello World, How are you today?\nGood thanks. Thank god!";
const char STR_POKER_GAME_START[] = "Poker game started";
const char STR_POKER_GAME_TAKING_BLINDS[] = "Blinds taken.";
const char STR_POKER_GAME_CARDS_DEALT[] = "Cards dealt.";
const char STR_POKER_GAME_CARDS_FLOPPED[] = "Cards flopped";
@@ -30,4 +38,11 @@ const char STR_POKER_GAME_AI_ALL_IN[] = "AI All In";
const char STR_POKER_GAME_AI_ALL_IN_BLUFF[] = "AI All In\nBut Bluffing";
const char STR_POKER_GAME_AI_CHECK[] = "AI Checking";
const char STR_POKER_GAME_AI_CHECK_BLUFF[] = "AI Checking\nBut Bluffing";
const char STR_FOX[] = "The quick brown fox jumps over the lazy dog.";
const char STR_FOX[] = "The quick brown fox jumps over the lazy dog.";
const char *STR_PLAYER_NAMES[] = {
"Player",
"Mikuru",
"Haruhi",
"Matoi"
};

View File

@@ -8,6 +8,13 @@
#pragma once
#include "libs.h"
extern const char STR_GAME_BEGIN[];
extern const char STR_ERROR[];
extern const char STR_HELLO[];
@@ -31,4 +38,6 @@ extern const char STR_POKER_GAME_AI_ALL_IN[];
extern const char STR_POKER_GAME_AI_ALL_IN_BLUFF[];
extern const char STR_POKER_GAME_AI_CHECK[];
extern const char STR_POKER_GAME_AI_CHECK_BLUFF[];
extern const char STR_FOX[];
extern const char STR_FOX[];
extern const char *STR_PLAYER_NAMES[];