trucoshi 0.0.22 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -674
- package/README.md +37 -37
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -0
- package/dist/lib/classes/Deck.d.ts +16 -3
- package/dist/lib/classes/Deck.js +38 -38
- package/dist/lib/classes/GameLoop.d.ts +20 -0
- package/dist/lib/classes/GameLoop.js +103 -0
- package/dist/lib/classes/Hand.d.ts +38 -2
- package/dist/lib/classes/Hand.js +233 -233
- package/dist/lib/classes/Lobby.d.ts +27 -0
- package/dist/lib/classes/Lobby.js +114 -0
- package/dist/lib/classes/Match.d.ts +18 -2
- package/dist/lib/classes/Match.js +115 -115
- package/dist/lib/classes/Play.d.ts +21 -2
- package/dist/lib/classes/Play.js +39 -39
- package/dist/lib/classes/Player.d.ts +24 -3
- package/dist/lib/classes/Player.js +71 -71
- package/dist/lib/classes/Round.d.ts +17 -2
- package/dist/lib/classes/Round.js +34 -34
- package/dist/lib/classes/Table.d.ts +12 -2
- package/dist/lib/classes/Table.js +30 -30
- package/dist/lib/classes/Team.d.ts +17 -3
- package/dist/lib/classes/Team.js +58 -58
- package/dist/lib/classes/Truco.d.ts +18 -2
- package/dist/lib/classes/Truco.js +110 -110
- package/dist/lib/classes/index.d.ts +11 -0
- package/dist/lib/classes/index.js +27 -0
- package/dist/lib/constants.d.ts +45 -52
- package/dist/lib/constants.js +85 -93
- package/dist/lib/index.d.ts +2 -17
- package/dist/lib/index.js +18 -211
- package/dist/lib/types.d.ts +50 -206
- package/dist/lib/types.js +34 -26
- package/dist/lib/utils.d.ts +5 -5
- package/dist/lib/utils.js +59 -59
- package/dist/server/classes/MatchTable.d.ts +32 -30
- package/dist/server/classes/MatchTable.js +77 -77
- package/dist/server/classes/User.d.ts +5 -5
- package/dist/server/classes/User.js +11 -11
- package/dist/server/{match.d.ts → classes/index.d.ts} +0 -0
- package/dist/server/{match.js → classes/index.js} +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +379 -391
- package/dist/server/types.d.ts +36 -35
- package/dist/server/types.js +26 -26
- package/dist/test/autoplay.d.ts +1 -1
- package/dist/test/autoplay.js +94 -94
- package/dist/test/play.d.ts +1 -1
- package/dist/test/play.js +214 -214
- package/dist/types.d.ts +83 -0
- package/dist/types.js +57 -0
- package/package.json +2 -2
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
3
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
4
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
5
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
6
|
-
function step(op) {
|
|
7
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
8
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
9
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
10
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
11
|
-
switch (op[0]) {
|
|
12
|
-
case 0: case 1: t = op; break;
|
|
13
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
14
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
15
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
16
|
-
default:
|
|
17
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
18
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
19
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
20
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
21
|
-
if (t[2]) _.ops.pop();
|
|
22
|
-
_.trys.pop(); continue;
|
|
23
|
-
}
|
|
24
|
-
op = body.call(thisArg, _);
|
|
25
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
26
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.Match = void 0;
|
|
31
|
-
var Deck_1 = require("./Deck");
|
|
32
|
-
var Hand_1 = require("./Hand");
|
|
33
|
-
function Match(table, teams, matchPoint) {
|
|
34
|
-
if (teams === void 0) { teams = []; }
|
|
35
|
-
if (matchPoint === void 0) { matchPoint = 9; }
|
|
36
|
-
var deck = (0, Deck_1.Deck)().shuffle();
|
|
37
|
-
var size = teams[0].players.length;
|
|
38
|
-
if (size !== teams[1].players.length) {
|
|
39
|
-
throw new Error("Team size mismatch");
|
|
40
|
-
}
|
|
41
|
-
function handsGeneratorSequence() {
|
|
42
|
-
var hand, value, teams_1, winner;
|
|
43
|
-
return __generator(this, function (_a) {
|
|
44
|
-
switch (_a.label) {
|
|
45
|
-
case 0:
|
|
46
|
-
if (!!match.winner) return [3 /*break*/, 4];
|
|
47
|
-
deck.shuffle();
|
|
48
|
-
hand = match.setCurrentHand((0, Hand_1.Hand)(match, deck, match.hands.length + 1));
|
|
49
|
-
match.pushHand(hand);
|
|
50
|
-
_a.label = 1;
|
|
51
|
-
case 1:
|
|
52
|
-
if (!!hand.finished()) return [3 /*break*/, 3];
|
|
53
|
-
value = hand.getNextPlayer().value;
|
|
54
|
-
if (value && value.finished()) {
|
|
55
|
-
return [3 /*break*/, 1];
|
|
56
|
-
}
|
|
57
|
-
match.setCurrentHand(value);
|
|
58
|
-
return [4 /*yield*/, match];
|
|
59
|
-
case 2:
|
|
60
|
-
_a.sent();
|
|
61
|
-
return [3 /*break*/, 1];
|
|
62
|
-
case 3:
|
|
63
|
-
match.setCurrentHand(null);
|
|
64
|
-
teams_1 = match.addPoints(hand.points);
|
|
65
|
-
winner = teams_1.find(function (team) { return team.points.winner; });
|
|
66
|
-
if (winner) {
|
|
67
|
-
match.setWinner(winner);
|
|
68
|
-
match.setCurrentHand(null);
|
|
69
|
-
return [3 /*break*/, 4];
|
|
70
|
-
}
|
|
71
|
-
match.table.nextTurn();
|
|
72
|
-
return [3 /*break*/, 0];
|
|
73
|
-
case 4: return [4 /*yield*/, match];
|
|
74
|
-
case 5:
|
|
75
|
-
_a.sent();
|
|
76
|
-
return [2 /*return*/];
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
var handsGenerator = handsGeneratorSequence();
|
|
81
|
-
var match = {
|
|
82
|
-
winner: null,
|
|
83
|
-
teams: teams,
|
|
84
|
-
hands: [],
|
|
85
|
-
table: table,
|
|
86
|
-
currentHand: null,
|
|
87
|
-
play: function () {
|
|
88
|
-
match.getNextTurn();
|
|
89
|
-
if (!match.currentHand) {
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
return match.currentHand.play();
|
|
93
|
-
},
|
|
94
|
-
addPoints: function (points) {
|
|
95
|
-
match.teams[0].addPoints(matchPoint, points[0]);
|
|
96
|
-
match.teams[1].addPoints(matchPoint, points[1]);
|
|
97
|
-
return match.teams;
|
|
98
|
-
},
|
|
99
|
-
pushHand: function (hand) {
|
|
100
|
-
match.hands.push(hand);
|
|
101
|
-
},
|
|
102
|
-
setCurrentHand: function (hand) {
|
|
103
|
-
match.currentHand = hand;
|
|
104
|
-
return match.currentHand;
|
|
105
|
-
},
|
|
106
|
-
setWinner: function (winner) {
|
|
107
|
-
match.winner = winner;
|
|
108
|
-
},
|
|
109
|
-
getNextTurn: function () {
|
|
110
|
-
return handsGenerator.next();
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
return match;
|
|
114
|
-
}
|
|
115
|
-
exports.Match = Match;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
3
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
4
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
5
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
6
|
+
function step(op) {
|
|
7
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
8
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
9
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
10
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
11
|
+
switch (op[0]) {
|
|
12
|
+
case 0: case 1: t = op; break;
|
|
13
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
14
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
15
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
16
|
+
default:
|
|
17
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
18
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
19
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
20
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
21
|
+
if (t[2]) _.ops.pop();
|
|
22
|
+
_.trys.pop(); continue;
|
|
23
|
+
}
|
|
24
|
+
op = body.call(thisArg, _);
|
|
25
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
26
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.Match = void 0;
|
|
31
|
+
var Deck_1 = require("./Deck");
|
|
32
|
+
var Hand_1 = require("./Hand");
|
|
33
|
+
function Match(table, teams, matchPoint) {
|
|
34
|
+
if (teams === void 0) { teams = []; }
|
|
35
|
+
if (matchPoint === void 0) { matchPoint = 9; }
|
|
36
|
+
var deck = (0, Deck_1.Deck)().shuffle();
|
|
37
|
+
var size = teams[0].players.length;
|
|
38
|
+
if (size !== teams[1].players.length) {
|
|
39
|
+
throw new Error("Team size mismatch");
|
|
40
|
+
}
|
|
41
|
+
function handsGeneratorSequence() {
|
|
42
|
+
var hand, value, teams_1, winner;
|
|
43
|
+
return __generator(this, function (_a) {
|
|
44
|
+
switch (_a.label) {
|
|
45
|
+
case 0:
|
|
46
|
+
if (!!match.winner) return [3 /*break*/, 4];
|
|
47
|
+
deck.shuffle();
|
|
48
|
+
hand = match.setCurrentHand((0, Hand_1.Hand)(match, deck, match.hands.length + 1));
|
|
49
|
+
match.pushHand(hand);
|
|
50
|
+
_a.label = 1;
|
|
51
|
+
case 1:
|
|
52
|
+
if (!!hand.finished()) return [3 /*break*/, 3];
|
|
53
|
+
value = hand.getNextPlayer().value;
|
|
54
|
+
if (value && value.finished()) {
|
|
55
|
+
return [3 /*break*/, 1];
|
|
56
|
+
}
|
|
57
|
+
match.setCurrentHand(value);
|
|
58
|
+
return [4 /*yield*/, match];
|
|
59
|
+
case 2:
|
|
60
|
+
_a.sent();
|
|
61
|
+
return [3 /*break*/, 1];
|
|
62
|
+
case 3:
|
|
63
|
+
match.setCurrentHand(null);
|
|
64
|
+
teams_1 = match.addPoints(hand.points);
|
|
65
|
+
winner = teams_1.find(function (team) { return team.points.winner; });
|
|
66
|
+
if (winner) {
|
|
67
|
+
match.setWinner(winner);
|
|
68
|
+
match.setCurrentHand(null);
|
|
69
|
+
return [3 /*break*/, 4];
|
|
70
|
+
}
|
|
71
|
+
match.table.nextTurn();
|
|
72
|
+
return [3 /*break*/, 0];
|
|
73
|
+
case 4: return [4 /*yield*/, match];
|
|
74
|
+
case 5:
|
|
75
|
+
_a.sent();
|
|
76
|
+
return [2 /*return*/];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
var handsGenerator = handsGeneratorSequence();
|
|
81
|
+
var match = {
|
|
82
|
+
winner: null,
|
|
83
|
+
teams: teams,
|
|
84
|
+
hands: [],
|
|
85
|
+
table: table,
|
|
86
|
+
currentHand: null,
|
|
87
|
+
play: function () {
|
|
88
|
+
match.getNextTurn();
|
|
89
|
+
if (!match.currentHand) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
return match.currentHand.play();
|
|
93
|
+
},
|
|
94
|
+
addPoints: function (points) {
|
|
95
|
+
match.teams[0].addPoints(matchPoint, points[0]);
|
|
96
|
+
match.teams[1].addPoints(matchPoint, points[1]);
|
|
97
|
+
return match.teams;
|
|
98
|
+
},
|
|
99
|
+
pushHand: function (hand) {
|
|
100
|
+
match.hands.push(hand);
|
|
101
|
+
},
|
|
102
|
+
setCurrentHand: function (hand) {
|
|
103
|
+
match.currentHand = hand;
|
|
104
|
+
return match.currentHand;
|
|
105
|
+
},
|
|
106
|
+
setWinner: function (winner) {
|
|
107
|
+
match.winner = winner;
|
|
108
|
+
},
|
|
109
|
+
getNextTurn: function () {
|
|
110
|
+
return handsGenerator.next();
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
return match;
|
|
114
|
+
}
|
|
115
|
+
exports.Match = Match;
|
|
@@ -1,2 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { ECommand, EHandState, EnvidoState } from "../../types";
|
|
2
|
+
import { ICard } from "./Deck";
|
|
3
|
+
import { IHand } from "./Hand";
|
|
4
|
+
import { IPlayer } from "./Player";
|
|
5
|
+
import { IRound } from "./Round";
|
|
6
|
+
import { ITeam } from "./Team";
|
|
7
|
+
import { ITruco } from "./Truco";
|
|
8
|
+
export interface IPlayInstance {
|
|
9
|
+
teams: [ITeam, ITeam];
|
|
10
|
+
handIdx: number;
|
|
11
|
+
roundIdx: number;
|
|
12
|
+
state: EHandState;
|
|
13
|
+
truco: ITruco;
|
|
14
|
+
envido: EnvidoState;
|
|
15
|
+
player: IPlayer | null;
|
|
16
|
+
commands: Array<ECommand> | null;
|
|
17
|
+
rounds: Array<IRound> | null;
|
|
18
|
+
use(idx: number, card: ICard): ICard | null;
|
|
19
|
+
say(command: ECommand): ECommand | null;
|
|
20
|
+
}
|
|
21
|
+
export declare function PlayInstance(hand: IHand, teams: [ITeam, ITeam]): IPlayInstance;
|
package/dist/lib/classes/Play.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PlayInstance = void 0;
|
|
4
|
-
var types_1 = require("
|
|
5
|
-
function PlayInstance(hand, teams) {
|
|
6
|
-
var _a, _b, _c;
|
|
7
|
-
var instance = {
|
|
8
|
-
state: hand.state,
|
|
9
|
-
teams: teams,
|
|
10
|
-
truco: hand.truco,
|
|
11
|
-
envido: hand.envido,
|
|
12
|
-
handIdx: hand.idx,
|
|
13
|
-
roundIdx: hand.rounds.length,
|
|
14
|
-
player: hand.currentPlayer,
|
|
15
|
-
commands: [],
|
|
16
|
-
rounds: hand.rounds,
|
|
17
|
-
use: function (idx, card) {
|
|
18
|
-
return hand.use(idx, card);
|
|
19
|
-
},
|
|
20
|
-
say: function (command) {
|
|
21
|
-
var _a;
|
|
22
|
-
if (!hand._currentPlayer || !((_a = instance.commands) === null || _a === void 0 ? void 0 : _a.includes(command))) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
hand.commands[command](hand._currentPlayer);
|
|
26
|
-
return command;
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
(_a = instance.commands) === null || _a === void 0 ? void 0 : _a.push(types_1.ESayCommand.MAZO);
|
|
30
|
-
(_b = instance.commands) === null || _b === void 0 ? void 0 : _b.push(types_1.ESayCommand.TRUCO);
|
|
31
|
-
if (hand.rounds.length === 1) {
|
|
32
|
-
(_c = instance.commands) === null || _c === void 0 ? void 0 : _c.push(types_1.EEnvidoCommand.ENVIDO);
|
|
33
|
-
}
|
|
34
|
-
if (hand.state === types_1.EHandState.WAITING_FOR_TRUCO_ANSWER) {
|
|
35
|
-
instance.commands = [types_1.ESayCommand.TRUCO, types_1.ESayCommand.QUIERO, types_1.ESayCommand.NO_QUIERO];
|
|
36
|
-
}
|
|
37
|
-
return instance;
|
|
38
|
-
}
|
|
39
|
-
exports.PlayInstance = PlayInstance;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlayInstance = void 0;
|
|
4
|
+
var types_1 = require("../../types");
|
|
5
|
+
function PlayInstance(hand, teams) {
|
|
6
|
+
var _a, _b, _c;
|
|
7
|
+
var instance = {
|
|
8
|
+
state: hand.state,
|
|
9
|
+
teams: teams,
|
|
10
|
+
truco: hand.truco,
|
|
11
|
+
envido: hand.envido,
|
|
12
|
+
handIdx: hand.idx,
|
|
13
|
+
roundIdx: hand.rounds.length,
|
|
14
|
+
player: hand.currentPlayer,
|
|
15
|
+
commands: [],
|
|
16
|
+
rounds: hand.rounds,
|
|
17
|
+
use: function (idx, card) {
|
|
18
|
+
return hand.use(idx, card);
|
|
19
|
+
},
|
|
20
|
+
say: function (command) {
|
|
21
|
+
var _a;
|
|
22
|
+
if (!hand._currentPlayer || !((_a = instance.commands) === null || _a === void 0 ? void 0 : _a.includes(command))) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
hand.commands[command](hand._currentPlayer);
|
|
26
|
+
return command;
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
(_a = instance.commands) === null || _a === void 0 ? void 0 : _a.push(types_1.ESayCommand.MAZO);
|
|
30
|
+
(_b = instance.commands) === null || _b === void 0 ? void 0 : _b.push(types_1.ESayCommand.TRUCO);
|
|
31
|
+
if (hand.rounds.length === 1) {
|
|
32
|
+
(_c = instance.commands) === null || _c === void 0 ? void 0 : _c.push(types_1.EEnvidoCommand.ENVIDO);
|
|
33
|
+
}
|
|
34
|
+
if (hand.state === types_1.EHandState.WAITING_FOR_TRUCO_ANSWER) {
|
|
35
|
+
instance.commands = [types_1.ESayCommand.TRUCO, types_1.ESayCommand.QUIERO, types_1.ESayCommand.NO_QUIERO];
|
|
36
|
+
}
|
|
37
|
+
return instance;
|
|
38
|
+
}
|
|
39
|
+
exports.PlayInstance = PlayInstance;
|
|
@@ -1,3 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export
|
|
1
|
+
import { ECommand } from "../../types";
|
|
2
|
+
import { ICard } from "./Deck";
|
|
3
|
+
export interface IPlayer {
|
|
4
|
+
teamIdx: number;
|
|
5
|
+
id: string;
|
|
6
|
+
session?: string;
|
|
7
|
+
hand: Array<ICard>;
|
|
8
|
+
commands: Array<ECommand>;
|
|
9
|
+
usedHand: Array<ICard>;
|
|
10
|
+
prevHand: Array<ICard>;
|
|
11
|
+
isTurn: boolean;
|
|
12
|
+
disabled: boolean;
|
|
13
|
+
ready: boolean;
|
|
14
|
+
setTurn(turn: boolean): void;
|
|
15
|
+
getPublicPlayer(): IPlayer;
|
|
16
|
+
setSession(session: string): void;
|
|
17
|
+
enable(): void;
|
|
18
|
+
disable(): void;
|
|
19
|
+
setReady(ready: boolean): void;
|
|
20
|
+
setHand(hand: Array<ICard>): Array<ICard>;
|
|
21
|
+
useCard(idx: number, card: ICard): ICard | null;
|
|
22
|
+
}
|
|
23
|
+
export type IPublicPlayer = Pick<IPlayer, "id" | "disabled" | "ready" | "hand" | "usedHand" | "prevHand" | "teamIdx" | "session" | "isTurn">;
|
|
24
|
+
export declare function Player(id: string, teamIdx: number): IPlayer;
|
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
14
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
15
|
-
if (ar || !(i in from)) {
|
|
16
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
17
|
-
ar[i] = from[i];
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
|
-
};
|
|
22
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.Player = void 0;
|
|
24
|
-
function Player(id, teamIdx) {
|
|
25
|
-
var player = {
|
|
26
|
-
id: id,
|
|
27
|
-
session: undefined,
|
|
28
|
-
teamIdx: teamIdx,
|
|
29
|
-
hand: [],
|
|
30
|
-
commands: [],
|
|
31
|
-
usedHand: [],
|
|
32
|
-
prevHand: [],
|
|
33
|
-
isTurn: false,
|
|
34
|
-
disabled: false,
|
|
35
|
-
ready: false,
|
|
36
|
-
setTurn: function (turn) {
|
|
37
|
-
player.isTurn = turn;
|
|
38
|
-
},
|
|
39
|
-
getPublicPlayer: function () {
|
|
40
|
-
return __assign(__assign({}, player), { hand: player.hand.map(function () { return "xx"; }), session: undefined });
|
|
41
|
-
},
|
|
42
|
-
setSession: function (session) {
|
|
43
|
-
player.session = session;
|
|
44
|
-
},
|
|
45
|
-
enable: function () {
|
|
46
|
-
player.disabled = false;
|
|
47
|
-
},
|
|
48
|
-
disable: function () {
|
|
49
|
-
player.disabled = true;
|
|
50
|
-
},
|
|
51
|
-
setReady: function (ready) {
|
|
52
|
-
player.ready = ready;
|
|
53
|
-
},
|
|
54
|
-
setHand: function (hand) {
|
|
55
|
-
player.prevHand = __spreadArray([], player.usedHand, true);
|
|
56
|
-
player.hand = hand;
|
|
57
|
-
player.usedHand = [];
|
|
58
|
-
return hand;
|
|
59
|
-
},
|
|
60
|
-
useCard: function (idx, card) {
|
|
61
|
-
if (player.hand[idx] && player.hand[idx] === card) {
|
|
62
|
-
var card_1 = player.hand.splice(idx, 1)[0];
|
|
63
|
-
player.usedHand.push(card_1);
|
|
64
|
-
return card_1;
|
|
65
|
-
}
|
|
66
|
-
return null;
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
return player;
|
|
70
|
-
}
|
|
71
|
-
exports.Player = Player;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
14
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
15
|
+
if (ar || !(i in from)) {
|
|
16
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
17
|
+
ar[i] = from[i];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.Player = void 0;
|
|
24
|
+
function Player(id, teamIdx) {
|
|
25
|
+
var player = {
|
|
26
|
+
id: id,
|
|
27
|
+
session: undefined,
|
|
28
|
+
teamIdx: teamIdx,
|
|
29
|
+
hand: [],
|
|
30
|
+
commands: [],
|
|
31
|
+
usedHand: [],
|
|
32
|
+
prevHand: [],
|
|
33
|
+
isTurn: false,
|
|
34
|
+
disabled: false,
|
|
35
|
+
ready: false,
|
|
36
|
+
setTurn: function (turn) {
|
|
37
|
+
player.isTurn = turn;
|
|
38
|
+
},
|
|
39
|
+
getPublicPlayer: function () {
|
|
40
|
+
return __assign(__assign({}, player), { hand: player.hand.map(function () { return "xx"; }), session: undefined });
|
|
41
|
+
},
|
|
42
|
+
setSession: function (session) {
|
|
43
|
+
player.session = session;
|
|
44
|
+
},
|
|
45
|
+
enable: function () {
|
|
46
|
+
player.disabled = false;
|
|
47
|
+
},
|
|
48
|
+
disable: function () {
|
|
49
|
+
player.disabled = true;
|
|
50
|
+
},
|
|
51
|
+
setReady: function (ready) {
|
|
52
|
+
player.ready = ready;
|
|
53
|
+
},
|
|
54
|
+
setHand: function (hand) {
|
|
55
|
+
player.prevHand = __spreadArray([], player.usedHand, true);
|
|
56
|
+
player.hand = hand;
|
|
57
|
+
player.usedHand = [];
|
|
58
|
+
return hand;
|
|
59
|
+
},
|
|
60
|
+
useCard: function (idx, card) {
|
|
61
|
+
if (player.hand[idx] && player.hand[idx] === card) {
|
|
62
|
+
var card_1 = player.hand.splice(idx, 1)[0];
|
|
63
|
+
player.usedHand.push(card_1);
|
|
64
|
+
return card_1;
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
return player;
|
|
70
|
+
}
|
|
71
|
+
exports.Player = Player;
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { ICard, IPlayedCard } from "./Deck";
|
|
2
|
+
import { IPlayer } from "./Player";
|
|
3
|
+
export interface IRound {
|
|
4
|
+
tie: boolean;
|
|
5
|
+
winner: IPlayer | null;
|
|
6
|
+
highest: number;
|
|
7
|
+
cards: Array<IPlayedCard>;
|
|
8
|
+
turn: number;
|
|
9
|
+
nextTurn(): void;
|
|
10
|
+
use(playedCard: IPlayedCard): ICard;
|
|
11
|
+
}
|
|
12
|
+
export interface IRoundPoints {
|
|
13
|
+
0: number;
|
|
14
|
+
1: number;
|
|
15
|
+
ties: number;
|
|
16
|
+
}
|
|
17
|
+
export declare function Round(turn: number): IRound;
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Round = void 0;
|
|
4
|
-
var utils_1 = require("../utils");
|
|
5
|
-
var Deck_1 = require("./Deck");
|
|
6
|
-
function Round(turn) {
|
|
7
|
-
var round = {
|
|
8
|
-
turn: turn,
|
|
9
|
-
highest: -1,
|
|
10
|
-
winner: null,
|
|
11
|
-
cards: [],
|
|
12
|
-
tie: false,
|
|
13
|
-
nextTurn: function () {
|
|
14
|
-
round.turn++;
|
|
15
|
-
},
|
|
16
|
-
use: function (_a) {
|
|
17
|
-
var _b;
|
|
18
|
-
var card = _a.card, player = _a.player;
|
|
19
|
-
var value = (0, utils_1.getCardValue)(card);
|
|
20
|
-
if (value === round.highest && player.teamIdx !== ((_b = round.winner) === null || _b === void 0 ? void 0 : _b.teamIdx)) {
|
|
21
|
-
round.tie = true;
|
|
22
|
-
}
|
|
23
|
-
if (value > round.highest) {
|
|
24
|
-
round.tie = false;
|
|
25
|
-
round.highest = value;
|
|
26
|
-
round.winner = player;
|
|
27
|
-
}
|
|
28
|
-
round.cards.push((0, Deck_1.PlayedCard)(player, card));
|
|
29
|
-
return card;
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
return round;
|
|
33
|
-
}
|
|
34
|
-
exports.Round = Round;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Round = void 0;
|
|
4
|
+
var utils_1 = require("../utils");
|
|
5
|
+
var Deck_1 = require("./Deck");
|
|
6
|
+
function Round(turn) {
|
|
7
|
+
var round = {
|
|
8
|
+
turn: turn,
|
|
9
|
+
highest: -1,
|
|
10
|
+
winner: null,
|
|
11
|
+
cards: [],
|
|
12
|
+
tie: false,
|
|
13
|
+
nextTurn: function () {
|
|
14
|
+
round.turn++;
|
|
15
|
+
},
|
|
16
|
+
use: function (_a) {
|
|
17
|
+
var _b;
|
|
18
|
+
var card = _a.card, player = _a.player;
|
|
19
|
+
var value = (0, utils_1.getCardValue)(card);
|
|
20
|
+
if (value === round.highest && player.teamIdx !== ((_b = round.winner) === null || _b === void 0 ? void 0 : _b.teamIdx)) {
|
|
21
|
+
round.tie = true;
|
|
22
|
+
}
|
|
23
|
+
if (value > round.highest) {
|
|
24
|
+
round.tie = false;
|
|
25
|
+
round.highest = value;
|
|
26
|
+
round.winner = player;
|
|
27
|
+
}
|
|
28
|
+
round.cards.push((0, Deck_1.PlayedCard)(player, card));
|
|
29
|
+
return card;
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
return round;
|
|
33
|
+
}
|
|
34
|
+
exports.Round = Round;
|
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { IPlayedCard } from "./Deck";
|
|
2
|
+
import { IPlayer } from "./Player";
|
|
3
|
+
import { ITeam } from "./Team";
|
|
4
|
+
export interface ITable {
|
|
5
|
+
forehandIdx: number;
|
|
6
|
+
cards: Array<Array<IPlayedCard>>;
|
|
7
|
+
players: Array<IPlayer>;
|
|
8
|
+
nextTurn(): IPlayer;
|
|
9
|
+
player(idx?: number): IPlayer;
|
|
10
|
+
getPlayerPosition(id: string): number;
|
|
11
|
+
}
|
|
12
|
+
export declare function Table(players: Array<IPlayer>, teams: Array<ITeam>): ITable;
|