-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic_ai.py
42 lines (33 loc) · 1.14 KB
/
basic_ai.py
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
# Written by Angus Corr
# Last Updated 18/09/2022
from __future__ import annotations
from cards import Card, Rank, Suit
from player import Player
class BasicAIPlayer(Player):
def __init__(self, name: str) -> None:
Player.__init__(self, name)
# Playing lowest value card
def play_card(self, trick: list[Card], broken_hearts: bool) -> Card:
sortedHand = self.sort_hand_by_value()
valid = False
i = 0
check = self.check_valid_play(sortedHand[i], trick, broken_hearts)
valid = check[0]
while not valid:
i += 1
check = self.check_valid_play(sortedHand[i], trick, broken_hearts)
valid = check[0]
self.hand.remove(sortedHand[i])
return sortedHand[i]
def pass_cards(self) -> list[Card]:
sortedHand = self.sort_hand_by_value()
returnList = []
for i in range(-3, 0):
self.hand.remove(sortedHand[i])
returnList.append(sortedHand[i])
return returnList
if __name__ == "__main__":
cards = []
for i in range(13):
for j in range(4):
cards.append(Card(Rank[i], Suit[j]))