code cleanup
This commit is contained in:
parent
0321296014
commit
c6def1169f
@ -1,8 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import random
|
import random
|
||||||
import socket
|
|
||||||
import responder
|
|
||||||
from app_instance import api
|
from app_instance import api
|
||||||
from routes import *
|
from routes import *
|
||||||
import wiz_game
|
import wiz_game
|
||||||
|
@ -5,7 +5,6 @@ from wiz_game import the_game
|
|||||||
|
|
||||||
@api.route("/control/")
|
@api.route("/control/")
|
||||||
def index(req, resp):
|
def index(req, resp):
|
||||||
current_round = the_game.current_round
|
|
||||||
hand_finished = the_game.is_hand_finished()
|
hand_finished = the_game.is_hand_finished()
|
||||||
trick_finished = the_game.is_trick_finished()
|
trick_finished = the_game.is_trick_finished()
|
||||||
|
|
||||||
@ -38,7 +37,7 @@ async def start_next_hand(req, resp):
|
|||||||
try:
|
try:
|
||||||
await ws.send_text("reload")
|
await ws.send_text("reload")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("ws: got {}".format(e))
|
pass
|
||||||
api.redirect(resp, '/control/', status_code=303)
|
api.redirect(resp, '/control/', status_code=303)
|
||||||
|
|
||||||
|
|
||||||
@ -49,10 +48,6 @@ async def start_next_trick(req, resp):
|
|||||||
try:
|
try:
|
||||||
await ws.send_text("reload")
|
await ws.send_text("reload")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("ws: got {}".format(e))
|
pass
|
||||||
api.redirect(resp, '/control/', status_code=303)
|
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()
|
playing_lock = asyncio.Lock()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@api.route("/player/{player}")
|
@api.route("/player/{player}")
|
||||||
def show(req, resp, player: str):
|
def show(req, resp, player: str):
|
||||||
p = int(player)
|
p = int(player)
|
||||||
name = the_game.players[p].name
|
|
||||||
tcard = the_game.trump_card
|
tcard = the_game.trump_card
|
||||||
tcolor = the_game.get_trump_color()
|
tcolor = the_game.get_trump_color()
|
||||||
#isActive = the_game.is_players_turn(p)
|
|
||||||
try:
|
try:
|
||||||
isActive = the_game.players_ordered[the_game.active_player].id == p
|
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:
|
except IndexError:
|
||||||
isActive = False
|
isActive = False
|
||||||
print("show p: {} | {}".format('None', p))
|
|
||||||
|
|
||||||
#active_player = the_game.active_player
|
|
||||||
prev_player = the_game.get_prev_player()
|
prev_player = the_game.get_prev_player()
|
||||||
if tcard and tcard.value == 'Z' and tcolor == '-':
|
if tcard and tcard.value == 'Z' and tcolor == '-':
|
||||||
choose_trump_color = True
|
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
|
isActive = the_game.players_ordered[the_game.active_player].id == p
|
||||||
except IndexError:
|
except IndexError:
|
||||||
isActive = False
|
isActive = False
|
||||||
print("show p: {} | {}".format('None', p))
|
|
||||||
if isActive:
|
if isActive:
|
||||||
the_game.play_card(p, c)
|
the_game.play_card(p, c)
|
||||||
if the_game.is_hand_finished():
|
if the_game.is_hand_finished():
|
||||||
print("hand finished")
|
|
||||||
trick_winner, highest_card = the_game.get_trick_winner()
|
trick_winner, highest_card = the_game.get_trick_winner()
|
||||||
trick_winner.take_trick()
|
trick_winner.take_trick()
|
||||||
#the_game.next_hand()
|
|
||||||
elif the_game.is_trick_finished():
|
elif the_game.is_trick_finished():
|
||||||
print("trick finished")
|
|
||||||
trick_winner, highest_card = the_game.get_trick_winner()
|
trick_winner, highest_card = the_game.get_trick_winner()
|
||||||
trick_winner.take_trick()
|
trick_winner.take_trick()
|
||||||
the_game.next_trick()
|
the_game.next_trick()
|
||||||
@ -64,7 +54,7 @@ async def play(req, resp, player: str, card: str):
|
|||||||
try:
|
try:
|
||||||
await ws.send_text("reload")
|
await ws.send_text("reload")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("ws: got {}".format(e))
|
pass
|
||||||
api.redirect(resp, url, status_code=303)
|
api.redirect(resp, url, status_code=303)
|
||||||
|
|
||||||
@api.route("/player/{player}/set_trump/{trump}")
|
@api.route("/player/{player}/set_trump/{trump}")
|
||||||
@ -76,7 +66,7 @@ async def set_trump_color(req, resp, player, trump):
|
|||||||
try:
|
try:
|
||||||
await ws.send_text("reload")
|
await ws.send_text("reload")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("ws: got {}".format(e))
|
pass
|
||||||
api.redirect(resp, url, status_code=303)
|
api.redirect(resp, url, status_code=303)
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
import random
|
import random
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
|
|
||||||
|
|
||||||
def chunks(lst, n):
|
def chunks(lst, n):
|
||||||
"""Yield successive n-sized chunks from lst."""
|
"""Yield successive n-sized chunks from lst."""
|
||||||
for i in range(0, len(lst), n):
|
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
|
returns: True if card2 beats card1, otherwise False
|
||||||
"""
|
"""
|
||||||
if card2.value == 'N':
|
if card2.value == 'N':
|
||||||
# no way to win in 'N' comes in second
|
# no way to win if 'N' comes in second
|
||||||
return False
|
return False
|
||||||
elif card1.value == 'Z':
|
elif card1.value == 'Z':
|
||||||
# no way to win if 'Z' was already played
|
# no way to win if 'Z' was already played
|
||||||
@ -199,7 +200,6 @@ class WizGame:
|
|||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
self.trump_card = Card(trump_color, 'Z')
|
self.trump_card = Card(trump_color, 'Z')
|
||||||
#self.trump_card.color = trump_color
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get_prev_player(self):
|
def get_prev_player(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user