Commit dfa6afc1 authored by Wellintong Soto's avatar Wellintong Soto

initial commit

parent 6a8a23f2
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\poker.js"
}
]
}
\ No newline at end of file
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<!-- <script src="poker.js"></script> -->
</body>
</html>
\ No newline at end of file
{
"lockfileVersion": 1
}
/* FUNCIONES */
// ELIMINAR VALORES DUPLICADOS DE ARRAY
function deleteDuplicate(arr) {
var i,
len=arr.length,
out=[],
obj={};
for (i=0;i<len;i++) {
obj[arr[i]]=0;
}
for (i in obj) {
out.push(i);
}
return out;
}
// ELIMINAR DATO DE ARRAY POR VALOR
function deleteValueFromArray(array, deleteVal, nameKey = '') {
if ( nameKey ) {
array.forEach(function(val, i) {
var valJs = "val." + nameKey;
// console.log({valJs: eval(valJs)});
if ( eval(valJs) == deleteVal ) {
array.splice(i, 1);
}
});
} else {
array.forEach(function(val, i) {
if ( val == deleteVal ) {
array.splice(i, 1);
}
});
}
return array;
}
class Card {
constructor (name, suit, value) {
this.name = name;
this.suit = suit
this.value = value;
}
}
class PokerHand {
constructor (player) {
this.player = player;
this.cards = [];
}
addCard (card) {
this.cards.push(card)
}
printHand () {
console.log('Hand');
this.highCard();
this.cards.forEach(card => {
console.log(card.name);
});
}
highCard () {
this.cards.sort(function (a, b) {
if (a.value > b.value) {
return 1;
}
if (a.value < b.value) {
return -1;
}
// a must be equal to b
return 0;
});
// console.log(this.cards);
}
pairs () {
var pairs = [];
this.cards.forEach((card, i) => {
this.cards.forEach((card2, j) => {
if (i != j) {
if (card.value == card2.value) {
pairs.push(card.value);
}
}
});
});
return deleteDuplicate(pairs);
}
straight () {
let straightFlash = false;
let straightTo = "";
if (this.cards[4] === this.cards[0] + 4) {
straightTo = this.cards[4].value;
straightFlash = !this.cards.find(card => card.suit !== this.cards[0].suit);
}
return { straightFlash, straightTo };
}
repeated () {
let repeat = [];
let pairs = [];
let triples = [];
let fulls = [];
this.cards.forEach((card, i) => {
this.cards.forEach((card2, j) => {
if (i != j) {
if (card.value == card2.value) {
switch (repeat[i]) {
case 2:
repeat[i] = card.value;
triples.push(card);
deleteValueFromArray(pairs, card, 'value');
break;
case 3:
repeat[i] = card.value;
fulls.push(card);
deleteValueFromArray(triples, card, 'value');
break;
default:
repeat[i] = card.value;
pairs.push(card);
break;
}
}
}
});
});
return {repeat, pairs, triples, fulls};
}
}
let pokerDeck = [
new Card('2S', 'S', 2),
new Card('3S', 'S', 3),
new Card('4S', 'S', 4),
new Card('5S', 'S', 5),
new Card('6S', 'S', 6),
new Card('7S', 'S', 7),
new Card('8S', 'S', 8),
new Card('9S', 'S', 9),
new Card('TS', 'S', 10),
new Card('JS', 'S', 11),
new Card('QS', 'S', 12),
new Card('KS', 'S', 13),
new Card('AS', 'S', 14),
new Card('2H', 'H', 2),
new Card('3H', 'H', 3),
new Card('4H', 'H', 4),
new Card('5H', 'H', 5),
new Card('6H', 'H', 6),
new Card('7H', 'H', 7),
new Card('8H', 'H', 8),
new Card('9H', 'H', 9),
new Card('TH', 'H', 10),
new Card('JH', 'H', 11),
new Card('QH', 'H', 12),
new Card('KH', 'H', 13),
new Card('AH', 'H', 14),
new Card('2C', 'C', 2),
new Card('3C', 'C', 3),
new Card('4C', 'C', 4),
new Card('5C', 'C', 5),
new Card('6C', 'C', 6),
new Card('7C', 'C', 7),
new Card('8C', 'C', 8),
new Card('9C', 'C', 9),
new Card('TC', 'C', 10),
new Card('JC', 'C', 11),
new Card('QC', 'C', 12),
new Card('KC', 'C', 13),
new Card('AC', 'C', 14),
new Card('2D', 'D', 2),
new Card('3D', 'D', 3),
new Card('4D', 'D', 4),
new Card('5D', 'D', 5),
new Card('6D', 'D', 6),
new Card('7D', 'D', 7),
new Card('8D', 'D', 8),
new Card('9D', 'D', 9),
new Card('TD', 'D', 10),
new Card('JD', 'D', 11),
new Card('QD', 'D', 12),
new Card('KD', 'D', 13),
new Card('AD', 'D', 14)
];
const BESTS_HAND = [
{ name: 'Straight', }
]
// let card1 = new Card(CARDS_VALUES[2], CARDS_SUITS[1]);
// console.log(card1.value);
// console.log(card1.name);
let players = 2;
for (let index = 1; index <= players; index++) {
console.log('PLAYER ' + index + ' ---------------------------------');
let pokerHand = new PokerHand('Player' + index);
for (let index = 0; index <= 4; index++) {
var card = "";
while (!card) {
let randomCard = parseInt(Math.random() * 52);
card = pokerDeck[randomCard];
pokerDeck[randomCard] = "";
}
pokerHand.addCard(card);
// console.log('Name', card.name);
// console.log('Value ', card.value);
}
console.log(pokerHand.printHand());
console.log(pokerHand.repeated(), 'repeat');
console.log(pokerHand.straight(), 'Escalera');
}
// console.log(parseInt(Math.random() * 14))
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment