PokerCheck

Developer
Size
7,323 Kb
Views
56,672

How do I make an pokercheck?

Evaluates a n-player game of pokerrecognizes straight flush, four of a kind, full house, flush, straight, three of a kind, two pair, one pair, and high card. What is a pokercheck? How do you make a pokercheck? This script and codes were developed by Not Important on 13 July 2022, Wednesday.

PokerCheck Previews

PokerCheck - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>pokerCheck</title> <link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/mocha/1.20.1/mocha.css'>
<link rel='stylesheet prefetch' href='https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css'> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class='container'> <div class='row'> <div class='col-md-12'> <div class='panel panel-default'> <div class='panel-heading'> Game Results ( <a href='#' id='newGame'> play again </a> ) </div> <table class='table'> <tbody id='hands'></tbody> </table> </div> </div> </div>
</div>
<div id='mocha'></div> <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mocha/1.20.1/mocha.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/sinon.js/1.7.3/sinon-min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/chai/1.9.1/chai.js'></script>
<script src='https://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

PokerCheck - Script Codes CSS Codes

@import url(http://fonts.googleapis.com/css?family=Open+Sans);
body { margin-top: 60px;
}
#hands { background-color: #23A484; color: #fff; font-weight: bold;
}
#hands > tr.success > td { background-color: #48cfad;
}
.card { color: #333; font-family: 'Open Sans', sans-serif; display: table; border-radius: 4.8px; background-color: #fff; box-sizing: border-box; box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.2); height: 41px; width: 28px; margin: 0 auto;
}
.card__rank { display: table-cell; font-size: 16.272px; line-height: 16.272px; text-align: center; vertical-align: middle; font-weight: bold;
}
.card__rank:before { box-sizing: border-box; width: 100%; height: 15px; text-align: center; display: block;
}
.card--H,
.card--D { color: #fc6e51;
}
.card--H .card__rank:before { content: '\2665';
}
.card--D .card__rank:before { content: '\2666';
}
.card--S .card__rank:before { content: '\2660';
}
.card--C .card__rank:before { content: '\2663';
}

PokerCheck - Script Codes JS Codes

