Пример #1
0
def dest_add(self, rhs):
    if self == Dest.D and rhs == Dest.M:
        return Comp.ADD_DM
    elif self == Dest.D and rhs == Dest.A:
        return Comp.ADD_DA
    elif self == Dest.D and rhs == Dest.M:
        return Comp.ADD_DM
    elif self == D and rhs == 1:
        return Comp.INCD
    elif self == A and rhs == 1:
        return Comp.INCA
    if self == M and rhs == 1:
        return Comp.INCM


Dest.__add__ = dest_add


def dest_sub(self, rhs):
    if self == Dest.D and rhs == Dest.M:
        return Comp.SUB_DM
    elif self == Dest.D and rhs == Dest.A:
        return Comp.SUB_DA
    elif self == Dest.D and rhs == Dest.M:
        return Comp.SUB_DM
    elif self == D and rhs == 1:
        return Comp.DECD
    elif self == A and rhs == 1:
        return Comp.DECA
    if self == M and rhs == 1:
        return Comp.DECM
Пример #2
0
from collections import namedtuple
from enum import Enum
import itertools
import sys

Seat = Enum("Seat", zip("NESW", range(4)))
Seat.N._s, Seat.E._s, Seat.S._s, Seat.W._s = ("North", "East", "South", "West")
Seat.__str__ = lambda self: self._s
Seat.__index__ = lambda self: self.value
Seat.__add__ = lambda self, val: Seat((self.value + val) % len(Seat))


class Suit(Enum):
    S = 0, " S", "♠"
    H = 1, " H", "♡"
    D = 2, " D", "♢"
    C = 3, " C", "♣"

    def __init__(self, value, sym, unicode_sym):
        self._value_ = value
        self._sym = (unicode_sym
                     if sys.stdout.encoding.lower() == "utf-8" else sym)
        self._unicode_sym = unicode_sym

    def __str__(self):
        return self._unicode_sym if SUITS_FORCE_UNICODE else self._sym

    def __index__(self):
        return self.value

    # Yes, the order is reversed.