labag 2.6.7 → 3.0.1
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/dist/index.d.ts +2 -11
- package/dist/index.js +1 -20
- package/dist/labag.d.ts +10 -96
- package/dist/labag.js +36 -267
- package/dist/test.js +21 -35
- package/dist/types/index.d.ts +9 -18
- package/package.json +1 -1
- package/src/index.ts +2 -29
- package/src/labag.ts +42 -294
- package/src/test.ts +23 -42
- package/src/types/index.ts +9 -27
- package/src/mode.ts +0 -90
- package/src/modes/greenwei.ts +0 -97
- package/src/modes/index.ts +0 -5
- package/src/modes/pikachu.ts +0 -52
- package/src/modes/superhhh.ts +0 -88
- package/src/pattern.ts +0 -31
- package/src/recordChecker.ts +0 -74
- package/src/recorder.ts +0 -93
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
1
|
import { LaBaG } from "./labag";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { Mode } from "./mode";
|
|
5
|
-
import { patterns } from "./pattern";
|
|
6
|
-
import { Recorder, GameRecord } from "./recorder";
|
|
7
|
-
import { RecordChecker } from "./recordChecker";
|
|
8
|
-
import { ModeName } from "./types";
|
|
9
|
-
declare const labag: LaBaG;
|
|
10
|
-
declare const recorder: Recorder;
|
|
11
|
-
declare const checker: RecordChecker;
|
|
12
|
-
export { labag, recorder, checker, modes, patterns, LaBaG, Recorder, RecordChecker, Mode, type LaBaGEvent, type Pattern, type PatternName, type GameRecord, type ModeName, };
|
|
2
|
+
import { Pattern, Payout } from "./types";
|
|
3
|
+
export { LaBaG, Pattern, Payout };
|
package/dist/index.js
CHANGED
|
@@ -1,24 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.LaBaG = void 0;
|
|
4
4
|
const labag_1 = require("./labag");
|
|
5
5
|
Object.defineProperty(exports, "LaBaG", { enumerable: true, get: function () { return labag_1.LaBaG; } });
|
|
6
|
-
const modes_1 = require("./modes");
|
|
7
|
-
Object.defineProperty(exports, "modes", { enumerable: true, get: function () { return modes_1.modes; } });
|
|
8
|
-
const mode_1 = require("./mode");
|
|
9
|
-
Object.defineProperty(exports, "Mode", { enumerable: true, get: function () { return mode_1.Mode; } });
|
|
10
|
-
const pattern_1 = require("./pattern");
|
|
11
|
-
Object.defineProperty(exports, "patterns", { enumerable: true, get: function () { return pattern_1.patterns; } });
|
|
12
|
-
const recorder_1 = require("./recorder");
|
|
13
|
-
Object.defineProperty(exports, "Recorder", { enumerable: true, get: function () { return recorder_1.Recorder; } });
|
|
14
|
-
const recordChecker_1 = require("./recordChecker");
|
|
15
|
-
Object.defineProperty(exports, "RecordChecker", { enumerable: true, get: function () { return recordChecker_1.RecordChecker; } });
|
|
16
|
-
const labag = new labag_1.LaBaG();
|
|
17
|
-
exports.labag = labag;
|
|
18
|
-
modes_1.modes.forEach((mode) => {
|
|
19
|
-
labag.addMode(mode);
|
|
20
|
-
});
|
|
21
|
-
const recorder = new recorder_1.Recorder(labag);
|
|
22
|
-
exports.recorder = recorder;
|
|
23
|
-
const checker = new recordChecker_1.RecordChecker(labag);
|
|
24
|
-
exports.checker = checker;
|
package/dist/labag.d.ts
CHANGED
|
@@ -1,99 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Pattern, LaBaGEvent, ModeName } from "./types";
|
|
3
|
-
/**
|
|
4
|
-
* 拉霸遊戲的主要類別。
|
|
5
|
-
*/
|
|
1
|
+
import { Pattern, Payout } from "./types";
|
|
6
2
|
export declare class LaBaG {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
score: number;
|
|
15
|
-
/** 邊際分數 */
|
|
16
|
-
marginScore: number;
|
|
17
|
-
/** 產生的隨機數字 */
|
|
18
|
-
randNums: number[];
|
|
19
|
-
/** 當前轉出的圖案組合 */
|
|
20
|
-
patterns: [Pattern | null, Pattern | null, Pattern | null];
|
|
21
|
-
/** 遊戲模式列表 */
|
|
22
|
-
modes: Mode[];
|
|
23
|
-
/** 事件監聽器列表 */
|
|
24
|
-
eventListeners: Record<LaBaGEvent, ((game: LaBaG) => void)[]>;
|
|
25
|
-
__defaultMode__: Mode;
|
|
26
|
-
constructor(times?: number);
|
|
27
|
-
/**
|
|
28
|
-
* 觸發指定事件。
|
|
29
|
-
* @param event - 要觸發的事件名稱。
|
|
30
|
-
*/
|
|
31
|
-
private emit;
|
|
32
|
-
/**
|
|
33
|
-
* 新增事件監聽器。
|
|
34
|
-
* @param event - 要監聽的事件名稱。
|
|
35
|
-
* @param listener - 事件觸發時要執行的函式。
|
|
36
|
-
* @remarks 可以為同一事件添加多個監聽器,這些監聽器將按照添加的順序依次執行。
|
|
37
|
-
* @example
|
|
38
|
-
* game.addEventListener("gameStart", (game) => {
|
|
39
|
-
* console.log("遊戲開始了!");
|
|
40
|
-
* });
|
|
41
|
-
* game.addEventListener("roundEnd", (game) => {
|
|
42
|
-
* console.log("一輪結束了!");
|
|
43
|
-
* });
|
|
44
|
-
*/
|
|
45
|
-
addEventListener(event: LaBaGEvent, callbackFn: (game: LaBaG) => void): void;
|
|
46
|
-
/**
|
|
47
|
-
* 移除事件監聽器。
|
|
48
|
-
* @param event - 要移除監聽器的事件名稱。
|
|
49
|
-
* @param listener - 要移除的監聽器函式。
|
|
50
|
-
* @remarks 這將從指定事件的監聽器列表中移除第一個匹配的函式。
|
|
51
|
-
* @example
|
|
52
|
-
* const onGameStart = (game) => {
|
|
53
|
-
* console.log("遊戲開始了!");
|
|
54
|
-
* };
|
|
55
|
-
* game.addEventListener("gameStart", onGameStart);
|
|
56
|
-
* // 之後如果想要移除這個監聽器:
|
|
57
|
-
* game.removeEventListener("gameStart", onGameStart);
|
|
58
|
-
*/
|
|
59
|
-
removeEventListener(event: LaBaGEvent, callbackFn: (game: LaBaG) => void): void;
|
|
60
|
-
/**
|
|
61
|
-
* 新增遊戲模式。
|
|
62
|
-
* @param mode - 要新增的遊戲模式實例。
|
|
63
|
-
* @remarks 這將把指定的模式添加到遊戲的模式列表中,並自動註冊該模式定義的事件監聽器。
|
|
64
|
-
* @example
|
|
65
|
-
* const myMode = new Mode({
|
|
66
|
-
* active: false,
|
|
67
|
-
* name: "myMode",
|
|
68
|
-
* rates: {
|
|
69
|
-
* gss: 10,
|
|
70
|
-
* hhh: 20,
|
|
71
|
-
* hentai: 30,
|
|
72
|
-
* handson: 20,
|
|
73
|
-
* kachu: 10,
|
|
74
|
-
* rrr: 10,
|
|
75
|
-
* },
|
|
76
|
-
* });
|
|
77
|
-
* game.addMode(myMode);
|
|
78
|
-
*/
|
|
79
|
-
addMode(mode: Mode<any>): void;
|
|
80
|
-
/**
|
|
81
|
-
* 取得目前遊戲的相關設定
|
|
82
|
-
*/
|
|
83
|
-
getCurrentConfig(): {
|
|
84
|
-
modes: Mode<Record<string, any>, string>[];
|
|
85
|
-
ranges: {
|
|
86
|
-
threshold: number;
|
|
87
|
-
pattern: Pattern;
|
|
88
|
-
}[];
|
|
3
|
+
patterns: Pattern[];
|
|
4
|
+
reels: Pattern[];
|
|
5
|
+
payouts: Payout[];
|
|
6
|
+
constructor(patterns: Pattern[], payouts: Payout[]);
|
|
7
|
+
spin(): {
|
|
8
|
+
reels: Pattern[];
|
|
9
|
+
reward: number;
|
|
89
10
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
rollSlots(): void;
|
|
93
|
-
calculateScore(): void;
|
|
94
|
-
roundEnd(): void;
|
|
95
|
-
gameOver(): void;
|
|
96
|
-
play(): void;
|
|
97
|
-
getMode(name: ModeName): Mode<Record<string, any>, string> | undefined;
|
|
98
|
-
get isRunning(): boolean;
|
|
11
|
+
randomPattern(): Pattern;
|
|
12
|
+
caculateReward(reels: Pattern[]): number;
|
|
99
13
|
}
|
package/dist/labag.js
CHANGED
|
@@ -1,283 +1,52 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LaBaG = void 0;
|
|
4
|
-
const mode_1 = require("./mode");
|
|
5
|
-
const pattern_1 = require("./pattern");
|
|
6
4
|
const randInt_1 = require("./utils/randInt");
|
|
7
|
-
/**
|
|
8
|
-
* 拉霸遊戲的主要類別。
|
|
9
|
-
*/
|
|
10
5
|
class LaBaG {
|
|
11
|
-
/** 總遊玩次數限制 */
|
|
12
|
-
times;
|
|
13
|
-
/** 已遊玩次數 */
|
|
14
|
-
played;
|
|
15
|
-
/** 當前進行的輪次 */
|
|
16
|
-
rounds;
|
|
17
|
-
/** 當前分數 */
|
|
18
|
-
score;
|
|
19
|
-
/** 邊際分數 */
|
|
20
|
-
marginScore;
|
|
21
|
-
/** 產生的隨機數字 */
|
|
22
|
-
randNums;
|
|
23
|
-
/** 當前轉出的圖案組合 */
|
|
24
6
|
patterns;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
this.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
roundStart: [],
|
|
43
|
-
roundEnd: [],
|
|
44
|
-
rollSlots: [],
|
|
45
|
-
calculateScore: [],
|
|
7
|
+
reels;
|
|
8
|
+
payouts;
|
|
9
|
+
constructor(patterns, payouts) {
|
|
10
|
+
this.patterns = patterns;
|
|
11
|
+
this.reels = [patterns[0], patterns[1], patterns[2]];
|
|
12
|
+
this.payouts = payouts;
|
|
13
|
+
}
|
|
14
|
+
spin() {
|
|
15
|
+
this.reels = [
|
|
16
|
+
this.randomPattern(),
|
|
17
|
+
this.randomPattern(),
|
|
18
|
+
this.randomPattern(),
|
|
19
|
+
];
|
|
20
|
+
const reward = this.caculateReward(this.reels);
|
|
21
|
+
return {
|
|
22
|
+
reels: this.reels,
|
|
23
|
+
reward,
|
|
46
24
|
};
|
|
47
|
-
this.__defaultMode__ = new mode_1.Mode({
|
|
48
|
-
active: true,
|
|
49
|
-
name: "normal",
|
|
50
|
-
rates: {
|
|
51
|
-
gss: 36,
|
|
52
|
-
hhh: 24,
|
|
53
|
-
hentai: 17,
|
|
54
|
-
handson: 12,
|
|
55
|
-
kachu: 8,
|
|
56
|
-
rrr: 3,
|
|
57
|
-
},
|
|
58
|
-
eventListener: {
|
|
59
|
-
gameStart: (game) => {
|
|
60
|
-
game.played = 0;
|
|
61
|
-
game.rounds = 0;
|
|
62
|
-
game.score = 0;
|
|
63
|
-
game.marginScore = 0;
|
|
64
|
-
game.randNums = [];
|
|
65
|
-
game.patterns = [null, null, null];
|
|
66
|
-
},
|
|
67
|
-
roundStart: (game) => {
|
|
68
|
-
game.played += 1;
|
|
69
|
-
game.rounds += 1;
|
|
70
|
-
game.marginScore = 0;
|
|
71
|
-
},
|
|
72
|
-
rollSlots: (game) => {
|
|
73
|
-
const { ranges } = game.getCurrentConfig();
|
|
74
|
-
const rangesAcc = ranges.length > 0 ? ranges[ranges.length - 1].threshold : 0;
|
|
75
|
-
// 產生 3 個隨機數字並直接尋找對應圖案
|
|
76
|
-
for (let i = 0; i < 3; i++) {
|
|
77
|
-
const num = (0, randInt_1.randInt)(1, rangesAcc);
|
|
78
|
-
game.randNums[i] = num;
|
|
79
|
-
let matchedPattern = null;
|
|
80
|
-
for (let j = 0; j < ranges.length; j++) {
|
|
81
|
-
if (num <= ranges[j].threshold) {
|
|
82
|
-
matchedPattern = ranges[j].pattern;
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
game.patterns[i] = matchedPattern;
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
calculateScore: (game, mode) => {
|
|
90
|
-
const [p1, p2, p3] = game.patterns;
|
|
91
|
-
if (!p1 || !p2 || !p3) {
|
|
92
|
-
game.marginScore = 0;
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
if (p1.name === p2.name && p2.name === p3.name) {
|
|
96
|
-
// 三個圖案相同
|
|
97
|
-
this.marginScore += p1.scores[0];
|
|
98
|
-
}
|
|
99
|
-
else if (p1.name === p2.name ||
|
|
100
|
-
p2.name === p3.name ||
|
|
101
|
-
p1.name === p3.name) {
|
|
102
|
-
// 兩個圖案相同
|
|
103
|
-
if (p1.name === p2.name) {
|
|
104
|
-
this.marginScore += p1.scores[1];
|
|
105
|
-
this.marginScore += p3.scores[2];
|
|
106
|
-
}
|
|
107
|
-
else if (p2.name === p3.name) {
|
|
108
|
-
this.marginScore += p2.scores[1];
|
|
109
|
-
this.marginScore += p1.scores[2];
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
this.marginScore += p1.scores[1];
|
|
113
|
-
this.marginScore += p2.scores[2];
|
|
114
|
-
}
|
|
115
|
-
this.marginScore = Math.round(this.marginScore / mode.variable.twoMatchDivisor);
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
// 三個圖案皆不同
|
|
119
|
-
this.marginScore += p1.scores[2];
|
|
120
|
-
this.marginScore += p2.scores[2];
|
|
121
|
-
this.marginScore += p3.scores[2];
|
|
122
|
-
this.marginScore = Math.round(this.marginScore / mode.variable.allDifferentDivisor);
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
roundEnd: (game) => {
|
|
126
|
-
game.score += game.marginScore;
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
variable: {
|
|
130
|
-
twoMatchDivisor: 1.4,
|
|
131
|
-
allDifferentDivisor: 3,
|
|
132
|
-
},
|
|
133
|
-
});
|
|
134
|
-
this.addMode(this.__defaultMode__);
|
|
135
25
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* 新增事件監聽器。
|
|
148
|
-
* @param event - 要監聽的事件名稱。
|
|
149
|
-
* @param listener - 事件觸發時要執行的函式。
|
|
150
|
-
* @remarks 可以為同一事件添加多個監聽器,這些監聽器將按照添加的順序依次執行。
|
|
151
|
-
* @example
|
|
152
|
-
* game.addEventListener("gameStart", (game) => {
|
|
153
|
-
* console.log("遊戲開始了!");
|
|
154
|
-
* });
|
|
155
|
-
* game.addEventListener("roundEnd", (game) => {
|
|
156
|
-
* console.log("一輪結束了!");
|
|
157
|
-
* });
|
|
158
|
-
*/
|
|
159
|
-
addEventListener(event, callbackFn) {
|
|
160
|
-
this.eventListeners[event].push(callbackFn);
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* 移除事件監聽器。
|
|
164
|
-
* @param event - 要移除監聽器的事件名稱。
|
|
165
|
-
* @param listener - 要移除的監聽器函式。
|
|
166
|
-
* @remarks 這將從指定事件的監聽器列表中移除第一個匹配的函式。
|
|
167
|
-
* @example
|
|
168
|
-
* const onGameStart = (game) => {
|
|
169
|
-
* console.log("遊戲開始了!");
|
|
170
|
-
* };
|
|
171
|
-
* game.addEventListener("gameStart", onGameStart);
|
|
172
|
-
* // 之後如果想要移除這個監聽器:
|
|
173
|
-
* game.removeEventListener("gameStart", onGameStart);
|
|
174
|
-
*/
|
|
175
|
-
removeEventListener(event, callbackFn) {
|
|
176
|
-
const listeners = this.eventListeners[event];
|
|
177
|
-
const index = listeners.indexOf(callbackFn);
|
|
178
|
-
if (index !== -1) {
|
|
179
|
-
listeners.splice(index, 1);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* 新增遊戲模式。
|
|
184
|
-
* @param mode - 要新增的遊戲模式實例。
|
|
185
|
-
* @remarks 這將把指定的模式添加到遊戲的模式列表中,並自動註冊該模式定義的事件監聽器。
|
|
186
|
-
* @example
|
|
187
|
-
* const myMode = new Mode({
|
|
188
|
-
* active: false,
|
|
189
|
-
* name: "myMode",
|
|
190
|
-
* rates: {
|
|
191
|
-
* gss: 10,
|
|
192
|
-
* hhh: 20,
|
|
193
|
-
* hentai: 30,
|
|
194
|
-
* handson: 20,
|
|
195
|
-
* kachu: 10,
|
|
196
|
-
* rrr: 10,
|
|
197
|
-
* },
|
|
198
|
-
* });
|
|
199
|
-
* game.addMode(myMode);
|
|
200
|
-
*/
|
|
201
|
-
addMode(mode) {
|
|
202
|
-
this.modes.push(mode);
|
|
203
|
-
// 註冊特定模式的監聽器
|
|
204
|
-
Object.entries(mode.eventListener).forEach(([event, listener]) => {
|
|
205
|
-
if (listener) {
|
|
206
|
-
this.addEventListener(event, (game) => listener(game, mode));
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* 取得目前遊戲的相關設定
|
|
212
|
-
*/
|
|
213
|
-
getCurrentConfig() {
|
|
214
|
-
const activeModes = this.modes.filter((m) => m.active);
|
|
215
|
-
if (activeModes.length === 0) {
|
|
216
|
-
throw new Error("目前沒有啟用中的模式,無法轉動拉霸機。");
|
|
217
|
-
}
|
|
218
|
-
// 合併所有啟用中模式的機率設定
|
|
219
|
-
const combinedRates = {
|
|
220
|
-
gss: 0,
|
|
221
|
-
hhh: 0,
|
|
222
|
-
hentai: 0,
|
|
223
|
-
handson: 0,
|
|
224
|
-
kachu: 0,
|
|
225
|
-
rrr: 0,
|
|
226
|
-
};
|
|
227
|
-
for (let i = 0; i < activeModes.length; i++) {
|
|
228
|
-
const mode = activeModes[i];
|
|
229
|
-
for (const patternName in mode.rates) {
|
|
230
|
-
combinedRates[patternName] +=
|
|
231
|
-
mode.rates[patternName];
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
// 預先計算合併後的區間
|
|
235
|
-
const ranges = [];
|
|
236
|
-
let acc = 0;
|
|
237
|
-
for (const pattern of pattern_1.patterns) {
|
|
238
|
-
const rate = combinedRates[pattern.name];
|
|
239
|
-
if (rate !== undefined) {
|
|
240
|
-
acc += rate;
|
|
241
|
-
ranges.push({ threshold: acc, pattern });
|
|
26
|
+
randomPattern() {
|
|
27
|
+
const totalWeight = this.patterns.reduce((sum, pattern) => sum + pattern.weight, 0);
|
|
28
|
+
const randNum = (0, randInt_1.randInt)(1, totalWeight);
|
|
29
|
+
let cumulativeWeight = 0;
|
|
30
|
+
for (const pattern of this.patterns) {
|
|
31
|
+
cumulativeWeight += pattern.weight;
|
|
32
|
+
if (randNum <= cumulativeWeight) {
|
|
33
|
+
return pattern;
|
|
242
34
|
}
|
|
243
35
|
}
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
init() {
|
|
247
|
-
this.emit("gameStart");
|
|
248
|
-
}
|
|
249
|
-
roundStart() {
|
|
250
|
-
this.emit("roundStart");
|
|
251
|
-
}
|
|
252
|
-
rollSlots() {
|
|
253
|
-
this.emit("rollSlots");
|
|
254
|
-
}
|
|
255
|
-
calculateScore() {
|
|
256
|
-
this.emit("calculateScore");
|
|
36
|
+
throw new Error("No pattern found");
|
|
257
37
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
this.emit("gameOver");
|
|
263
|
-
}
|
|
264
|
-
play() {
|
|
265
|
-
if (!this.isRunning) {
|
|
266
|
-
throw new Error("遊戲已結束,無法繼續遊玩。");
|
|
38
|
+
caculateReward(reels) {
|
|
39
|
+
const patternCounts = {};
|
|
40
|
+
for (const pattern of reels) {
|
|
41
|
+
patternCounts[pattern.id] = (patternCounts[pattern.id] || 0) + 1;
|
|
267
42
|
}
|
|
268
|
-
|
|
269
|
-
this.
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
this.gameOver();
|
|
43
|
+
let totalReward = 0;
|
|
44
|
+
for (const payout of this.payouts) {
|
|
45
|
+
if (patternCounts[payout.pattern_id] === payout.match_count) {
|
|
46
|
+
totalReward += payout.reward;
|
|
47
|
+
}
|
|
274
48
|
}
|
|
275
|
-
|
|
276
|
-
getMode(name) {
|
|
277
|
-
return this.modes.find((m) => m.name === name);
|
|
278
|
-
}
|
|
279
|
-
get isRunning() {
|
|
280
|
-
return this.played < this.times;
|
|
49
|
+
return totalReward;
|
|
281
50
|
}
|
|
282
51
|
}
|
|
283
52
|
exports.LaBaG = LaBaG;
|
package/dist/test.js
CHANGED
|
@@ -1,38 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
console.log(`
|
|
22
|
-
|
|
23
|
-
});
|
|
24
|
-
index_1.labag.init();
|
|
25
|
-
index_2.recorder.init();
|
|
26
|
-
while (index_1.labag.isRunning) {
|
|
27
|
-
index_1.labag.play();
|
|
3
|
+
const labag_1 = require("./labag");
|
|
4
|
+
const patterns = [
|
|
5
|
+
{ id: "A", weight: 50, image: "A.png" },
|
|
6
|
+
{ id: "B", weight: 30, image: "B.png" },
|
|
7
|
+
{ id: "C", weight: 20, image: "C.png" },
|
|
8
|
+
];
|
|
9
|
+
const payouts = [
|
|
10
|
+
{ id: "payout1", pattern_id: "A", match_count: 3, reward: 100 },
|
|
11
|
+
{ id: "payout2", pattern_id: "B", match_count: 3, reward: 50 },
|
|
12
|
+
{ id: "payout3", pattern_id: "C", match_count: 3, reward: 20 },
|
|
13
|
+
{ id: "payout4", pattern_id: "A", match_count: 2, reward: 10 },
|
|
14
|
+
{ id: "payout5", pattern_id: "B", match_count: 2, reward: 5 },
|
|
15
|
+
{ id: "payout6", pattern_id: "C", match_count: 2, reward: 2 },
|
|
16
|
+
];
|
|
17
|
+
const labag = new labag_1.LaBaG(patterns, payouts);
|
|
18
|
+
let totalReward = 0;
|
|
19
|
+
for (let i = 0; i < 10; i++) {
|
|
20
|
+
const result = labag.spin();
|
|
21
|
+
console.log(`Spin ${i + 1}:`, result);
|
|
22
|
+
totalReward += result.reward;
|
|
28
23
|
}
|
|
29
|
-
console.log("
|
|
30
|
-
console.log(`Final Score: ${index_1.labag.score}`);
|
|
31
|
-
console.log(`Active Modes at end: ${index_1.labag
|
|
32
|
-
.getCurrentConfig()
|
|
33
|
-
.modes.map((m) => m.name)
|
|
34
|
-
.join(", ")}`);
|
|
35
|
-
console.log(`record: ${JSON.stringify(index_2.recorder.getRecord(), null, 2)}`);
|
|
36
|
-
console.log(index_1.checker.check(index_2.recorder.getRecord())
|
|
37
|
-
? "Record is valid!"
|
|
38
|
-
: "Record is invalid!");
|
|
24
|
+
console.log("Total Reward:", totalReward);
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,20 +1,11 @@
|
|
|
1
|
-
import { modes } from "../modes";
|
|
2
|
-
import { patterns } from "../pattern";
|
|
3
|
-
/**
|
|
4
|
-
* 拉霸遊戲的事件類型。
|
|
5
|
-
*/
|
|
6
|
-
export type LaBaGEvent = "gameOver" | "gameStart" | "roundStart" | "roundEnd" | "rollSlots" | "calculateScore";
|
|
7
|
-
/**
|
|
8
|
-
* 代表一個圖案及其對應的分數。
|
|
9
|
-
*/
|
|
10
1
|
export type Pattern = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
id: string;
|
|
3
|
+
weight: number;
|
|
4
|
+
image: string;
|
|
5
|
+
};
|
|
6
|
+
export type Payout = {
|
|
7
|
+
id: string;
|
|
8
|
+
pattern_id: Pattern["id"];
|
|
9
|
+
match_count: number;
|
|
10
|
+
reward: number;
|
|
15
11
|
};
|
|
16
|
-
/**
|
|
17
|
-
* 圖案名稱的型別。
|
|
18
|
-
*/
|
|
19
|
-
export type PatternName = (typeof patterns)[number]["name"];
|
|
20
|
-
export type ModeName = (typeof modes)[number]["name"] | "normal";
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,31 +1,4 @@
|
|
|
1
1
|
import { LaBaG } from "./labag";
|
|
2
|
-
import {
|
|
3
|
-
import { LaBaGEvent, Pattern, PatternName } from "./types";
|
|
4
|
-
import { Mode } from "./mode";
|
|
5
|
-
import { patterns } from "./pattern";
|
|
6
|
-
import { Recorder, GameRecord } from "./recorder";
|
|
7
|
-
import { RecordChecker } from "./recordChecker";
|
|
8
|
-
import { ModeName } from "./types";
|
|
2
|
+
import { Pattern, Payout } from "./types";
|
|
9
3
|
|
|
10
|
-
|
|
11
|
-
modes.forEach((mode) => {
|
|
12
|
-
labag.addMode(mode);
|
|
13
|
-
});
|
|
14
|
-
const recorder = new Recorder(labag);
|
|
15
|
-
const checker = new RecordChecker(labag);
|
|
16
|
-
export {
|
|
17
|
-
labag,
|
|
18
|
-
recorder,
|
|
19
|
-
checker,
|
|
20
|
-
modes,
|
|
21
|
-
patterns,
|
|
22
|
-
LaBaG,
|
|
23
|
-
Recorder,
|
|
24
|
-
RecordChecker,
|
|
25
|
-
Mode,
|
|
26
|
-
type LaBaGEvent,
|
|
27
|
-
type Pattern,
|
|
28
|
-
type PatternName,
|
|
29
|
-
type GameRecord,
|
|
30
|
-
type ModeName,
|
|
31
|
-
};
|
|
4
|
+
export { LaBaG, Pattern, Payout };
|