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

Change Reward function to give points to number of unique pokemon #167

Open
martin-cala1 opened this issue Feb 11, 2024 · 2 comments
Open

Comments

@martin-cala1
Copy link

Hi,

Came across the tutorial on youtube and got the program running. How can I change the reward function to give points to number of unique pokemon? The idea is to try to train the agent to Catch them all.

I also have access to cloud resources of several GPUs. I want to try to run run_baseline_parallel_fast.py to simulate hundreds of games at once to see how fast I can get it to capture 10 unique pokemon.

@Xe-Xo
Copy link

Xe-Xo commented Feb 11, 2024

Hi, You can access the reward function in the the get_game_state_reward function in red_gym_env.py

The memory addresses you need to access are 0xD2F7 - 0xD309 with each bit representing a boolean whether you own that specific pokemon. You can find more memory addresses here.
https://datacrystal.romhacking.net/wiki/Pok%C3%A9mon_Red_and_Blue/RAM_map#Pokedex

you could write something along the lines of
def get_unique_pokemon(self):
for i in range(0,18):
pokemon_caught += self.bit_count(self.read_m(0xD2F7 + i))
return pokemon_caught

then add to the state_score dictionary something like
'unique_pokemon': self.reward_scale*self.get_unique_pokemon(),

i would not recommend removing the other rewards as the agent probably wont leave pallet town unless it has some exploration reward but you are welcome to experiment.

good luck!

@mdreano
Copy link

mdreano commented Feb 28, 2024

If it can help you, i went for the same reward.

In the game state rewards

'seen_pokemons': self.reward_scale * self.seen_pokemons

RedGym

    def update_seen_pokemons(self):
        initial_seen_pokemon = 3  # it seems like it has already encountered a bird
        self.seen_pokemons = sum(self.reader.read_seen_pokemons()) - initial_seen_pokemon

Reader (i extracted everything related to memory in a different class)

    def read_seen_pokemons(self):
        return [self.bit_count(self.read_m(a)) for a in SEEN_POKEMONS_ADDRESSES]

Memory addresses

    SEEN_POKEMONS_ADDRESSES = [0xD30A, 0xD30B, 0xD30C, 0xD30D, 0xD30E, 0xD30F, 0xD310, 0xD311, 0xD312, 0xD313, 0xD314, 0xD315, 0xD316, 0xD317, 0xD318, 0xD319, 0xD31A, 0xD31B, 0xD31C]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants