Randomize starting player
This commit is contained in:
parent
9b894b8dbc
commit
0f482aade5
@ -6,31 +6,44 @@ Created on Wed Mar 4 22:20:15 2020
|
|||||||
@author: AlexandreMouchel
|
@author: AlexandreMouchel
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import random
|
||||||
|
|
||||||
from opale.carte import *
|
from opale.carte import *
|
||||||
from opale.board import Board
|
from opale.board import Board
|
||||||
from opale.player import Player
|
from opale.player import Player
|
||||||
|
|
||||||
class Game():
|
class Game():
|
||||||
|
|
||||||
def __init__(self, player1_name, player2_name):
|
def __init__(self, *player_names):
|
||||||
self.board = Board()
|
self.board = Board()
|
||||||
self.player1 = Player(player1_name)
|
|
||||||
self.player2 = Player(player2_name)
|
|
||||||
self.round = 0
|
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
|
@property
|
||||||
def current_player(self):
|
def current_player(self):
|
||||||
if self.round % 2:
|
return self.players[self.round % 2]
|
||||||
return self.player2
|
|
||||||
else:
|
|
||||||
return self.player1
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_partner(self):
|
def current_partner(self):
|
||||||
if self.round % 2:
|
return self.players[(self.round + 1) % 2]
|
||||||
return self.player1
|
|
||||||
else:
|
|
||||||
return self.player2
|
|
||||||
|
|
||||||
def isFinished(self):
|
def isFinished(self):
|
||||||
return self.board.isFinished() or self.player1.cantpioche or self.player2.cantpioche
|
return self.board.isFinished() or self.player1.cantpioche or self.player2.cantpioche
|
||||||
|
Loading…
Reference in New Issue
Block a user