-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
John Davison
committed
Jul 9, 2023
1 parent
ec45baf
commit eca8ce1
Showing
8 changed files
with
101 additions
and
43 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { Difficulty } from "../src/app/play/[id]/types"; | ||
import { PrismaClient } from "@prisma/client"; | ||
|
||
const prisma = new PrismaClient(); | ||
|
||
const getSolutions = async () => { | ||
return await prisma.solution.findMany({ | ||
include: { | ||
solutionPieces: true, | ||
}, | ||
}); | ||
}; | ||
|
||
/** | ||
* Create levels from all the solutions | ||
*/ | ||
getSolutions().then((solutions) => { | ||
solutions.map(async (solution) => { | ||
const difficulty = getDifficulty(solution.id); | ||
return await prisma.level.create({ | ||
data: { | ||
id: solution.id, | ||
difficulty, | ||
solutionId: solution.id, | ||
solutionPieces: { | ||
connect: getRandomSolutionPieces(difficulty).map((id) => ({ | ||
id, | ||
})), | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
const getDifficulty = (id: number): Difficulty => { | ||
const modulo = (id % 4) as 1 | 2 | 3 | 0; | ||
switch (modulo) { | ||
case 1: | ||
return "EASY"; | ||
case 2: | ||
return "INTERMEDIATE"; | ||
case 3: | ||
return "EXPERT"; | ||
case 0: | ||
return "WIZARD"; | ||
} | ||
}; | ||
|
||
/** | ||
* Returns an array of 12 numbers in random order | ||
*/ | ||
const shuffle = () => { | ||
return [...Array(12)] | ||
.map((_, i) => i + 1) | ||
.map((value) => ({ value, sort: Math.random() })) | ||
.sort((a, b) => a.sort - b.sort) | ||
.map(({ value }) => value); | ||
}; | ||
|
||
/** | ||
* Return the first x number of ids from the shuffled array | ||
*/ | ||
const getRandomSolutionPieces = (difficulty: Difficulty): number[] => { | ||
switch (difficulty) { | ||
case "EASY": | ||
return shuffle().slice(0, 8); | ||
case "INTERMEDIATE": | ||
return shuffle().slice(0, 6); | ||
case "EXPERT": | ||
return shuffle().slice(0, 4); | ||
case "WIZARD": | ||
return shuffle().slice(0, 2); | ||
default: | ||
throw new Error("Invalid difficulty"); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { PrismaClient } from "@prisma/client"; | ||
|
||
const prisma = new PrismaClient(); | ||
|
||
const getSolutions = async () => { | ||
return await prisma.solution.findMany({ | ||
include: { | ||
solutionPieces: true, | ||
}, | ||
}); | ||
}; | ||
|
||
getSolutions().then((solutions) => { | ||
const noIdSolutions = solutions.map(({ id, ...rest }) => | ||
JSON.stringify(rest) | ||
); | ||
console.log(noIdSolutions); | ||
|
||
const uniqueSolutions = [...new Set(noIdSolutions)]; | ||
console.log("Unique Solutions:", uniqueSolutions.length); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters