def testRotateList(self): self.assertListEqual([], util.rotateList([], 10)) self.assertListEqual([1,2,3,4,5], util.rotateList([1,2,3,4,5], 0)) self.assertListEqual([3,4,5,1,2], util.rotateList([1,2,3,4,5], 2)) self.assertListEqual([4,5,1,2,3], util.rotateList([1,2,3,4,5], -2)) self.assertListEqual([3,4,5,1,2], util.rotateList([1,2,3,4,5], 7)) self.assertListEqual([4,5,1,2,3], util.rotateList([1,2,3,4,5], -7)) self.assertListEqual([1,2,3,4,5], util.rotateList(util.rotateList([1,2,3,4,5], -8), 8))
def testRotateList(self): self.assertListEqual([], util.rotateList([], 10)) self.assertListEqual([1, 2, 3, 4, 5], util.rotateList([1, 2, 3, 4, 5], 0)) self.assertListEqual([3, 4, 5, 1, 2], util.rotateList([1, 2, 3, 4, 5], 2)) self.assertListEqual([4, 5, 1, 2, 3], util.rotateList([1, 2, 3, 4, 5], -2)) self.assertListEqual([3, 4, 5, 1, 2], util.rotateList([1, 2, 3, 4, 5], 7)) self.assertListEqual([4, 5, 1, 2, 3], util.rotateList([1, 2, 3, 4, 5], -7)) self.assertListEqual([1, 2, 3, 4, 5], util.rotateList( util.rotateList([1, 2, 3, 4, 5], -8), 8))
def playOneGame(self): self.deal() ordPlayers = self.orderedPlayers() ordPlayers[0].role = ROLE_LEADER ordPlayers[1].role = ROLE_COOP1 ordPlayers[2].role = ROLE_COOP2 leader = ordPlayers[0] gameType = leader.selectGameType() print(gameType) leader.hand.addCards(self.deck[7:12]) if isinstance(gameType, StdGameType): gameType = leader.specifyStdGame() print(gameType) print("Trump:", gameType.trump) print("Trump card:", gameType.revealedTrumpCard) self.rules = StdGameRules(gameType) else: raise Exception("Game type not supported") talon = leader.selectTalon(self.rules) print("Talon:", talon) leader.hand.removeCards(talon) scores = [0] * PLAYER_CNT turnHistory = [] # Cards played, ordered from the turn starting player's one table = [] startingPlayerIdx = self.leaderIdx for i in range(10): table = [] # Map relative index (to the turn starting player) -> absolute index absIndices = rotateList(list(range(PLAYER_CNT)), startingPlayerIdx) # ordered players from the turn starting player ordPlayers = rotateList(self.players, startingPlayerIdx) for player in ordPlayers: table.append(player.play(table, self.rules)) print("Played:", table[-1]) print("Table:", table) turnScores, takingPlayerRelIdx = self.rules.scoreTurn(table, ordPlayers) takingPlayerIdx = absIndices[takingPlayerRelIdx] turnHistory.append((rotateList(table, startingPlayerIdx), startingPlayerIdx, takingPlayerIdx)) print("Taking player: ", takingPlayerIdx + 1) for idx, score in zip(absIndices, turnScores): scores[idx] += score print("Scores:", scores) startingPlayerIdx = takingPlayerIdx scores[startingPlayerIdx] += 10 print("Scores:", scores) moneyGains = self.rules.moneyGains(self.players, scores, turnHistory) print("Money gains:", moneyGains)
def orderedPlayers(self): # starting from the leader return rotateList(self.players, self.leaderIdx)