Ces exemples d'articles décrivent comment calculer la valeur nominale des cartes Hold'em du Texas par JS. Partagez-le pour votre référence. Les détails sont les suivants:
1. Le code est le suivant:
Copiez le code comme suit: var poker = fonction (n) {
this.num = (n% 13) + 2;
this.ch = this.num> 9? ("ABCDEF" [this.num-10]): this.num;
this.show = "0,1,2,3,4,5,6,7,8,9,10, j, q, k, a",. Split (",") [this.num];
this.color = "♠ ♥ ♣ ♦" [n / 13 | 0];
this.toString = function () {
Renvoie ce.color + this.show;
};
};
var z = fonction (arg) {// flush
var a = arg,
t = a [0];
pour (var i = 1; i <a.length; i ++) {
if (a [i] .color === t.color && a [i] .num === t.num + 1) {
t = a [i];
} else if (i === a.length-1 && t.num === 5 && a [i] .num === 14 && a [i] .color === t.color) {
t = a [0];
}autre{
retour;
}
};
retourner "z" + t.ch;
};
var y = fonction (arg) {// quatre éléments
var a = arg.map (fonction (p) {
retour p.ch;
}).rejoindre(""),
mat = a.match (/ (/ w *) (/ w) / 2/2/2 (/ w *) /);
if (mat) {
return "y" + mat [2] + mat [1] + mat [3];
}
};
var x = fonction (arg) {// gourd
var a = arg.map (fonction (p) {
retour p.ch;
}).rejoindre(""),
tapis;
if (mat = a.match (/ (/ w) / 1 (/ w) / 2/2 /)) {
return "x" + mat [2] + mat [1];
} else if (mat = a.match (/ (/ w) / 1/1 (/ w) / 2 /)) {
return "x" + mat [1] + mat [2];
}
};
var w = fonction (arg) {// synonymes
var a = arg,
t = a [0];
pour (var i = 1; i <a.length; i ++) {
if (a [i] .color === t.color) {
t = a [i];
}autre{
retour;
}
};
return "w" + arg.map (fonction (p) {
retour p.ch;
}).rejoindre("");
};
var v = fonction (arg) {// shizi
var a = arg,
t = a [0];
pour (var i = 1; i <a.length; i ++) {
if (a [i] .num === t.num + 1) {
t = a [i];
} else if (i === a.length-1 && t.num === 5 && a [i] .num === 14) {
t = a [0];
}autre{
retour;
}
};
retourner "v" + t.ch;
};
var u = fonction (arg) {// trois éléments
var a = arg.map (fonction (p) {
retour p.ch;
}).rejoindre(""),
tapis;
if (mat = a.match (/ (/ w *) (/ w) / 2/2 (/ w *) /)) {
return "u" + mat [2] + mat [1] + mat [3];
}
};
var t = fonction (arg) {// deux paires
var a = arg.map (fonction (p) {
retour p.ch;
}).rejoindre(""),
tapis;
if (mat = a.match (/ (/ w *) (/ w) / 2 (/ w) / 3 (/ w *) /) {
return "T" + Mat [3] + Mat [2] + Mat [1] + Mat [4];
} else if (mat = a.match (/ (/ w) / 1 (/ w) (/ w) / 3 /)) {
return "t" + mat [3] + mat [1] + mat [2];
}
};
var s = fonction (arg) {// une paire
var a = arg.map (fonction (p) {
retour p.ch;
}).rejoindre(""),
tapis;
if (mat = a.match (/ (/ w *) (/ w) / 2 (/ w *) /)) {
return "S" + Mat [2] + Mat [1] + Mat [3];
}
};
var r = fonction (arg) {// carte haute
return arg.map (fonction (p) {
retour p.ch;
}).rejoindre("");
};
var score = function () {
var a = [] .map.call (arguments, fonction (p) {
retourner le nouveau poker (P);
}). Soi (fonction (p1, p2) {
retour p1.num - p2.num;
});
console.log (a.join (","));
retourner z (a) || y (a) || x (a) || W (a) || v (a) || u (a) || t (a) || S (a) || r (a);
};
Console.log (score (50, 49, 47, 46, 48)); // rincer
Console.log (score (36, 49, 23, 10, 48)); // quatre articles
Console.log (score (36, 49, 23, 22, 48)); // gourde
Console.log (score (50, 40, 47, 43, 48)); // même fleur
Console.log (score (50, 36, 47, 46, 48)); // Shunzi
Console.log (score (36, 49, 25, 22, 48)); // deux paires
Console.log (score (36, 49, 20, 27, 47)); // une paire
Console.log (score (36, 11, 20, 27, 47)); // carte haute
2. L'effet de fonctionnement est illustré dans la figure ci-dessous:
J'espère que cet article sera utile à la programmation JavaScript de tous.