Forked an application for the first time

avatar
(Edited)

I have been using a bot designed by someone else to play my extra Splinterlands cards. The application the bot uses had some issues upon first use and since then I have made a few changes to the scripts to make it run better on my virtual machines. And figured it would be a good idea to make my own fork of the application.

My first change was made to the package.json file. When I tried to run the application for the first time I got a package conflict error, upon opening up the file in a text editor I saw the following near the bottom.

`<<<<<<< HEAD
"puppeteer": "^2.1.1"
=======
"puppeteer": "^2.1.1",
"minimist": ">=1.2.3"
>>>>>>> ad56a3a8c469f49ccb88a7656245efe54ae43f9e`

I believe having two puppeteer entries was causing this error, so I removed one and the other invalid json in that file. Below is now how the package.json file looks. Puppeteer uses Chromium to launch an automated session in the browser, it can reload pages, enter login info and click through the menus.

`{
"name": "Solo's fork of splinter-scraper",
"version": "1.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"dimas-kmeans": "^1.0.3",
"dotenv": "^8.2.0",
"hierarchical-clustering": "^1.1.0",
"minimist": ">=0.2.1",
"node-cron": "^2.0.3",
"node-fetch": "^2.6.0",
"pg": "^8.0.3",
"puppeteer": "^2.1.1"
  } 
}`

Now when I run the script it no longer gets a package conflict, and I added my name to the fork along with changing the version to 1.0.1

I made the readme more clear, and added how you can add an .env file to the working directory of the script instead of having to use a global environmental variable file. Since I am running multiple accounts I find this a needed addition.

This is a fork of alfficcadenti's BOT to play the game Splinterlands

Changes have been made to resolve package conflicts, and to resolve script time outs/stops

index.js
run npm start index.js

to start BOT login routine. username and password needs to be specified in the file .env as variable like:                       
ACCOUNT=yourhiveusername PASSWORD=yourhiveprivatepostingkey Create .env text file with the above in the working directory of the             
splinterlands bot and add .env text file to .gitignore

https://peakd.com/hive-13323/@solominer/set-up-my-own-splinterlands-bots

Next up was changes to the index.js file. Right now I am running this bot on a virtual machine, and it does not make use of my graphics card for rendering. So alot of CPU is used instead, this is causing the rendering of the website to take longer. Also seems the popup windows have changed since alfficcadenti's last changes to the script. So I needed to add another set of puppeteer commands to get it working.

    await page.reload();
    await page.waitFor(5000)

Now it does reloads the page three times and waits 5 seconds each time. Without this recently I found the script to stop working. I guess the lands popup is now gone and affecting the script.

As I mentioned my virtual machine runs a little slower than it would on a bare metal machine, I had to adjust the await page.waitfor command. It was set to 3 seconds which I saw the script timing out when my virtual machine could not keep up.

So I added a zero making it wait 30 seconds, more than enough time now for the rendering on the website to catch up. Now it looks like below.

await page.waitFor(30000);

I made some other changes, but found them not working as well as what was set up originally, so I reverted back to what alfficcadenti's defaults were. An example of this was the cron job timing for each battle. It was set to 14 minutes between battles and I found this to be too long. But after battling at 7 minutes for a season I started to get login denies from the Spinterlands.com stating my API calls are too frequent.

