Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forget pokemon set to not capture #3175

Closed
luckyvictor opened this issue Aug 9, 2016 · 19 comments
Closed

Forget pokemon set to not capture #3175

luckyvictor opened this issue Aug 9, 2016 · 19 comments

Comments

@luckyvictor
Copy link

Please check configuration at http://jsonlint.com/ before posting an issue.

This is not exactly an issue but an improvement rather, just want to ask whether this can be implemented.

Expected Behavior

The bot to forget the pokemon that is filtered as not to capture

Actual Behavior

The bot keeps seeing the same pokemon that is filtered as not to capture, seems like time is wasted on this pokemon

Steps to Reproduce

Other Information

OS:
Git Commit: (run 'git log -n 1 --pretty=format:"%H"' and paste it here)
Python Version: (run 'python -V' and paste it here)

@kyleboe
Copy link

kyleboe commented Aug 9, 2016

Would you mind putting something like [SUGGESTION] in the title so people can quickly sort through recent issues? Thanks 😃

@nelsong
Copy link

nelsong commented Aug 9, 2016

Have you tried adding said pokemon to the catch filter and marking it as "always_catch": false? I believe this is what you are looking for.

@luckyvictor luckyvictor changed the title Forget pokemon not to capture [Suggestion] Forget pokemon not to capture Aug 9, 2016
@luckyvictor
Copy link
Author

@kyleboe Thanks for pointing this out mate, done!

@luckyvictor
Copy link
Author

@nelsong by setting always_catch = false, does it mean that I will never catch that particular pokemon please? no matter its cp or lv?

because I actually want to filter it by cp or lv

@luckyvictor
Copy link
Author

@g2384
Thanks for sharing your code! I see how you do it, basically you are preventing the message to display again and again.

Do you think it is possible to 'completely' ignore this pokemon? e.g. not calling catchpokemonworker at all?

I understand it may be a bit difficult, as the logic to evalulate whether to catch or not is inside catchpokemonworker, so that means we may have to return a value to its upper level to 'delete' or 'remove' this particular pokemon from the api response, and this is where I am stuck.

@luckyvictor
Copy link
Author

@g2384

The should_capture_pokemon funciton is however inside the catch_pokemon_worker, surely we can copy it, but to evaluate the CP and IV of this particular pokemon, it is done in the work in catch_pokemon_worker, that means we have to copy that part of code out and call it before we decide to call catch_pokemon_worker.

Sounds like it is more like merging or basically embed half of the catch_pokemon_worker into other upper level modules, e.g catch_lured_pokemon.py and catch_visible_pokemon.py

Does it sound right to you?

@luckyvictor
Copy link
Author

@g2384

That is very interesting, and i think u nail it. Using global variable so that two modules can communicate.

I am not so good at coding, just in my early learning stage. May I ask what/why this code here for please? what is this magic number 20 please?

            if len(ignored_poke_arr) > 20:
                ignored_poke_arr.pop(0)

@g2384
Copy link

g2384 commented Aug 9, 2016

Just in case if the length of ignored_poke_arr becomes larger and larger. 20 is a rough estimation. It assumes that after ignoring 20 unique pokemon, the first pokemon has already disappeared/expired, so remove that one from the list. I didn't use timestamp here because for the lured pokemon, no timestamp is available.

Two modules cannot communicate, the global variables are separate, although they have the same name.

I'm really glad that you are interested in this question and discuss this issue with me. I'm disappointed by the contributors (lack of communication). So I won't post anything here anymore.

@luckyvictor
Copy link
Author

Thank you!

So why using pop but not remove please?

and do you think that it could 'save' some time by ignoring the unwanted pokemon and hence increase the efficiency of catching wanted pokemon?

@g2384
Copy link

g2384 commented Aug 9, 2016

I checked the differences and tested the speed.

  • pop : Takes Index & returns Value
  • remove : Takes value, removes first occurrence and returns nothing
  • delete : Takes index, removes value at that index and returns nothing

Surprisingly, remove is faster than pop. However, I think remove is not the best function, because we don't know what the first element is. It's easier to delete by index. If the code can be redesigned, remove should be considered.

