prinzstani / CookieBot

Automatic Playthrough for Cookie Clicker
GNU General Public License v3.0
50 stars 33 forks source link

Don't require 100% uptime #79

Open pie3636 opened 2 years ago

pie3636 commented 2 years ago

Due to various reasons I cannot leave Cookie Clicker running 24/7 on my computer.

The issue is that sometimes, I'll start the game and the bot will instantly prestige, even if very little progress has been made and there is almost no active playtime on the current prestige.

I would suggest making the prestige timer count active time only rather than offline time as well, since otherwise there is no way for infrequent players like me to get to the endgame.

I am playing on Steam, if it changes anything.

prinzstani commented 2 years ago

Currently, the bot ascends at the latest after 40 days with the idea that there would have been some progress since then. It is tricky to measure the active time because the bot could not be active but the game could be active. We might be able to introduce a threshold for when it is meaningful to ascend - something like 5% more prestige gained. BTW, normally the bot does not run at night anyway, so it should be fine if you switch off the computer overnight.

Kikithecat12345 commented 2 years ago

Doesn't the stats timer only count time with the game open? I may be wrong, but this issue would be dead easy to solve by just switching which timer we use.

Alternatively, we could add (and save) a milliseconds value since the bot has been running. Therefore when you close the game it saves that value and loads it as part of initialization. We then use this value as a reference everywhere else instead of real-time.

prinzstani commented 2 years ago

In Stats there is only the difference of now to the starting time of the current game. There is a reason that cookie clicker does not count the active time - because it si computationally expensive: You have to check every now and then whether you are still active. Remember that you do not always get a signal when the game is left. In this case, I still think it is better to think of an alternative way to detect whether to ascend: timing is not too good anyway.

The easiest way to do it is to introduce a threshold for ascend (see above). 5% new prestige seems reasonable (in addition to the timing).

pie3636 commented 2 years ago

I think there might be more to this issue than what was described above. I opened the game a few times yesterday and today, leaving the game run from 3 to 12ish hours each time. The bot never prestiged during those active hours. However, whenever I started the game, it always systematically restarted, even if the game had only been closed for one or two hours prior to me starting it.

As a result, those prestiges have had various levels of usefulness. The one that ran the longest yielded a decent HC increase, while the other ones have been next to useless.

My only mods are this bot and CookieMonster.

If it can be of any use, I saved the bot's log at https://pastebin.com/LQHSr9Ns.

prinzstani commented 2 years ago

That is really interesting, and I assume it is related to Steam. I see that the bot cannot detect that you have already achieved the Elder calm achievement. This is strange because you get it just quickly after. My assumption is that this is a problem of timing. It seems the bot is starting up too early, and at this time the clicker is not completely ready yet, so the bot gets the wrong information. I do not completely understand the start sequence of the bot in Steam, but it seems we need to delay the bot a bit to make everything work. @Kikithecat12345 Is there any way to check that the clicker is up and running?

Kikithecat12345 commented 2 years ago

@prinzstani Not sure, I will check when I can.

thelmexx commented 2 years ago

Bumping this issue since as pie experienced, it seems that restarting steam client will have the bot trigger an ascension. This seems to happen no matter how far into a run. I had to restart my game after 4 days of uptime, right after a fresh ascension, and when I opened the game up again, the bot ascended for a second time after a mere 800~ cookies.

Kikithecat12345 commented 2 years ago

The easiest way to fix this seems to be to keep track of the time ourselves. It would also help with a bunch of other stuff as well.

prinzstani commented 2 years ago

I have put in a quick fix that should block the ascend if the prestige gain is less than 10%. Let me know if it works. Thinking about it, maybe the best way to solve the issue is to introduce a configuration parameter that enables or disables the hard ascend. Alternatively, we can drop this whole feature and only ascend when the gain is big enough, like 25%.

prinzstani commented 2 years ago

Comment on keeping track of time: There is a reason that the clicker itself does not keep time. This is difficult to get correct and it is a lot of work. What we might be able to do is to keep the number of iterations we do in the bot, which somewhat amounts to the time that is spent in the bot. That would mean we do not catch the cumulative time spent in the bot, just the time spent in the current run with the bot. All in all, I think this is more work than gain, so I would advise against keeping time unless someone has a clever idea of how to do it.

thelmexx commented 1 year ago

Still having the issue of ascension after barely 1-2 days of uptime, and only after restart. It's possible that the bot is just loading before cookie clicker itself is done loading on the Steam version, since most of the times when on restart, I get popups for the completions of achievements such as tiny cookie, olden days, stifling the press, etc. Potential fix would be adding a bot start delay?

prinzstani commented 1 year ago

I have added a graceful launch of the bot, such that it checks that the clicker is ready before it starts. This is in the beta version as of now (as also the last quick fix). Check whether it helps with the problem.

thelmexx commented 1 year ago

Still occurred on 5/7 startups of the game. Bot still seems to go through the process of unlocking all the easy click achievements, then tries to declare a covenant with the grandmatriarchs, realizes that it has achieved that, then ascends, all before the game can load building graphics.

prinzstani commented 1 year ago

That sounds strange to me. Can you get me an export save of the status before you switch off your computer, and then the log of the bot activities when you restart? With log I mean the printout of the bot in the console. Thanks in advance.

mvicari commented 1 year ago

I've been experiencing the same issue. If my system happens to crash (which it does from time to time unfortunately) and reboot, when I restart Cookie Clicker Cookie Bot always decides to ascend instead of continue from its last save.

Here is the raw paste data from the Cookie Bot Log: https://gist.github.com/mvicari/df7ca01c58827844a4e914b233e4f07a

prinzstani commented 1 year ago

This is really strange. It seems that the bot is too early, but then again it is waiting until the game is on. I cannot see why this behavior would happen. Are you using Steam? How does the startup work in detail? It is possible to delay the startup - currently, the bot starts when it is activated if the game is on. We could wait some seconds before that, which would maybe solve the issue, but introduce an extra waiting time for users that start the bot manually. Can you get access to the console log of the bot (the things the bot writes onto the console)?

mvicari commented 1 year ago

I am using the cookieAutoPlayBeta 2.045 for Steam version 2.048.

I start the game by just running it through Steam, if that makes sense. Just hitting the 'Play' button.

I do also use CookieMonster (and CCSE which is a required addon)

Is there anyway to access the console other than hovering over the version number in-game? The bot ascends so quickly I cannot get a screenshot before ascension and the screen fades to black.

prinzstani commented 1 year ago

I have added some debug messages that will show up in the cookie bot log. Have a look at what you can see there.

mvicari commented 1 year ago

Here's the readout from the cookie bot log: https://gist.github.com/mvicari/df7ca01c58827844a4e914b233e4f07a?permalink_comment_id=4438614#gistcomment-4438614

Edit: Here's a longer log (from earlier, which was too big to paste into a gist): https://pastebin.com/1NeusAtr

prinzstani commented 1 year ago

This seems to be quite tricky. The bot says it is ready when it is initialized, but before it loads the current state. It does not indicate when this is finished. Unfortunately, I cannot see the difference between a new run and a run that still needs to be loaded. I have created a tentative version that checks whether there is a save somewhere and then waits until at least the first achievement is loaded. Please try whether this helps, then I can improve and fail-safe the handling. Please send the few last lines of the log for me to see what happens.

mvicari commented 1 year ago

This fix may have done the trick. Loaded the game up and it did not auto ascend. Saved + Quit then reloaded the game and still did not auto-ascend.

debug logging autoplay V2.045: ### Game is not loaded yet, waiting ...

debug logging autoplay V2.045: ### Trying to get achievement: Bake 100 novemdecillion cookies in one ascension.

debug logging autoplay V2.045: ### value of won for next achievement: 0

debug logging autoplay V2.045: ### #debug logging autoplay V2.045: ### Game is not loaded yet, waiting ...

debug logging autoplay V2.045: ### Trying to get achievement: Bake 100 novemdecillion cookies in one ascension.

debug logging autoplay V2.045: ### value of won for next achievement: 0

debug logging autoplay V2.045: ### Game is not loaded yet, waiting ...

debug logging autoplay V2.045: ### Trying to get achievement: Bake 100 novemdecillion cookies in one ascension.

debug logging autoplay V2.045: ### value of won for next achievement: 0

debug logging autoplay V2.045: ### Trying to get achievement: Bake 100 novemdecillion cookies in one ascension.

debug logging autoplay V2.045: ### value of won for next achievement: 0

There is a pop-up alert that reads "Game is not loaded yet, waiting ..." and doesn't auto close. Clicking the 'X' dismisses it.

prinzstani commented 1 year ago

Looks good. I will need to beautify the solution a bit and put it into the main branch. For now, the beta will do the trick.