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

Add isEpisodeTimeoutReached/is_episode_timeout_reached method to the core API #587

Merged
merged 4 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
11 changes: 11 additions & 0 deletions docs/api/cpp/doomGame.md → docs/api/cpp/doom_game.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@ Returns true if the current episode is in the terminal state (is finished).
will take no effect after this point (unless [`newEpisode`](#newepisode) method is called).


---
### `isEpisodeTimeoutReached`

| C++ | `bool isEpisodeTimeoutReached()` |
| :-- | :-- |
| Python | `is_episode_timeout_reached() -> bool` |

Returns true if the current episode is in the terminal state due to exceeding the time limit (timeout)
set with [`setEpisodeTimeout`](#setepisodetimeout) method or via `+timelimit` parameter.


---
### `isPlayerDead`

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ DoomGame is the main object of the ViZDoom library, representing a single instan
.. autofunction:: vizdoom.DoomGame.make_action
.. autofunction:: vizdoom.DoomGame.is_new_episode
.. autofunction:: vizdoom.DoomGame.is_episode_finished
.. autofunction:: vizdoom.DoomGame.is_episode_timeout_reached
.. autofunction:: vizdoom.DoomGame.is_player_dead
.. autofunction:: vizdoom.DoomGame.respawn_player
.. autofunction:: vizdoom.DoomGame.send_game_command
Expand Down
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ game.close()
:hidden:
:caption: Introduction
introduction/pythonQuickstart
introduction/python_quickstart
introduction/building
introduction/apisAndWrappers
introduction/apis_and_wrappers
```

```{toctree}
Expand All @@ -70,16 +70,16 @@ introduction/apisAndWrappers
api/python
api/cpp
api/configurationFiles
api/configuration_files
```

```{toctree}
:hidden:
:caption: Environments
environments/default
environments/thirdParty
environments/creatingCustom
environments/third_party
environments/creating_custom
```

```{toctree}
Expand Down
1 change: 1 addition & 0 deletions include/ViZDoomGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ namespace vizdoom {

bool isNewEpisode();
bool isEpisodeFinished();
bool isEpisodeTimeoutReached();
bool isPlayerDead();
void respawnPlayer();
void sendGameCommand(std::string cmd);
Expand Down
4 changes: 2 additions & 2 deletions scenarios/basic.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ render_decals = false
render_particles = false
window_visible = true

# make episodes start after 20 tics (after unholstering the gun)
# Make episodes start after 20 tics (after unholstering the gun)
episode_start_time = 14

# make episodes finish after 300 actions (tics)
# Make episodes finish after 300 actions (tics)
episode_timeout = 300

# Available buttons
Expand Down
2 changes: 1 addition & 1 deletion scenarios/cig.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

doom_scenario_path = cig.wad

#12 minutes
# Make episodes finish after 12 minutes
episode_timeout = 25200

# Rendering options
Expand Down
4 changes: 4 additions & 0 deletions scenarios/deadly_corridor.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ render_decals = false
render_particles = false
window_visible = true

# Make episodes start in the first tic
episode_start_time = 1

# Make episodes finish after 2100 actions (tics)
episode_timeout = 2100

# Available buttons
Expand Down
5 changes: 4 additions & 1 deletion scenarios/deathmatch.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ render_decals = false
render_particles = false
window_visible = true

# make episodes finish after 4200 actions (tics)
# Make episodes start in the first tic
episode_start_time = 1

# Make episodes finish after 4200 actions (tics)
episode_timeout = 4200

# Available buttons
Expand Down
4 changes: 2 additions & 2 deletions scenarios/defend_the_center.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ render_decals = false
render_particles = false
window_visible = true

# make episodes start after 10 tics (after unholstering the gun)
# Make episodes start after 10 tics (after unholstering the gun)
episode_start_time = 10

# make episodes finish after 2100 actions (tics)
# Make episodes finish after 2100 actions (tics)
episode_timeout = 2100

# Available buttons
Expand Down
3 changes: 1 addition & 2 deletions scenarios/defend_the_line.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ render_decals = false
render_particles = false
window_visible = true

# make episodes start after 10 tics (after unholstering the gun)
# Make episodes start after 10 tics (after unholstering the gun)
episode_start_time = 10


# Available buttons
available_buttons =
{
Expand Down
2 changes: 1 addition & 1 deletion scenarios/health_gathering.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ render_decals = false
render_particles = false
window_visible = true

# make episodes finish after 2100 actions (tics)
# Make episodes finish after 2100 actions (tics)
episode_timeout = 2100

# Available buttons
Expand Down
2 changes: 1 addition & 1 deletion scenarios/health_gathering_supreme.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ render_decals = false
render_particles = false
window_visible = true

# make episodes finish after 2100 actions (tics)
# Make episodes finish after 2100 actions (tics)
episode_timeout = 2100

# Available buttons
Expand Down
8 changes: 6 additions & 2 deletions scenarios/learning.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Lines starting with # are treated as comments (or with whitespaces+#).
# It doesn't matter if you use capital letters or not.
# It doesn't matter if you use underscore or camel notation for keys, e.g. episode_timeout is the same as episodeTimeout.

doom_scenario_path = basic.wad

# Rewards
Expand All @@ -13,10 +17,10 @@ render_decals = false
render_particles = false
window_visible = false

# make episodes start after 20 tics (after unholstering the gun)
# Make episodes start after 20 tics (after unholstering the gun)
episode_start_time = 14

# make episodes finish after 300 actions (tics)
# Make episodes finish after 300 actions (tics)
episode_timeout = 300

# Available buttons
Expand Down
1 change: 0 additions & 1 deletion scenarios/multi.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ render_particles = false

window_visible = true


# Available buttons
available_buttons =
{
Expand Down
4 changes: 4 additions & 0 deletions scenarios/multi_duel.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Lines starting with # are treated as comments (or with whitespaces+#).
# It doesn't matter if you use capital letters or not.
# It doesn't matter if you use underscore or camel notation for keys, e.g. episode_timeout is the same as episodeTimeout.

doom_scenario_path = multi_duel.wad

screen_resolution = RES_320X240
Expand Down
4 changes: 2 additions & 2 deletions scenarios/my_way_home.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ render_decals = false
render_particles = false
window_visible = true

# make episodes start after 10 tics (after unholstering the gun)
# Make episodes start after 10 tics (after unholstering the gun)
episode_start_time = 10

# make episodes finish after 2100 actions (tics)
# Make episodes finish after 2100 actions (tics)
episode_timeout = 2100

# Available buttons
Expand Down
4 changes: 2 additions & 2 deletions scenarios/predict_position.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ render_decals = false
render_particles = false
window_visible = true

# make episodes start after 16 tics (after the rocket launcher is ready)
# Make episodes start after 16 tics (after the rocket launcher is ready)
episode_start_time = 16

# make episodes finish after 300 actions (tics)
# Make episodes finish after 300 actions (tics)
episode_timeout = 300

# Available buttons
Expand Down
4 changes: 2 additions & 2 deletions scenarios/rocket_basic.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ render_weapon = true
render_decals = false
render_particles = false

# make episodes start after 14 tics (after unholstering the gun)
# Make episodes start after 14 tics (after unholstering the gun)
episode_start_time = 14

# make episodes finish after 300 actions (tics)
# Make episodes finish after 300 actions (tics)
episode_timeout = 300

# Available buttons
Expand Down
8 changes: 6 additions & 2 deletions scenarios/simpler_basic.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Lines starting with # are treated as comments (or with whitespaces+#).
# It doesn't matter if you use capital letters or not.
# It doesn't matter if you use underscore or camel notation for keys, e.g. episode_timeout is the same as episodeTimeout.

doom_scenario_path = simpler_basic.wad

# Rewards
Expand All @@ -13,10 +17,10 @@ render_weapon = true
render_decals = false
render_particles = false

# make episodes start after 20 tics (after unholstering the gun)
# Make episodes start after 20 tics (after unholstering the gun)
episode_start_time = 14

# make episodes finish after 300 actions (tics)
# Make episodes finish after 300 actions (tics)
episode_timeout = 300

# Available buttons
Expand Down
3 changes: 3 additions & 0 deletions scenarios/take_cover.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ render_decals = false
render_particles = false
window_visible = true

# Make episodes start in the first tic
episode_start_time = 1

# Available buttons
available_buttons =
{
Expand Down
4 changes: 2 additions & 2 deletions scripts/create_python_docs_from_cpp_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

FILES_TO_PARSE = [
{
"input_filepath": "docs/api/cpp/doomGame.md",
"output_filepath": "docs/api/python/doomGame.md",
"input_filepath": "docs/api/cpp/doom_game.md",
"output_filepath": "docs/api/python/doom_game.md",
"submodule": "DoomGame.",
"append_to_header": """
```{eval-rst}
Expand Down
2 changes: 1 addition & 1 deletion scripts/create_python_docstrings_from_cpp_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def camel_case_to_snake_case(text):


FILES_TO_PARSE = [
{"filepath": "docs/api/cpp/doomGame.md", "namespace": "DoomGamePython"},
{"filepath": "docs/api/cpp/doom_game.md", "namespace": "DoomGamePython"},
{"filepath": "docs/api/cpp/utils.md"},
]
OUTPUT_FILE = "src/lib_python/ViZDoomMethodsDocstrings.h"
Expand Down
14 changes: 9 additions & 5 deletions src/lib/ViZDoomController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,7 @@ namespace vizdoom {
}

bool DoomController::isTicPossible() {
return !((!this->gameState->GAME_MULTIPLAYER && this->gameState->PLAYER_DEAD)
|| (this->mapTimeout > 0 && this->mapTimeout + this->mapStartTime <= this->gameState->MAP_TIC)
|| (this->gameState->MAP_TICLIMIT > 0 && this->gameState->MAP_TICLIMIT <= this->gameState->MAP_TIC)
|| (this->gameState->MAP_END));
return !(this->isMapEnded() || this->isMapTimeoutReached());
}

void DoomController::tic(bool update) {
Expand Down Expand Up @@ -601,7 +598,14 @@ namespace vizdoom {
}

bool DoomController::isMapEnded() {
return this->doomRunning && this->gameState->MAP_END;
// Check if the map has ended or the player is dead (in single player mode)
return (!this->gameState->GAME_MULTIPLAYER && this->gameState->PLAYER_DEAD) || (this->gameState->MAP_END);
}

bool DoomController::isMapTimeoutReached() {
// Check if internal or user-defined map timeout has been reached
return (this->mapTimeout > 0 && this->mapTimeout + this->mapStartTime <= this->gameState->MAP_TIC)
|| (this->gameState->MAP_TICLIMIT > 0 && this->gameState->MAP_TICLIMIT <= this->gameState->MAP_TIC);
}

unsigned int DoomController::getMapLastTic() {
Expand Down
1 change: 1 addition & 0 deletions src/lib/ViZDoomController.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ namespace vizdoom {
bool isMapLastTic();
bool isMapFirstTic();
bool isMapEnded();
bool isMapTimeoutReached();
unsigned int getMapLastTic();

void setNoConsole(bool console);
Expand Down
5 changes: 5 additions & 0 deletions src/lib/ViZDoomGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,11 @@ namespace vizdoom {
return !this->doomController->isTicPossible();
}

bool DoomGame::isEpisodeTimeoutReached() {
if (!this->isRunning()) throw ViZDoomIsNotRunningException();
return this->doomController->isMapTimeoutReached();
}

bool DoomGame::isPlayerDead() {
if (!this->isRunning()) throw ViZDoomIsNotRunningException();
return this->doomController->isPlayerDead();
Expand Down
3 changes: 3 additions & 0 deletions src/lib_python/ViZDoomMethodsDocstrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ processes the specified number of tics, updates the state and calculates a new r
:meth:`make_action` and :meth:`advance_action` methods
will take no effect after this point (unless :meth:`new_episode` method is called).)DOCSTRING";

const char *isEpisodeTimeoutReached = R"DOCSTRING(Returns ``True`` if the current episode is in the terminal state due to exceeding the time limit (timeout)
set with :meth:`set_episode_timeout`` method or via ``+timelimit` parameter.)DOCSTRING";

const char *isPlayerDead = R"DOCSTRING(Returns ``True`` if the player is dead.
In singleplayer, the player's death is equivalent to the end of the episode.
In multiplayer, when the player is dead :meth:`respawn_player` method can be called.)DOCSTRING";
Expand Down
1 change: 1 addition & 0 deletions src/lib_python/ViZDoomPythonModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ PYBIND11_MODULE(vizdoom, vz){
CLASS_FUNC_2_PYT_WITH_ARGS("new_episode", DoomGamePython::newEpisode, pyb::arg("recording_file_path") = "")
CLASS_FUNC_2_PYT_WITH_ARGS("replay_episode", DoomGamePython::replayEpisode, pyb::arg("file_path"), pyb::arg("player") = 0)
CLASS_FUNC_2_PYT("is_episode_finished", DoomGamePython::isEpisodeFinished)
CLASS_FUNC_2_PYT("is_episode_timeout_reached", DoomGamePython::isEpisodeTimeoutReached)
CLASS_FUNC_2_PYT("is_new_episode", DoomGamePython::isNewEpisode)
CLASS_FUNC_2_PYT("is_player_dead", DoomGamePython::isPlayerDead)
CLASS_FUNC_2_PYT("respawn_player", DoomGamePython::respawnPlayer)
Expand Down
Loading