Randomize starting player

This commit is contained in:
nemunaire 2020-03-15 11:22:17 +01:00
parent 9b894b8dbc
commit 0f482aade5

View File

@ -6,31 +6,44 @@ Created on Wed Mar 4 22:20:15 2020
@author: AlexandreMouchel
"""
import random
from opale.carte import *
from opale.board import Board
from opale.player import Player
class Game():
def __init__(self, player1_name, player2_name):
def __init__(self, *player_names):
self.board = Board()
self.player1 = Player(player1_name)
self.player2 = Player(player2_name)
self.round = 0
self.players = []
for pname in player_names:
self.players.append(Player(pname))
random.shuffle(self.players)
@property
def player1(self):
if type(self.players[0]) == Computer:
return self.players[1]
return self.players[0]
@property
def player2(self):
if type(self.players[0]) == Computer:
return self.players[0]
return self.players[1]
@property
def current_player(self):
if self.round % 2:
return self.player2
else:
return self.player1
return self.players[self.round % 2]
@property
def current_partner(self):
if self.round % 2:
return self.player1
else:
return self.player2
return self.players[(self.round + 1) % 2]
def isFinished(self):
return self.board.isFinished() or self.player1.cantpioche or self.player2.cantpioche