A single-player plays the game with the computer. The deck is composed of 16 cards: ● 3 black 1's, 2 black 2's, 2 black 3's and 1 black 4 ● 3 white 1's, 2 white 2's, 2 white 3's and 1 white 4 The aim is to stack the cards one by one in sorted order in the stack (blacks from 1 to 4 and whites from 1 to 4). Game Rules: Starting the game: ● The deck is shuffled and three cards are dealt with each player. ● Players can only see their partner's hand. They can not see their own hands. ● In the beginning, players have a total number of 3 tips. ● In the beginning, players have a total number of 2 lives. ● The stack is empty. ● The trash is empty. Playing the game: ● Game is played in turns. In each turn, a player selects one of the following moves: ○ Give tip: Player spends a tip (if there is any) and gives some information to his/her partner about his/her cards: ■ The tip can only be about the colour or the value of the cards. For example, you can not say a card is a black 2. You can either say it is black or it is 2. ■ The tip has to include the location of all cards which have the same value or the same colour. For example, if your partner's hand is “black 1, white 1, white 3”, you can not say the first card is 1 or the second card is white. You have to say the first and second cards are 1 or second and third cards are white. ○ Stack card: Player picks one of his/her own cards to place in the stack and draws a new card from the deck (if there is any). ■ If the card can be stacked, it is added in the stack. ■ Otherwise, the card is added to the trash and a life is lost. ○ Discard a card: Player picks one of his/her own cards to place in the trash and draws a new card from the deck (if there is any). One tip is earned. The game ends when: ● no lives left (zero), or ● no cards left to play, or ● the stack has all 8 cards ● The final score is the total number of cards in the stack. Obviously, the maximum possible score is 8.
import random
def tips(arg):
res = []
colour = {'black':[],
'white':[]}
number = {'1':[],'2':[],'3':[],'4':[]}
for item in range(len(arg)):
number[arg[item].split()[0]].append(item+1)
colour[arg[item].split()[1]].append(item+1)
for key in number:
if number[key]:
res.append(f'Cards nominal {key} are in position {number[key]}')
for key in colour:
if colour[key]:
res.append(f'Cards colour {key} are in position {colour[key]}')
return res
cardes = ['1 black','1 black','1 black',
'2 black','2 black',
'3 black','3 black',
'4 black',
'1 white','1 white','1 white',
'2 white','2 white',
'3 white','3 white',
'4 white']
random.shuffle(cardes)
card_comp = cardes[:3]
card_man = cardes[3:6]
cardes =cardes[6:]
life_comp = 2
life_man = 2
tip_comp = 3
tip_man = 3
stack = ['1 black','2 black','3 black','4 black',
'1 white','2 white','3 white','4 white']
while True:
print('Cards Comp ', ', '.join(card_comp))
choises = ['stack card - enter 1','discard card - enter 2','give tip - enter 3']
if tip_man == 0:
choises = choises [:-1]
print('Player turn')
print('Possible options', ', '.join(choises))
choise = input('Make your choice, correct input is your responsibility- ')
if choise == '1':
print('count of yours cards',len(card_man))
card_number = int(input('enter card number to stack card'))
if card_man[card_number -1] != stack[0]:
life_man -= 1
elif card_man[card_number -1] == stack[0]:
del stack[0]
del card_man[card_number -1]
if cardes:
card_man.append(cardes[0])
del cardes[0]
if choise == '2':
print('count of yours cards',len(card_man))
card_number = int(input('enter card number to discard card'))
del card_man[card_number -1]
if cardes:
card_man.append(cardes[0])
del cardes[0]
tip_man += 1
if choise == '3':
tip_give = tips(card_comp)
print('number of tips',len(tip_give))
print('Possible tips:')
for item in tip_give:
print (item)
tip_number = int(input('enter tips number- '))
print (tip_give[tip_number -1])
#Comp turn randome choise
print('Comp turn:')
choises = ['1','2','3']
if tip_comp == 0:
choises = choises [:-1]
choise = random.choice(choises)
random.shuffle(card_comp)
if choise == '1':
print('stack card')
if card_comp[0] != stack[0]:
life_comp -= 1
elif card_comp[0] == stack[0]:
del stack[0]
if cardes:
card_comp.append(cardes[0])
del cardes[0]
del card_comp[0]
if choise == '2':
print('discard card')
del card_comp[0]
if cardes:
card_comp.append(cardes[0])
del cardes[0]
tip_comp += 1
if choise == '3':
print(random.choice(tips(card_man)))
if life_comp == 0 or life_man == 0:
break
if len(card_comp) == 0 or len(card_man) == 0:
break
print ('Final score ', len(stack))
Comments
Leave a comment