From 6edc8a823259445f18a6f6fb7b45eadd96f4cd48 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Thu, 24 Feb 2022 22:42:47 +0100 Subject: [PATCH] Some algo tweaks for interesting daily challenges --- src/algo.ts | 4 ++++ src/globals.ts | 1 + src/views/GameView.vue | 27 +++++++++++---------------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/algo.ts b/src/algo.ts index 9ca2f8a..0dc2203 100644 --- a/src/algo.ts +++ b/src/algo.ts @@ -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 && diff --git a/src/globals.ts b/src/globals.ts index 5e9ace6..33dad83 100644 --- a/src/globals.ts +++ b/src/globals.ts @@ -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 { diff --git a/src/views/GameView.vue b/src/views/GameView.vue index 9f8665a..fc7cabf 100644 --- a/src/views/GameView.vue +++ b/src/views/GameView.vue @@ -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 | 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')