tangled
alpha
login
or
join now
clxxiii.dev
/
osu-bingo
0
fork
atom
Two teams try and fill in any horizontal, vertical, or diagonal line on a bingo board by playing maps on osu!
osu.bingo
osu
0
fork
atom
overview
issues
pulls
pipelines
correctly check 3x3 and 7x7 boards
clxxiii
1 year ago
fc76f904
1137a915
+23
-15
1 changed file
expand all
collapse all
unified
split
src
lib
bingo-helpers
check_win.ts
+23
-15
src/lib/bingo-helpers/check_win.ts
···
24
24
export const checkWin = (game: Bingo.Card) => {
25
25
if (!game.squares) return null;
26
26
27
27
-
// Arrange the board into a 2D array.
28
28
-
const yMax = Math.max(...game.squares.map((x) => x.y_pos));
29
29
-
const xMax = Math.max(...game.squares.map((x) => x.x_pos));
30
30
-
31
31
-
const board: (string | null)[] = new Array((yMax + 1) * (xMax + 1));
32
32
-
for (const square of game.squares) {
33
33
-
const index = square.y_pos * 5 + square.x_pos;
34
34
-
board[index] = square.claimed_by?.team_name ?? null;
35
35
-
}
36
36
-
37
37
-
// Get lines from template
27
27
+
// Get board and lines from template
38
28
let template: Template;
39
29
try {
40
30
template = JSON.parse(game.template.data);
41
31
} catch {
42
42
-
return bingoCheck(board);
32
32
+
throw "Template is invalid";
43
33
}
44
44
-
const { lines } =
45
45
-
typeof template.setup.board == 'string' ? boards[template.setup.board] : template.setup.board;
46
34
47
47
-
return bingoCheck(board, lines);
35
35
+
// Get board and lines from template
36
36
+
let board: Template.Board;
37
37
+
if (typeof template.setup.board == 'string') {
38
38
+
board = boards[template.setup.board];
39
39
+
} else {
40
40
+
board = template.setup.board;
41
41
+
}
42
42
+
43
43
+
if (!board) {
44
44
+
throw "Template does not have a valid board";
45
45
+
}
46
46
+
47
47
+
const boardMarks: (string | null)[] = new Array(board.squares.length);
48
48
+
for (let i = 0; i < board.squares.length; i++) {
49
49
+
const coords = board.squares[i];
50
50
+
const square = game.squares.find((x) => ((x.x_pos == coords[1]) && (x.y_pos == coords[0])))
51
51
+
if (!square) continue;
52
52
+
boardMarks[i] = square.claimed_by?.team_name?.toUpperCase() ?? null
53
53
+
}
54
54
+
55
55
+
return bingoCheck(boardMarks, board.lines);
48
56
};
49
57
50
58
/**