From c6def1169f1f46cef4cf65f08262c0984705fe85 Mon Sep 17 00:00:00 2001 From: Stefan Rupp Date: Mon, 18 May 2020 21:35:46 +0200 Subject: [PATCH] code cleanup --- server.py | 2 -- views/control.py | 9 ++------- views/player.py | 14 ++------------ wiz_game.py | 4 ++-- 4 files changed, 6 insertions(+), 23 deletions(-) diff --git a/server.py b/server.py index e50abd0..1bf6d10 100755 --- a/server.py +++ b/server.py @@ -1,8 +1,6 @@ #!/usr/bin/env python3 import random -import socket -import responder from app_instance import api from routes import * import wiz_game diff --git a/views/control.py b/views/control.py index 6c8fc7a..10ef8db 100644 --- a/views/control.py +++ b/views/control.py @@ -5,7 +5,6 @@ from wiz_game import the_game @api.route("/control/") def index(req, resp): - current_round = the_game.current_round hand_finished = the_game.is_hand_finished() trick_finished = the_game.is_trick_finished() @@ -38,7 +37,7 @@ async def start_next_hand(req, resp): try: await ws.send_text("reload") except Exception as e: - print("ws: got {}".format(e)) + pass api.redirect(resp, '/control/', status_code=303) @@ -49,10 +48,6 @@ async def start_next_trick(req, resp): try: await ws.send_text("reload") except Exception as e: - print("ws: got {}".format(e)) + pass api.redirect(resp, '/control/', status_code=303) -#@api.route("/control/deal/{cards}") -#def deal(req, resp, cards): -# the_game.deal_cards(int(cards)) -# api.redirect(resp, '/control/', status_code=303) diff --git a/views/player.py b/views/player.py index 7e947db..3f0c151 100644 --- a/views/player.py +++ b/views/player.py @@ -8,22 +8,16 @@ import asyncio playing_lock = asyncio.Lock() - @api.route("/player/{player}") def show(req, resp, player: str): p = int(player) - name = the_game.players[p].name tcard = the_game.trump_card tcolor = the_game.get_trump_color() - #isActive = the_game.is_players_turn(p) try: isActive = the_game.players_ordered[the_game.active_player].id == p - print("show p: {} | {}".format(the_game.players_ordered[the_game.active_player].id, p)) except IndexError: isActive = False - print("show p: {} | {}".format('None', p)) - #active_player = the_game.active_player prev_player = the_game.get_prev_player() if tcard and tcard.value == 'Z' and tcolor == '-': choose_trump_color = True @@ -45,16 +39,12 @@ async def play(req, resp, player: str, card: str): isActive = the_game.players_ordered[the_game.active_player].id == p except IndexError: isActive = False - print("show p: {} | {}".format('None', p)) if isActive: the_game.play_card(p, c) if the_game.is_hand_finished(): - print("hand finished") trick_winner, highest_card = the_game.get_trick_winner() trick_winner.take_trick() - #the_game.next_hand() elif the_game.is_trick_finished(): - print("trick finished") trick_winner, highest_card = the_game.get_trick_winner() trick_winner.take_trick() the_game.next_trick() @@ -64,7 +54,7 @@ async def play(req, resp, player: str, card: str): try: await ws.send_text("reload") except Exception as e: - print("ws: got {}".format(e)) + pass api.redirect(resp, url, status_code=303) @api.route("/player/{player}/set_trump/{trump}") @@ -76,7 +66,7 @@ async def set_trump_color(req, resp, player, trump): try: await ws.send_text("reload") except Exception as e: - print("ws: got {}".format(e)) + pass api.redirect(resp, url, status_code=303) diff --git a/wiz_game.py b/wiz_game.py index 03998a9..8b83e05 100644 --- a/wiz_game.py +++ b/wiz_game.py @@ -2,6 +2,7 @@ import random from operator import attrgetter + def chunks(lst, n): """Yield successive n-sized chunks from lst.""" for i in range(0, len(lst), n): @@ -28,7 +29,7 @@ def get_higher_card(card1: Card, card2: Card, trump_color: str): returns: True if card2 beats card1, otherwise False """ if card2.value == 'N': - # no way to win in 'N' comes in second + # no way to win if 'N' comes in second return False elif card1.value == 'Z': # no way to win if 'Z' was already played @@ -199,7 +200,6 @@ class WizGame: return False else: self.trump_card = Card(trump_color, 'Z') - #self.trump_card.color = trump_color return True def get_prev_player(self):