Reducing API calls will increase the efficiency, according to the discussion in another issue (I won't make a reference). The minimum interval between API calls is 5-10 sec if I understand it correctly.

@luckyvictor
Copy link
Author

I am glad to have some discuss as well, and you answer questions very promptly.

In fact, I forgot to ask, you say two modules cannot communicate, the global variables are separate, although they have the same name.

I think u mean the global variable are the same variable, right? I mean it has to be the same variable so it can be called in different modules and act as a flag to decide whether to ignore or not.

@luckyvictor
Copy link
Author

luckyvictor commented Aug 11, 2016

@g2384

I hope that you are interested on discussing the code with me, as I just struggle to understand the following:

In the original catch_visible_pokemon.py, I have insert a print statement to help me debug

class CatchVisiblePokemon(BaseTask):
SUPPORTED_TASK_API_VERSION = 1

def work(self):
    if 'catchable_pokemons' in self.bot.cell and len(self.bot.cell['catchable_pokemons']) > 0:
        # Sort all by distance from current pos- eventually this should
        # build graph & A* it
        print('Victor: Catchable pokemon')
        self.bot.cell['catchable_pokemons'].sort(
            key=
            lambda x: distance(self.bot.position[0], self.bot.position[1], x['latitude'], x['longitude'])
        )

and the result on the console is

2016-08-11 08:26:18,991 [MoveToFort] [INFO] [moving_to_fort] Moving towards pokestop One Tree Hill - 0.07km
Victor: Catchable pokemon
2016-08-11 08:26:30,860 [PokemonCatchWorker] [INFO] [pokemon_appeared] A wild Drowzee appeared! [CP 374] [Potential 0.62] [S/A/D 14/2/12]
2016-08-11 08:26:33,012 [MoveToFort] [INFO] [moving_to_fort] Moving towards pokestop One Tree Hill - 0.06km
Victor: Catchable pokemon
2016-08-11 08:26:44,112 [MoveToFort] [INFO] [moving_to_fort] Moving towards pokestop One Tree Hill - 0.05km
Victor: Catchable pokemon
2016-08-11 08:26:54,912 [MoveToFort] [INFO] [moving_to_fort] Moving towards pokestop One Tree Hill - 0.04km
Victor: Catchable pokemon
2016-08-11 08:27:07,453 [PokemonCatchWorker] [INFO] [pokemon_appeared] A wild Drowzee appeared! [CP 374] [Potential 0.62] [S/A/D 14/2/12]

so the question I have is, why this print statement would be called every time after moving_to_fort? I just don't see how the catch_visible_pokemon.work is called.

@g2384
Copy link

g2384 commented Aug 11, 2016

It is not after moving_to_fort, it is before PokemonCatchWorker.

I don't really understand the code either. But it starts with:

  1. pokecli.py -> main() -> while True: bot.tick()
  2. tick() is defined in pokemongo_bot/__init__.py
  3. in tick(), self.cell = self.get_meta_cell() adds new tasks (catch pokemon and spin forts)
  4. in get_meta_cell(), cells = self.find_close_cells(*location) gets all objects from the map, and those objects are from API.
  5. the first task is initialised by config.json and created in pokecli.py, this line tree = TreeConfigBuilder(bot, config.raw_tasks).build() (and this is why in some issues, developers suggested to move some tasks up in the config.json file.)
  6. 'catch_visible_pokemon' is executed because of CatchVisiblePokemon in your config.json, try to remove that setting to see what will happen.

For the global variable part, I didn't test it so I don't know the exact answer. Please let me know if you discovered something.

@luckyvictor
Copy link
Author

i agree with you, it is called before PokemonCatchWorker, but three times? and only after the last time, it shows 'A Wild Drowzee appeared'

This is where I get lost....

@g2384
Copy link

g2384 commented Aug 11, 2016

It keeps checking catchable pokemon every tick (or every N ticks) even though there's no pokemon around you. That's why you see that print() frequently.

@luckyvictor
Copy link
Author

but then, from where the catch_visible_pokemon is called?? CatchVisiblePokemon is set in my config, but i just don't see where it calls this function, apparently it is not from Move_to_Map_Pokemon, as I have added a statement there before pokemoncatchworker is called, but this statement never print...

@k4n30
Copy link
Contributor

k4n30 commented Aug 16, 2016

@luckyvictor fixed?

@k4n30 k4n30 changed the title [Suggestion] Forget pokemon not to capture Forget pokemon set to not capture Aug 17, 2016
@luckyvictor
Copy link
Author

my account is now permanently banned (I guess, because I have been seeing server is busy or offline for 3 days), so I can't do it anymore unless I create a new account

@k4n30
Copy link
Contributor

k4n30 commented Aug 18, 2016

Going to close, happy to reopen if any raises that it still needs to be done

@k4n30 k4n30 closed this as completed Aug 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants