|
| 1 | +# card–A basic playing card |
| 2 | + |
| 3 | + |
| 4 | +<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! --> |
| 5 | + |
| 6 | +We will be using numbers to represent playing card clubs and ranks. |
| 7 | +These are the suits: |
| 8 | + |
| 9 | +``` python |
| 10 | +suits |
| 11 | +``` |
| 12 | + |
| 13 | + ['♣️', '♦️', '❤️', '♠️'] |
| 14 | + |
| 15 | +For instance the suit at index `0`: |
| 16 | + |
| 17 | +``` python |
| 18 | +suits[0] |
| 19 | +``` |
| 20 | + |
| 21 | + '♣️' |
| 22 | + |
| 23 | +These are the ranks: |
| 24 | + |
| 25 | +``` python |
| 26 | +ranks |
| 27 | +``` |
| 28 | + |
| 29 | + [None, 'A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'] |
| 30 | + |
| 31 | +For instance the rank at index `1` (note that there isn’t a playing card |
| 32 | +at position `0`, since we want the ranks to match the indicies where |
| 33 | +possible): |
| 34 | + |
| 35 | +``` python |
| 36 | +ranks[1] |
| 37 | +``` |
| 38 | + |
| 39 | + 'A' |
| 40 | + |
| 41 | +------------------------------------------------------------------------ |
| 42 | + |
| 43 | +### Card |
| 44 | + |
| 45 | +> Card (suit:int, rank:int) |
| 46 | +
|
| 47 | +*A playing card* |
| 48 | + |
| 49 | +<table> |
| 50 | +<thead> |
| 51 | +<tr> |
| 52 | +<th></th> |
| 53 | +<th><strong>Type</strong></th> |
| 54 | +<th><strong>Details</strong></th> |
| 55 | +</tr> |
| 56 | +</thead> |
| 57 | +<tbody> |
| 58 | +<tr> |
| 59 | +<td>suit</td> |
| 60 | +<td>int</td> |
| 61 | +<td>An index into <code>suits</code></td> |
| 62 | +</tr> |
| 63 | +<tr> |
| 64 | +<td>rank</td> |
| 65 | +<td>int</td> |
| 66 | +<td>An index into <code>ranks</code></td> |
| 67 | +</tr> |
| 68 | +</tbody> |
| 69 | +</table> |
| 70 | + |
| 71 | +Here’s an example of creating and displaying a card: |
| 72 | + |
| 73 | +``` python |
| 74 | +c = Card(suit=1, rank=3) |
| 75 | +c |
| 76 | +``` |
| 77 | + |
| 78 | + 3♦️ |
| 79 | + |
| 80 | +## Comparison operators |
| 81 | + |
| 82 | +Equality, less than, and greater than work on the rank and suit indices. |
| 83 | + |
| 84 | +------------------------------------------------------------------------ |
| 85 | + |
| 86 | +### Card.\_\_gt\_\_ |
| 87 | + |
| 88 | +> Card.__gt__ (a:__main__.Card) |
| 89 | +
|
| 90 | +*Return self\>value.* |
| 91 | + |
| 92 | +------------------------------------------------------------------------ |
| 93 | + |
| 94 | +### Card.\_\_lt\_\_ |
| 95 | + |
| 96 | +> Card.__lt__ (a:__main__.Card) |
| 97 | +
|
| 98 | +*Return self\<value.* |
| 99 | + |
| 100 | +------------------------------------------------------------------------ |
| 101 | + |
| 102 | +### Card.\_\_eq\_\_ |
| 103 | + |
| 104 | +> Card.__eq__ (a:__main__.Card) |
| 105 | +
|
| 106 | +*Return self==value.* |
| 107 | + |
| 108 | +For instance, here’s a test of equality… |
| 109 | + |
| 110 | +``` python |
| 111 | +test_eq(Card(suit=1, rank=3), Card(suit=1, rank=3)) |
| 112 | +``` |
| 113 | + |
| 114 | +…and a test of `<`… |
| 115 | + |
| 116 | +``` python |
| 117 | +assert Card(suit=1, rank=3)<Card(suit=2, rank=3) |
| 118 | +``` |
| 119 | + |
| 120 | +…and finally of `>`: |
| 121 | + |
| 122 | +``` python |
| 123 | +assert Card(suit=3, rank=3)>Card(suit=2, rank=3) |
| 124 | +assert not Card(suit=1, rank=3)>Card(suit=2, rank=3) |
| 125 | +``` |
0 commit comments