This article illustrates the method of JS calculating the face value of Texas poker. Share to everyone for your reference. Specifically as follows:
1. The code is as follows:
Copy Code code as follows:
var Poker = function (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 () {
return This.color + this.show;
};
};
var z = function (arg) {//Flush
var a = arg,
t = a[0];
for (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 = = && A[i].color = = T.color) {
t = a[0];
}else{
Return
}
};
Return "Z" + t.ch;
};
var y = function (arg) {//Four
var a = Arg.map (function (p) {
return p.ch;
}). Join (""),
Mat = A.match (/(\w*) (\w) \2\2\2 (\w*)/);
if (MAT) {
Return "Y" +mat[2]+mat[1]+mat[3];
}
};
var x = function (ARG) {//Hoist
var a = Arg.map (function (p) {
return p.ch;
}). Join (""),
Mat
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 = function (ARG) {//Same flower
var a = arg,
t = a[0];
for (var i = 1; i < a.length; i++) {
if (A[i].color = = T.color) {
t = A[i];
}else{
Return
}
};
Return "W" + Arg.map (function (p) {
return p.ch;
}). Join ("");
};
var v = function (arg) {//Shun Zi
var a = arg,
t = a[0];
for (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];
}else{
Return
}
};
Return "V" + t.ch;
};
var u = function (arg) {//Three
var a = Arg.map (function (p) {
return p.ch;
}). Join (""),
Mat
if (Mat = A.match (/(\w*) (\w) \2\2 (\w*)/)) {
Return "U" + mat[2] + mat[1] + mat[3];
}
};
var t = function (ARG) {//two pair
var a = Arg.map (function (p) {
return p.ch;
}). Join (""),
Mat
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 = function (ARG) {//Pair
var a = Arg.map (function (p) {
return p.ch;
}). Join (""),
Mat
if (Mat = A.match (/(\w*) (\w) \2 (\w*)/)) {
Return "s" + mat[2] + mat[1] + mat[3];
}
};
var r = function (ARG) {//High card
Return Arg.map (function (p) {
return p.ch;
}). Join ("");
};
var score = function () {
var a = [].map.call (arguments, function (p) {
return new Poker (p);
}). sort (function (P1,P2) {
return p1.num-p2.num;
});
Console.log (A.join (","));
Return 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)); Same flush.
Console.log (Score (36, 49, 23, 10, 48)); Four articles
Console.log (Score (36, 49, 23, 22, 48)); Gourd
Console.log (Score (50, 40, 47, 43, 48)); With flowers
Console.log (Score (50, 36, 47, 46, 48)); Shun Zi
Console.log (Score (36, 49, 25, 22, 48)); Two pairs
Console.log (Score (36, 49, 20, 27, 47)); A
Console.log (Score (36, 11, 20, 27, 47)); High card
2. The operation effect is shown in the following illustration:
I hope this article will help you with your JavaScript programming.