Skip to content

Commit

Permalink
update the reset function
Browse files Browse the repository at this point in the history
  • Loading branch information
taufeeque9 committed May 28, 2024
1 parent 1abbeb8 commit 268c93d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
17 changes: 11 additions & 6 deletions envpool/sokoban/sokoban_envpool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace sokoban {

void SokobanEnv::Reset() {
void SokobanEnv::ResetWithoutWrite() {
const int max_episode_steps = spec_.config["max_episode_steps"_];
const int min_episode_steps = spec_.config["min_episode_steps"_];
current_max_episode_steps_ =
Expand Down Expand Up @@ -52,6 +52,10 @@ void SokobanEnv::Reset() {
}
}
current_step_ = 0;
}

void SokobanEnv::Reset() {
ResetWithoutWrite();
WriteState(0.0f);
}

Expand Down Expand Up @@ -142,11 +146,8 @@ void SokobanEnv::Step(const Action& action_dict) {
reward_box_ * static_cast<double>(prev_unmatched_boxes -
unmatched_boxes_) +
((unmatched_boxes_ == 0) ? reward_finished_ : 0.0f);
if (IsDone()) {
Reset();
} else {
WriteState(static_cast<float>(reward));
}

WriteState(static_cast<float>(reward));
}

constexpr std::array<std::array<uint8_t, 3>, kPlayerOnTarget + 1> kTinyColors{{
Expand Down Expand Up @@ -181,6 +182,10 @@ void SokobanEnv::WriteState(float reward) {
throw std::runtime_error(msg.str());
}

if (IsDone()) {
ResetWithoutWrite();
}

std::vector<uint8_t> out(3 * world_.size());
for (int rgb = 0; rgb < 3; rgb++) {
for (size_t i = 0; i < world_.size(); i++) {
Expand Down
1 change: 1 addition & 0 deletions envpool/sokoban/sokoban_envpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class SokobanEnv : public Env<SokobanEnvSpec> {

[[nodiscard]] uint8_t WorldAt(int x, int y) const;
void WorldAssignAt(int x, int y, uint8_t value);
void ResetWithoutWrite();
};

using SokobanEnvPool = AsyncEnvPool<SokobanEnv>;
Expand Down

0 comments on commit 268c93d

Please sign in to comment.