forked from test/mau_mau_bot
ea881cf520
* Changes for possible bug * New sanic mode wip * More changes for fast mode, WIP * Fast mode is playable (code is ugly tho) * Fixed skip error * Fixed fast mode error * Bug fixing * Possible fix for the /leave bug before the game starts * Update README to include Codacy badge * Fixing error prone code * Removing code smells * Removing more code smells * How long can this go on? (More smells according to Codacy) * Compile locale fixed for Linux. Small es_ES fix. * Major refactoring * Wild mode finished. Changed emojis for text in log. * Removing test prints, back to emojis * Code cleaning and fix for player time in fast mode * Changing help to not override builtin function * Decreased bot.py's complexity * Default gamemode is now Fast. Added a bot configuration file * back to random * Moved logger to shared_vars * Added MIN_FAST_TURN_TIME to config and fixed 'skipped 4 times' message * Pull review changes * More review changes * Removing codacy badge linked to my account for pull request * Fixed first special card issue, logger back to how it was (with just one logging init) * Renamed gameplay config file to gameplay_config.py.
86 lines
2.7 KiB
Python
86 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
#
|
|
# Telegram bot to play UNO in group chats
|
|
# Copyright (c) 2016 Jannes Höke <uno@jhoeke.de>
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
# License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
from random import shuffle
|
|
import logging
|
|
|
|
import card as c
|
|
from card import Card
|
|
from errors import DeckEmptyError
|
|
|
|
|
|
class Deck(object):
|
|
""" This class represents a deck of cards """
|
|
|
|
def __init__(self):
|
|
self.cards = list()
|
|
self.graveyard = list()
|
|
self.logger = logging.getLogger(__name__)
|
|
|
|
self.logger.debug(self.cards)
|
|
|
|
def shuffle(self):
|
|
"""Shuffles the deck"""
|
|
self.logger.debug("Shuffling Deck")
|
|
shuffle(self.cards)
|
|
|
|
def draw(self):
|
|
"""Draws a card from this deck"""
|
|
try:
|
|
card = self.cards.pop()
|
|
self.logger.debug("Drawing card " + str(card))
|
|
return card
|
|
except IndexError:
|
|
if len(self.graveyard):
|
|
while len(self.graveyard):
|
|
self.cards.append(self.graveyard.pop())
|
|
self.shuffle()
|
|
return self.draw()
|
|
else:
|
|
raise DeckEmptyError()
|
|
|
|
def dismiss(self, card):
|
|
"""Returns a card to the deck"""
|
|
self.graveyard.append(card)
|
|
|
|
def _fill_classic_(self):
|
|
# Fill deck with the classic card set
|
|
self.cards.clear()
|
|
for color in c.COLORS:
|
|
for value in c.VALUES:
|
|
self.cards.append(Card(color, value))
|
|
if not value == c.ZERO:
|
|
self.cards.append(Card(color, value))
|
|
for special in c.SPECIALS:
|
|
for _ in range(4):
|
|
self.cards.append(Card(None, None, special=special))
|
|
self.shuffle()
|
|
|
|
def _fill_wild_(self):
|
|
# Fill deck with a wild card set
|
|
self.cards.clear()
|
|
for color in c.COLORS:
|
|
for value in c.WILD_VALUES:
|
|
for _ in range(4):
|
|
self.cards.append(Card(color, value))
|
|
for special in c.SPECIALS:
|
|
for _ in range(6):
|
|
self.cards.append(Card(None, None, special=special))
|
|
self.shuffle()
|