GithubHelp home page GithubHelp logo

linus-jansson / btd6farmer Goto Github PK

View Code? Open in Web Editor NEW
32.0 3.0 11.0 2.68 MB

A tool to make autonomous macros in Bloons Td 6. Relies on OCR and template matchmating for navigation. Made in python

Home Page: https://discord.gg/qyKT6bzqZQ

License: MIT License

Python 99.70% Batchfile 0.30%
bot btd6 python

btd6farmer's Introduction

Hello there Im Linus👋

A software developer based in Sweden 🇸🇪

This is usually what im working with:

spotify-github-profile

btd6farmer's People

Contributors

alampole avatar linus-jansson avatar litesung avatar mirko93s avatar santiagorich avatar thefutureknight avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

btd6farmer's Issues

Press escape instead of clicking confirm button

Tried on chimps and apopalypse and seems like its possible to press escape to make the dialog dissapear. Will remove the need for needing to hardcode the position of the button

btd6farmer/Bot.py

Lines 390 to 396 in d816fa6

# Only need to press confirm button if we play chimps or impoppable
if self.settings["GAMEMODE"] == "CHIMPS_MODE" or \
self.settings["GAMEMODE"] == "IMPOPPABLE" or \
self.settings["GAMEMODE"] == "DEFLATION":
self.click(self.settings["DIFFICULTY"])
self.click("CONFIRM_CHIMPS")

[CLOSED] Trying to make this work on Linux.

Hi, I followed every step but I'm having problems running it. It seems I'm typing the gameplan directory wrong?

If I do python main.py /home/jx/Descargas/btd6farmer-main/Instructions/Dark_Castle_Hard_Standard
it doesn't recognize the directory
File "/home/jx/Descargas/btd6farmer-main/main.py", line 20, in <module> raise Exception("No valid argument for directory.. 'python main.py <directory to gameplan>'") Exception: No valid argument for directory.. 'python main.py <directory to gameplan>'. Any idea? Thanks in advance.

Current Bugs

  • Cannot detect the Level Up screen and freezes
  • Won't start game on some maps on Easy mode, it is reading 1/40 as "THO" in debug
  • It is skipping some insctructions, EG: on default chimps instructions, it completely skips R56 and 59 upgrading instructions and then continues with with R61 working fine, and no logs in debug, doesn't attempt to upgrade towers.
  • Sometimes when the game starts it opens the ESC menu before anything else and breaks the bot, this seems to be random and i cannot repeat it again, but my friend is/was having the same issue. EDIT: It started happening again, i found a temp fix and changed line 408 from time.sleep(0.2) to time.sleep(1). But it's probably not a good fix.

Language

Maybe you can add to ReadMe that the people should set the language to English so it works flawlessly.

Load gameplans from url

Gameplans shared in discord could be used as a parameter, downloaded and loaded into the bot in memory which removes the need for it to be on the users computer.

Not sure about requesting from discord servers with out headers etc but may work.

Dynamic Map Selection

Map page indices get out of date fairly quickly with releases of new maps. It would be better to find the maps dynamically by interpreting the text itself.

Unable to locate current round on 4k monitors

round_area.png might be upscaled to an all-white image which would not be located on the screen.

PY C:\Git\btd6farmer\main.py -p C:\Git\btd6farmer\Instructions\Dark_Castle_Hard_Standard\ -d
Setting up Bot...
Using gameplan located in: C:\Git\btd6farmer\Instructions\Dark_Castle_Hard_Standard
RUNNING IN DEBUG MODE, DEBUG FILES WILL BE GENERATED
Waiting for Home screen. Please switch to Bloons TD 6 window.
Waiting for loading screen..
Waiting for loading screen..
Waiting for loading screen..
Waiting for loading screen..
selecting map
Scaling: [0.438671875, 0.8666666666666667] -> (1684, 1872)
Scaling: [0.69453125, 0.9055555555555556] -> (2667, 1956)
Scaling: [0.30390625, 0.9055555555555556] -> (1167, 1956)
Scaling: [0.856640625, 0.4041666666666667] -> (3289, 873)
Scaling: [0.5546875, 0.24305555555555555] -> (2130, 525)
Scaling: [0.675390625, 0.3902777777777778] -> (2593, 843)
Scaling: [0.330859375, 0.5416666666666666] -> (1270, 1170)
Scaling: [0.59375, 0.6763888888888889] -> (2280, 1461)
Waiting for loading screen..
Waiting for loading screen..
Game start
(2968, 27, 96, 17)
C:\Git\btd6farmer\BotUtils.py:98: RuntimeWarning: invalid value encountered in true_divide
  gainDivision = np.where(localMax == 0, 0, (screenshot/localMax))
