Gold digging game “number puzzle” algorithm assistant

Non – plugins oh, just the fastest to find the algorithm, still need to complete the game according to the algorithm manually

On a dark and windy night, a programmer accidentally found JJ’s new game while fishing. After playing for a while, he had to admire JJ’s operation and technical mind, which was too brain-burning. In the mode of co-construction, it can not only collect topics but also mobilize participation. With the complicated disintegration and abnormal trap routes, SaoD can not Sao any more.

Based on the algorithm of one of my friends, further refined and processed, the warehouse Juejin-maths-game notes the address

enhanced

  • 🎉 Double mode double waiting, automatically read the level’s numbers, operators, target numbers.
  • 🧩 answer extraction, added to the hundreds of results of filtering and extraction, closer to the answer value.
  • 🪂 nail PUSH, can be pushed to nail, mobile phone computer two-step
  • 🧬 optimized Maths library ING for.Merge operators for parsing
  • 🤡 for learning only, welcome to improve togetherGameAutomatic path finding function

model

There are two modes: manual and automatic, which can be switched according to different scenarios. The default mode is automatic

Manual mode, according to the game level to display the numbers, results, characters input into the command, and then run, this mode does not need cookies and UID

# src/index.js
handleRunning([1.2.3.4], ['/'.The '*'.The '-'].10)
Copy the code

Automatic mode, according to the user’s information automatically log in the game to query the level data, and directly run the parsing algorithm, give the correct results. If cleared, execute automatic mode command again.

# src/index.js
autoRunning()
Copy the code

code

class Maths {
    / / parsing algorithm part - upgraded version of the source address: https://juejin.cn/post/7067862481800003591
    constructor(nums, options, target) {
        this.nums = nums;
        this.options = options;
        this.target = target;
        this.cache = {}
    }
    calc(a, option, b) {
        let res;
        let formula;
        switch (option) {
            case '+':
                res = a.value + b.value;
                formula = a.formula + '+' + b.formula;
                break;
            case The '-':
                res = a.value - b.value;
                formula = a.formula + The '-' + b.formula;
                break;
            case The '*':
                res = a.value * b.value;
                formula = a.formula + The '*' + b.formula;
                break;
            case '/':
                res = a.value / b.value;
                formula = a.formula + '/' + b.formula;
                break;
            case '. ':
                res = Number([a.value, b.value].join(""));
                formula = a.formula + '. ' + b.formula;
                break;
        }

        if (res < 0 || res % 1! = =0) {
            res = NaN;
        }
        return {
            value: res,
            formula: '(' + formula + ') ',};; };calcSum() {
        let cha = this.nums.length - 1 - this.options.length;
        if (cha) {
            this.options.push(...'. '.repeat(cha))
        }
        this.options.sort()
        for (let i of this.nums) {
            this.cache[i] = {
                value: i,
                formula: i,
            }
        }
        this.calcLoop(this.nums, this.options, this.target)

    };
    calcLoop(nums, options, target) {
        if (nums.length === 1 && options.length == 0 && this.cache[nums[0]].value == target) {
            // console.log(nums[0]);
            return;
        }
        nums.sort()
        let key = [...nums].join() + '|' + nums.join();
        if (this.cache[key]) {
            return
        }
        this.cache[key] = true
        for (let i of '* + - /.') {
            let index = options.indexOf(i);
            if (index >= 0) {
                let newOptions = [...options];
                newOptions.splice(index, 1);
                let len = nums.length
                for (let j = 0; j < len - 1; j++) {
                    let newNums = [...nums];
                    newNums.splice(nums.indexOf(nums[j]), 1);
                    for (let k = j + 1; k < len; k++) {
                        let newNums2 = [...newNums];
                        newNums2.splice(newNums2.indexOf(nums[k]), 1);
                        let newNum = this.calc(this.cache[nums[j]], i, this.cache[nums[k]])
                        if (isNaN(newNum.value)) {
                        }
                        else {
                            this.cache[newNum.formula] = newNum;
                            let t = [newNum.formula, ...newNums2];
                            this.calcLoop(t, newOptions, target);
                        }
                        if(i ! ='+'&& i ! =The '*') {
                            let newNum = this.calc(this.cache[nums[k]], i, this.cache[nums[j]]);
                            if (isNaN(newNum.value)) {
                            }
                            else {
                                this.cache[newNum.formula] = newNum;
                                let t = [newNum.formula, ...newNums2];
                                this.calcLoop(t, newOptions, target);
                            }
                        }
                    }
                }
            }
        }
    }

}
Copy the code

use

Env don’t fork, don’t upload your env data, just run it locally

USERID= # DINGTALK_WEBHOOK= # DINGTALK_SECRET=Copy the code
# clone 
$ git clone  https://github.com/study-vue3/fast-vue3.git

PNPM/YARN/NPM can be installed
$ pnpm install

# run
$ npm run start
Copy the code

The last

  • Welcome to join the front water friends group, paddling, everyone paddling together, now the fan group rarely discuss technology, so let’s swim together. Welcome to my public account sweeping the floor blind monk.

  • Cutting-edge technology, all kinds of experience, interactive related technology, all kinds of translation, research newspaper perspective in advance.

  • White piao, promise to release all paid resources, fans all free white piao, otherwise we who have time to play with you, hey hey.