File size: 1,061 Bytes
6e3fa72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/card.ipynb.

# %% auto 0
__all__ = ['suits', 'ranks', 'Card']

# %% ../nbs/card.ipynb 3
from fastcore.test import *
from fastcore.utils import *
from . import *

# %% ../nbs/card.ipynb 5
suits = ["♦️", "♣️", "♥️", "♣️"]
ranks = [None, "A"] + [str(x) for x in range(2, 11)] + ["J", "Q", "K"]

# %% ../nbs/card.ipynb 11
class Card:
    def __init__(
        self, suit: int, rank: int  # An index to the `suits`  # An index to the `ranks`
    ):
        self.suit = suit
        self.rank = rank

    def __str__(self):
        return f"{ranks[self.rank]}{suits[self.suit]}"

    __repr__ = __str__

# %% ../nbs/card.ipynb 16
@patch
def __eq__(self: Card, other: Card):
    return (self.suit, self.rank) == (other.suit, other.rank)

# %% ../nbs/card.ipynb 17
@patch
def __lt__(self: Card, other: Card):
    return (self.suit, self.rank) < (other.suit, other.rank)

# %% ../nbs/card.ipynb 18
@patch
def __gt__(self: Card, other: Card):
    return (self.suit, self.rank) > (other.suit, other.rank)