From 57df847230d48094f4c1e7c8d64f7e7803b01adf Mon Sep 17 00:00:00 2001 From: Kenny Date: Sun, 13 Sep 2020 16:09:02 -0400 Subject: [PATCH 1/2] Remove the use of the Mars weather API At the time of writing this, the weather API is only returning 5 days of weather when our weekly weather data anticipates 7. This is causing an issue making the game unplayable. These changes removes the use of the weekly weather data to use a default values for the `wind_speed` and `temperature` variables. --- mysterious-mice/spacebook/game/utils.py | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/mysterious-mice/spacebook/game/utils.py b/mysterious-mice/spacebook/game/utils.py index e98b6d1a9..ec3b24f6e 100644 --- a/mysterious-mice/spacebook/game/utils.py +++ b/mysterious-mice/spacebook/game/utils.py @@ -1,7 +1,6 @@ import math import random from .models import HighScore -from mars_weather.services import get_week_weather # All coordinates are stored as tuples of (x, y) @@ -12,22 +11,8 @@ def new_game(request): Generates a new game, resetting the location of all components and the rover. """ - # Attempt to pull the weather for the current sol - # If weather data is missing for current sol, get data for previous sol - # If data is still missing, use default values - week_weather = get_week_weather(request) - for sol in range(-1, -3, -1): - sol_weather = week_weather["weekly_weather"][sol] - sol_weather_key = list(sol_weather.keys())[0] - sol_weather_data = sol_weather[sol_weather_key] - if "HWS" in sol_weather_data and "AT" in sol_weather_data: - wind_speed = sol_weather_data["HWS"]["av"] - temperature = sol_weather_data["AT"]["av"] - break - if wind_speed is None or wind_speed == "": - wind_speed = 6 - if temperature is None or temperature == "": - temperature = -60 + wind_speed = 6 + temperature = -60 # Get wind direction wind_direction = (random.randint(-1, 1), random.randint(-1, 1)) From 14eaba9b6d8a5e43e3f9bfcafd011c25269988a2 Mon Sep 17 00:00:00 2001 From: Kenny Date: Sun, 13 Sep 2020 16:17:55 -0400 Subject: [PATCH 2/2] Fix how the dust storm location gets updated The tuple representing the dust storm location previously had its x and y values updated independently. This sometimes (but not consistently) raises an error since tuples are immutable, rendering the game unplayable. The changes here correct this issue. --- mysterious-mice/spacebook/game/utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mysterious-mice/spacebook/game/utils.py b/mysterious-mice/spacebook/game/utils.py index ec3b24f6e..ffa2ece9f 100644 --- a/mysterious-mice/spacebook/game/utils.py +++ b/mysterious-mice/spacebook/game/utils.py @@ -293,9 +293,10 @@ def command_move(game_data, direction): # Move dust storm cur_dust = game_data['obstacles']['dust_storm'] - cur_dust[0] += game_data['wind'][0] - cur_dust[1] += game_data['wind'][1] - game_data['obstacles'].update({"dust_storm": cur_dust}) + new_dust_x = cur_dust[0] + game_data['wind'][0] + new_dust_y = cur_dust[1] + game_data['wind'][1] + new_dust = (new_dust_x, new_dust_y) + game_data['obstacles'].update({"dust_storm": new_dust}) # deplete battery game_data["battery"] = game_data["battery"] - game_data["power_usage"] if game_data["has_solar_panels"]: