Apps Home
|
Create an App
Baccarat
Author:
slavabo
Description
Source Code
Launch App
Current Users
Created by:
Slavabo
//Baccarat v20130318 by slavabo [cbslavabo[at]gmail.com] var tct = 0; //TipCounT var wct = 0; //WinCounT var lct = 0; //LoseCounT var shoe = []; cb.settings_choices = [ {name:"cost", type:"int", minValue:1, maxValue:1000, defaultValue:25, label: "Token Cost Per Hand (1-1000): "}, ]; cb.tipOptions(function(user) { return {options:[{label: "player"}, {label: "banker"}, {label: "tie"}], label:"Bet on a hand:"}; }); cb.onTip(function (tip) { tct += tip['amount']; if (tip['amount']>=cb.settings.cost&&tip['message']!="player"&&tip['message']!="banker"&&tip['message']!="tie") cb.chatNotice("Please select player, banker or tie from the drop down list in the tip window to participate in Baccarat.",tip['from_user']); else if (tip['amount']>=cb.settings.cost) { if (shoe.length<7) cutShoe(); hands = [[0,[]],[0,[]]]; //[0]=player, [1]=banker cb.chatNotice(tip['from_user']+" has bet on "+tip['message']+"."); var scores = coup(); var output = "Player: ["+scores[0][1]+"] = "+scores[0][0]+" | Banker: ["+scores[1][1]+"] = "+scores[1][0]+"\n"; if ((scores[0][0]>scores[1][0]&&tip['message']=="player")||(scores[0][0]<scores[1][0]&&tip['message']=="banker")||(scores[0][0]==scores[1][0]&&tip['message']=="tie")) { output += "Congratulations, "+tip['from_user']+"! You bet on the winning hand."; wct++; } else { output += "Sorry, "+tip['from_user']+", you bet on the wrong hand."; lct++; } cb.chatNotice(output); } cb.drawPanel(); }); cb.onDrawPanel(function(user) { return { 'template': '3_rows_of_labels', 'row1_label': 'Tips Received:', 'row1_value': tct, 'row2_label': 'Win Ratio: ', 'row2_value': wct+':'+lct, 'row3_label': 'Hand Cost:', 'row3_value': (cb.settings.cost==1)?cb.settings.cost+' token':cb.settings.cost+' tokens' }; }); cb.onMessage(function (msg) { if (msg['m'] == '/rules') { msg['X-Spam'] = true; cb.chatNotice("Baccarat is a game of luck; the goal is to bet on the hand which will score closer to 9.\n"+ "A=1, 2-9=face value, 10,J,Q,K=0. If value exceeds 10, score is value less 10.\n"+ "This game app is based on 'punto banco' Baccarat rules on Wikipedia.",msg['user']); } return msg; }); function cutShoe() { shoe = ["SA","S2","S3","S4","S5","S6","S7","S8","S9","S10","SJ","SQ","SK", "SA","S2","S3","S4","S5","S6","S7","S8","S9","S10","SJ","SQ","SK", "SA","S2","S3","S4","S5","S6","S7","S8","S9","S10","SJ","SQ","SK", "SA","S2","S3","S4","S5","S6","S7","S8","S9","S10","SJ","SQ","SK", "CA","C2","C3","C4","C5","C6","C7","C8","C9","C10","CJ","CQ","CK", "CA","C2","C3","C4","C5","C6","C7","C8","C9","C10","CJ","CQ","CK", "CA","C2","C3","C4","C5","C6","C7","C8","C9","C10","CJ","CQ","CK", "CA","C2","C3","C4","C5","C6","C7","C8","C9","C10","CJ","CQ","CK", "HA","H2","H3","H4","H5","H6","H7","H8","H9","H10","HJ","HQ","HK", "HA","H2","H3","H4","H5","H6","H7","H8","H9","H10","HJ","HQ","HK", "HA","H2","H3","H4","H5","H6","H7","H8","H9","H10","HJ","HQ","HK", "HA","H2","H3","H4","H5","H6","H7","H8","H9","H10","HJ","HQ","HK", "DA","D2","D3","D4","D5","D6","D7","D8","D9","D10","DJ","DQ","DK", "DA","D2","D3","D4","D5","D6","D7","D8","D9","D10","DJ","DQ","DK", "DA","D2","D3","D4","D5","D6","D7","D8","D9","D10","DJ","DQ","DK", "DA","D2","D3","D4","D5","D6","D7","D8","D9","D10","DJ","DQ","DK",]; //four decks for (i=0;i<shoe.length;i++) { shoe[i] = shoe[i].replace("S",String.fromCharCode(9824)); shoe[i] = shoe[i].replace("C",String.fromCharCode(9827)); shoe[i] = shoe[i].replace("H",String.fromCharCode(9829)); shoe[i] = shoe[i].replace("D",String.fromCharCode(9830)); } } function cardVal(card) { switch (card.charAt(card.length-1)) { case "A": return 1; case "J": case "Q": case "K": return 0; default: return parseInt(card.charAt(card.length-1)); } } function dealCard(whose) { var rnd = Math.floor(Math.random()*shoe.length); hands[whose][0]+=cardVal(shoe[rnd]); if (hands[whose][0]>9) hands[whose][0]-=10; hands[whose][1].push(shoe[rnd]); shoe.splice(rnd,1); } function coup() { for (p1=0;p1<2;p1++) for (p2=0;p2<2;p2++) dealCard(p1); //deal 2 cards each to player and banker if (hands[0][0]>=8||hands[1][0]>=8) return hands; //natural win else if (hands[0][0]<=5) { dealCard(0); var tmp=cardVal(hands[0][1][2]); if (tmp==8) tmp=2; else if (tmp==9) tmp=1; if (hands[1][0]<=((tmp-(tmp%2))/2)+3) dealCard(1); } else if (hands[1][0]<=5) dealCard(1); return hands; }
© Copyright Camscaster.Com 2011- 2025. All Rights Reserved.