Skip to content

Commit

Permalink
Default accuracy to 0, game over print out improvement, NaN handling …
Browse files Browse the repository at this point in the history
…in Spaceship
  • Loading branch information
brandonmkunkel committed Apr 8, 2021
1 parent 365df5f commit 4b9cbc1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [1.2.1] - 8 April 2021

- Default accuracy value changed to 0% not 100%
- Improved print statements for end of scenario to say what scenario was evaluated
- Resolved crash which would occur when turn_rate/thrust given to SpaceShip are NaN

## [1.2.0] - 5 April 2021

- Added `turn rate` + `thrust` control meters to the graphics and moved lives to center/bottom
Expand Down
2 changes: 1 addition & 1 deletion src/fuzzy_asteroids/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.2.0"
__version__ = "1.2.1"
5 changes: 5 additions & 0 deletions src/fuzzy_asteroids/fuzzy_controller.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import math
from typing import Tuple, Dict, Any

from .sprites import ShipSprite
Expand Down Expand Up @@ -58,6 +59,8 @@ def turn_rate(self, turn_rate: float):
turn_rate = self.output_space["turn_rate"][0]
elif turn_rate > self.output_space["turn_rate"][1]:
turn_rate = self.output_space["turn_rate"][1]
elif math.isnan(turn_rate):
raise ValueError("value given to SpaceShip.turn_rate.setter() cannot be NaN")

self._turn_rate = turn_rate

Expand All @@ -71,6 +74,8 @@ def thrust(self, thrust: float):
thrust = self.output_space["thrust"][0]
elif thrust > self.output_space["thrust"][1]:
thrust = self.output_space["thrust"][1]
elif math.isnan(thrust):
raise ValueError("value given to SpaceShip.thrust.setter() cannot be NaN")

self._thrust = thrust

Expand Down
3 changes: 2 additions & 1 deletion src/fuzzy_asteroids/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ def on_update(self, delta_time: float = 1/60) -> None:
self.score.stopping_condition = self.game_over

self._print_terminal("**********************************************************")
self._print_terminal(f"Game over at {self.score.time:.3f} seconds | ({self.game_over}) ")
self._print_terminal(f"Scenario: {self.scenario.name}")
self._print_terminal(f"Game over at {self.score.time:.3f} seconds | ({self.game_over})")
self._print_terminal("**********************************************************")

if self.graphics_on:
Expand Down
2 changes: 1 addition & 1 deletion src/fuzzy_asteroids/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __repr__(self):

@property
def accuracy(self) -> float:
return 1.0 if not self.bullets_fired else self.asteroids_hit / self.bullets_fired
return 0.0 if not self.bullets_fired else self.asteroids_hit / self.bullets_fired

@property
def fraction_total_asteroids_hit(self):
Expand Down

0 comments on commit 4b9cbc1

Please sign in to comment.