Skip to content

Commit

Permalink
pylinted to conform - disabled personally disliked flags
Browse files Browse the repository at this point in the history
  • Loading branch information
beardyFace committed Dec 1, 2023
1 parent 93d8390 commit 04c52db
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,14 @@ jobs:
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py') --disable=logging-fstring-interpolation --extension-pkg-whitelist=cv2 --generated-members=cv2.* --fail-under 9 --fail-on E
pylint $(git ls-files '*.py') --disable=logging-fstring-interpolation \
--disable=too-few-public-methods \
--disable=missing-module-docstring \
--disable=missing-function-docstring \
--disable=missing-class-docstring \
--disable=too-many-locals \
--disable=W0511 \
--disable=too-many-arguments \
--max-line-length 130 \
--extension-pkg-whitelist=cv2 --generated-members=cv2.* \
--fail-under 9 --fail-on E
16 changes: 8 additions & 8 deletions scripts/envrionments/pyboy/mario/mario_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,12 @@ def _world_reward(self, new_state):
return (new_state["world"] - self.prior_game_stats["world"]) * 5

def _game_over_reward(self, new_state):
if new_state["game_over"] == 1:
return -5
return 0
return -5 if new_state["game_over"] == 1 else 0

def _check_if_done(self, game_stats):
# Setting done to true if agent beats first level
# TODO dunno if this works
return True if game_stats["stage"] > self.prior_game_stats["stage"] else False
return game_stats["stage"] > self.prior_game_stats["stage"]

def _get_lives(self):
return self._bit_count(self._read_m(0xDA15))
Expand All @@ -106,10 +104,12 @@ def _get_score(self):
return self._bit_count(self._read_m(0xC0A0))

def _get_powerup(self):
# 0x00 = small, 0x01 = growing, 0x02 = big with or without superball, 0x03 = shrinking, 0x04 = invincibility blinking
if self._read_m(0xFF99) == 0x02 or self._read_m(0xFF99) == 0x04:
return 1
return 0
# 0x00 = small,
# 0x01 = growing,
# 0x02 = big with or without superball,
# 0x03 = shrinking,
# 0x04 = invincibility blinking
return 1 if self._read_m(0xFF99) == 0x02 or self._read_m(0xFF99) == 0x04 else 0

def _get_coins(self):
return self._bit_count(self._read_m(0xFFFA))
Expand Down
20 changes: 12 additions & 8 deletions scripts/envrionments/pyboy/pokemon/pokemon_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


def load_dict(path):
with open(path, "r") as fp:
with open(path, "r", encoding="utf-8") as fp:
info = json.load(fp)
data = {}
for k, v in info.items():
Expand All @@ -19,7 +19,7 @@ def load_dict(path):


def get_pokemon(pokemon_id):
if pokemon_id in pokemon.keys():
if pokemon_id in pokemon:
return pokemon[pokemon_id]
return "Unknown Pokemon"

Expand All @@ -28,14 +28,14 @@ def get_pokemon(pokemon_id):


def get_type(type_id):
if type_id in types.keys():
if type_id in types:
return types[type_id]
return "Unknown Type"


def get_status(status_id):
status = {}
if status_id in status.keys():
if status_id in status:
return status[status_id]
return "Unknown Status"

Expand All @@ -45,15 +45,15 @@ def get_status(status_id):

def get_map_location(map_idx):
# https://github.com/pret/pokered/blob/91dc3c9f9c8fd529bb6e8307b58b96efa0bec67e/constants/map_constants.asm
if map_idx in map_locations.keys():
if map_idx in map_locations:
return map_locations[map_idx]
return "Unknown Location"


if __name__ == "__main__":
def main():
file_path = f"{Path.home()}/cares_rl_configs/pokemon/map_constants.asm"
save_path = file_path.replace("asm", "json")
with open(file_path, "r") as f:
with open(file_path, "r", encoding="utf-8") as f:
lines = f.readlines()
lines = [line for line in lines if "mapconst" in line]
lines = lines[1:]
Expand All @@ -67,5 +67,9 @@ def get_map_location(map_idx):

print(data)

with open(save_path, "w") as f:
with open(save_path, "w", encoding="utf-8") as f:
json.dump(data, f)


if __name__ == "__main__":
main()
10 changes: 7 additions & 3 deletions scripts/envrionments/pyboy/pokemon/pokemon_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _event_reward(self, new_state: Dict[str, any]) -> int:

def _check_if_done(self, game_stats: Dict[str, any]) -> bool:
# Setting done to true if agent beats first gym (temporary)
return True if self.prior_game_stats["badges"] > 0 else False
return self.prior_game_stats["badges"] > 0

def _get_location(self) -> Dict[str, any]:
x_pos = self._read_m(0xD362)
Expand Down Expand Up @@ -178,10 +178,14 @@ def _read_hp(self, start: int) -> int:
return 256 * self._read_m(start) + self._read_m(start + 1)

def _read_caught_pokemon_count(self) -> int:
return sum([self._bit_count(self._read_m(i)) for i in range(0xD2F7, 0xD30A)])
return sum(
list(self._bit_count(self._read_m(i)) for i in range(0xD2F7, 0xD30A))
)

def _read_seen_pokemon_count(self) -> int:
return sum([self._bit_count(self._read_m(i)) for i in range(0xD30A, 0xD31D)])
return sum(
list(self._bit_count(self._read_m(i)) for i in range(0xD30A, 0xD31D))
)

def _read_money(self) -> int:
return (
Expand Down
4 changes: 2 additions & 2 deletions scripts/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def key_to_action(button: int):
if button in key_map:
logging.info(f"Map: {key_map[button]}")
return key_map[button]
else:
return -1
return -1


if __name__ == "__main__":
Expand All @@ -48,6 +47,7 @@ def key_to_action(button: int):
if action == -1:
break

# TODO - action needs to be made continuous
state, reward, done, _ = env.step(action)
image = env.grab_frame()

Expand Down

0 comments on commit 04c52db

Please sign in to comment.