def goal(self): """Prints generic win message and closes logger for program exit""" if not self.quit: # Winning message only printed if a player did not quit Logger.log('Player {} has won the game'.format(self.currentPlayer + 1)) self.closeLogger()
def executeMove(self): """Executes player-selected move when valid""" move = self.playerMoves[self.selectedMove] if not self.playerIsHuman(): # Print move selected by AI so human players can see selection Logger.log(' ' * 4, repr(move), '\n') # Execute move using type defined in moves dictionary self.moves[move.moveType](move)
def printBoard(self): """Prints game board for human players to analyze Note: Board layout and printing should be handled through the repr() method of a game's associated Board class """ if self.playerIsHuman(): Logger.log(repr(self.board), '\n')
def printMoves(self): """Retrieves possible moves for current player and prints list only for human players""" self.playerMoves = self.rulebook.getMoves(self) # Always add quit option to move list; can be overrided if game does not allow quits self.playerMoves += [Move(None, None, None, 'QUIT')] if self.playerIsHuman(): for i in range(len(self.playerMoves)): Logger.log('{:>4}. {}'.format(i + 1, repr(self.playerMoves[i]))) Logger.log('')
def chooseMove(self): try: Logger.log('Choose your next move:') userInput = input() # Attempt to force user input as integer selectedMove = int(userInput) - 1 Logger.log(str(selectedMove + 1), printLog=False) except ValueError: # Set input as invalid selection if error occurs selectedMove = -1 Logger.log(userInput, printLog=False) Logger.log('') return selectedMove
bot_thread.start() btc = Currency('BTC', 'USD') eth = Currency('ETH', 'USD') btc_price = btc.get_price() eth_price = eth.get_price() last_prices = log.get_last_line() if not last_prices == None: last_prices = last_prices.split(",") btc_last_price = float(last_prices[1]) eth_last_price = float(last_prices[2]) btc_delta = (btc_last_price - btc_price) / btc_last_price * 100 eth_delta = (eth_last_price - eth_price) / eth_last_price * 100 else: btc_delta = 0.0 eth_delta = 0.0 log.log([btc_price, eth_price], [btc_delta, eth_delta]) while True: print("\n" * 20) print("%s\t|%s\t|%s\t|%s\t|%s" % ('DATE'.center(30), 'BTC'.center(30), 'ETH'.center(30), 'DELTA_BTC %'.center(30), 'DELTA_ETH %'.center((30)))) lines = log.get_n_lines(GRAPH) for line in lines: line = line.strip("\n") line = line.split(",") print("%s\t|%s\t|%s\t|%s\t|%s" % (line[0].center(30), line[1].center(30), line[2].center(30), line[3].center(30), line[4].center(30))) time.sleep(UPDATE_TIME) btc_price = btc.get_price() eth_price = eth.get_price()
def printHand(self): """Prints player hand if any cards present""" if len(self.players[self.currentPlayer].hand): Logger.log("Player {}'s Hand: {}\n".format( self.currentPlayer + 1, repr(self.players[self.currentPlayer].hand)))
def printRound(self): """Prints round number if game allows rounds to be displayed""" # Round numbers are only printed after reaching the first player once per iteration if self.showRounds and self.currentPlayer == 0 and not self.invalid: roundNum = int(self.moveCount / len(self.players) + 1) Logger.log(' Round {} '.format(roundNum).center(50, '='), '\n')
def printBanner(self): """Prints banner containing name of game""" Logger.log('-' * 50) Logger.log('|', self.name.center(48), '|') Logger.log('-' * 50, '\n')
def chooseSuit(self): # Randomly select suit to play selectedSuit = random.choice(range(0, 4)) Logger.log('Suit has been changed to {}\n'.format(suits[selectedSuit])) return selectedSuit
def chooseSuit(self): # Prints suits as list of options suitOptions = '' for i in range(len(suits)): suitOptions += '{:>4}. {}\n'.format(i + 1, suitCharacters[suits[i]]) # Continue asking for selected suit until valid input received selectedSuit = -1 while selectedSuit < 0: Logger.log(suitOptions, '\n', 'Choose suit to switch to:') try: userInput = input() # Attempt to force use input as integer selectedSuit = int(userInput) - 1 Logger.log(str(selectedSuit + 1), printLog=False) except ValueError: # Set input as invalid selection if error occurs selectedSuit = -1 Logger.log(userInput, printLog=False) Logger.log('') if not selectedSuit in range(0, 4): # Print invalid selection message if index out of bounds Logger.log('Invalid suit selection. Please try again.', '\n') selectedSuit = -1 Logger.log('Suit has been changed to {}\n'.format(suits[selectedSuit])) return selectedSuit
def printInvalidMoveMessage(self): """Prints invalid move message""" Logger.log('Invalid move selection. Please try again.', '\n')
def printQuit(self): """Prints quit message and associated player""" Logger.log('Player {} has quit the game'.format(self.currentPlayer + 1))