mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-23 15:04:20 +00:00
Remove trailing whitespaces. Make line breaks adhere to 80 character limit (not all, but quite a few). Remove unused imports. Other miscellaneous PEP-8 fixes.
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
from __future__ import division
|
|
from gym.envs.algorithmic import algorithmic_env
|
|
|
|
|
|
class ReversedAdditionEnv(algorithmic_env.GridAlgorithmicEnv):
|
|
def __init__(self, rows=2, base=3):
|
|
super(ReversedAdditionEnv, self).__init__(rows=rows, base=base, chars=False)
|
|
|
|
def target_from_input_data(self, input_strings):
|
|
curry = 0
|
|
target = []
|
|
for digits in input_strings:
|
|
total = sum(digits) + curry
|
|
target.append(total % self.base)
|
|
curry = total // self.base
|
|
|
|
if curry > 0:
|
|
target.append(curry)
|
|
return target
|
|
|
|
@property
|
|
def time_limit(self):
|
|
# Quirk preserved for the sake of consistency: add the length of the input
|
|
# rather than the length of the desired output (which may differ if there's
|
|
# an extra carried digit).
|
|
# TODO: It seems like this time limit is so strict as to make Addition3-v0
|
|
# unsolvable, since agents aren't even given enough time steps to look at
|
|
# all the digits. (The solutions on the scoreboard seem to only work by
|
|
# save-scumming.)
|
|
return self.input_width*2 + 4
|