掘金游戏“数字谜题”算法助手
非外挂哦,只是最快速找到算法,仍需要根据算法手动完成游戏
某个夜黑风高的晚上,某程序员摸鱼时无意间发现到了JJ的新游戏,玩了一会不得不佩服JJ运营和技术的头脑,太烧脑了。
模式上采用共建方式,既能收集题目又能调动参与,复杂的解体再加上变态的陷阱路线,简直SaoD不能再Sao。
基于某位掘友的算法,进行进一步改良和加工,仓库juejin-maths-game
感谢wangscaler提供的可视化地址:shuzi.wangscaler.com/
加强版
- 🎉 双模双待,自动读取关卡的数字,运算符,目标数字。
- 🧩 答案萃取,增加了对上百种结果的过滤和萃取,更加接近答案值。
- 🪂 钉钉PUSH,可以推到钉钉,手机电脑两步走
- 🧬 优化了Maths库ing,针对
.合并运算符进行解析处理 - 🤡 仅供学习,欢迎一起完善
Game的自动寻路功能
模式
有两种模式分别是手动和自动,针对不同的使用场景可自由切换,默认为自动模式
手动模式,需要自己根据游戏关卡展示的数字,结果,字符输入到命令,然后运行,此模式不需要COOKIE和UID
# src/index.js
handleRunning([1,2,3,4], ['/', '*', '-'], 10)
自动模式,根据用户的信息自动登录游戏查询到关卡数据,并且直接运行解析算法,给出正确结果。如果通关,再次执行自动模式命令即可。
# src/index.js
autoRunning()
代码
class Maths {
//解析算法部分-升级改造版 源地址: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 '-':
res = a.value - b.value;
formula = a.formula + '-' + b.formula;
break;
case '*':
res = a.value * b.value;
formula = a.formula + '*' + 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 != '*') {
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);
}
}
}
}
}
}
}
}
使用
.env 不要fork,不要上传你的env数据,本地跑就可以
# 用户cookie
COOKIE=
# 用户ID,随便url可查
USERID=
# 钉钉机器人
DINGTALK_WEBHOOK=
# 钉钉机器人密钥
DINGTALK_SECRET=
# clone
$ git clone https://github.com/study-vue3/fast-vue3.git
# pnpm/yarn/npm均可安装
$ pnpm install
# 运行
$ npm run start