cron.schedule('*/15 * * * *', async () => {

I now run 5 of the bots using PM2, a process monitor I have in Ubuntu. I have tried getting this setup to run on my RaspberryPi4 but the ARM build of puppeteer and Chromium seem to have some issues getting it to work. The browser is failing to launch sometimes, so I need to do more research on that to get it running. If I can get it working ill do another fork of alfficcadenti's app just for ARM use.

Still some issues to iron out, such as some battles are aborted due to an error saying there are no teams available for battle. Seems to happen when new rulesets are encountered the and script does not know what to do. It also seems to have issues with calls to herokuapp, stating invalid json sometimes. Maybe the new rulesets need to be added into the script.

Feels good I was able to fix and do some improvements on the script that someone else made. Since it has not been updated since October of last year it was due for a couple changes and glad I was able to do it. Now I have my own github account and forked my first application, with the more and more scripting I do. I can see more forks happening in the future as well.

You can find a link to my fork below:

https://github.com/solominer0/splinterlands-bot

Posted with STEMGeeks



0
0
0.000
16 comments
avatar

Haha yah!

You are a coding dynamo now! Must be great to be able to troubleshoot and customize a solution so granular.

Has using the bot increased your success/stake in Splinterlands?

0
0
0.000
avatar

Hehe I have alot to learn, so for now I am just copying others apps and making small changes. Yeah it was a little daunting at first, but just taking my time reading it line by line it mostly makes sense whats happening.

Yes! I have made about half my money back in just 1 season of playing. My up front costs were 5x spell books so it cost me around $50 for 5 bots to get started. I found a lvl 2 gold fire spitter in one of my rewards. And another got over 10k DEC for the season rewards. So seems ill be in profit in the next month or so. The bots usually get up into Bronze I or Silver III. But my Solominer account I play usually gets somewhere into Gold.

0
0
0.000
avatar
(Edited)

Good job with your fixes! I'm more of a dCity's girl, however, I forked your repo so maybe I could put my Splinterlands cards to work for me. 😉

Edit #1: I don't know if I'm doing something wrong, but could you give me a hand, please. The process gets stuck at the start and it stays like the image and won't progress.

VirtualBox_Ubuntu20_29_01_2021_10_42_45.png

Edit #2: It actually worked, just took a little while (~5 minutes just to start and open chromium). Maybe my machine sucks. 😅

0
0
0.000
avatar

nope this bot takes forever to process as written (no clue why), but at least it works!

0
0
0.000
avatar

Ah glad you got it working, theres a 14 minute cron job delay in the script. So it can take up to 14 minutes to run sometimes. I tried reducing this number, but Splinterlands.com was rejecting my logins when trying to play too often with my bots.

Cool you play dCity, I know alot of people that play that. But all my free time is tied up in Splinterlands.

0
0
0.000
avatar

thanks for the post and sharing the original guys work. I took his code and got it to work for me, but as you mentioned he is missing teams for the new rulesets and his logic on team selection could be a bit better. Was also thinking you need to update a bunch of his data tables with your cards and the new ones that have since been added. I'm going to be working on utilizing the SDK published by splinterlands to change the code around. Will share when I get somewhere!

0
0
0.000
avatar

Thanks for checking it out, yeah seems a little outdated. I believe the logic is in a database that the app queries. Ill have to see if I can wrap my head around it.

Best of luck making changes, happy to add them to my fork if you want. Or you can start your own.

0
0
0.000
avatar

yeah I thought the same that he stored the logic in a database, After I have a list of card combos that works for my card set, I'm going to override his logic (still trying to decipher most of what he did). The better option would probably be to start using the splinterlands sdk and their pre built commands. https://github.com/steem-monsters/splinterlands-js

0
0
0.000
avatar

Ah okay, Ill take a look at the SDK and see if I can incorporate it into the bot.

0
0
0.000
avatar

fix to the summoner logic on possibleTeams.js

const summoners = [{ 5: 'fire' },
{ 16: 'water' },
{ 27: 'earth' },
{ 38: 'white' },
{ 49: 'death' },
{ 56: 'dragon' },
{ 70: 'fire' },
{ 71: 'water' },
{ 72: 'earth' },
{ 73: 'life' },
{ 74: 'death' },
{ 78: 'dragon' },
{ 88: 'dragon' },
{ 109: 'death' },
{ 110: 'fire' },
{ 111: 'water' },
{ 112: 'earth' },
{ 113: 'life' },
{ 114: 'dragon' },
{ 130: 'dragon' },
{ 145: 'death' },
{ 156: 'life' },
{ 189: 'earth' },
{ 167: 'fire' },
{ 178: 'water' },
{ 180: 'earth' },
{ 189: 'earth' },
{ 200: 'dragon' },
{ 205: 'dragon' },
{ 224: 'dragon' },
{ 235: 'death' },
{ 236: 'fire' },
{ 239: 'life' },
{ 240: 'dragon' },
{ 240: 'water' },
{ 257: 'water' },
{ 258: 'death' },
{ 259: 'earth' },
{ 260: 'fire' },
{ 261: 'life' },
{ 262: 'dragon' },
{ 278: 'earth' }]

0
0
0.000
avatar

Great! I will update my github and try that out. Thanks so much for the research and changes. I will mention you did it in the comments on my github change.

0
0
0.000
avatar
(Edited)

@fitz1567 I tried out the new logic for possibleteams.js but seems to be still getting that no teams available to be played is happening.

image.png

Are you getting this too?

heres the rule it failed on..

image.png

0
0
0.000
avatar

Yes it fails at all the same points its because of return fetch(https://splinterlands-data-service.herokuapp.com/battlesruleset?ruleset=${rulesetEncoded}&mana=${mana}). He built his table without the new rulesets and combinations. So when you get the match details it fails to fetch these details. I'm consolidating my playable hands in an excel file with the rulesets and mana costs. Then i'm going to convert it to .json and learn to add new match data to my table. Something like mana,splinter,ruleset1,ruleset2, summoner,position1,2,3,etc. and then record, win%, win vs. fire, win vs. earth, etc.. Then when i pull the game details do <= mana, contains splinter and all the other rules. When I play I update the record and when I lose to a new hand not stored add the combination to the table. I'm going to let these bots fly in bronze and when i'm done with my logic switch it over. Can always add to the else that surrenders your own play logic if you want a quick fix!

0
0
0.000
avatar

Ah yeah that herokuapp seems like it needs to be updated too. Maybe if it can all be coded in the script and not need to pull data from an external place it would work better.

Okay if you get that working lemme know, happily add it to my github repo. Sounds like you have a better understanding of this than I do.

I was able to get up to Silver III with the bots so hopefully you can do the same.

0
0
0.000
avatar

"Maybe if it can all be coded in the script and not need to pull data from an external place it would work better." This is what i've been mulling over for a few days on how best to solve for this. I think the answer is either .json store the permutation or mysql (but would have to pay for this). I have an excel file with a good amount of basic account card permutations and wanted to use the exceljs package to just use excel, but getting hungup on sort and filter functions as I really only see an autofilter function. I'm now converting my excel file to .json and then i'm going to work on how to play my hands and store the record.

0
0
0.000