Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions database.rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"mode": {
".write": "auth != null && auth.uid == data.parent().child('host').val() && data.parent().child('status').val() == 'waiting' && newData.exists()",
".validate": "newData.isString() && newData.val().matches(/^normal|junior|setchain|ultraset|ultrachain|ultra9|megaset|ghostset|4set|4setjr|4setjrchain|puzzle|ultra9puzzle|shuffle|memory$/)"
".validate": "newData.isString() && newData.val().matches(/^normal|junior|setchain|ultraset|ultrachain|ultra9|megaset|ghostset|4set|4setjr|4setjrchain|puzzle|ultra9puzzle|4setjrpuzzle|shuffle|memory$/)"
},
"enableHint": {
".write": "auth != null && auth.uid == data.parent().child('host').val() && data.parent().child('status').val() == 'waiting' && newData.exists()",
Expand Down Expand Up @@ -52,7 +52,7 @@
"events": {
"$eventId": {
".write": "!data.exists() && newData.exists() && auth != null && root.hasChild('games/' + $gameId + '/users/' + auth.uid) && root.child('games/' + $gameId + '/status').val() == 'ingame'",
".validate": "newData.hasChildren(['user', 'time', 'c1', 'c2', 'c3']) && (newData.hasChild('c4') == root.child('games/' + $gameId + '/mode').val().matches(/^ultraset|ultrachain|ultra9|ultra9puzzle|ghostset|4set|4setjr|4setjrchain$/)) && (newData.hasChildren(['c5', 'c6']) == (root.child('games/' + $gameId + '/mode').val() == 'ghostset'))",
".validate": "newData.hasChildren(['user', 'time', 'c1', 'c2', 'c3']) && (newData.hasChild('c4') == root.child('games/' + $gameId + '/mode').val().matches(/^ultraset|ultrachain|ultra9|ultra9puzzle|ghostset|4set|4setjr|4setjrchain|4setjrpuzzle$/)) && (newData.hasChildren(['c5', 'c6']) == (root.child('games/' + $gameId + '/mode').val() == 'ghostset'))",
"user": {
".validate": "newData.isString() && newData.val() == auth.uid"
},
Expand Down
13 changes: 12 additions & 1 deletion functions/src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,16 @@ function findSet4Set(deck: string[], gameMode: GameMode, state: FindState) {
const deckSet = new Set(deck);
const first =
modes[gameMode].chain && state.lastSet!.length > 0 ? state.lastSet! : deck;
const foundSets = modes[gameMode].puzzle && state.foundSets!;
for (let i = 0; i < first.length; i++) {
for (let j = i + 1; j < first.length; j++) {
for (let k = first === deck ? j + 1 : 0; k < deck.length; k++) {
const c = conjugateCard4Set(first[i], first[j], deck[k]);
if (deckSet.has(c)) {
return [first[i], first[j], deck[k], c];
const set = [first[i], first[j], deck[k], c];
if (!(foundSets && foundSets.has(set.sort().join("|")))) {
return set;
}
}
}
}
Expand Down Expand Up @@ -478,6 +482,13 @@ export const modes = {
puzzle: true,
minBoardSize: 9,
},
"4setjrpuzzle": {
setType: "4Set",
traits: 3,
chain: 0,
puzzle: true,
minBoardSize: 11,
},
shuffle: {
setType: "Set",
traits: 4,
Expand Down
16 changes: 15 additions & 1 deletion src/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,16 @@ function findSet4Set(deck, gameMode, state) {
const deckSet = new Set(deck);
const first =
modes[gameMode].chain && state.lastSet.length > 0 ? state.lastSet : deck;
const foundSets = modes[gameMode].puzzle && state.foundSets;
for (let i = 0; i < first.length; i++) {
for (let j = i + 1; j < first.length; j++) {
for (let k = first === deck ? j + 1 : 0; k < deck.length; k++) {
const c = conjugateCard4Set(first[i], first[j], deck[k]);
if (deckSet.has(c)) {
return [first[i], first[j], deck[k], c];
const set = [first[i], first[j], deck[k], c];
if (!(foundSets && foundSets.has(set.sort().join("|")))) {
return set;
}
}
}
}
Expand Down Expand Up @@ -609,6 +613,16 @@ export const modes = {
puzzle: true,
minBoardSize: 9,
},
"4setjrpuzzle": {
name: "4Set Jr-Puzzle",
color: "indigo",
description: "Find all 4Sets on the board before moving to the next board.",
setType: "4Set",
traits: 3,
chain: 0,
puzzle: true,
minBoardSize: 11,
},
shuffle: {
name: "Shuffle",
color: "blue",
Expand Down
12 changes: 12 additions & 0 deletions src/game.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,16 @@ describe("findSet()", () => {
verify4Set(findSet(["0000", "0102", "0210", "0003"], "4setjrchain", state));
verify4Set(findSet(["0000", "0102", "0210", "3201"], "4setjrchain", state));
});

it("can find puzzle 4sets", () => {
const board = ["0000", "0102", "0210", "0312", "1111", "1013", "1203"];
const state = { foundSets: new Set() };
for (let i = 0; i < 7; i++) {
const set = findSet(board, "4setjrpuzzle", state);
verify4Set(set);
expect(state.foundSets.has(set.slice().sort().join("|"))).toBe(false);
state.foundSets.add(set.slice().sort().join("|"));
}
expect(findSet(board, "4setjrpuzzle", state)).toBe(null);
});
});