Skip to content

Commit 03ed0a5

Browse files
authored
Merge pull request #587 from Farama-Foundation/core-updates
Add isEpisodeTimeoutReached/is_episode_timeout_reached method to the core API
2 parents 8419abf + 563a2a4 commit 03ed0a5

34 files changed

+81
-34
lines changed
File renamed without changes.

Diff for: docs/api/cpp/doomGame.md renamed to docs/api/cpp/doom_game.md

+11
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,17 @@ Returns true if the current episode is in the terminal state (is finished).
179179
will take no effect after this point (unless [`newEpisode`](#newepisode) method is called).
180180

181181

182+
---
183+
### `isEpisodeTimeoutReached`
184+
185+
| C++ | `bool isEpisodeTimeoutReached()` |
186+
| :-- | :-- |
187+
| Python | `is_episode_timeout_reached() -> bool` |
188+
189+
Returns true if the current episode is in the terminal state due to exceeding the time limit (timeout)
190+
set with [`setEpisodeTimeout`](#setepisodetimeout) method or via `+timelimit` parameter.
191+
192+
182193
---
183194
### `isPlayerDead`
184195

File renamed without changes.

Diff for: docs/api/python/doomGame.md renamed to docs/api/python/doom_game.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ DoomGame is the main object of the ViZDoom library, representing a single instan
2424
.. autofunction:: vizdoom.DoomGame.make_action
2525
.. autofunction:: vizdoom.DoomGame.is_new_episode
2626
.. autofunction:: vizdoom.DoomGame.is_episode_finished
27+
.. autofunction:: vizdoom.DoomGame.is_episode_timeout_reached
2728
.. autofunction:: vizdoom.DoomGame.is_player_dead
2829
.. autofunction:: vizdoom.DoomGame.respawn_player
2930
.. autofunction:: vizdoom.DoomGame.send_game_command
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: docs/index.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ game.close()
5959
:hidden:
6060
:caption: Introduction
6161
62-
introduction/pythonQuickstart
62+
introduction/python_quickstart
6363
introduction/building
64-
introduction/apisAndWrappers
64+
introduction/apis_and_wrappers
6565
```
6666

6767
```{toctree}
@@ -70,16 +70,16 @@ introduction/apisAndWrappers
7070
7171
api/python
7272
api/cpp
73-
api/configurationFiles
73+
api/configuration_files
7474
```
7575

7676
```{toctree}
7777
:hidden:
7878
:caption: Environments
7979
8080
environments/default
81-
environments/thirdParty
82-
environments/creatingCustom
81+
environments/third_party
82+
environments/creating_custom
8383
```
8484

8585
```{toctree}
File renamed without changes.
File renamed without changes.

Diff for: include/ViZDoomGame.h

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ namespace vizdoom {
6262

6363
bool isNewEpisode();
6464
bool isEpisodeFinished();
65+
bool isEpisodeTimeoutReached();
6566
bool isPlayerDead();
6667
void respawnPlayer();
6768
void sendGameCommand(std::string cmd);

Diff for: scenarios/basic.cfg

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ render_decals = false
1818
render_particles = false
1919
window_visible = true
2020

21-
# make episodes start after 20 tics (after unholstering the gun)
21+
# Make episodes start after 20 tics (after unholstering the gun)
2222
episode_start_time = 14
2323

24-
# make episodes finish after 300 actions (tics)
24+
# Make episodes finish after 300 actions (tics)
2525
episode_timeout = 300
2626

2727
# Available buttons

Diff for: scenarios/cig.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
doom_scenario_path = cig.wad
66

7-
#12 minutes
7+
# Make episodes finish after 12 minutes
88
episode_timeout = 25200
99

1010
# Rendering options

Diff for: scenarios/deadly_corridor.cfg

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ render_decals = false
2121
render_particles = false
2222
window_visible = true
2323

24+
# Make episodes start in the first tic
25+
episode_start_time = 1
26+
27+
# Make episodes finish after 2100 actions (tics)
2428
episode_timeout = 2100
2529

2630
# Available buttons

Diff for: scenarios/deathmatch.cfg

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ render_decals = false
1515
render_particles = false
1616
window_visible = true
1717

18-
# make episodes finish after 4200 actions (tics)
18+
# Make episodes start in the first tic
19+
episode_start_time = 1
20+
21+
# Make episodes finish after 4200 actions (tics)
1922
episode_timeout = 4200
2023

2124
# Available buttons

Diff for: scenarios/defend_the_center.cfg

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ render_decals = false
1818
render_particles = false
1919
window_visible = true
2020

21-
# make episodes start after 10 tics (after unholstering the gun)
21+
# Make episodes start after 10 tics (after unholstering the gun)
2222
episode_start_time = 10
2323

24-
# make episodes finish after 2100 actions (tics)
24+
# Make episodes finish after 2100 actions (tics)
2525
episode_timeout = 2100
2626

2727
# Available buttons

Diff for: scenarios/defend_the_line.cfg

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ render_decals = false
1818
render_particles = false
1919
window_visible = true
2020

21-
# make episodes start after 10 tics (after unholstering the gun)
21+
# Make episodes start after 10 tics (after unholstering the gun)
2222
episode_start_time = 10
2323

24-
2524
# Available buttons
2625
available_buttons =
2726
{

Diff for: scenarios/health_gathering.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ render_decals = false
1919
render_particles = false
2020
window_visible = true
2121

22-
# make episodes finish after 2100 actions (tics)
22+
# Make episodes finish after 2100 actions (tics)
2323
episode_timeout = 2100
2424

2525
# Available buttons

Diff for: scenarios/health_gathering_supreme.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ render_decals = false
1919
render_particles = false
2020
window_visible = true
2121

22-
# make episodes finish after 2100 actions (tics)
22+
# Make episodes finish after 2100 actions (tics)
2323
episode_timeout = 2100
2424

2525
# Available buttons

Diff for: scenarios/learning.cfg

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Lines starting with # are treated as comments (or with whitespaces+#).
2+
# It doesn't matter if you use capital letters or not.
3+
# It doesn't matter if you use underscore or camel notation for keys, e.g. episode_timeout is the same as episodeTimeout.
4+
15
doom_scenario_path = basic.wad
26

37
# Rewards
@@ -13,10 +17,10 @@ render_decals = false
1317
render_particles = false
1418
window_visible = false
1519

16-
# make episodes start after 20 tics (after unholstering the gun)
20+
# Make episodes start after 20 tics (after unholstering the gun)
1721
episode_start_time = 14
1822

19-
# make episodes finish after 300 actions (tics)
23+
# Make episodes finish after 300 actions (tics)
2024
episode_timeout = 300
2125

2226
# Available buttons

Diff for: scenarios/multi.cfg

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ render_particles = false
1818

1919
window_visible = true
2020

21-
2221
# Available buttons
2322
available_buttons =
2423
{

Diff for: scenarios/multi_duel.cfg

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Lines starting with # are treated as comments (or with whitespaces+#).
2+
# It doesn't matter if you use capital letters or not.
3+
# It doesn't matter if you use underscore or camel notation for keys, e.g. episode_timeout is the same as episodeTimeout.
4+
15
doom_scenario_path = multi_duel.wad
26

37
screen_resolution = RES_320X240

Diff for: scenarios/my_way_home.cfg

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ render_decals = false
1818
render_particles = false
1919
window_visible = true
2020

21-
# make episodes start after 10 tics (after unholstering the gun)
21+
# Make episodes start after 10 tics (after unholstering the gun)
2222
episode_start_time = 10
2323

24-
# make episodes finish after 2100 actions (tics)
24+
# Make episodes finish after 2100 actions (tics)
2525
episode_timeout = 2100
2626

2727
# Available buttons

Diff for: scenarios/predict_position.cfg

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ render_decals = false
1818
render_particles = false
1919
window_visible = true
2020

21-
# make episodes start after 16 tics (after the rocket launcher is ready)
21+
# Make episodes start after 16 tics (after the rocket launcher is ready)
2222
episode_start_time = 16
2323

24-
# make episodes finish after 300 actions (tics)
24+
# Make episodes finish after 300 actions (tics)
2525
episode_timeout = 300
2626

2727
# Available buttons

Diff for: scenarios/rocket_basic.cfg

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ render_weapon = true
1212
render_decals = false
1313
render_particles = false
1414

15-
# make episodes start after 14 tics (after unholstering the gun)
15+
# Make episodes start after 14 tics (after unholstering the gun)
1616
episode_start_time = 14
1717

18-
# make episodes finish after 300 actions (tics)
18+
# Make episodes finish after 300 actions (tics)
1919
episode_timeout = 300
2020

2121
# Available buttons

Diff for: scenarios/simpler_basic.cfg

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Lines starting with # are treated as comments (or with whitespaces+#).
2+
# It doesn't matter if you use capital letters or not.
3+
# It doesn't matter if you use underscore or camel notation for keys, e.g. episode_timeout is the same as episodeTimeout.
4+
15
doom_scenario_path = simpler_basic.wad
26

37
# Rewards
@@ -13,10 +17,10 @@ render_weapon = true
1317
render_decals = false
1418
render_particles = false
1519

16-
# make episodes start after 20 tics (after unholstering the gun)
20+
# Make episodes start after 20 tics (after unholstering the gun)
1721
episode_start_time = 14
1822

19-
# make episodes finish after 300 actions (tics)
23+
# Make episodes finish after 300 actions (tics)
2024
episode_timeout = 300
2125

2226
# Available buttons

Diff for: scenarios/take_cover.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ render_decals = false
1919
render_particles = false
2020
window_visible = true
2121

22+
# Make episodes start in the first tic
23+
episode_start_time = 1
24+
2225
# Available buttons
2326
available_buttons =
2427
{

Diff for: scripts/create_python_docs_from_cpp_docs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
FILES_TO_PARSE = [
77
{
8-
"input_filepath": "docs/api/cpp/doomGame.md",
9-
"output_filepath": "docs/api/python/doomGame.md",
8+
"input_filepath": "docs/api/cpp/doom_game.md",
9+
"output_filepath": "docs/api/python/doom_game.md",
1010
"submodule": "DoomGame.",
1111
"append_to_header": """
1212
```{eval-rst}

Diff for: scripts/create_python_docstrings_from_cpp_docs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def camel_case_to_snake_case(text):
99

1010

1111
FILES_TO_PARSE = [
12-
{"filepath": "docs/api/cpp/doomGame.md", "namespace": "DoomGamePython"},
12+
{"filepath": "docs/api/cpp/doom_game.md", "namespace": "DoomGamePython"},
1313
{"filepath": "docs/api/cpp/utils.md"},
1414
]
1515
OUTPUT_FILE = "src/lib_python/ViZDoomMethodsDocstrings.h"

Diff for: src/lib/ViZDoomController.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,7 @@ namespace vizdoom {
281281
}
282282

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

290287
void DoomController::tic(bool update) {
@@ -601,7 +598,14 @@ namespace vizdoom {
601598
}
602599

603600
bool DoomController::isMapEnded() {
604-
return this->doomRunning && this->gameState->MAP_END;
601+
// Check if the map has ended or the player is dead (in single player mode)
602+
return (!this->gameState->GAME_MULTIPLAYER && this->gameState->PLAYER_DEAD) || (this->gameState->MAP_END);
603+
}
604+
605+
bool DoomController::isMapTimeoutReached() {
606+
// Check if internal or user-defined map timeout has been reached
607+
return (this->mapTimeout > 0 && this->mapTimeout + this->mapStartTime <= this->gameState->MAP_TIC)
608+
|| (this->gameState->MAP_TICLIMIT > 0 && this->gameState->MAP_TICLIMIT <= this->gameState->MAP_TIC);
605609
}
606610

607611
unsigned int DoomController::getMapLastTic() {

Diff for: src/lib/ViZDoomController.h

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ namespace vizdoom {
160160
bool isMapLastTic();
161161
bool isMapFirstTic();
162162
bool isMapEnded();
163+
bool isMapTimeoutReached();
163164
unsigned int getMapLastTic();
164165

165166
void setNoConsole(bool console);

Diff for: src/lib/ViZDoomGame.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@ namespace vizdoom {
342342
return !this->doomController->isTicPossible();
343343
}
344344

345+
bool DoomGame::isEpisodeTimeoutReached() {
346+
if (!this->isRunning()) throw ViZDoomIsNotRunningException();
347+
return this->doomController->isMapTimeoutReached();
348+
}
349+
345350
bool DoomGame::isPlayerDead() {
346351
if (!this->isRunning()) throw ViZDoomIsNotRunningException();
347352
return this->doomController->isPlayerDead();

Diff for: src/lib_python/ViZDoomMethodsDocstrings.h

+3
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ processes the specified number of tics, updates the state and calculates a new r
8484
:meth:`make_action` and :meth:`advance_action` methods
8585
will take no effect after this point (unless :meth:`new_episode` method is called).)DOCSTRING";
8686

87+
const char *isEpisodeTimeoutReached = R"DOCSTRING(Returns ``True`` if the current episode is in the terminal state due to exceeding the time limit (timeout)
88+
set with :meth:`set_episode_timeout`` method or via ``+timelimit` parameter.)DOCSTRING";
89+
8790
const char *isPlayerDead = R"DOCSTRING(Returns ``True`` if the player is dead.
8891
In singleplayer, the player's death is equivalent to the end of the episode.
8992
In multiplayer, when the player is dead :meth:`respawn_player` method can be called.)DOCSTRING";

Diff for: src/lib_python/ViZDoomPythonModule.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ PYBIND11_MODULE(vizdoom, vz){
630630
CLASS_FUNC_2_PYT_WITH_ARGS("new_episode", DoomGamePython::newEpisode, pyb::arg("recording_file_path") = "")
631631
CLASS_FUNC_2_PYT_WITH_ARGS("replay_episode", DoomGamePython::replayEpisode, pyb::arg("file_path"), pyb::arg("player") = 0)
632632
CLASS_FUNC_2_PYT("is_episode_finished", DoomGamePython::isEpisodeFinished)
633+
CLASS_FUNC_2_PYT("is_episode_timeout_reached", DoomGamePython::isEpisodeTimeoutReached)
633634
CLASS_FUNC_2_PYT("is_new_episode", DoomGamePython::isNewEpisode)
634635
CLASS_FUNC_2_PYT("is_player_dead", DoomGamePython::isPlayerDead)
635636
CLASS_FUNC_2_PYT("respawn_player", DoomGamePython::respawnPlayer)

0 commit comments

Comments
 (0)