Some algo tweaks for interesting daily challenges

This commit is contained in:
Simon Cambier 2022-02-24 22:42:47 +01:00
parent dcc6a696fc
commit 6edc8a8232
3 changed files with 16 additions and 16 deletions

View File

@ -4,6 +4,10 @@ import { shuffle } from './utils'
type HistoryType = { a: number; b: number; op: OperatorType }[] type HistoryType = { a: number; b: number; op: OperatorType }[]
export function isHardEnough(num: number): boolean {
return num % 100 > 0
}
export function isOperationResultValid(op: Operation): boolean { export function isOperationResultValid(op: Operation): boolean {
return ( return (
!!op.operator && !!op.operator &&

View File

@ -10,6 +10,7 @@ export const operators = ['+', '-', '*', '/'] as const
export const pools = { 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], 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], 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 } as const
export enum GameState { export enum GameState {

View File

@ -78,6 +78,7 @@ import { useRoute, useRouter } from 'vue-router'
import { import {
getEmptyOperation, getEmptyOperation,
isHardEnough,
isOperationReady, isOperationReady,
isOperationResultValid, isOperationResultValid,
isSolvable, isSolvable,
@ -117,7 +118,7 @@ const { t } = useI18n() // call `useI18n`, and spread `t` from `useI18n` return
* Computed & refs * Computed & refs
*/ */
const difficultyLevel = ref<1 | 2>(1) const pool = ref<1 | 2 | 3>(1)
const cmpPlaquettes = ref<InstanceType<typeof PlaquettesList> | null>(null) const cmpPlaquettes = ref<InstanceType<typeof PlaquettesList> | null>(null)
const isDaily = computed(() => useRoute()?.name === 'daily') const isDaily = computed(() => useRoute()?.name === 'daily')
@ -192,22 +193,15 @@ function reboot(): void {
do { do {
// Find a problem // Find a problem
// result.value = randRange(101, 1000) // result.value = randRange(101, 1000)
difficultyLevel.value = randItem([1, 1, 1, 1, 2]) pool.value = randItem([1, 1, 1, 1, 1, 2, 3])
result.value = (() => { result.value = randRange(minValue, 1000)
switch (difficultyLevel.value) {
case 1:
return randRange(minValue, 1000)
case 2:
return randRange(minValue, 1000)
}
})()
// result.value = 29 // result.value = 29
// Reset Operations list // Reset Operations list
clearOperationsList() clearOperationsList()
// Generate result and plaquettes // Generate result and plaquettes
plaquettes.value = [] plaquettes.value = []
const poolCopy = [...pools[difficultyLevel.value]] const poolCopy = [...pools[pool.value]]
for (let i = 0; i < 6; ++i) { for (let i = 0; i < 6; ++i) {
const rndItem = Math.floor(random() * poolCopy.length) const rndItem = Math.floor(random() * poolCopy.length)
const el = poolCopy.splice(rndItem, 1)[0] const el = poolCopy.splice(rndItem, 1)[0]
@ -219,6 +213,7 @@ function reboot(): void {
// })) // }))
// Solve it // Solve it
} while ( } while (
(isDaily.value ? !isHardEnough(result.value) : false) ||
!isSolvable( !isSolvable(
result.value, result.value,
plaquettes.value.map(p => p.value), plaquettes.value.map(p => p.value),
@ -232,11 +227,11 @@ function reboot(): void {
*/ */
onMounted(() => { onMounted(() => {
if (!isDaily.value && !hasPlayed(getCurrentSessionKey())) { // if (!isDaily.value && !hasPlayed(getCurrentSessionKey())) {
const router = useRouter() // const router = useRouter()
router.replace({ name: 'home' }) // router.replace({ name: 'home' })
return // return
} // }
if (isDaily.value) { if (isDaily.value) {
console.log('daily rng') console.log('daily rng')