add interface and readme

This commit is contained in:
Jean Lapostolle 2023-04-10 17:54:04 +02:00
parent 307f81185d
commit 6ae16f88f6
2 changed files with 58 additions and 0 deletions

23
README.md Normal file
View File

@ -0,0 +1,23 @@
Poker Hand est une implémentation en Python du Kata "Poker Hands" dont vous pouvez retrouvez la définition [sur codingdojo.org](https://codingdojo.org/kata/PokerHands/).
Pour l'utiliser, il suffit de lancer main.py
```shell
python main.py
```
Une invite de commande vous proposera alors de noter vos mains de la manière suivante
```shell
Mains : Black: 2H 3D 5S 9C KD White: 2D 3H 5C 9S KH
```
Ce format a été choisit afin de pouvoir utiliser les exemples donner sur le site de codingdojo.
```python
Black: 2H 3D 5S 9C KD White: 2C 3H 4S 8C AH
Black: 2H 4S 4C 2D 4H White: 2S 8S AS QS 3S
Black: 2H 3D 5S 9C KD White: 2C 3H 4S 8C KH
Black: 2H 3D 5S 9C KD White: 2D 3H 5C 9S KH
```
Mais bien sûr, vous pouvez en utiliser d'autres.

35
main.py Normal file
View File

@ -0,0 +1,35 @@
import re
from hand_utils import compare_hand
def construct_hand(list_of_cards):
hand= {
"color" : [],
"value" : []
}
for card in list_of_cards:
value, color = card[0], card[1]
hand["color"].append(color)
hand["value"].append(value)
return hand
def split_input_to_hands(input):
hand_1_cards = input.split(" ")[1:6]
hand_2_cards = input.split(" ")[8:13]
hand_1 = construct_hand(hand_1_cards)
hand_2 = construct_hand(hand_2_cards)
return hand_1, hand_2
if __name__ == "__main__":
text_input = input("Mains : ")
while not re.match('^[a-zA-Z]+:\s([2-9TJQKA][CDHS][\s]+){5}[\s]*[a-zA-Z]+:\s([2-9TJQKA][CDHS][\s]+){4}([2-9TJQKA][CDHS])[\s]*$', text_input):
print("Erreur! Vérifiez que votre main est au bon format (Exemple 'Black: 2H 3D 5S 9C KD White: 2D 3H 5C 9S KH'")
text_input= input("Mains : ")
result = compare_hand(*split_input_to_hands(text_input))
print(result[1])