code cleanup
This commit is contained in:
parent
0321296014
commit
c6def1169f
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user