Skip to content

Commit

Permalink
perf: 调整随机数
Browse files Browse the repository at this point in the history
  • Loading branch information
iDerekLi committed Jan 21, 2022
1 parent 2ba46d8 commit d3cc3ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
18 changes: 7 additions & 11 deletions scripts/seaGold.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ async function run(args) {

const astar = new Astar(maze);
const path = astar.search(
[startPos.x, startPos.y], // start
[endPos.x, endPos.y], // end
{ // option
rightAngle: true, // default:false,Allow diagonal
optimalResult: true // default:true,In a few cases, the speed is slightly slower
[startPos.x, startPos.y],
[endPos.x, endPos.y],
{
rightAngle: true,
optimalResult: true
}
);

Expand Down Expand Up @@ -330,10 +330,6 @@ async function run(args) {

const seaGold = await SeaGold.init();

function randomWaitTime(start = 500, end = 1000) {
return (Math.random() * (end - start) + start) >> 0;
}

async function runOnceGame() {
if (seaGold.isGaming) {
await seaGold.gameOver();
Expand All @@ -342,7 +338,7 @@ async function run(args) {
let run = true;
while (run) {
try {
await utils.wait(randomWaitTime(1000, 1500));
await utils.wait(utils.randomRangeNumber(1000, 1500));
await seaGold.executeGameCommand();
} catch (e) {
run = false;
Expand All @@ -358,7 +354,7 @@ async function run(args) {
console.log(`准备挖矿!`);
console.log(`当前进度: ${seaGold.userInfo.todayDiamond}/${seaGold.userInfo.todayLimitDiamond} 矿石`);
while (seaGold.userInfo.todayDiamond < seaGold.userInfo.todayLimitDiamond) {
await utils.wait(randomWaitTime(1000, 1500));
await utils.wait(utils.randomRangeNumber(1000, 1500));
await runOnceGame();
console.log(`当前进度: ${seaGold.userInfo.todayDiamond}/${seaGold.userInfo.todayLimitDiamond} 矿石`);
}
Expand Down
3 changes: 3 additions & 0 deletions scripts/utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module.exports = {
async wait(time = 0) {
return new Promise(resolve => setTimeout(resolve, time));
},
randomRangeNumber(start = 500, end = 1000) {
return (Math.random() * (end - start) + start) >> 0;
}
}

0 comments on commit d3cc3ff

Please sign in to comment.