How to calculate the face value of a Texas poker _javascript skill

Source: Internet
Author: User
Tags flush

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.