From 46084d4f648dd1ceb5fda9fe50800b08984d48d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Mon, 6 May 2019 15:17:33 +0300 Subject: [PATCH] Turn ___ into _ --- gameloop.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/gameloop.py b/gameloop.py index 76d8c21..83e619e 100644 --- a/gameloop.py +++ b/gameloop.py @@ -5,7 +5,6 @@ from collections import namedtuple import cardcast_api # TODO: rando -# TODO: collapse several _ in a row into one # TODO: keep track of where cards come from purge from hand when deck remove class events(enum.Enum): @@ -151,6 +150,26 @@ def game(send, notice, get_event): # Get cards calls, responses = cardcast_api.cards(code) + # Preprocess calls so that ___ becomes only one _ + # _ are indicated by splitting the card at that point, e.g. + # ['foo ', '.'] is "foo _." + # Two blanks a row will thus be ['foo ', '', '.'] + # We can't just remove every single '', since it can be valid + # at the start and the end of a card + for i in range(len(calls)): + call = [] + for index, part in enumerate(calls[i]): + if index == 0 or index == len(calls[i]) - 1: + # Always pass these ones through + call.append(part) + elif part == '': + # Remove '' in the middle + continue + else: + call.append(part) + + calls[i] = call + # Add a new deck to list of decks decks[code] = Deck( code = code,