Apps Home
|
My Uploads
|
Create an App
Texas Hold'em
Author:
romeo_john
Description
Source Code
Launch App
Current Users
Created by:
Romeo_John
App Images
var TEXAS_HOLDEM = (function(){ var _chances = [ { name: "Most Common", weight: 350 }, { name: "More Common", weight: 250 }, { name: "Common", weight: 150 }, { name: "Less Common", weight: 120 }, { name: "Least Common", weight: 90 }, { name: "Rare", weight: 25 }, { name: "Very Rare", weight: 10 }, { name: "Extremely Rare", weight: 4 }, { name: "Ultra Rare", weight: 1 } ]; var _deck = [ { rank: "2", suit: "S", order: 2 }, { rank: "3", suit: "S", order: 3 }, { rank: "4", suit: "S", order: 4 }, { rank: "5", suit: "S", order: 5 }, { rank: "6", suit: "S", order: 6 }, { rank: "7", suit: "S", order: 7 }, { rank: "8", suit: "S", order: 8 }, { rank: "9", suit: "S", order: 9 }, { rank: "10", suit: "S", order: 10 }, { rank: "J", suit: "S", order: 11 }, { rank: "Q", suit: "S", order: 12 }, { rank: "K", suit: "S", order: 13 }, { rank: "A", suit: "S", order: 14 }, { rank: "2", suit: "C", order: 2 }, { rank: "3", suit: "C", order: 3 }, { rank: "4", suit: "C", order: 4 }, { rank: "5", suit: "C", order: 5 }, { rank: "6", suit: "C", order: 6 }, { rank: "7", suit: "C", order: 7 }, { rank: "8", suit: "C", order: 8 }, { rank: "9", suit: "C", order: 9 }, { rank: "10", suit: "C", order: 10 }, { rank: "J", suit: "C", order: 11 }, { rank: "Q", suit: "C", order: 12 }, { rank: "K", suit: "C", order: 13 }, { rank: "A", suit: "C", order: 14 }, { rank: "2", suit: "H", order: 2 }, { rank: "3", suit: "H", order: 3 }, { rank: "4", suit: "H", order: 4 }, { rank: "5", suit: "H", order: 5 }, { rank: "6", suit: "H", order: 6 }, { rank: "7", suit: "H", order: 7 }, { rank: "8", suit: "H", order: 8 }, { rank: "9", suit: "H", order: 9 }, { rank: "10", suit: "H", order: 10 }, { rank: "J", suit: "H", order: 11 }, { rank: "Q", suit: "H", order: 12 }, { rank: "K", suit: "H", order: 13 }, { rank: "A", suit: "H", order: 14 }, { rank: "2", suit: "D", order: 2 }, { rank: "3", suit: "D", order: 3 }, { rank: "4", suit: "D", order: 4 }, { rank: "5", suit: "D", order: 5 }, { rank: "6", suit: "D", order: 6 }, { rank: "7", suit: "D", order: 7 }, { rank: "8", suit: "D", order: 8 }, { rank: "9", suit: "D", order: 9 }, { rank: "10", suit: "D", order: 10 }, { rank: "J", suit: "D", order: 11 }, { rank: "Q", suit: "D", order: 12 }, { rank: "K", suit: "D", order: 13 }, { rank: "A", suit: "D", order: 14 } ]; var _hands_played = 0; var _last_hand = "-"; var _last_player = "-"; var _last_prize = "-"; var _model_name = cb.room_slug; var _notice_font_light_colour = "#D49A6A"; var _notice_font_dark_colour = "#552700"; var _panel_data = { //bg: "55dab81d-fb84-490f-b61a-50c52f1801f9", // Testbed bg: "7e5ed272-9527-4cce-b338-5bd5b425a378", font_size: 11, font_weight: "normal", font_colour: _getNoticeFontLightColour() }; var _prizes = [ { slug: "highcard", name: "High Card", default: "Sorry, try again", rank: 1, chance: 17.4, display_chance: 43.8, chance_rank: 3, rollthedice_chance_index: 0 }, { slug: "onepair", name: "One Pair", default: "Smile", rank: 2, chance: 43.8, display_chance: 23.5, chance_rank: 1, rollthedice_chance_index: 1 }, { slug: "twopair", name: "Two Pair", default: "Boobs", rank: 3, chance: 23.5, display_chance: 17.4, chance_rank: 2, rollthedice_chance_index: 2 }, { slug: "threeofakind", name: "Three of a Kind", default: "Ass", rank: 4, chance: 4.83, display_chance: 4.83, chance_rank: 4, rollthedice_chance_index: 3 }, { slug: "straight", name: "Straight", default: "Pussy", rank: 5, chance: 4.62, display_chance: 4.62, chance_rank: 5, rollthedice_chance_index: 4 }, { slug: "flush", name: "Flush", default: "Naked", rank: 6, chance: 3.03, display_chance: 3.03, chance_rank: 6, rollthedice_chance_index: 5 }, { slug: "fullhouse", name: "Full House", default: "Cum show", rank: 7, chance: 2.6, display_chance: 2.6, chance_rank: 7, rollthedice_chance_index: 6 }, { slug: "fourofakind", name: "Four of a Kind", default: "Password show (15 mins)", rank: 8, chance: 0.168, display_chance: 0.168, chance_rank: 8, rollthedice_chance_index: 7 }, { slug: "straightflush", name: "Straight Flush", default: "Password show (30 mins)", rank: 9, chance: 0.0279, display_chance: 0.0279, chance_rank: 9, rollthedice_chance_index: 7 }, { slug: "royalflush", name: "Royal Flush", default: "Password show (1 hour)", rank: 10, chance: 0.0032, display_chance: 0.0032, chance_rank: 10, rollthedice_chance_index: 8 } ]; var _total_tokens = 0; var _weight_table = []; function _addSetting(setting) { cb.settings_choices.push(setting); } function _advertiseApp(user = null) { var msg = ""; var divider = "##########################################"; var username = user === null ? null : user["user"]; var tokens_text = cb.settings.price == 1 ? "token" : "tokens"; var hands_text = cb.settings.max_price_multiples == 1 ? "hand" : "hands"; msg += divider + " \n"; msg += ":texas-holdem-logo \n"; msg += "We are playing Texas Hold'em Poker!!!\n"; msg += "Tip " + cb.settings.price + " " + tokens_text + " to play a hand. \n"; msg += "You will be dealt 2 Hole cards, 3 Flop cards, 1 Turn card, and 1 River card. \n"; msg += "The best possible poker hand from all 7 cards will be automatically calculated for you, and the corresponding prize for that hand will be displayed in chat. \n"; if (cb.settings.use_price_multiples == "Yes") { msg += "You may tip more than " + cb.settings.price + " " + tokens_text + " with a single tip to play multiple times, but no more than " + cb.settings.max_price_multiples + " " + hands_text + " in a single tip (" + (cb.settings.price * cb.settings.max_price_multiples) + " tokens). \n"; } msg += "Type \"!prizes\" to see the list of prizes. \n"; msg += "Type \"!prizes all\" if you are the broadcaster (or a mod) to show the list of prizes to all users. \n"; msg += divider; cb.sendNotice(msg, username, null, _getNoticeFontDarkColour(), "bold"); } function _buildWeightedPrizeTable() { let p, w, prize, chance, weight; for (p = 0; p < _prizes.length; p++) { prize = _prizes[p]; chance = _getPrizeChanceFromSettings(prize); weight = chance.weight; for (w = 0; w < weight; w++) { _weight_table.push(p); } } } function _convertCardsToStrings(cards) { var i, card, card_strings = []; for (i = 0; i < cards.length; i++) { card = cards[i]; card_strings.push(card.rank.toString() + card.suit.toString()); } return card_strings; } function _displayCards(cards, format = "image") { var i, card, text = ""; for (i = 0; i < cards.length; i++) { card = cards[i]; if (format === "image") { text += ":playingcard-" + card.rank + card.suit + " "; } else { text += "[" + card.rank + card.suit + "] " } } return text; } function _displayPrizes(username = null) { var i, prize, msg = ""; var divider = "##########################################"; msg += divider + " \n"; msg += ":texas-holdem-logo \n"; msg += "PRIZES: \n"; for (i = 0; i < _prizes.length; i++) { prize = _prizes[i]; msg += prize.name + " = " + cb.settings["prize_" + prize.slug] + " \n"; } msg += divider; cb.sendNotice(msg, username, null, _getNoticeFontDarkColour(), "bold"); } function _formatSettingsHeading(heading_text) { return heading_text.toUpperCase(); } function _getCardName(rank, suit) { var symbol; if (suit === "S") { symbol = "♠"; } else if (suit === "C") { symbol = "♣"; } else if (suit === "H") { symbol = "♥"; } else if (suit === "D") { symbol = "♦"; } return rank + symbol; } function _getIndexOfCard(cards, card) { var card_strings = _convertCardsToStrings(cards); var card_string = card.rank.toString() + card.suit.toString(); return card_strings.indexOf(card_string); } function _getNewDeck() { return _deck.slice(0); } function _getNoticeFontLightColour() { return _notice_font_light_colour; } function _getNoticeFontDarkColour() { return _notice_font_dark_colour; } function _getNumHandsFromTipAmount(tip_amount) { var price = parseInt(cb.settings.price); tip_amount = parseInt(tip_amount); if (tip_amount > price) { let hands = 0; while (tip_amount >= price) { hands++; tip_amount -= price; } return hands; } return 1; } function _getOddsFromChanceIndex(index) { let weight, total_weight = _getOddsTotal(); weight = _chances[index].weight; return parseFloat(weight / total_weight).toFixed(2); } function _getOddsTotal() { let i, total_weight = 0; for (i = 0; i < _chances.length; i++) { total_weight += _chances[i].weight; } return total_weight; } function _getPrizeChanceFromSettings(prize) { let c, chance, chance_name; chance_name = cb.settings["chance_rollthedice_" + prize.slug]; cb.log(cb.settings["chance_rollthedice_" + prize.slug]); for (c = 0; c < _chances.length; c++) { chance = _chances[c]; if (chance_name === chance.name + "(" + _getOddsFromChanceIndex(c) + "%)") { //return chance; } } return chance; } function _getRandomHand(prize_slug = "highcard") { let hands = []; switch (prize_slug) { case "highcard": hands.push([ { rank: "4", suit: "S", order: 4 }, { rank: "5", suit: "C", order: 5 }, { rank: "10", suit: "C", order: 10 }, { rank: "6", suit: "H", order: 6 }, { rank: "2", suit: "D", order: 2 }, { rank: "Q", suit: "D", order: 12 }, { rank: "A", suit: "D", order: 14 } ]); break; case "onepair": hands.push([ { rank: "3", suit: "S", order: 3 }, { rank: "A", suit: "S", order: 14 }, { rank: "5", suit: "C", order: 5 }, { rank: "A", suit: "C", order: 14 }, { rank: "6", suit: "H", order: 6 }, { rank: "K", suit: "H", order: 13 }, { rank: "9", suit: "D", order: 9 } ]); break; case "twopair": hands.push([ { rank: "5", suit: "S", order: 5 }, { rank: "Q", suit: "S", order: 12 }, { rank: "5", suit: "C", order: 5 }, { rank: "Q", suit: "C", order: 12 }, { rank: "4", suit: "H", order: 4 }, { rank: "K", suit: "H", order: 13 }, { rank: "10", suit: "D", order: 10 } ]); break; case "threeofakind": hands.push([ { rank: "2", suit: "S", order: 2 }, { rank: "J", suit: "S", order: 11 }, { rank: "J", suit: "C", order: 11 }, { rank: "7", suit: "H", order: 7 }, { rank: "J", suit: "H", order: 11 }, { rank: "3", suit: "D", order: 3 }, { rank: "10", suit: "D", order: 10 } ]); break; case "straight": hands.push([ { rank: "4", suit: "S", order: 4 }, { rank: "5", suit: "S", order: 5 }, { rank: "6", suit: "C", order: 6 }, { rank: "7", suit: "C", order: 7 }, { rank: "8", suit: "C", order: 8 }, { rank: "A", suit: "H", order: 14 }, { rank: "10", suit: "D", order: 10 } ]); break; case "flush": hands.push([ { rank: "J", suit: "S", order: 11 }, { rank: "6", suit: "H", order: 6 }, { rank: "8", suit: "H", order: 8 }, { rank: "10", suit: "H", order: 10 }, { rank: "Q", suit: "H", order: 12 }, { rank: "A", suit: "H", order: 14 }, { rank: "2", suit: "D", order: 2 } ]); break; case "fullhouse": hands.push([ { rank: "10", suit: "S", order: 10 }, { rank: "A", suit: "S", order: 14 }, { rank: "10", suit: "C", order: 10 }, { rank: "A", suit: "C", order: 14 }, { rank: "A", suit: "H", order: 14 }, { rank: "8", suit: "D", order: 8 }, { rank: "K", suit: "D", order: 13 } ]); break; case "fourofakind": hands.push([ { rank: "4", suit: "S", order: 4 }, { rank: "4", suit: "C", order: 4 }, { rank: "8", suit: "C", order: 8 }, { rank: "4", suit: "H", order: 4 }, { rank: "4", suit: "D", order: 4 }, { rank: "Q", suit: "D", order: 12 }, { rank: "A", suit: "D", order: 14 } ]); break; case "straightflush": hands.push([ { rank: "K", suit: "C", order: 13 }, { rank: "6", suit: "D", order: 6 }, { rank: "7", suit: "D", order: 7 }, { rank: "8", suit: "D", order: 8 }, { rank: "9", suit: "D", order: 9 }, { rank: "10", suit: "D", order: 10 }, { rank: "A", suit: "D", order: 14 } ]); break; case "royalflush": hands.push([ { rank: "10", suit: "S", order: 10 }, { rank: "J", suit: "S", order: 11 }, { rank: "Q", suit: "S", order: 12 }, { rank: "K", suit: "S", order: 13 }, { rank: "A", suit: "S", order: 14 }, { rank: "4", suit: "H", order: 4 }, { rank: "7", suit: "D", order: 7 } ]); break; default: break; } return hands[0]; } function _getRandomNumber(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } function _getWeightedRandomPrize() { let rnd = _getRandomNumber(0, (_weight_table.length - 1)); return _prizes[_weight_table[rnd]]; } /* c: message color m: the message text user: username of message sender f: message font in_fanclub: is the user in the broadcasters fan club has_tokens: does the user have at least 1 token is_mod: is the user a moderator tipped_recently: is the user a “dark blue”? tipped_alot_recently: is the user a “purple”? tipped_tons_recently: is the user a “dark purple”? gender: “m” (male), “f” (female), “s” (trans), or “c” (couple) */ function _handleMessage(msg) { switch (msg['m']) { case "!play": if (_isBroadcaster(msg['user']) || msg['is_mod']) { _playHand(msg); } break; case "!prizes": _displayPrizes(msg['user']); break; case "!prizes all": if (_isBroadcaster(msg['user']) || msg['is_mod']) { _displayPrizes(null); } break; default: break; } return msg; } /* amount: amount of tip message: message in tip to_user: user who received tip from_user: user who sent tip from_user_in_fanclub: is the user in the broadcasters fan club from_user_has_tokens: does the user have at least 1 token from_user_is_mod: is the user a moderator from_user_tipped_recently: is the user a “dark blue”? from_user_tipped_alot_recently: is the user a “purple”? from_user_tipped_tons_recently: is the user a “dark purple”? from_user_gender: “m” (male), “f” (female), “s” (trans), or “c” (couple) */ function _handleTip(tip) { var tip_amount = parseInt(tip['amount']); var price = parseInt(cb.settings.price); if (tip_amount === price) { _total_tokens += price; _playHand(tip); } else if (cb.settings.use_price_multiples == "Yes" && tip_amount > price) { var hands = _getNumHandsFromTipAmount(tip_amount); var max_price_multiples = parseInt(cb.settings.max_price_multiples); var i; for (i = 1; i <= hands; i++) { if (i > max_price_multiples) { break; } _total_tokens += price; _playHand(tip); } } } function _hideMessage(msg) { msg["X-Spam"] = true; return msg; } function _isBroadcaster(username) { return username.trim().toLowerCase() == cb.room_slug.trim().toLowerCase(); } function _isFlush(hand) { var i; var cards = hand.slice(0); var suits = []; for (i = 0; i < cards.length; i++) { suits.push(cards[i].suit); } suits.sort(); var dstr_suits = suits.join(","); if (dstr_suits.indexOf("S,S,S,S,S") !== -1) { return true; } if (dstr_suits.indexOf("C,C,C,C,C") !== -1) { return true; } if (dstr_suits.indexOf("H,H,H,H,H") !== -1) { return true; } if (dstr_suits.indexOf("D,D,D,D,D") !== -1) { return true; } return false; } function _isFourOfAKind(hand) { var i; var cards = hand.slice(0); var orders = []; for (i = 0; i < cards.length; i++) { orders.push(cards[i].order); } orders.sort(function(a, b) { a = parseInt(a); b = parseInt(b); if (a < b) { return -1; } if (a > b) { return 1; } return 0; }); var dstr_orders = orders.join(","); if (dstr_orders.indexOf("2,2,2,2") !== -1) { return true; } if (dstr_orders.indexOf("3,3,3,3") !== -1) { return true; } if (dstr_orders.indexOf("4,4,4,4") !== -1) { return true; } if (dstr_orders.indexOf("5,5,5,5") !== -1) { return true; } if (dstr_orders.indexOf("6,6,6,6") !== -1) { return true; } if (dstr_orders.indexOf("7,7,7,7") !== -1) { return true; } if (dstr_orders.indexOf("8,8,8,8") !== -1) { return true; } if (dstr_orders.indexOf("9,9,9,9") !== -1) { return true; } if (dstr_orders.indexOf("10,10,10,10") !== -1) { return true; } if (dstr_orders.indexOf("11,11,11,11") !== -1) { return true; } if (dstr_orders.indexOf("12,12,12,12") !== -1) { return true; } if (dstr_orders.indexOf("13,13,13,13") !== -1) { return true; } if (dstr_orders.indexOf("14,14,14,14") !== -1) { return true; } return false; } function _isFullHouse(hand) { var i, j, k, card, tmp_card_1, tmp_card_2, new_cards; var cards = hand.slice(0); for (i = 0; i < cards.length; i++) { card = cards[i]; for (j = 0; j < cards.length; j++) { if (i === j) { continue; } tmp_card_1 = cards[j]; if (card.rank === tmp_card_1.rank) { for (k = 0; k < cards.length; k++) { if (k === i || k === j) { continue; } tmp_card_2 = cards[k]; if (card.rank === tmp_card_2.rank) { new_cards = cards.slice(0); new_cards = _removeCardFromHand(new_cards, card); new_cards = _removeCardFromHand(new_cards, tmp_card_1); new_cards = _removeCardFromHand(new_cards, tmp_card_2); if (_isPair(new_cards)) { return true; } } } } } } return false; } function _isPair(hand) { var i, j, card, tmp_card; var cards = hand.slice(0); for (i = 0; i < cards.length; i++) { card = cards[i]; for (j = 0; j < cards.length; j++) { if (i === j) { continue; } tmp_card = cards[j]; if (card.rank === tmp_card.rank) { return true; } } } return false; } function _isRoyalFlush(hand) { var s, suits, suit, card_strings, dstr_cards; var cards = hand.slice(0); cards.sort(function compare(a, b) { if (a.order < b.order) { return -1; } if (a.order > b.order) { return 1; } return 0; }); card_strings = _convertCardsToStrings(cards); dstr_cards = card_strings.join(","); suits = ["S", "C", "H", "D"]; for (s = 0; s < suits.length; s++) { suit = suits[s]; if (dstr_cards.indexOf("10" + suit + ",J" + suit + ",Q" + suit + ",K" + suit + ",A" + suit) !== -1) { return true; } } return false; } function _isModeStandard() { return cb.settings["gamemode"].toLowerCase().indexOf("standard") !== -1; } function _isModeRollTheDice() { return cb.settings["gamemode"].toLowerCase().indexOf("dice") !== -1; } function _isStraight(hand) { var i; var cards = hand.slice(0); var orders = []; for (i = 0; i < cards.length; i++) { orders.push(cards[i].order); } orders.sort(function(a, b) { a = parseInt(a); b = parseInt(b); if (a < b) { return -1; } if (a > b) { return 1; } return 0; }); var dstr_orders = orders.join(","); if (dstr_orders.indexOf("2,3,4,5,6") !== -1) { return true; } if (dstr_orders.indexOf("3,4,5,6,7") !== -1) { return true; } if (dstr_orders.indexOf("4,5,6,7,8") !== -1) { return true; } if (dstr_orders.indexOf("5,6,7,8,9") !== -1) { return true; } if (dstr_orders.indexOf("6,7,8,9,10") !== -1) { return true; } if (dstr_orders.indexOf("7,8,9,10,11") !== -1) { return true; } if (dstr_orders.indexOf("8,9,10,11,12") !== -1) { return true; } if (dstr_orders.indexOf("9,10,11,12,13") !== -1) { return true; } if (dstr_orders.indexOf("10,11,12,13,14") !== -1) { return true; } return false; } function _isStraightFlush(hand) { var s, suits, suit, card_strings, dstr_cards; var cards = hand.slice(0); cards.sort(function compare(a, b) { if (a.order < b.order) { return -1; } if (a.order > b.order) { return 1; } return 0; }); card_strings = _convertCardsToStrings(cards); dstr_cards = card_strings.join(","); suits = ["S", "C", "H", "D"]; for (s = 0; s < suits.length; s++) { suit = suits[s]; if (dstr_cards.indexOf("2" + suit + ",3" + suit + ",4" + suit + ",5" + suit + ",6" + suit) !== -1) { return true; } if (dstr_cards.indexOf("3" + suit + ",4" + suit + ",5" + suit + ",6" + suit + ",7" + suit) !== -1) { return true; } if (dstr_cards.indexOf("4" + suit + ",5" + suit + ",6" + suit + ",7" + suit + ",8" + suit) !== -1) { return true; } if (dstr_cards.indexOf("5" + suit + ",6" + suit + ",7" + suit + ",8" + suit + ",9" + suit) !== -1) { return true; } if (dstr_cards.indexOf("6" + suit + ",7" + suit + ",8" + suit + ",9" + suit + ",10" + suit) !== -1) { return true; } if (dstr_cards.indexOf("7" + suit + ",8" + suit + ",9" + suit + ",10" + suit + ",J" + suit) !== -1) { return true; } if (dstr_cards.indexOf("8" + suit + ",9" + suit + ",10" + suit + ",J" + suit + ",Q" + suit) !== -1) { return true; } if (dstr_cards.indexOf("9" + suit + ",10" + suit + ",J" + suit + ",Q" + suit + ",K" + suit) !== -1) { return true; } if (dstr_cards.indexOf("10" + suit + ",J" + suit + ",Q" + suit + ",K" + suit + ",A" + suit) !== -1) { return true; } } return false; } function _isThreeOfAKind(hand) { var i, j, k, card, tmp_card_1, tmp_card_2; var cards = hand.slice(0); for (i = 0; i < cards.length; i++) { card = cards[i]; for (j = 0; j < cards.length; j++) { if (i === j) { continue; } tmp_card_1 = cards[j]; if (card.rank === tmp_card_1.rank) { for (k = 0; k < cards.length; k++) { if (k === i || k === j) { continue; } tmp_card_2 = cards[k]; if (card.rank === tmp_card_2.rank) { return true; } } } } } return false; } function _isTwoPair(hand) { var i, j, card, tmp_card, new_cards; var cards = hand.slice(0); for (i = 0; i < cards.length; i++) { card = cards[i]; for (j = 0; j < cards.length; j++) { if (i === j) { continue; } tmp_card = cards[j]; if (card.rank === tmp_card.rank) { new_cards = _removeCardFromHand(cards, card); new_cards = _removeCardFromHand(new_cards, tmp_card); if (_isPair(new_cards)) { return true; } } } } return false; } function _onDrawPanel(user) { // _hands_played = 5; // _last_prize = "Doggystyle in panties"; // _last_player = "kjhjksdh_sdhks1234444"; return { "template": "image_template", "layers": [ {"type": "image", "fileID": _panel_data.bg}, { "type": "text", "text": "Last hand:", "top": 3, "left": 10, "font-size": _panel_data.font_size, "font-weight": _panel_data.font_weight, "color": _panel_data.font_colour }, { "type": "text", "text": _last_hand, "top": 3, "left": 97, "font-size": _panel_data.font_size, "font-weight": _panel_data.font_weight, "color": _panel_data.font_colour }, { "type": "text", "text": "Last prize won:", "top": 20, "left": 10, "font-size": _panel_data.font_size, "font-weight": _panel_data.font_weight, "color": _panel_data.font_colour }, { "type": "text", "text": _last_prize, "top": 20, "left": 97, "font-size": _panel_data.font_size, "font-weight": _panel_data.font_weight, "color": _panel_data.font_colour }, { "type": "text", "text": "Last player:", "top": 37, "left": 10, "font-size": _panel_data.font_size, "font-weight": _panel_data.font_weight, "color": _panel_data.font_colour }, { "type": "text", "text": _last_player, "top": 37, "left": 97, "font-size": _panel_data.font_size, "font-weight": _panel_data.font_weight, "color": _panel_data.font_colour }, { "type": "text", "text": "Hands played: " + _hands_played + " | Pot: " + _total_tokens, "top": 54, "left": 10, "font-size": _panel_data.font_size, "font-weight": _panel_data.font_weight, "color": _panel_data.font_colour }, ] }; } function _onEnter(user) { _advertiseApp(user); } /* amount: amount of tip message: message in tip to_user: user who received tip from_user: user who sent tip from_user_in_fanclub: is the user in the broadcasters fan club from_user_has_tokens: does the user have at least 1 token from_user_is_mod: is the user a moderator from_user_tipped_recently: is the user a “dark blue”? from_user_tipped_alot_recently: is the user a “purple”? from_user_tipped_tons_recently: is the user a “dark purple”? from_user_gender: “m” (male), “f” (female), “s” (trans), or “c” (couple) */ function _playHand(tip) { var i, j, prize, hand, hole = [], flop = [], turn = [], river = [], cards, result = "", msg = "", lowest_prize = false, hand_data = {}; // cards = [ // { rank: "J", suit: "S", order: 11 }, // { rank: "Q", suit: "S", order: 12 }, // { rank: "K", suit: "S", order: 13 }, // { rank: "A", suit: "S", order: 14 }, // { rank: "9", suit: "S", order: 9 }, // { rank: "3", suit: "D", order: 3 }, // { rank: "10", suit: "S", order: 10 } // ]; if (_isModeStandard()) { /* In real Texas Hold'em, the chances of the worst 3 hands are as follows: - High Card = 17.4% - One Pair = 43.8% - Two Pair = 23.5% This is counter-intuitve because one would expect the worst hand to have the highest chance, and most models will choose the prizes based on this expectation. So... in order to make the chances of High Card, One Pair, and Two Pair more accurately reflect their rank, we need to tweak the simulation algorithm to get as close to the following chances as possible: - High Card = 43.8% - One Pair = 23.5% - Two Pair = 17.4% We will do this by re-simulating the hand 5 times when the first result is One Pair to see if we can get a High Card as the final result, thereby skewing the chances enough such that High Card occurs more frequently than One Pair. */ hand_data.hole = []; hand_data.flop = []; hand_data.turn = []; hand_data.river = []; hand_data.result = ""; hand_data.msg = ""; hand_data.prize = null; for (j = 1; j <= 5; j++) { hole = []; flop = []; turn = []; river = []; result = ""; msg = ""; cards = _shuffle(_getNewDeck()); //Hole for (i = 0; i < 2; i++) { hole.push(cards.pop()); } msg += _displayCards(hole) + "(Hole) \n"; //Flop for (i = 0; i < 3; i++) { flop.push(cards.pop()); } msg += _displayCards(flop) + "(Flop) \n"; //Turn & River for (i = 0; i < 1; i++) { turn.push(cards.pop()); } for (i = 0; i < 1; i++) { river.push(cards.pop()); } msg += _displayCards(turn) + _displayCards(river) + "(Turn & River) \n"; //Hand hand = hole.concat(flop, turn, river); hand.sort(function compare(a, b) { if (a.order < b.order) { return -1; } if (a.order > b.order) { return 1; } return 0; }); msg += "Board: " + _displayCards(hand, "text") + " \n"; //Results if (true === false) { } else if (_isRoyalFlush(hand)) { result += "Royal Flush"; prize = _prizes[9]; } else if (_isStraightFlush(hand)) { result += "Straight Flush"; prize = _prizes[8]; } else if (_isFourOfAKind(hand)) { result += "Four of a Kind"; prize = _prizes[7]; } else if (_isFullHouse(hand)) { result += "Full House"; prize = _prizes[6]; } else if (_isFlush(hand)) { result += "Flush"; prize = _prizes[5]; } else if (_isStraight(hand)) { result += "Straight"; prize = _prizes[4]; } else if (_isThreeOfAKind(hand)) { result += "Three of a Kind"; prize = _prizes[3]; } else if (_isTwoPair(hand)) { result += "Two Pair"; prize = _prizes[2]; } else if (_isPair(hand)) { result += "One Pair"; prize = _prizes[1]; } else { result += "High Card"; prize = _prizes[0]; } msg += "Best Hand: " + result; if ((lowest_prize === false && (prize.slug === "onepair" || prize.slug === "twopair")) || lowest_prize !== false) { if (lowest_prize === false) { lowest_prize = prize; hand_data = _setHandData(hole, flop, turn, river, result, msg, prize); } else { if (prize.rank < lowest_prize.rank && prize.slug !== "onepair") { lowest_prize = prize.chance_rank; hand_data = _setHandData(hole, flop, turn, river, result, msg, prize); } } } else { hand_data = _setHandData(hole, flop, turn, river, result, msg, prize); break; } if (hand_data.prize.slug === "highcard") { break; } } _last_hand = hand_data.result; _last_prize = cb.settings["prize_" + hand_data.prize.slug]; cb.sendNotice(hand_data.msg, null, null, _getNoticeFontDarkColour(), "bold"); cb.sendNotice("Prize: " + cb.settings["prize_" + hand_data.prize.slug], null, _getNoticeFontDarkColour(), _getNoticeFontLightColour(), "bold"); } else if (_isModeRollTheDice()) { prize = _getWeightedRandomPrize(); cards = _shuffle(_getRandomHand(prize.slug)); //Hole for (i = 0; i < 2; i++) { hole.push(cards.pop()); } msg += _displayCards(hole) + "(Hole) \n"; //Flop for (i = 0; i < 3; i++) { flop.push(cards.pop()); } msg += _displayCards(flop) + "(Flop) \n"; //Turn & River for (i = 0; i < 1; i++) { turn.push(cards.pop()); } for (i = 0; i < 1; i++) { river.push(cards.pop()); } msg += _displayCards(turn) + _displayCards(river) + "(Turn & River) \n"; // Hand hand = hole.concat(flop, turn, river); //Results result = prize.name; _last_hand = result; hand.sort(function compare(a, b) { if (a.order < b.order) { return -1; } if (a.order > b.order) { return 1; } return 0; }); msg += "Board: " + _displayCards(hand, "text") + " \n"; msg += "Best Hand: " + result; cb.sendNotice(msg, null, null, _getNoticeFontDarkColour(), "bold"); cb.sendNotice("Prize: " + cb.settings["prize_" + prize.slug], null, _getNoticeFontDarkColour(), _getNoticeFontLightColour(), "bold"); _last_prize = cb.settings["prize_" + prize.slug]; } _hands_played++; _last_player = tip["from_user"]; cb.drawPanel(); } function _reminder() { _advertiseApp(); cb.setTimeout(_reminder, (parseInt(cb.settings.advertisement_interval) * 60 * 1000)); } function _removeCardFromHand(hand, card) { var cards = hand.slice(0); var index = _getIndexOfCard(cards, card); cards.splice(index, 1); return cards; } function _setHandData(hole, flop, turn, river, result, msg, prize) { let hand_data = {}; hand_data.hole = hole; hand_data.flop = flop; hand_data.turn = turn; hand_data.river = river; hand_data.result = result; hand_data.msg = msg; hand_data.prize = prize; return hand_data; } function _setTimeout(func, msecs) { var id = cb.setTimeout(func, msecs); return id; } function _setupSettings() { var p, prize, c, chance, setting; cb.settings_choices = []; _addSetting({ name: "heading_general", type: "choice", label: _formatSettingsHeading("General"), required: false }); _addSetting({ name: "gamemode", type: "choice", label: "Game Mode", choice1: "Standard (Simulated hands, Mostly-authentic chances)", choice2: "\"Roll the Dice\" (Non-simulated hands, Configurable chances)" }); _addSetting({ name: "advertisement_interval", type: "int", label: "How often should the app advertise itself (in minutes)? ", minValue: 1, maxValue: 1000, defaultValue: 10, required: true }); _addSetting({ name: "heading_prices", type: "choice", label: _formatSettingsHeading("Prices"), required: false }); _addSetting({ name: "price", type: "int", label: "How many tokens should it cost to play a hand of Texas Hold'em? ", minValue: 0, maxValue: 10000, defaultValue: 25, required: true }); _addSetting({ name: "use_price_multiples", type: "choice", label: "Should tips that are higher than the hand price result in multiple hands being played? ", choice1: "Yes", choice2: "No", defaultValue: "Yes" }); _addSetting({ name: "max_price_multiples", type: "int", label: "What is the maximum number of hands allowed from a single tip? ", minValue: 0, maxValue: 100, defaultValue: 20, required: true }); // Prizes _addSetting({ name: "heading_prizes", type: "choice", label: _formatSettingsHeading("Prizes"), required: false }); for (p = 0; p < _prizes.length; p++) { prize = _prizes[p]; _addSetting({ name: "prize_" + prize.slug, type: "str", label: "Prize for " + prize.name + " (" + prize.display_chance.toString() + "% chance)", minLength: 0, maxLength: 1000, defaultValue: prize.default, required: false }); } _addSetting({ name: "heading_chances_rollthedice", type: "choice", label: _formatSettingsHeading("Chances for \"Roll the Dice\" mode"), required: false }); for (p = 0; p < _prizes.length; p++) { prize = _prizes[p]; setting = {}; setting["name"] = "chance_rollthedice_" + prize.slug; setting["type"] = "choice"; setting["label"] = "Chance for " + prize.name; setting["required"] = false; for (c = 0; c < _chances.length; c++) { chance = _chances[c]; setting["choice" + (c + 1).toString()] = chance.name + "(" + _getOddsFromChanceIndex(c) + "%)"; if (c == prize.rollthedice_chance_index) { setting["defaultValue"] = chance.name + "(" + _getOddsFromChanceIndex(c) + "%)"; } } _addSetting(setting); } } function _shuffle(arr) { var j, x, i; for (i = arr.length - 1; i > 0; i--) { j = Math.floor(Math.random() * (i + 1)); x = arr[i]; arr[i] = arr[j]; arr[j] = x; } return arr; } function _timestamp() { return Math.floor(Date.now() / 1000); } return { init: function() { //cb.log(Reflect.ownKeys(cb)); cb.log("Loading Texas Hold'em..."); _setupSettings(); _buildWeightedPrizeTable(); cb.onDrawPanel(function(user) { return _onDrawPanel(user); }); cb.onEnter(function(user) { _onEnter(user); }); cb.onMessage(function (msg) { return _handleMessage(msg); }); cb.onTip(function(tip) { _handleTip(tip); }); cb.setTimeout(_reminder, (parseInt(cb.settings.advertisement_interval) * 60 * 1000)); _advertiseApp(); cb.drawPanel(); } }; })(); TEXAS_HOLDEM.init();
© Copyright Chaturbate 2011- 2025. All Rights Reserved.