Skip to content

Instantly share code, notes, and snippets.

@thexa4
Last active February 13, 2018 16:56
Show Gist options
  • Save thexa4/9f70e3a5442300cd14a0f7a75e7e6c77 to your computer and use it in GitHub Desktop.
Save thexa4/9f70e3a5442300cd14a0f7a75e7e6c77 to your computer and use it in GitHub Desktop.
import copy
class ParallelPlayer
def __init__(self, prototype, concurrent_games):
self.prototype = prototype
self.instances = [None] * concurrent_games
self.seen_hand = [False] * concurrent_games
def start_game(self, game_id):
self.instances[game_id] = copy.deepcopy(self.prototype)
self.instances[game_id].announce_score(Score())
def give_hand(self, cards):
for i in range(0, len(self.instances)):
if not self.seen_hand[i]:
self.instances[i].give_hand(cards[i])
def make_bid(self, bids, can_blind, get_hand):
result = [-1] * len(self.instances)
for i in range(0, len(self.instances)):
self.seen_hand[i] = False
if can_blind[i]:
if self.instances[i].offer_blind_nill(bids[i])):
result[i] = 'B'
for i in range(0, len(self.instances)):
if result[i] == -1:
self.instances[i].give_hand(get_hand(i))
self.seen_hand[i] = True
result[i] = self.instances[i].make_bid(bids[i])
return result
def play_card(self, tricks):
result = []
for i in range(0, len(self.instances)):
result.append(self.instances[i].play_card(tricks[i]))
return result
def receive_blind_nill_cards(self, cards):
for i in range(0, len(self.instances)):
if cards[i] != None:
self.instances[i].receive_blind_nill_cards(cards[i])
def request_blind_nill_cards(self, games):
result = [None] * len(self.instances)
for i in games:
if cards[i] != None:
result[i] = self.instances[i].request_blind_nill_cards()
return result
def announce_bids(self, bids):
for i in range(0, len(self.instances)):
self.instances[i].announce_bids(tricks[i])
def announce_trick(self, tricks):
for i in range(0, len(self.instances)):
self.instances[i].announce_trick(tricks[i])
def announce_score(self, scores):
for i in range(0, len(self.instances)):
self.instances[i].announce_score(scores[i])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment