Compare commits

..

No commits in common. "3435e4ce7a4dcb292bd63ee71043c066712615eb" and "e39a19da558c1cbaeb5fd84c5d3d746a3beb1077" have entirely different histories.

4 changed files with 17 additions and 28 deletions

View File

@ -69,7 +69,7 @@ class GuessModel(BaseModel):
guess_id = UUIDField(primary_key=True)
player = ForeignKeyField(PlayerModel, backref="guesses")
game = ForeignKeyField(GameModel, backref="guesses")
game_id = ForeignKeyField(GameModel, backref="guesses")
guess = IntegerField(default=0)
difference = IntegerField(null=True)
@ -80,4 +80,4 @@ def create_models():
"""Create database tables"""
with database:
database.create_tables([GameModel, GuessModel, PlayerModel])
database.create_tables([GameModel, GuessModel, PlayerModel()])

View File

@ -152,10 +152,9 @@ class GameManager:
# How many valid guesses got placed?
guess_count = (
Guess.select().join(Game)
.where((Guess.game.game_id == self.game.game_id) & (Guess.guess > 0))
.count()
)
Guess.select().where((Guess.game.game_id == self.game.game_id)
& (Guess.guess > 0)
).count())
# Discard the game if there weren't enough players
if guess_count < 3:
@ -171,13 +170,9 @@ class GameManager:
)
pitch_value = await self.update_pitch_value()
guess_processor = ProcessGuess(game=self, pitch_value=pitch_value, message=message)
guess_processor = ProcessGuess(game=self, pitch_value=pitch_value)
(
message,
closest_player_id,
furthest_player_id,
) = guess_processor.process_guesses()
message, closest_player_id, furthest_player_id = guess_processor.process_guesses()
message += (
f"\nCongrats <@{closest_player_id}>! You were the closest!\n"
@ -210,13 +205,15 @@ class GameManager:
# Create the guess (or allow us to say update successful)
_, created = Guess.get_or_create(
guess_id=uuid.uuid4(), game_id=self.game.game_id, player_id=player.player_id
guess_id=uuid.uuid4(),
game_id=self.game.game_id,
player_id=player.player_id,
player_name=player.player_name,
)
Guess.update({"guess": value}).where(
# (Guess.game_id == self.game.game_id)
# &
(Guess.player_id == self.message.author.id)
(Guess.game_id == self.game.game_id)
& (Guess.player_id == self.message.author.id)
).execute()
if created:

View File

@ -7,7 +7,6 @@ from database.models import (
PlayerModel as Player,
)
class ProcessGuess:
def __init__(self, game, **kwargs):
self.game_manager = game
@ -32,7 +31,7 @@ class ProcessGuess:
)
.join(Player)
.where(
(Guess.game == self.game_manager.game.game_id)
(Guess.game_id == self.game_manager.game.game_id)
& (Guess.guess > 0)
& (Guess.player.player_id == Player.player_id)
)
@ -43,7 +42,7 @@ class ProcessGuess:
def update_difference_value(self):
# Update player's difference in guessed value
Guess.update({"difference": self.difference}).where(
(Guess.game.game_id == self.game_manager.game.game_id)
(Guess.game_id == self.game_manager.game.game_id)
& (Guess.player.player_id == self.guess.player.player_id)
& (Guess.guess_id == self.guess.guess_id)
).execute()
@ -61,7 +60,7 @@ class ProcessGuess:
def get_difference(self, guess=None):
"""Difference calculation, includes "loop over" effect"""
if not guess:
guess = self.guess.guess
guess = self.guess
difference = abs(guess - self.pitch_value)
@ -81,7 +80,7 @@ class ProcessGuess:
def get_winner_loser(self):
# Determine which guesses are closest and furthest from the pitch_value
guess_values = [record.guess for record in self.get_guesses()]
guess_values = [record.guess for record in self.guesses]
# Closest to the pitch_value
winner = min(guess_values, key=lambda guess: self.get_difference(guess))
# Furthest from the pitch_value

View File

@ -32,10 +32,3 @@ The original code is in [src](./src/). Feel free to try to get this working.
1. Bot should then connect to discord and start responding to commands defined in game.py
## Roadmap
Things that would be nice to add:
* (yaml) Config file for tweaking various internals
* Admin commands: table clear, record deletion, record update
* Audit log of admin commands, and previous values for anything changed