Found text 'i. WA' does not match regex requirements
Saved screenshot of what was found
Failsafe triggered. Exiting bot.

get_current_round_failed.png
get_current_round_failed

round.png
round

error

import mouse, keyboard
ModuleNotFoundError: No module named 'mouse'

Dynamic abilityAvaliabe

I was planing to help out with the
TODO: Make this more general to support more gameplans

so i was wondering where did you get the time used in
abilityAvaliabe(ability_one_timer, 35) from and if those ability times are static for each hero.

Gameplan not really working as aspected

I got a defeat at round 35 from camo balloons. Dart monkeys were not being upgraded at all.

Then after restarting the script, I got a defeat at round 63 with $38,964.
dart monkey1 0-0-2
dart monkey2 0-0-0
super monkey 0-0-1
both sub 2-0-3
alchemist 3-0-0
obyn placed and level 13
both monkey villages 0-0-2

Reference from #15 ..

Unable to locate current round on 1080p monitors

As seen in #21 the new locate current round system does not seem to work properly on 1080p monitors, thus the bot is not able to run on 1080p.

Taken from debug logs:

RUNNING IN DEBUG MODE, DEBUG FILES WILL BE GENERATED
Waiting for 5 seconds... Please select the Bloons TD 6 window during this time.
Selecting OBYN
Scaling: [799, 1272] -> (599.25, 954.0)
...
selecting map
Scaling: [1123, 1248] -> (842.25, 936.0)
...
Waiting for loading screen..
Game start
Could not find round area, setting default values
Scaling: [35, 1850] -> (26.25, 1387.5)
Found text 'OS' does not match regex requirements

and the debug picture is a black image which indicates that the screenshot is out of bounds, probably wrong scaled default values as it cant seem to found round area at all.

better tests

write tests to prevent possible small unnoticeable issues

  • Validate gameplans
  • Validate that all coords are normalized
    etc...

Crashing if Obyn is not selected

I have Etienne selected as my hero, and it prints the selecting obyn message and then crashes:

python main.py "\\Instructions\\Dark_Castle_Hard_Standard"
Setting up Bot...
Setup Complete.
Waiting for 5 seconds... Please select the Bloons TD 6 window during this time.
Selecting obyn if not selected
Traceback (most recent call last):
  File "C:\Users\Jason\Downloads\btd6farmer-main\main.py", line 43, in <module>
    bot.hero_select()
  File "C:\Users\Jason\Downloads\btd6farmer-main\bot.py", line 333, in hero_select
    utils.button_click(self.settings["HERO"])
  File "C:\Users\Jason\Downloads\btd6farmer-main\l_utils.py", line 118, in button_click
    move_mouse(scaling(static.button_positions[btn]))
KeyError: 'OBYN'

Error when choosing heros

error in command line
"
Setting up Bot...
Waiting for 5 seconds... Please select the Bloons TD 6 window during this time.
Traceback (most recent call last):
File "C:\Users\Documents\btd6farmer-main\main.py", line 34, in
bot.hero_select()
File "C:\Users\Documents\btd6farmer-main\Bot.py", line 261, in hero_select
self.log(f"Selecting {self.settings['hero']}")
KeyError: 'hero'
"

then exits python
any fixes?

Proper logging

In file and in terminal (Need to think about this)

  • Win & defeat
  • Debug mode should take screenshots and save to debug folder for ease of debugging. Makes it possible to test the bot for hours without being present at the PC.
  • Add logging to file and fix try excepts so errors get logged to file
  • Verbose mode for user to print actions to the terminal (Current round, different detections etc...)

https://docs.python.org/3/howto/logging.html

Problems with selecting the correct map

When trying the latest release, as mentioned in #23 , the bot will stop working after selecting the screen.

It doesn't even seem to click anywhere, it just happens after it registers the screen.

Setting up Bot...
Waiting for 5 seconds... Please select the Bloons TD 6 window during this time.
Traceback (most recent call last):
  File "C:\Users\Jason\Downloads\btd6farmer\main.py", line 34, in <module>
    bot.hero_select()
  File "C:\Users\Jason\Downloads\btd6farmer\Bot.py", line 261, in hero_select
    self.log(f"Selecting {self.settings['hero']}")
KeyError: 'hero'

Bot skips instructions causing the bot to fail

the bot lost at round 78 and is not handling the defeat screen. options for home, restart, review map, and continue. and the cmd window just prints the following while it clicks around missing any actual buttons:

selecting map
Game start
selecting map
Game start
selecting map
Game start
selecting map
Game start

map review:
image

defeat screen:
image

Bot gets stuck on "Game start"

I start the bot and it selects the hero, map, and difficulty. Then it starts the game. but after the bot closes the popup mentioning impoppable, it just sits watching the map and not doing anything. The last thing printed in the command line is "Game start". Playing on fullscreen resolution 2560x1440.

Below is a screenshot of the output after I kill the python code from the command line.
image

Discord

I think a discord server would be cool so people can share there gameplans.

❗Before opening issue: ImportError: No module named mss...

With the next release of the bot (#25). Pyautogui will be removed as a dependency and mss will be added causing the bot to fail on runtime if you don't have it installed. To fix this please run Install_Requirements.bat to refresh the dependencies needed for the bot if you are getting ImportErrors.

Why?

Earlier in development I used pyautogui for sending keys and clicking with the mouse. But I had issues with the clicks and keys not being registered in game. See this for explanation.

So I switched over to the mouse & keyboard lib to handle this problem. The only thing that I really needed pyautogui for now was locating stuff on screen. I thought that was quite unneccesary to have a navigation lib just for locating buttons on screen. So with PR the next release (#25) I have built that into the bot and replaced the pyautogui functions that were used..

2 issues current build

  • Bot freezes on level up screen sometimes
  • On startup bot fails to go to settings to change language, you need to aid it by exiting back to home screen else it won't do so on itself and fail to run completely (manages to go to powers)

bot not detecting instamonkeys

I've tried lowering the confidence, separating the levelup and instamonkey checkFor, and replacing the image but still can't get it to work, I'm on a 1920x1080 monitor, not sure if this is the same as #4

getting this in console but not sure what it means:
\btd6bot\src\ocr.py:22: RuntimeWarning: invalid value encountered in true_divide
gainDivision = np.where(localMax == 0, 0, (screenshot / localMax))

Some upgrades are not bought thus causing game to lose

Stage starts normally. Both monkeys, subs and hero are placed. However right after they're placed sometimes the bot opens a tower menu but doesn't buy any upgrade and close the tab afterwards.

After checking Instructions I found that "14" is not being executed.

"14": [
{
"TOWER": "SUBMARINE",
"UPGRADE": "0-0-1",
"UPGRADE_DIFF": "0-0-1",
"TARGET": null,
"TARGET_POS": null,
"POSITION": [1452, 922],
"ROUND_START": false
}
],

Am I missing something like turning auto start off? Or maybe my extra 200 money at the beggining is causing it to fail?

Additional info:

Some upgrades after the one mentioned are not bought aswell. Tried turning off monkey knowledge but to no avail.

Screen size: 1920x1080
Monitor: 1920x1080 59.9hz
Windows 10

Monkey Knowledge don't work.

I tried to add a delay but doesn't really help. Maybe i have done it wrong or something but I tried: if self.levelup_check() or self.insta_monkey_check():
self.click(middle_of_screen, amount=2)
time.sleep(5)
self.click(middle_of_screen, amount=2)

Unable to get information printed from F11

Pretty new to all of this but I think it needs a .json file. if a string file is needed, the log.py has an error where it looks for a ".join" file. idk if this is right or not, but I think it's supposed to be .json?

Collection Events

Hey, so not sure if this bot is still being actively maintained or not- seems like it's been a bit, but a new collection event has began, and I saw you talked about this in an earlier issue.

So first- a workaround for anyone trying to use the bot right now- disconnect your device (or just the game window, I'm sure that's possible using some software) from the internet while the script runs. The game won't prompt you to open any crates, but you'll still get the progress towards the crates, so when you reconnect to internet you can open all the crates you would have received, all at once.

Next- a more robust solution to be added to the bot. Either a option, or maybe make it default, to instead of clicking the main menu screen after a game finishes, to instead click the freeplay button, then open the pause menu via hotkey, and press restart. Not only does this save time between games, but it prevents ever traveling to the main menu and therefore getting unwanted pop-ups. Honestly, I can't say with 100% certainty the menus haven't been changed, but a bot I used more than a year ago used this method and it worked perfectly at the time- I assume it works the same way now- sadly I can't test right now and I figured I'd write this issue as early as possible so that anyone looking at the issues page can use the temporary solution listed above.

Thanks in advance- doesn't look like you're actively updating this bot, but figured I'd let you know anyways, before you possibly went through the effort of detecting all sorts of different collection event images for different events like you mentioned in that other issue. I think this freeplay-> restart solution could work uniformly across all events with minimal effort required.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.