def __init__(self, names, server): """Holds the current Black card""" self.currentCard = {"text": "", "pick": 0} self.serverid = server self.serverName = "" """The b & w decks""" self.black = Deck("blackCards") self.white = Deck("whiteCards") """Holds the current player to do an action""" self.currentPlayer = Player("", self.white) """A list of all players""" self.players = {} for i in names: self.players[i] = Player(i, self.white) """A list of all the player names, wil act as indexing""" self.playerNames = [] """Holds All submitted Cards""" self.submitted = {} self.submittedCards = [] """ Geeeeeet ready!!!!!! Our champions wil battle with intence ferocity! """ """No open world im afraid""" self.choices = {1: self.checkCards, 2: self.submit}
def __init__(self): self.turn = 1 self.whitePlayer = Player(ChessConstants.COLOR[0], self.instantiateAll(ChessConstants.COLOR[0])) self.blackPlayer = Player(ChessConstants.COLOR[1], self.instantiateAll(ChessConstants.COLOR[1])) self.newBoard = Board(self.whitePlayer.piecesAlive, self.blackPlayer.piecesAlive) self.isGameOver = False self.loser = ""
def setUp(self): self.players=[] player1=Player("Messi", "Barcelona", True, 100) player2=Player("Ronaldo", "Madrid", True, 80) player3=Player("Maradona", "Barcelona", True, 100) player4=Player("Tevez", "Boca", False, 50) self.players.append(player1) self.players.append(player2) self.players.append(player3) self.players.append(player4) self.teams=Team.create_teams(self.players)
def chooseGamemode(): """ Function to choose the game mode and difficulty. :returns: A list of the two players, either ai or player. """ print('What do you want to do? Pick from the options below.\n' '1: Play against another player.\n' '2: Play against the computer.\n' '3: Smart (starting) against stupid computer.\n' '4: Stupid (starting) against Smart computer.\n' '5: Smart against smart computer.\n' '0: Exit') val = input('Choose an option: ') print() if val == '0': print('Hope to see you again :)') return 'End' elif val == '1': player1 = Player('Player 1', -1) player2 = Player('Player 2', 1) elif val == '2': print('Which difficulty do you want to play against?\n' '0: Easy.\n' '1: Hard.\n' '2: Impossible') difficulty = input('(default: 0): ') if difficulty not in ['0', '1', '2']: difficulty = '0' print('Defaultet to 0: Easy') print() player1 = Player('Player 1', -1) player2 = AI('AI', 1, difficulty) elif val == '3': player1 = AI('Smart AI', -1, '1') player2 = AI('Stupid AI', 1, '0') elif val == '4': player1 = AI('Stupid AI 1', -1, '0') player2 = AI('Smart AI 2', 1, '1') elif val == '5': player1 = AI('Smart AI 1', -1, '1') player2 = AI('Smart AI 2', 1, '1') else: print('Not an option.') return None return [player1, player2]
def __init__(self, gui, game, players=[Player('X'), Player('O')]): self.game = game self.gui = gui self.players = players self.current_player_number = 0 self.winner = None for player in self.players: if type(player) == Learner: player.history = {} if self.gui: self.gui.start()
def init_game(self): pygame.init() self.clock = pygame.time.Clock() self.graphics.init() self.players = [] self.players.append(Player.Player("Lucas")) self.players.append(Player.Player("Charlie")) self.players[0].position = pygame.math.Vector2(50, 50) self.players[1].position = pygame.math.Vector2(950, 950) self.map = pygame.image.load( 'F:\\Workspace\\Hungry Lions Battle\\testmap.png').convert()
def test_compare_teams(self): player1=Player("Messi", "Barcelona", True, 100) player2=Player("Ronaldo", "Madrid", True, 80) player3=Player("Maradona", "Barcelona", True, 100) player4=Player("Tevez", "Boca", False, 50) newPlayers=[] #I add the players in diferent orders newPlayers.append(player2) newPlayers.append(player1) newPlayers.append(player4) newPlayers.append(player3) self.assertEqual(str(self.teams),str(Team.create_teams(newPlayers)))
def add_new_player(human): Globals.PLAYERS.append( Player( Globals.TEMP_VARS['avail_names'].pop( randrange(len(Globals.TEMP_VARS['avail_names']))), Globals.TEMP_VARS['avail_colors'].pop( randrange(len(Globals.TEMP_VARS['avail_colors']))), human))
def server_register_player(self, name, color, imgindex, netid, aiship=None): """ Called by the server when a new client registration message is received Has all information pertaining to a player entity Parameters: ship: Ship object - used to register AI Ships to the game world """ if not self._players.has_key(netid): if (self.__started and self.__allowafterstart) or not self.__started: # create new player # p = Player(name, color, imgindex, netid, self._primary_victory_high) self.player_added(p, BasicGame._ADD_REASON_REGISTER_) self._players[netid] = p if aiship != None: self.__aiships[netid] = aiship if self.__autostart: self._game_add_ship_for_player(netid, roundstart=True) logging.info("Registering Player: %s %d", name, netid) return True return False
def start_game(self, player_count=3, starting_money=1000, starting_bid=None, small_blind=None, linear=True, increasing=0, inc_per_x_rounds=3): players = [ Player([], f'Player {x}', starting_money) for x in range(player_count) ] if small_blind == None: small_blind = random.randint(0, player_count - 1) turn = Turn(small_blind) playing = True round_count = 0 while playing: self.start_round(players, turn) if round_count != 0 and round_count % inc_per_x_rounds == 0: if linear: starting_bid += increasing elif increasing != 0: starting_bid *= increasing round_count += 1 if len(players) < 2: playing = False print( f'Congratulations {players[0].name}, you won and are taking home ${players[0].bank}!' )
def test_is_winner_negative(self): player = Player('X') row = column = 1 self.tictactoe.play(row, column, player) self.assertFalse(self.tictactoe.is_winner(player)) print('test_is_winner_negative:') self.tictactoe.print_board()
def test_learn_single(self): self.learner = Learner('X') self.other_player = Player('O') self.tictactoe = TicTacToe() fields = [(0, 0), (0, 1), (0, 2)] for field in fields: self.tictactoe.play(*field, self.learner) self.assertEqual(fields, self.tictactoe.is_winner(self.learner)) self.learner.learn(self.tictactoe, 100, self.learner) print(self.learner.rewards) self.tictactoe = TicTacToe() while (self.tictactoe.available_moves() and not self.tictactoe.is_winner(self.learner) and not self.tictactoe.is_winner(self.other_player)): self.tictactoe.play(*self.learner.next_move(self.tictactoe), self.learner) print(self.tictactoe.board) self.assertFalse(self.tictactoe.is_winner(self.other_player)) self.assertEqual(fields, self.tictactoe.is_winner(self.learner))
def test_learn_single_starting(self): self.learner = Learner() self.other_player = Player() self.tictactoe = TicTacToe() fields = [(0, 0), (0, 1), (0, 2)] other_fields = [(1, 0), (1, 1)] for field in range(len(fields)): self.tictactoe.play(*fields[field], self.learner) try: self.tictactoe.play(*other_fields[field], self.other_player) except (IndexError): pass self.learner.look(self.tictactoe) self.assertEqual(fields, self.tictactoe.is_winner(self.learner)) self.learner.learn(self.tictactoe, 100, self.learner) print(self.learner.rewards) self.tictactoe = TicTacToe() while (self.tictactoe.available_moves() and not self.tictactoe.is_winner(self.learner) and not self.tictactoe.is_winner(self.other_player)): self.tictactoe.play(*self.learner.next_move(self.tictactoe), self.learner) if (other_fields): self.tictactoe.play(*other_fields.pop(0), self.other_player) print(self.tictactoe.board) self.assertFalse(self.tictactoe.is_winner(self.other_player)) self.assertEqual(fields, self.tictactoe.is_winner(self.learner))
def test_available_moves_none(self): player = Player('X') for row in range(self.tictactoe.board_size()): for column in range(self.tictactoe.board_size()): self.tictactoe.play(row, column, player) self.assertFalse(self.tictactoe.available_moves()) print('test_available_moves_none:') self.tictactoe.print_board()
def test_play_retrieve(self): player = Player('X') row = column = 1 self.tictactoe.play(row, column, player) self.assertIsNotNone(self.tictactoe.retrieve(row, column)) self.assertEqual(self.tictactoe.retrieve(row, column), 'X') print('test_play_retrieve:') self.tictactoe.print_board()
def test_play_retrieve_boundary(self): player = Player('X') row = column = self.tictactoe.board_size() - 1 self.tictactoe.play(row, column, player) self.assertIsNotNone(self.tictactoe.retrieve(row, column)) self.assertEqual(self.tictactoe.retrieve(row, column), player.name) print('test_play_retrieve_boundary:') self.tictactoe.print_board()
def test_available_moves(self): player = Player('X') test_position = (1, 1) self.tictactoe.play(*test_position, player) available_moves = self.tictactoe.available_moves() self.assertTrue(available_moves) self.assertNotIn(test_position, available_moves) print('test_available_moves:') self.tictactoe.print_board()
def test_is_winner_diagonal2(self): player = Player('X') fields = [(0, 2), (1, 1), (2, 0)] for field in fields: self.tictactoe.play(*field, player) self.assertTrue(self.tictactoe.is_winner(player)) self.assertEqual(fields, self.tictactoe.is_winner(player)) print('test_is_winner_diagonal2:') self.tictactoe.print_board()
def test_is_winner_column(self): player = Player('X') column = 0 fields = [(row, column) for row in range(self.tictactoe.board_size())] for field in fields: self.tictactoe.play(*field, player) self.assertTrue(self.tictactoe.is_winner(player)) self.assertEqual(fields, self.tictactoe.is_winner(player)) print('test_is_winner_column:') self.tictactoe.print_board()
def __init__(self, noplayers, initial_stake): self.players = [] self.dealer = Player("Dealer", 10000) self.deck = Deck() self.deck.shuffle() cards = self.deck.deal(2) dealerHand = Hand() dealerHand.add_cards(cards) self.dealer.initialHand(dealerHand) for i in range(0, noplayers): player = Player("Player" + str(i + 1), initial_stake) cards = self.deck.deal(2) playerHand = Hand() playerHand.add_cards(cards) player.initialHand(playerHand) self.players.append(player) print_all_hands(self.dealer, self.players) self.play_rounds()
def main(self): self.canvas.pack() self.img = PhotoImage(width=self.WIDTH, height=self.HEIGHT) self.canvas.create_image((self.WIDTH / 2, self.HEIGHT / 2), image=self.img, state="normal") one = Functions.numberPicker() two = Functions.numberPicker() three = Functions.numberPicker() four = Functions.numberPicker() five = Functions.numberPicker() six = Functions.numberPicker() x = round(self.WIDTH / 2) y = round(self.HEIGHT / 2) # button1 = Button(window, text = "Restart", command = os.system('C:\Users\s7840363\PycharmProjects\untitled\venv\Scripts\python.exe C:/Users/s7840363/PycharmProjects/untitled/Players.py')) # button1.pack(side='left', padx=10) self.map = [['#000000' for i in range(self.HEIGHT)] for j in range(self.WIDTH)] for i in range(0, 100000): b = random.randint(0, 1) c = random.randint(0, 1) if b == 0: x = x + 1 else: x = x - 1 if c == 0: y = y + 1 else: y = y - 1 if x > self.WIDTH - 1: x = self.WIDTH - 1 if x < 0: x = 1 if y > self.HEIGHT - 1: y = self.HEIGHT - 1 if y < 0: y = 1 if i == 0: playerStart = (x, y) a = Functions.sixPick(one, two, three, four, five, six) self.img.put(a, (abs(x), abs(y))) self.map[x][y] = a self.goal = [x, y] self.canvas.create_line(self.goal[0] + 15, self.goal[1] + 15, self.goal[0], self.goal[1], fill='white', width=2, arrow=LAST) player = Player(playerStart[0], playerStart[1], self) #player = Player(x, y, self) self.window.bind("<KeyPress>", player.movementCheck) self.window.focus_set() r = self.redirector() self.window.mainloop()
def startGame(self): """ Gets the mode and difficulty from the dropdown menues and sets the players. Starts the game loop to handle a possible ai. """ mode = self.OPTIONS[self.var_mode.get()] diff = self.DIFFICULTY[self.var_diff.get()] if mode == 1: player1 = Player('Player 1', -1) player2 = Player('Player 2', 1) elif mode == 2: player1 = Player('Player 1', -1) player2 = AI('AI', 1, diff) elif mode == 3: player1 = AI('Smart AI', -1, 1) player2 = AI('Stupid AI', 1, 0) elif mode == 4: player1 = AI('Stupid AI 1', -1, 0) player2 = AI('Smart AI 2', 1, 1) elif mode == 5: player1 = AI('Stupid AI 1', -1, 0) player2 = AI('Smart AI 2', 1, 1) else: # mode == '6': player1 = AI('Ultra AI 1', -1, 2) player2 = AI('Ultra AI 2', 1, 2) # Reset the board state self.board.resetBoard() self.players = [player1, player2] self.player_iterator = self.toggleValue() self.current_player = next(self.player_iterator) self.createGameGrid(self.fr_gamegrid) self.lbl_curr_player['text'] = f'Current player: {self.players[self.current_player].name} ' \ f'({self.board.signs[self.players[self.current_player].sign]})' self.game_loop()
def test_available_moves_border(self): player = Player('X') for row in range(self.tictactoe.board_size() - 1): for column in range(self.tictactoe.board_size() - 1): self.tictactoe.play(row, column, player) available_moves = self.tictactoe.available_moves() for position in range(self.tictactoe.board_size()): self.assertIn((position, self.tictactoe.board_size() - 1), available_moves) self.assertIn((self.tictactoe.board_size() - 1, position), available_moves) print('test_available_moves_border:') self.tictactoe.print_board()
def main(decks): d = Deck(decks) p = Player(d) if not p.check_score(): return h = Dealer(d) if not h.check_score(): return p.hit(d) h.hit(d) if p.score > h.score: print("Player Wins!") else: print("Dealer Wins") return
from Menu import Menu from Game import Game from Players import Player yourBoard = Game(0, 9) you = Player(0, yourBoard) opponentBoard = Game(0, 9) opponent = Player(1, yourBoard) menu = Menu(you, opponent, yourBoard, opponentBoard) menu.show() menu.run()
def test_add_one_player(self): player=Player("Marcos","No One",True,100) for team in self.teams: self.assertEqual(False,team.add_payer(player))
logging.debug('Appending %s' % x) chain_.append(x) else: logging.debug('Card %s is ignored' % x) rejected.append(x) deck_.add(rejected) logging.info('Chain has been initialized') def hinter_pick_max3_cards_from_grid(): global grid_ validI = [] for i, c in enumerate(grid_): if is_valid_card(c): validI.append(i) picked = [] random.shuffle(validI) pickI = validI[:3] for p in validI[:3]: picked.append(grid_[p]) grid_[p] = deal(1) return picked players_ = [Player(i, i) for i in range(4)] grid_ = deal(9) rule_ = Rule('(PREV.color==red)?CUR.color==black:True')
def create_players_list(): Globals.PLAYERS = [ Player(Globals.SETTINGS['pl_name'], Globals.SETTINGS['pl_color'], True) ]
# -*- coding: utf-8 -*- """ Created on Thu Dec 5 13:01:41 2019 @author: Mazurka """ from Players import Player import random as rn P1 = Player(1) P2 = Player(2) P3 = Player(3) P4 = Player(4) def Combat_round(Attacker, Defender): print("Hráč", Attacker.getname(), "útočí na hráče", Defender.getname()) A_damage = Attacker.getdamage() D_hp = Defender.gethp() D_hp -= A_damage print("Hráči", Defender.getname(), "zbývá", D_hp, "životů") return D_hp def Combat(LeftSideList, RightSideList): L = LeftSideList R = RightSideList try: if isinstance(L, list): pass
else: print('Try again!') return None def play_command(self, row, column, player): success = self.game.play(row=row, column=column, player=player) os.system('cls') self.game.print_board() return success def game_over(self, winner=None): if winner: print("Congratulations {}!".format(winner.name)) else: print("It's a draw!") if __name__ == '__main__': game = TicTacToe() player = Player() gui = KtinterGui(game) gui.start() move1 = (1, 1) gui.game.play(*move1, player) gui.play_view(*move1, player) move2 = gui.next_move(player) gui.play_view(*move2, player) gui.game_over() gui.game_over(player)