Farama-Foundation / Gymnasium

An API standard for single-agent reinforcement learning environments, with popular reference environments and related utilities (formerly Gym)
https://gymnasium.farama.org
MIT License
7.12k stars 790 forks source link

[Question] Can `utils.play.Play` be used for playing `Blackjack`? #802

Closed goekce closed 5 months ago

goekce commented 10 months ago

Question

I would like to use utils.play.Play to play Blackjack, however I failed. utils.play.Play does not wait for keypresses and proceed with the next step using the noop key (default 0) if the user does not provide any input.

Can utils.play.Play be used for playing Blackjack? Or: Is utils.play.Play primarily implemented for high fps games like CarRacing?

If yes, I can happily open an enhancement request to note that in the docs.

pseudo-rnd-thoughts commented 10 months ago

I believe you will need to define the keys_to_action parameter that specifies keyboard presses to actions in the game

goekce commented 10 months ago

@pseudo-rnd-thoughts you can try this example:

import gymnasium as gym
from gymnasium.utils.play import play

env = gym.make("Blackjack-v1", render_mode="rgb_array")
play(
    env,
    keys_to_action={
        "0": 0,
        "1": 1,
    },
    # noop=0, default is `0`
)
env.close()

Play automatically continues after each step to not interrupt the environment.

pseudo-rnd-thoughts commented 7 months ago

@goekce Apologies for not replying, yes, play was designed for high fps games, therefore, does not consider turn based games where you want to wait for a user action. We would happily accept a PR to add this feature

goekce commented 7 months ago

I don't have the capacity to improve play right now. At least a note in the docs could save time for the users.