-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplayer.py
More file actions
68 lines (58 loc) · 2.65 KB
/
Copy pathplayer.py
File metadata and controls
68 lines (58 loc) · 2.65 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
##############################################################################
# Trois is a modified version of the world-renowned game, Uno, that is jointly
# developed by Anthony Lua and Wei Herng Moo Yong as part of a Hackathon
# project. Trois is a one-player game against three desicion-making bots, and
# the goal of Trois is to get rid of all your cards before the time limit or
# to have the least number fo cards by the time limit. Instructions on how to
# play Trois will be on the READ.ME.md file. We hope that you will enjoy
# playing Trois! Thank you!
# Date (dd/mm/yyyy) of Authorship delcaration for Anthony Lua: 14/01/2022
# Date (dd/mm/yyyy) of Authorship delcaration for Wei Herng Moo Yong: 16/01/2022
##############################################################################
import game
from constants import INITIAL_DECK, PLUS_2, PLUS_4, \
PLAYABLE, NOT_PLAYABLE, DEAL, PLAY
class Player:
def __init__(self, given_hand, player_name):
self.hand = given_hand
self.username = player_name
# remove card from hand, returns nothing
def remove_card(self, card):
self.hand.remove(card)
# add card to hand, returns nothing
def add_card(self, card):
self.hand.append(card)
# pick up a card from the deck
def pick_card(self):
picked_cards = []
card = game.Game.random_card(PLAY)
if card in INITIAL_DECK:
self.add_card(card)
picked_cards.append(card)
elif card == PLUS_2:
self.remove_card(card)
for _ in range(2):
new_card = game.Game.random_card(PLAY)
if new_card == PLUS_2 or new_card == PLUS_4:
self.remove_card(new_card)
else:
self.add_card(new_card)
picked_cards.append(new_card)
elif card == PLUS_4:
self.remove_card(card)
for _ in range(4):
new_card = game.Game.random_card(PLAY)
if new_card == PLUS_2 or new_card == PLUS_4:
self.remove_card(new_card)
else:
self.add_card(new_card)
picked_cards.append(new_card)
return picked_cards
# check if card is playable - returns 1 if playable and 0 otherwise
def check_playable(self, top_pile, current_card):
# need to discuss about this
if len(current_card) == 2 and (top_pile[0] == current_card[0] or \
top_pile[1] == current_card[1]):
return PLAYABLE
else:
return NOT_PLAYABLE