Assignment 2
Implement the following card game. The game is played with 52 cards, each card has one of four suits (which are irrelevant to the game) and one of 13 sizes (2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A, in increasing order). Each player gets six random cards. The game consists of five tricks. For a trick, each player plays exactly one card. The players play the cards in a trick sequentially. The player starting the trick may play arbitrary card. Subsequent players must play a card greater or equal in size than the largest card in the trick or play their lowest card (minimal). The player who played the biggest card wins the trick, if more than one player played the biggest card, the last player that played such card wins the trick. The player that wins a trick starts the next one. At the end each player has exactly one card. The player(s) with lowest remaining card wins.
Scoring (not a part of the assignment): The player with lowest card gets 0 points. The players with higher cards get points according to the difference of their card and the lowest card. E.g. id the lowest card is 6 and somebody has J left, he gets 5 points. first player to get more than 21 points loses and the game ends.
I prepared a basic design. Although, the design divides the responsibilities quite well, the classes are too coupled (and the design is not complete, e.g. you do not have constructors in the design). To reduce coupling you want to put some interfaces in-between the classes and use some dependency injection. You may modify the design if you wish, e.g. it still makes sense to split some classes.
Implement the classes as follows.
- Use Python with type annotations. Your program should pass mypy typecheck.
- Define interfaces between cooperating classes. When you use static typechecking, explicit interface classes make sense in Python.
- Each class and interface should be contained in a separate file.
- Classes should not import other non-interface classes.
- Write simple tests for your classes (you should do it anyway just to be sure that your stuff works). They may be sociable. But write solitary test for Hand class.
- To demonstrate the gained flexibility, modify the game in several ways without modifying the underlying classes (you need to replace some of your classes with others). The requested rule changes are:
- Your card contain subsets of {1, 2, 3, 4, 5, 6, 7}. We have just partial ordering. A card is lowest if there is no lower card (while implementing hand carefully distinguish minimal and minimum).
- From equal cards, the player that played the equal card earliest wins the trick.
Send your solution to lukotka.pts@gmail.com. The first deadline is 10.4.2021 23:59:59. The deadline for reviewed solution is 17.4.2021 23:59:59. The solutions sent later will be accepted, however the number of points awarded may be reduced.