Some algo tweaks for interesting daily challenges
This commit is contained in:
parent
dcc6a696fc
commit
6edc8a8232
|
@ -4,6 +4,10 @@ import { shuffle } from './utils'
|
|||
|
||||
type HistoryType = { a: number; b: number; op: OperatorType }[]
|
||||
|
||||
export function isHardEnough(num: number): boolean {
|
||||
return num % 100 > 0
|
||||
}
|
||||
|
||||
export function isOperationResultValid(op: Operation): boolean {
|
||||
return (
|
||||
!!op.operator &&
|
||||
|
|
|
@ -10,6 +10,7 @@ export const operators = ['+', '-', '*', '/'] as const
|
|||
export const pools = {
|
||||
1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 25],
|
||||
2: [2, 2, 3, 3, 5, 5, 7, 11, 13, 17, 19, 23],
|
||||
3: [5, 5, 5, 5, 5, 2, 2, 2, 2, 2],
|
||||
} as const
|
||||
|
||||
export enum GameState {
|
||||
|
|
|
@ -78,6 +78,7 @@ import { useRoute, useRouter } from 'vue-router'
|
|||
|
||||
import {
|
||||
getEmptyOperation,
|
||||
isHardEnough,
|
||||
isOperationReady,
|
||||
isOperationResultValid,
|
||||
isSolvable,
|
||||
|
@ -117,7 +118,7 @@ const { t } = useI18n() // call `useI18n`, and spread `t` from `useI18n` return
|
|||
* Computed & refs
|
||||
*/
|
||||
|
||||
const difficultyLevel = ref<1 | 2>(1)
|
||||
const pool = ref<1 | 2 | 3>(1)
|
||||
const cmpPlaquettes = ref<InstanceType<typeof PlaquettesList> | null>(null)
|
||||
|
||||
const isDaily = computed(() => useRoute()?.name === 'daily')
|
||||
|
@ -192,22 +193,15 @@ function reboot(): void {
|
|||
do {
|
||||
// Find a problem
|
||||
// result.value = randRange(101, 1000)
|
||||
difficultyLevel.value = randItem([1, 1, 1, 1, 2])
|
||||
result.value = (() => {
|
||||
switch (difficultyLevel.value) {
|
||||
case 1:
|
||||
return randRange(minValue, 1000)
|
||||
case 2:
|
||||
return randRange(minValue, 1000)
|
||||
}
|
||||
})()
|
||||
pool.value = randItem([1, 1, 1, 1, 1, 2, 3])
|
||||
result.value = randRange(minValue, 1000)
|
||||
// result.value = 29
|
||||
// Reset Operations list
|
||||
clearOperationsList()
|
||||
|
||||
// Generate result and plaquettes
|
||||
plaquettes.value = []
|
||||
const poolCopy = [...pools[difficultyLevel.value]]
|
||||
const poolCopy = [...pools[pool.value]]
|
||||
for (let i = 0; i < 6; ++i) {
|
||||
const rndItem = Math.floor(random() * poolCopy.length)
|
||||
const el = poolCopy.splice(rndItem, 1)[0]
|
||||
|
@ -219,6 +213,7 @@ function reboot(): void {
|
|||
// }))
|
||||
// Solve it
|
||||
} while (
|
||||
(isDaily.value ? !isHardEnough(result.value) : false) ||
|
||||
!isSolvable(
|
||||
result.value,
|
||||
plaquettes.value.map(p => p.value),
|
||||
|
@ -232,11 +227,11 @@ function reboot(): void {
|
|||
*/
|
||||
|
||||
onMounted(() => {
|
||||
if (!isDaily.value && !hasPlayed(getCurrentSessionKey())) {
|
||||
const router = useRouter()
|
||||
router.replace({ name: 'home' })
|
||||
return
|
||||
}
|
||||
// if (!isDaily.value && !hasPlayed(getCurrentSessionKey())) {
|
||||
// const router = useRouter()
|
||||
// router.replace({ name: 'home' })
|
||||
// return
|
||||
// }
|
||||
|
||||
if (isDaily.value) {
|
||||
console.log('daily rng')
|
||||
|
|
Loading…
Reference in New Issue
Block a user