-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rank.js
79 lines (79 loc) · 2.67 KB
/
Rank.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"use strict";
exports.__esModule = true;
exports.Rank = void 0;
var Rank = /** @class */ (function () {
// REQUIRES: stringRank is a string
// EXAMPLES: stringRank1 = "Ace", stringRank2 = "Eight"
function Rank(stringRank) {
this.name = stringRank;
}
//EFFECTS: returns a string of this rank
Rank.prototype.getRankName = function () {
return this.name;
};
//REQUIRES: otherRank is a Rank object
//EFFECTS: returns true if this object has same rank as otherCard, false otherwise
Rank.prototype.isSameRankAs = function (otherRank) {
return this.name == otherRank.name;
};
//REQUIRES: otherRank is a Rank object
//EFFECTS: returns true if this object has better rank than otherCard, false otherwise
Rank.prototype.isBetterRankThan = function (otherRank) {
// COMMENTS: these strength variables represent the importance of ranks
var firstRankStrength = Rank.rankStrengths.get(this.name);
var secondRankStrength = Rank.rankStrengths.get(otherRank.name);
return firstRankStrength > secondRankStrength;
};
//REQUIRES: otherRank is a Rank object
//EFFECTS: if this < otherRank, return -1. if this > other_suit, return 1. return 0 otherwise
Rank.prototype.compareToTheRank = function (otherRank) {
return Rank.compareTwoRanks(this, otherRank);
};
//REQUIRES: firstRank and secondRank are Rank objects
//EFFECTS: if firstRank < secondRank, return -1. if firstRank > secondRank, return 1. return 0 otherwise
//USAGE: ranksVector.sort(Rank.compareTwoRanks);
Rank.compareTwoRanks = function (firstRank, secondRank) {
// COMMENTS: these strength variables represent the importance of rank
var firstRankStrength = Rank.rankStrengths.get(firstRank.getRankName());
var secondRankStrength = Rank.rankStrengths.get(secondRank.getRankName());
// COMMENTS: go compare
if (firstRankStrength < secondRankStrength)
return -1;
else if (firstRankStrength == secondRankStrength) {
return 0;
}
return 1;
};
Rank.rankStrings = [
"Three",
"Four",
"Five",
"Six",
"Seven",
"Eight",
"Nine",
"Ten",
"Jack",
"Queen",
"King",
"Ace",
"Two",
];
Rank.rankStrengths = new Map([
["Three", 0],
["Four", 1],
["Five", 2],
["Six", 3],
["Seven", 4],
["Eight", 5],
["Nine", 6],
["Ten", 7],
["Jack", 8],
["Queen", 9],
["King", 10],
["Ace", 11],
["Two", 12],
]);
return Rank;
}());
exports.Rank = Rank;