preface
Automatic check-in, lucky draw what Low explosion, today the new generation of migrant workers to take you to realize the seabed mining challenge automatic mining!
The project address
Github project address: Click open
On the basis of @simund, this project adds the following functions: nailing webhook reminder and notification, automatic dipping, and automatic mining
Automatic check-in has been implemented by many students, so we will not repeat the wheel. Here we use the @Simund [original post] project as the basis to continue to complete our automatic mining.
ps
If you still don’t know what the Underwater Nuggets Challenge is, head over here to learn the rules:
Interpretation of the core
Rules of the game
The challenge is a bit like a visualized programming game for kids, but the challenge is to calculate the path to make sure you have enough movement instructions to prolong the game and get more ore rewards.
Pathfinding algorithm
Algorithm analysis
Since the algorithm of automatic path finding is beyond the scope of our discussion, we will implement a retardation version of artificial intelligence, namely: In the case that there are only three initial movement instructions, only the four positions of upper, lower, left and right can be moved, so that the four positions can be moved only using the initial movement instructions, which greatly reduces the difficulty of the algorithm.
Algorithm implementation
First we get the map data:
[0.0.230.136.0.228.0.243.129.248.0.0.0.114.224.0.114.128.0.256.0.232.0.0.0.6.108.0.6.0.0.6.6.159.0.102.157.0.112.0.0.6.0.221.248.6.246.0.1310.6.0.0.0.0.0.0.0.138.237.243.6.157.224.0.128.158.139.0.134.0.6.0.0.113.258.6.0.6.0.0.227.6.0.3.115.28.105.6.6.0.6.133.126.0.3.108.6.133.0.216.146.0.6.6.0.0.0.106.6.0.6.0.0.6.215.255.152.6.0.6.136.6.0.102.0.6.0.6.0.28.6.6.158.0.6.116.0.113.6.6.0.0.6.6.0.6.0.6.6.6.6.133.0.258.6.6.0.6.6.0.6.0.6.0.0.154.108.0.230.142.6.6.0.6.0.27.0.0.6.0.0.118.6.5.0.6.6.0.6.135.0.221.154.248.0.234.6.6.103.6.3.136.6.0.0.6.0.257.6.6.0.6.0.1110.107.0.4.256.0.0.241.6.0.0.106.6.6.6.107.0.132.0.6.0.219.6.122.0.237.113.6.223.6.227.0.158.105.1210.0.133.129.0.27.210.158.218.6.241.6.0.1310.154.4.6.6.0.6.256.6.0.0.117.4.6.0.6.104.6.231.6.104.0.0.0.132.6.235.6.6.3.6.152.6.1311.6.239.0.235.113.6]
Copy the code
By the analysis of
0
Represents blank space6
Stands for obstacle stone- In addition to
0
and6
The values outside are notMobile instruction
isOre reward
- An array of
[0 to 5]
Row 1 data, array[6-11]
Is line 2 data, and so on
First of all, we convert the map data into a two-dimensional array. The first layer of the array is the data group of each row, and the second layer is the array of all columns of a row. The code is as follows
/ * * *@desc Switch from a one-dimensional array to a two-dimensional array@param {Array} Arr raw data *@param {Number} Num Number of elements per dimension */
function ArrayOneToTwo(arr, num) {
let arrList = [];
arr.map((item, index) = > {
if (index % num == 0) {
arrList.push([item]);
} else {
arrList[arrList.length - 1].push(item); }});return arrList;
}
Copy the code
This is what the data looks like after the transfer
,0,230,136,0,228 [[0], [0, 0243129248], [0114224,0,114,128], [0256,0,232,0,0], [0,6,108,0,6,0], [0,6,6,159,0,102], [157, 0221248,6,246,0,0,0,6 0112], [], [1310,6,0,0,0,0], [0,0,0,138,237,243], [6157224,0,128,158], [139,0,134,0,6,0], [0113258 , 6,0,6], [0,0,227,6,0,3],,28,105,6,6,0 [115], [6133126,0,3,108], [6133,0,216,146,0], [6,6,0,0,0,106],,0,6,0,0,6 [6], [215, 25 136,6,0,102,0,6,6,0,6 5152], [], [0,6,0,28,6,6], [158,0,6,116,0,113],,6,0,0,6,6 [6], [0,6,0,6,6,6],,0,258,6,6 [6133], [0,6,6,0 , 6, 0],,0,0,154,108,0 [6], [230142,6,6,0,6], [0,27,0,0,6,0], [0118,6,5,0,6],,0,6,135,0,221 [6], [154248,0,234,6,6], [103,6,3, 136,6,0], [0,6,0,257,6,6], [0,6,0,1110,107,0], [4256,0,0,241,6], [0,0,106,6,6,6], [107,0,132,0,6,0], [219,6,122,0,237,113], [6 , 223,6,227,0,158], [105121 0,0,133,129,0], [27210158218,6,241],,0,1310,154,4,6 [6], [6,0,6,256,6,0], [0117,4,6,0,6], [104, 6231,6,104,0], [0,0,132,6,235,6],,3,6,152,6,1311 [6], [6239,0,235,113,6]]Copy the code
In this way, the data structure is much clearer, and we can get the data of a specific coordinate through the map array [row][column].
Based on the above data, we can calculate the walking trajectory in this way
const COLUMN = 6; / / the number of columns
const OBSTACLE = 6; / / obstacles
/** ** U above L left * R right * D below */
const mapsTrack = [
[3.1."U"],
[2.2."L"],
[4.2."D"],
[3.3."R"]];Example: the target coordinates [3, 1] are relative to the initial coordinates [3, 2] : the x coordinates are equal and the Y coordinates are 1 less than the initial coordinates, so the target is above the initial target, denoted by 'U'
const NAGETIVE_DIRECTION = {
"U": "D"."L": "R"."D": "U"."R": "L"};/ * * *@desc Calculate the walking trajectory *@param {Array} * / maps map
const getTarck = (maps) = > {
const mapsTree = ArrayOneToTwo(maps, COLUMN);
// Filter out the positions with obstacles
const trackXY = mapsTrack.filter((item) = > {
const x = item[0];
const y = item[1];
const xy = mapsTree[x][y];
returnxy ! == OBSTACLE;// Check whether it is an obstacle
});
// Move back to the original position after moving towards the target
const trackList = trackXY.map((item) = > {
const direction = item[2];
const nDirection = NAGETIVE_DIRECTION[item[2]].return [direction, nDirection];
}).flat();
return trackList;
};
Copy the code
Now, after we calculate the trajectory, we get the trajectory data that looks like this
["U"."D"."L"."R"."D"."U"."R"."L"]
Copy the code
Role of choice
Since our walking position is only 5 squares and the amount of ore we can eat is limited, the ability to improve a single bonus is very suitable for our artificial retards, so we chose this green character: CLICK
The deployment of
Local deployment:
$ git clone https://github.com/yunying1/juejin_auto_sign
$ cd ./juejin_auto_sign
$ npm install
Copy the code
$ npm run test
Copy the code
The result was this
Cloud Function Deployment
Cloud function deployment will not go into details, very simple good cut, can refer to @simund [original post]
To mine automatically, you only need one more step than he does: add the UID field to config.js, which is also written in the code
Write in the last
Automatic mining record
More and more
Check out Github for more details
Such as:
- Automatically Max out bonuses
- Forced termination for too many times of brushing (to prevent abnormal situations from causing an infinite loop, after all, the free amount of cloud functions is also limited)
- Automatically refresh the map with too few rewards
And so on…
In short, very silver, free hands to embrace artificial retarded!