I'm not sure what the best course of action is from here. For each player, I have created an array that holds both the community cards and its own cards, the one thing I have left to do is to evaluate the results.
I could of course brute force check every seven card combination, but a) that wouldn't be very elegant and quick, and b) I wouldn't know how to handle a tie, since then you'd have to look at the remaining high cards.
Here is the fiddle, I've used document.write() for everything, for testing purposes:
https://jsfiddle.net/bjp11yjb/1/
If anyone could point me in the right direction, without confusing me too much, I'd be much obliged!
var suits = ['Clubs', 'Spades', 'Hearts', 'Diamonds'];
var ranks = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King', 'Ace'];
var combinations = ['Royal Flush', 'Straight Flush', 'Four of a Kind', 'Full House', 'Flush', 'Straight', 'Three of a Kind', 'Two Pair', 'One Pair'];
var deck = [];
var players = [new Player(), new Player()];
var table = [];
function Player() {
this.hand = [];
this.result;
}
function Card(suit, rank) {
this.suit = suit;
this.rank = rank;
this.name = rank + ' of ' + suit;
}
function initDeck() {
deck = [];
for(var i = 0; i < 4; i++) {
for(var j = 0; j < 13; j++) {
deck.push(new Card(suits[i], ranks[j]));
}
}
}
function drawCard() {
var randNumber = Math.floor(Math.random() * deck.length);
var drawnCard = deck[randNumber];
deck.splice(randNumber, 1);
return drawnCard;
}
function dealCards() {
for(var i = 0; i < 2; i++) {
for(var j = 0; j < players.length; j++) {
var drawnCard = drawCard();
players[j].hand.push(drawnCard);
}
}
}
function flop() {
for(var i = 0; i < 3; i++) {
var drawnCard = drawCard();
table.push(drawnCard);
}
}
function turn() {
var drawnCard = drawCard();
table.push(drawnCard);
}
function river() {
var drawnCard = drawCard();
table.push(drawnCard);
}
function showDown() {
for(var i = 0; i < players.length; i++) {
evaluate(i);
document.write("<br>");
}
}
function evaluate(player) {
var totalHand = players[player].hand.concat(table);
for(var i = 0; i < totalHand.length; i++) {
}
}
initDeck();
dealCards();
document.write("Player 1: " + players[0].hand[0].name + ' and ' + players[0].hand[1].name + '<br>');
document.write("Player 2: " + players[1].hand[0].name + ' and ' + players[1].hand[1].name + '<br><br>');
flop();
document.write("Flop: " + table[0].name + ', ' + table[1].name + ' and ' + table[2].name + '<br>');
turn();
document.write("Turn: " + table[0].name + ', ' + table[1].name + ', ' + table[2].name + ' and ' + table[3].name + '<br>');
river();
document.write("River: " + table[0].name + ', ' + table[1].name + ', ' + table[2].name + ', ' + table[3].name + ' and ' + table[4].name + '<br>');
showDown();