diff --git a/CMakeLists.txt b/CMakeLists.txt index a73ea489..5a18b36b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ set(SETTING_GAME_POKER 1) set(SETTING_GAME_DAWN 2) set(SETTING_GAME_SANDBOX 3) -set(SETTING_GAME SETTING_GAME_SANDBOX) +set(SETTING_GAME SETTING_GAME_POKER) set(SETTING_GAME_NAME "DawnGame") ################################## Targets ##################################### @@ -71,13 +71,15 @@ if(${SETTING_PLATFORM} EQUAL ${SETTING_PLATFORM_SDL}) endif() #################################### ASSETS #################################### -set(SCRIPT_FILES scripts.js) -add_custom_command( - OUTPUT ${SCRIPT_FILES} - COMMAND npm run build - DEPENDS ${SOURCE_FILES} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} -) +if(${SETTING_GAME} EQUAL ${SETTING_GAME_SANDBOX}) + set(SCRIPT_FILES scripts.js) + add_custom_command( + OUTPUT ${SCRIPT_FILES} + COMMAND npm run build + DEPENDS ${SOURCE_FILES} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) +endif() file(COPY ${CMAKE_CURRENT_LIST_DIR}/assets DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/game/game.h b/src/game/game.h index bfdde266..4ba6f05d 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -12,7 +12,7 @@ #if SETTING_GAME == SETTING_GAME_POKER #include "poker/game.h" typedef pokergame_t game_t; - #define GAME_INIT poekrGameInit + #define GAME_INIT pokerGameInit #define GAME_UPDATE pokerGameUpdate #define GAME_DISPOSE pokerGameDispose diff --git a/src/libs.h b/src/libs.h index 5f45075f..e7df1e10 100644 --- a/src/libs.h +++ b/src/libs.h @@ -39,6 +39,7 @@ #include #include #include +#include #if defined(_WIN32) || defined(_WIN64) // Windows Fixes diff --git a/src/poker/turn.c b/src/poker/turn.c index eafb39e8..ffc1a8c7 100644 --- a/src/poker/turn.c +++ b/src/poker/turn.c @@ -8,12 +8,13 @@ #include "turn.h" pokerturn_t pokerTurnGet(poker_t *poker, uint8_t playerIndex) { + int32_t random, maxBet, bluffBet, callBet; + float winProbability, expectedGain, confidence, potOdds; + bool isBluff; + int32_t amount; pokerplayer_t *player; - float t, confidence, cardWeight, handWeight; - float betWeight, potWeight, inWeight, roundWeight, bet; - card_t bestCard; - uint8_t i, bestCardNumber; - int32_t chips; + pokerplayerwinning_t winning; + uint8_t i, cardNumber0, cardNumber1, suitNumber0, suitNumber1; player = poker->players + playerIndex; @@ -26,93 +27,97 @@ pokerturn_t pokerTurnGet(poker_t *poker, uint8_t playerIndex) { // needs to do one thing, decide whether or not they want to Bet or Not. // In future I may make checking optional, but for now there's really no // reason not to. - - // Get the current winning hand. - pokerplayerwinning_t winning; pokerWinnerPlayerGet(&poker->dealer, player, &winning); - // Now try and figure out how good the hand is - handWeight = 0; - for(i = 0; i < winning.setSize; i++) { - bestCard = winning.set[i]; - handWeight += pokerWinnerGetCardWeight(bestCard); + // Get the current winning hand. + if(poker->dealer.cardsFacing == 0 && player->cardCount >= 2) { + cardNumber0 = cardGetNumber(player->cards[0]); + cardNumber1 = cardGetNumber(player->cards[1]); + suitNumber0 = cardGetSuit(player->cards[0]); + suitNumber1 = cardGetSuit(player->cards[1]); + + i = mathAbs(cardNumber0 - cardNumber1); + + confidence = (float)cardNumber0 + (float)cardNumber1; + if(cardNumber0 == cardNumber1) { + confidence += 6; + } else if(suitNumber0 == suitNumber1) { + confidence += 4; + } + + if(i > 4) { + confidence -= 4; + } else if(i > 2) { + confidence -= i; + } + + confidence = confidence / 30.0f; + } else { + confidence = pokerWinnerGetTypeConfidence(winning.type); } - handWeight = handWeight / winning.setSize; - bestCard = pokerWinnerGetBestCard(winning.set, winning.setSize); - bestCardNumber = cardGetNumber(bestCard); - confidence = pokerWinnerGetTypeConfidence(winning.type); - cardWeight = pokerWinnerGetCardWeight(bestCard); - - // Now figure out what the risk of betting is. - inWeight = (float)player->currentBet / (float)player->chips; - roundWeight = ( - ((float)poker->dealer.cardsFacing) / ((float)POKER_DEALER_HAND_SIZE) - ); - betWeight = (float)( - poker->bet.currentBet - player->currentBet - ) / (float)player->chips; - potWeight = poker->bet.pot / (float)player->chips; + callBet = poker->bet.currentBet - player->currentBet; + winProbability = confidence; - - // We now need to act on these values. - printf("Card Weights - %.4f, %.4f, %.4f, %.4f\n", confidence, cardWeight, handWeight); - printf("Money Weights - %.4f, %.4f, %.4f, %.4f\n", inWeight, roundWeight, betWeight, potWeight); + if(callBet > 0) { + potOdds = (float)callBet / ((float)callBet + (float)poker->bet.pot); + } else { + potOdds = ( + 1.0f / (float)pokerBetGetRemainingPlayerCount(&poker->bet, poker->players) + ); + } + expectedGain = winProbability / potOdds; - // Chip weight, 1 is all in. - bet = 0; + random = randInt32() % 100; + maxBet = (int32_t)(poker->bet.currentBet / 1.75f) - (random / 2);//? + maxBet -= callBet;//? + bluffBet = random * maxBet / 100 / 2; - if(roundWeight == 0) { - // First Round + isBluff = false; + amount = 0; - if(betWeight < 0.1) { - // The bet is "low risk" to me. (<10% of my chips), play a bit loose. - // Take any card with 70% weighting and/or any hand with a pair or better. - // if(cardWeight > 0.7 || confidence >= POKER_WINNNIG_CONFIDENCE_PAIR) { - // bet = confidence * 0.7f; - // } else if(cardWeight >= 0.5 && betWeight > 0) { - // } - bet = (1.0f - mathMin(betWeight*10, 0.5f)) * (cardWeight * confidence * 2.0f); - } else if(betWeight < 0.4) { - // Bet is "medium" risk to me (less than 40% of my chips) - // Bet on any hand that has a good chance. - if(confidence >= POKER_WINNNIG_CONFIDENCE_PAIR) { - bet = (confidence * mathMax(cardWeight, betWeight)); - } - } else if(betWeight < 0.75) { - // Bet is "high" risk to me. - if(cardWeight > 0.6 && confidence >= POKER_WINNNIG_CONFIDENCE_PAIR) { - bet = (confidence * cardWeight); - } + if(expectedGain < 0.8 && winProbability < 0.8) { + if(random < 95) { + amount = 0;//FOLD } else { - // Bet is likely my last hand + amount = bluffBet; + isBluff = true; + } + } else if ((expectedGain < 1.0 && winProbability < 0.85) || winProbability < 0.1) { + if (random < 80) { + amount = 0;//FOLD + } else if(random < 5) { + amount = callBet; + isBluff = true; + } else { + amount = bluffBet; + isBluff = true; + } + } else if ((expectedGain < 1.3 && winProbability < 0.9) || winProbability < 0.5) { + if (random < 60 || winProbability < 0.5) { + amount = callBet; + } else { + amount = maxBet; + } + } else if (winProbability < 0.95 || poker->dealer.cardsFacing < 0x04) { + if(random < 30) { + amount = callBet; + } else { + amount = maxBet; } } else { - // Not first round. - if(confidence <= POKER_WINNNIG_CONFIDENCE_PAIR) { - bet = (confidence * cardWeight) / betWeight; - } else if(confidence <= POKER_WINNNIG_CONFIDENCE_THREE_OF_A_KIND) { - bet = (confidence * (cardWeight / handWeight)) / betWeight; - } else { - bet = confidence * (cardWeight / handWeight) * 2; - } + amount = (poker->bet.currentBet - callBet) * 9 / 10; } - - printf("Bet %.4f\n\n", bet); - // Now determine chips based on bet. - if(bet >= 0.75) { - chips = (int32_t)(bet * (float)player->chips); - chips = mathMin(chips, player->chips); - return pokerTurnRaise(poker, playerIndex, chips); - } else if(bet >= 0.25f) { - return pokerTurnCall(poker, playerIndex); + printf("Raw Amount %i\n", amount); + + // TODO: Make sure we don't get stuck in a raise loop. + if(amount > 0) { + amount = mathMin(amount, callBet); + return pokerTurnRaise(poker, playerIndex, amount); } - - // Well, now they have decided to "not bet", or really they think that their - // cards are not worth the effort. But if they CAN check, they will. if(pokerTurnCanPlayerCheck(poker, playerIndex)) { return pokerTurnCheck(poker, playerIndex); } @@ -183,11 +188,7 @@ pokerturn_t pokerTurnRaise(poker_t *poker, uint8_t playerIndex, int32_t chips) { turn.chips = chips; turn.type = POKER_TURN_TYPE_BET; - if(chips == poker->bet.currentBet) { - turn.type = POKER_TURN_TYPE_CALL; - } - - if(chips == 0) { + if(chips == (poker->bet.currentBet - player->currentBet)) { turn.type = POKER_TURN_TYPE_CALL; } } diff --git a/src/poker/turn.h b/src/poker/turn.h index 784f79f2..2e0bf61f 100644 --- a/src/poker/turn.h +++ b/src/poker/turn.h @@ -9,6 +9,7 @@ #include "../libs.h" #include "poker.h" #include "winner.h" +#include "../util/rand.h" #define POKER_TURN_TYPE_OUT 0x00 #define POKER_TURN_TYPE_FOLD 0x01 diff --git a/ts/main.ts b/ts/main.ts index d2d2c50c..3ac620d3 100644 --- a/ts/main.ts +++ b/ts/main.ts @@ -27,9 +27,11 @@ class TestScene extends Scene { this.shader.use(); this.shader.setCamera(this.camera); - this.shader.setPosition(0,0,0, 0,this.game.time.current,0); this.shader.setTexture(this.texture); - this.quad.draw(); + for(let i = 0; i < 3000; i++) { + this.shader.setPosition(0,0,0, 0,this.game.time.current + (i*0.0001),0); + this.quad.draw(); + } } dispose() {