(function() { var PokerCheck, buildCard, buildDeck, count, createHand, deck, expect, newGame, pokerRules, suitLookup; PokerCheck = (function() { function PokerCheck(rules) { var i, index, key, len, ref; this.rules = rules != null ? rules : {}; this.rankLookup = {}; ref = [2, 3, 4, 5, 6, 7, 8, 9].concat('TJQKA'.split('')); for (index = i = 0, len = ref.length; i < len; index = ++i) { key = ref[index]; this.rankLookup[key] = index; } } PokerCheck.prototype.evaluateGame = function(hands) { var hand, i, index, ref, result, winner, winnerIndex; winner = this.evaluateHand(hands[0]); winnerIndex = 0; for (index = i = 1, ref = hands.length; 1 <= ref ? i < ref : i > ref; index = 1 <= ref ? ++i : --i) { hand = hands[index]; result = this.evaluateHand(hand); if (result.handRank > winner.handRank) { winnerIndex = index; winner = result; } } return [winnerIndex, winner.handName]; }; PokerCheck.prototype.evaluateHand = function(hand) { var cards, handName, handRank, histogram, index, maxIndex, ref, ruleFn, size, width; cards = hand.split(' '); histogram = this.createHistogram(cards); index = 0; size = Object.keys(this.rules).length; width = Object.keys(this.rankLookup).length; maxIndex = Object.keys(this.rules).length - 1; ref = this.rules; for (handName in ref) { ruleFn = ref[handName]; if (handRank = ruleFn(histogram)) { handRank = (maxIndex - index) * width + handRank; return { handName: handName, handRank: handRank }; } index += 1; } }; PokerCheck.prototype.createHistogram = function(cards) { var base, card, i, len, name, name1, rank, rankCount, ranks, ref, suit, suitCount, suits; suits = {}; ranks = {}; for (i = 0, len = cards.length; i < len; i++) { card = cards[i]; ref = card.split(''), rank = ref[0], suit = ref[1]; suits[suit] || (suits[suit] = {}); (base = suits[suit])[name = this.rankLookup[rank]] || (base[name] = 0); suits[suit][this.rankLookup[rank]] += 1; ranks[name1 = this.rankLookup[rank]] || (ranks[name1] = 0); ranks[this.rankLookup[rank]] += 1; } rankCount = Object.keys(ranks).length; suitCount = Object.keys(suits).length; return { ranks: ranks, suits: suits, rankCount: rankCount, suitCount: suitCount }; }; return PokerCheck; })(); count = function(obj) { var handRank, key, ret; ret = {}; for (key in obj) { handRank = obj[key]; ret[handRank] = Math.max(ret[handRank] || 0, key); } return ret; }; pokerRules = { 'straight flush': function(histogram) { var isFlush, isStraight; isStraight = pokerRules['straight'](histogram); isFlush = pokerRules['flush'](histogram); if (!(isStraight && isFlush)) { return 0; } return Math.max.apply([], Object.keys(histogram.ranks)); }, 'four of a kind': function(histogram) { var counts; if (histogram.rankCount > 2) { return 0; } counts = count(histogram.ranks); return counts[4] || 0; }, 'full house': function(histogram) { var counts; if (histogram.rankCount > 2) { return 0; } counts = count(histogram.ranks); if (!counts[3]) { return 0; } if (!counts[2]) { return 0; } return counts[3]; }, 'flush': function(histogram) { if (histogram.suitCount !== 1) { return 0; } return Math.max.apply([], Object.keys(histogram.ranks)); }, 'straight': function(histogram) { var max, min; if (histogram.rankCount !== 5) { return 0; } max = Math.max.apply([], Object.keys(histogram.ranks)); min = Math.min.apply([], Object.keys(histogram.ranks)); if (max - min === 4) { return max; } return 0; }, 'three of a kind': function(histogram) { return count(histogram.ranks)[3] || 0; }, 'two pair': function(histogram) { var counts; if (histogram.rankCount > 3) { return; } counts = count(histogram.ranks); if (counts[2] && counts[1]) { return +counts[2]; } else { return 0; } }, 'one pair': function(histogram) { var counts; counts = count(histogram.ranks); if (!counts[2]) { return 0; } return +counts[2]; }, 'high card': function(histogram) { return Math.max.apply([], Object.keys(histogram.ranks)); } }; mocha.setup('bdd'); expect = chai.expect; describe('PokerCheck', function() { var poker; poker = void 0; beforeEach(function() { return poker = new PokerCheck(pokerRules); }); describe('core', function() { it('evaluates hand', function() { var result; result = poker.evaluateHand('8H 7H 6H 5H 4H'); return expect(result).to.deep.equal({ handName: 'straight flush', handRank: 110 }); }); it('evaluates game', function() { var handName, index, ref; ref = poker.evaluateGame(['8H 7H 6H 5H 4H', 'AD TD 9S 5C 4C']), index = ref[0], handName = ref[1]; expect(index).to.equal(0); return expect(handName).to.equal('straight flush'); }); return it('supports many players per game', function() { var handName, hands, index, ref; hands = ['TH TD TC 4C 4H', 'AD TD 9S 5C 4C', '8H 7H 6H 5H 4H', 'AD 8C 6S TC 5H']; ref = poker.evaluateGame(hands), index = ref[0], handName = ref[1]; return expect(index).to.equal(2); }); }); return describe('rules', function() { describe('straight flush', function() { it('basic', function() { var handName; handName = poker.evaluateHand('8H 7H 6H 5H 4H').handName; return expect(handName).to.equal('straight flush'); }); return it('tie breaker', function() { var index; index = poker.evaluateGame(['8H 7H 6H 5H 4H', '6S 5S 4S 3S 2S'])[0]; return expect(index).to.equal(0); }); }); describe('four of a kind', function() { it('basic', function() { var handName; handName = poker.evaluateHand('5S 5D 5C 5H AD').handName; return expect(handName).to.equal('four of a kind'); }); return it('tie breaker', function() { var index; index = poker.evaluateGame(['TC TD TH TS QD', '6D 6H 6S 6C 7S'])[0]; return expect(index).to.equal(0); }); }); describe('full house', function() { it('basic', function() { var handName; handName = poker.evaluateHand('TH TD TC 4C 4H').handName; return expect(handName).to.equal('full house'); }); return it('tie breaker', function() { var index; index = poker.evaluateGame(['TC TH TD 4S 4D', '9H 9C 9S AH AC'])[0]; return expect(index).to.equal(0); }); }); describe('flush', function() { it('basic', function() { var handName; handName = poker.evaluateHand('5D 4D 3D 2D AD').handName; return expect(handName).to.equal('flush'); }); return it('tie breaker', function() { var index; index = poker.evaluateGame(['AH QH TH 5H 3H', 'KS QS JS 9S 6S'])[0]; return expect(index).to.equal(0); }); }); describe('straight', function() { it('basic', function() { var handName; handName = poker.evaluateHand('5C 4D 3S 2S 6H').handName; return expect(handName).to.equal('straight'); }); return it('tie breaker', function() { var index; index = poker.evaluateGame(['8S 7S 6H 5H 4S', '6D 5S 4D 3H 2C'])[0]; return expect(index).to.equal(0); }); }); describe('three of a kind', function() { it('basic', function() { var handName; handName = poker.evaluateHand('AD 8C 8S 8C 5H').handName; return expect(handName).to.equal('three of a kind'); }); return it('tie breaker', function() { var index; index = poker.evaluateGame(['QS QC QD 5S 3C', '5C 5H 5D QD TC'])[0]; return expect(index).to.equal(0); }); }); describe('two pair', function() { it('basic', function() { var handName; handName = poker.evaluateHand('TH TD 2C 2S 4D').handName; return expect(handName).to.equal('two pair'); }); return it('tie breaker', function() { var index; index = poker.evaluateGame(['KH KD 2C 2D JH', 'JD JS TS TC 9S'])[0]; return expect(index).to.equal(0); }); }); describe('one pair', function() { it('basic', function() { var handName; handName = poker.evaluateHand('TC TH 3D 8C 7S').handName; return expect(handName).to.equal('one pair'); }); return it('tie breaker', function() { var index; index = poker.evaluateGame(['TC TS 6S 4H 2H', '9H 9C AH QD TD'])[0]; return expect(index).to.equal(0); }); }); return describe('high card', function() { it('basic', function() { var handName; handName = poker.evaluateHand('AD 8C 6S TC 5H').handName; return expect(handName).to.equal('high card'); }); return it('tie breaker', function() { var index; index = poker.evaluateGame(['AD TD 9S 5C 4C', 'KS QD JS 8H 7H'])[0]; return expect(index).to.equal(0); }); }); }); }); mocha.run(); deck = void 0; $(function() { deck = buildDeck(); return newGame(_.shuffle(deck)); }); $('#newGame').click(function(event) { event.preventDefault(); $('#hands').empty(); return newGame(_.shuffle(deck)); }); buildDeck = function() { var i, j, len, len1, rank, ref, ref1, suit; deck = []; ref = 'HDCS'.split(''); for (i = 0, len = ref.length; i < len; i++) { suit = ref[i]; ref1 = [2, 3, 4, 5, 6, 7, 8, 9].concat('TJQKA'.split('')); for (j = 0, len1 = ref1.length; j < len1; j++) { rank = ref1[j]; deck.push("" + rank + suit); } } return deck; }; newGame = function(deck, playerCount) { var bestHandIndex, bestHandRank, hand, handName, handRank, hands, i, playerIndex, poker, ref, ref1; if (playerCount == null) { playerCount = 4; } poker = new PokerCheck(pokerRules); hands = []; bestHandIndex = 0; bestHandRank = 0; for (playerIndex = i = 0, ref = playerCount; 0 <= ref ? i < ref : i > ref; playerIndex = 0 <= ref ? ++i : --i) { hand = deck.splice(0, 5); ref1 = poker.evaluateHand(hand.join(' ')), handName = ref1.handName, handRank = ref1.handRank; $('#hands').append(createHand(hand, handName)); if (handRank > bestHandRank) { bestHandRank = handRank; bestHandIndex = playerIndex; } } return $('#hands tr').eq(bestHandIndex).addClass('success'); }; suitLookup = { H: '&hearts;', D: '&diams;', C: '&clubs;', S: '&spades;' }; createHand = function(hand, handName) { var $row, $td, card, i, len, rank, ref, suit; $row = $('<tr>'); for (i = 0, len = hand.length; i < len; i++) { card = hand[i]; ref = card.split(''), rank = ref[0], suit = ref[1]; $td = $('<td>'); $td.html(buildCard(suit, rank)); $row.append($td); } $row.append($('<td>').html(handName)); return $row; }; buildCard = function(suit, rank) { var $cardEl, $rankEl; if (rank === 'T') { rank = '10'; } $cardEl = $('<div>'); $cardEl.addClass("card card--" + suit); $rankEl = $('<span>'); $rankEl.addClass('card__rank'); $rankEl.html(rank); $cardEl.append($rankEl); return $cardEl; };
}).call(this);
PokerCheck - Script Codes
PokerCheck - Script Codes
Home Page Home
Developer Not Important
Username clindsey
Uploaded July 13, 2022
Rating 3.5
Size 7,323 Kb
Views 56,672
Do you need developer help for PokerCheck?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Not Important (clindsey) Script Codes
Create amazing art & images with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!