Python player.Player() Examples

The following are 27 code examples of player.Player(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module player , or try the search function .
Example #1
Source File: rooms.py    From Simple-Game-Server with GNU General Public License v2.0 6 votes vote down vote up
def register(self, addr, udp_port):
        """
        Register player
        """
        player = None
        for registered_player in self.players.values():
            if registered_player.addr == addr:
                player = registered_player
                player.udp_addr((addr[0], udp_port))
                break

        if player is None:
            player = Player(addr, udp_port)
            self.players[player.identifier] = player

        return player 
Example #2
Source File: game.py    From text-adventure-tut with MIT License 6 votes vote down vote up
def play():
    world.load_tiles()
    player = Player()
    room = world.tile_exists(player.location_x, player.location_y)
    print(room.intro_text())
    while player.is_alive() and not player.victory:
        room = world.tile_exists(player.location_x, player.location_y)
        room.modify_player(player)
        # Check again since the room could have changed the player's state
        if player.is_alive() and not player.victory:
            print("Choose an action:\n")
            available_actions = room.available_actions()
            for action in available_actions:
                print(action)
            action_input = input('Action: ')
            for action in available_actions:
                if action_input == action.hotkey:
                    player.do_action(action, **action.kwargs)
                    break 
Example #3
Source File: bnet_player_monitor.py    From WC3StreamerOverlay with GNU General Public License v3.0 6 votes vote down vote up
def __packet_callback(self, packet):
    raw_payload = raw(packet.payload.payload.payload)

    if raw_payload[:2] == b'\xf7\x1e':
      self.__set_gateway(packet)

      player = Player()
      player.is_me = True
      self.__parse_player_packet(player, raw_payload, 19)
      BNetStatsScraper.get_stats(player, self.gateway)
      self.player_list.append(player)
    elif raw_payload[:2] == b'\xf7\x06':
      player_offset = 0
      while player_offset is not -1:
        player = Player()
        self.__parse_player_packet(player, raw_payload[player_offset:], 9)
        BNetStatsScraper.get_stats(player, self.gateway)
        self.player_list.append(player)
        player_offset = raw_payload.find(b'\xf7\x06', player_offset + 1) 
Example #4
Source File: test_player.py    From mau_mau_bot with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_reverse(self):
        p0 = Player(self.game, "Player 0")
        p1 = Player(self.game, "Player 1")
        p2 = Player(self.game, "Player 2")
        self.game.reverse()
        p3 = Player(self.game, "Player 3")

        self.assertEqual(p0, p3.next)
        self.assertEqual(p1, p2.next)
        self.assertEqual(p2, p0.next)
        self.assertEqual(p3, p1.next)

        self.assertEqual(p0, p2.prev)
        self.assertEqual(p1, p3.prev)
        self.assertEqual(p2, p1.prev)
        self.assertEqual(p3, p0.prev) 
Example #5
Source File: playitem.py    From service.upnext with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self):
        self.__dict__ = self._shared_state
        self.api = Api()
        self.player = Player()
        self.state = State() 
Example #6
Source File: play_tournament.py    From games-puzzles-algorithms with MIT License 5 votes vote down vote up
def main():
    args = tournament_args()

    logger = tournament_logger(verbose=args.verbose, log_file=args.log_file)

    players = [Player(invocation) for invocation in args.players]

    tournament = Tournament(players, args.num_games, args.size,
                            args.time_limit, logger)

    tournament.play_tournament()

    for p in players:
        p.exit() 
Example #7
Source File: echo.py    From usb_4_mic_array with Apache License 2.0 5 votes vote down vote up
def main():
    import time
    import datetime

    src = Source(frames_size=1600)
    route = Route()

    player = Player(pyaudio_instance=src.pyaudio_instance)

    # filename = '1.quiet.' + datetime.datetime.now().strftime("%Y%m%d.%H:%M:%S") + '.wav'
    # sink = FileSink(filename, channels=src.channels, rate=src.rate)

    src.pipeline(route)

    # src.link(sink)

    src.pipeline_start()

    time.sleep(1)
    player.play('respeaker.wav')
    time.sleep(1)
    player.play('respeaker.wav')

    for _ in range(10):
        time.sleep(1)
        if route.detect_mask == 0b111111:
            print('all channels detected')
            break

    src.pipeline_stop()

    if route.detect_mask != 0b111111:
        print('Not all channels detected') 
Example #8
Source File: main.py    From vHackXTBot-Python with MIT License 5 votes vote down vote up
def __init__(self):
        """
        Pull all variables from config.py file.
        """

        self.player = Player()
        self.database = config.database
        self.Max_point_tournament = config.Max_point_tournament
        self.BotNet_update = config.BotNet_update
        self.joinTournament = config.joinTournament
        self.tournament_potator = config.tournament_potator
        self.booster = config.booster
        self.Use_netcoins = config.Use_netcoins
        self.attacks_normal = config.attacks_normal
        self.updates = config.updates
        self.updatecount = config.updatecount
        self.maxanti_normal = config.maxanti_normal
        self.active_cluster_protection = config.active_cluster_protection
        self.mode = config.mode
        self.number_task = config.number_task
        self.min_energy_botnet = config.minimal_energy_botnet_upgrade
        self.stat = "0"
        self.wait_load = config.wait_load
        self.c = Console(self.player)
        self.u = Update(self.player)
        # disable botnet for > api v13
        self.b = Botnet(self.player)
        self.ddos = ddos.Ddos(self.player)
        self.m = Mails(self.player)
        self.init() 
Example #9
Source File: terminal_dungeon.py    From terminal_dungeon with MIT License 5 votes vote down vote up
def main(screen):
    init_curses(screen)

    game_map = Map("map1")
    player = Player(game_map)
    textures = ["wall1", "wall2", "dragon", "tree"]

    Controller(Renderer(screen, player, textures)).start()

    curses.flushinp()
    curses.endwin() 
Example #10
Source File: menu.py    From NetEase-MusicBox with MIT License 5 votes vote down vote up
def __init__(self):
        reload(sys)
        sys.setdefaultencoding('UTF-8')
        self.datatype = 'main'
        self.title = '网易云音乐'
        self.datalist = ['排行榜', '艺术家', '新碟上架', '精选歌单', '我的歌单', 'DJ节目', '打碟', '收藏', '搜索', '帮助']
        self.offset = 0
        self.index = 0
        self.presentsongs = []
        self.player = Player()
        self.ui = Ui()
        self.netease = NetEase()
        self.screen = curses.initscr()
        self.screen.keypad(1)
        self.step = 10
        self.stack = []
        self.djstack = []
        self.userid = None
        self.username = None
        try:
            sfile = file(home + "/netease-musicbox/flavor.json",'r')
            data = json.loads(sfile.read())
            self.collection = data['collection']
            self.account = data['account']
            sfile.close()
        except:
            self.collection = []        
            self.account = {} 
Example #11
Source File: monitor.py    From jellyfin-kodi with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):

        self.player = player.Player()
        self.device_id = get_device_id()
        self.listener = Listener(self)
        self.listener.start()
        self.webservice = WebService()
        self.webservice.start()
        xbmc.Monitor.__init__(self) 
Example #12
Source File: test_player.py    From mau_mau_bot with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_bluffing(self):
        p = Player(self.game, "Player 0")
        Player(self.game, "Player 01")

        self.game.last_card = c.Card(c.RED, '1')

        p.cards = [c.Card(c.RED, c.DRAW_TWO), c.Card(c.RED, '5'),
                   c.Card(c.BLUE, '0'), c.Card(c.GREEN, '5'),
                   c.Card(c.RED, '5'), c.Card(c.GREEN, c.DRAW_TWO),
                   c.Card(None, None, c.DRAW_FOUR),
                   c.Card(None, None, c.CHOOSE)]

        p.playable_cards()
        self.assertTrue(p.bluffing)

        p.cards = [c.Card(c.BLUE, '1'), c.Card(c.GREEN, '1'),
                   c.Card(c.GREEN, c.DRAW_TWO),
                   c.Card(None, None, c.DRAW_FOUR),
                   c.Card(None, None, c.CHOOSE)]

        p.playable_cards()

        p.play(c.Card(None, None, c.DRAW_FOUR))
        self.game.choose_color(c.GREEN)

        self.assertFalse(self.game.current_player.prev.bluffing) 
Example #13
Source File: test_player.py    From mau_mau_bot with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_playable_cards_on_draw_four(self):
        p = Player(self.game, "Player 0")

        self.game.last_card = c.Card(c.RED, None, c.DRAW_FOUR)
        self.game.draw_counter = 4

        p.cards = [c.Card(c.RED, c.DRAW_TWO), c.Card(c.RED, '5'),
                   c.Card(c.BLUE, '0'), c.Card(c.GREEN, '5'),
                   c.Card(c.GREEN, c.DRAW_TWO),
                   c.Card(None, None, c.DRAW_FOUR),
                   c.Card(None, None, c.CHOOSE)]

        expected = list()

        self.assertListEqual(p.playable_cards(), expected) 
Example #14
Source File: test_player.py    From mau_mau_bot with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_playable_cards_on_draw_two(self):
        p = Player(self.game, "Player 0")

        self.game.last_card = c.Card(c.RED, c.DRAW_TWO)
        self.game.draw_counter = 2

        p.cards = [c.Card(c.RED, c.DRAW_TWO), c.Card(c.RED, '5'),
                   c.Card(c.BLUE, '0'), c.Card(c.GREEN, '5'),
                   c.Card(c.GREEN, c.DRAW_TWO)]

        expected = [c.Card(c.RED, c.DRAW_TWO), c.Card(c.GREEN, c.DRAW_TWO)]

        self.assertListEqual(p.playable_cards(), expected) 
Example #15
Source File: test_player.py    From mau_mau_bot with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_playable_cards_simple(self):
        p = Player(self.game, "Player 0")

        self.game.last_card = c.Card(c.RED, '5')

        p.cards = [c.Card(c.RED, '0'), c.Card(c.RED, '5'), c.Card(c.BLUE, '0'),
                   c.Card(c.GREEN, '5'), c.Card(c.GREEN, '8')]

        expected = [c.Card(c.RED, '0'), c.Card(c.RED, '5'),
                    c.Card(c.GREEN, '5')]

        self.assertListEqual(p.playable_cards(), expected) 
Example #16
Source File: test_player.py    From mau_mau_bot with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_draw(self):
        p = Player(self.game, "Player 0")

        deck_before = len(self.game.deck.cards)
        top_card = self.game.deck.cards[-1]

        p.draw()

        self.assertEqual(top_card, p.cards[-1])
        self.assertEqual(deck_before, len(self.game.deck.cards) + 1) 
Example #17
Source File: test_player.py    From mau_mau_bot with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_leave(self):
        p0 = Player(self.game, "Player 0")
        p1 = Player(self.game, "Player 1")
        p2 = Player(self.game, "Player 2")

        p1.leave()

        self.assertEqual(p0, p2.next)
        self.assertEqual(p2, p0.next) 
Example #18
Source File: test_player.py    From mau_mau_bot with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_insert(self):
        p0 = Player(self.game, "Player 0")
        p1 = Player(self.game, "Player 1")
        p2 = Player(self.game, "Player 2")

        self.assertEqual(p0, p2.next)
        self.assertEqual(p1, p0.next)
        self.assertEqual(p2, p1.next)

        self.assertEqual(p0.prev, p2)
        self.assertEqual(p1.prev, p0)
        self.assertEqual(p2.prev, p1) 
Example #19
Source File: game_manager.py    From mau_mau_bot with GNU Affero General Public License v3.0 5 votes vote down vote up
def join_game(self, user, chat):
        """ Create a player from the Telegram user and add it to the game """
        self.logger.info("Joining game with id " + str(chat.id))

        try:
            game = self.chatid_games[chat.id][-1]
        except (KeyError, IndexError):
            raise NoGameInChatError()

        if not game.open:
            raise LobbyClosedError()

        if user.id not in self.userid_players:
            self.userid_players[user.id] = list()

        players = self.userid_players[user.id]

        # Don not re-add a player and remove the player from previous games in
        # this chat, if he is in one of them
        for player in players:
            if player in game.players:
                raise AlreadyJoinedError()

        try:
            self.leave_game(user, chat)
        except NoGameInChatError:
            pass
        except NotEnoughPlayersError:
            self.end_game(chat, user)

            if user.id not in self.userid_players:
                self.userid_players[user.id] = list()

            players = self.userid_players[user.id]

        player = Player(game, user)
        if game.started:
            player.draw_first_hand()

        players.append(player)
        self.userid_current[user.id] = player 
Example #20
Source File: main.py    From open-mtg with MIT License 5 votes vote down vote up
def start_games(amount_of_games):
    player_a_wins = 0
    player_b_wins = 0
    games_played = 0

    logging.info("Starting Open MTG. Playing {0} games".format(amount_of_games))
    for i in range(amount_of_games):
        gold_deck = deck.get_8ed_core_gold_deck()
        silver_deck = deck.get_8ed_core_silver_deck()
        current_game = game.Game([player.Player(gold_deck), player.Player(silver_deck)])
        current_game.start_game()

        if current_game.active_player.index == 0:
            logging.info("Gold player starts game")
        else:
            logging.info("Silver player starts game")
        while not current_game.is_over():
            if current_game.player_with_priority.index is 1:
                move = current_game.player_with_priority.determine_move(method="random", game=current_game)
            else:
                # move = game.player_with_priority.determine_move(method="random", game=game)
                if len(current_game.get_moves()) == 1:
                    move = current_game.get_moves()[0]
                else:
                    move = mcts.uct(current_game, itermax=5)

            current_game.make_move(move, False)

        if current_game.players[1].has_lost:
            player_a_wins += 1
        elif current_game.players[0].has_lost:
            player_b_wins += 1
        games_played += 1
        logging.info("Game {0} is over! current standings: "
                     "{1} - {2}".format(games_played, player_a_wins, player_b_wins))

    logging.info("Player A won {0} out of {1}".format(player_a_wins, games_played))
    logging.info("Player B won {0} out of {1}".format(player_b_wins, games_played))
    logging.info("Quitting Open MTG{0}{0}".format(os.linesep)) 
Example #21
Source File: game.py    From snakepit-game with The Unlicense 5 votes vote down vote up
def new_player(self, name, ws):
        self._last_id += 1
        player_id = self._last_id
        self.send_personal(ws, "handshake", name, player_id)

        self.send_personal(ws, "world", self._world)
        self.send_personal(ws, *self.top_scores_msg())
        for p in self._players.values():
            if p.alive:
                self.send_personal(ws, "p_joined", p._id, p.name, p.color, p.score)

        player = Player(player_id, name, ws)
        self._players[player_id] = player
        return player 
Example #22
Source File: server.py    From PyRoyale with GNU General Public License v3.0 5 votes vote down vote up
def block(self, reason):
        if self.blocked or len(self.player.match.players) == 1:
            return
        print("Player blocked: {0}".format(self.player.name))
        self.blocked = True
        if not self.player.dead:
            self.player.match.broadBin(0x11, Buffer().writeInt16(self.player.id), self.player.id) # KILL_PLAYER_OBJECT
        self.server.blockAddress(self.address, self.player.name, reason) 
Example #23
Source File: Server.py    From CineMonster with Apache License 2.0 5 votes vote down vote up
def command_cut(self, bot, update):
        group = update.message.chat_id
        try:
            player = player.Player(update.message.from_user.id)
            self.SESSIONS[group].player_quit(player)
            self.SESSIONS[update.message.chat_id].messenger.send(update,
                                                                 update.message.from_user.first_name + _("_left_the_game!"))
        except ValueError as e:
            self.SESSIONS[update.message.chat_id].messenger.send(
                update, update.message.from_user.first_name + e.args[0]) 
Example #24
Source File: Server.py    From CineMonster with Apache License 2.0 5 votes vote down vote up
def command_action(self, bot, update):
        group = update.message.chat_id
        try:
            player = player.Player(update.message.from_user.id)
            player.name = update.message.from_user.first_name + \
                " " + update.message.from_user.last_name
            self.SESSIONS[group].player_add(player)
            self.SESSIONS[update.message.chat_id].messenger.send(
                update, player.name + _(" joined_the_game"))
        except ValueError as e:
            self.SESSIONS[update.message.chat_id].messenger.send(
                update, update.message.from_user.first_name + e.args[0]) 
Example #25
Source File: playbackmanager.py    From service.upnext with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self):
        self.__dict__ = self._shared_state
        self.api = Api()
        self.play_item = PlayItem()
        self.state = State()
        self.player = Player() 
Example #26
Source File: game.py    From SwervinMervin with GNU General Public License v2.0 4 votes vote down vote up
def play(self):
        if s.TITLE_SCREEN:
            self.__title_screen()

        if s.PLAYER_SELECT:
            self.__player_select()

        self.player = p.Player(self.high_scores.minimum_score(), self.selected_player)

        for i, lvl in enumerate(s.LEVELS):
            self.level = l.Level(lvl)

            self.player.reset(self.level.laps)
            self.level.build()

            if s.COUNTDOWN:
                self.__countdown(i + 1)

            pygame.mixer.music.load(os.path.join("lib", self.level.song))
            pygame.mixer.music.play(-1)
            pygame.mixer.music.set_volume(s.MUSIC_VOLUME)

            while not self.player.finished():
                if self.paused:
                    self.__pause_cycle()
                else:
                    self.__game_cycle()

                pygame.display.update()
                self.clock.tick(s.FPS)

            pygame.mixer.music.fadeout(1500)

            if not self.player.alive():
                break

        if self.player.alive():
            self.__credits_screen()

        ## Post-game high scores and wait for new player.
        if self.high_scores.is_high_score(self.player.points):
            self.high_scores.add_high_score(math.trunc(self.player.points))

        self.waiting = True 
Example #27
Source File: dungeon.py    From ascii-combat with MIT License 4 votes vote down vote up
def go_new_location(self, inp):
        current_room = ROOMS[self.location]
        # Checks all DIRECTIONS, comparing them to user input
        for dir in DIRECTIONS:
            # If the DESTINATION is available and matches user input, move to it
            if current_room[dir] and dir == inp:
                target_room_id = current_room[dir]
                # Finds approperiate wording for the load screen!
                if inp == UP: load_text='Climbing'
                elif inp == DOWN: load_text='Descending'
                else: load_text = 'Walking'
                # Loader between screens
                transition(self.go_loadspeed, text=load_text + ' ' + inp + '!')
                # If target room contains enemies, prompt for combat
                if ROOMS[target_room_id][ENEMIES]:
                    # If fight
                    if self.ask_fight_or_flight(ROOMS[target_room_id], dir):
                        enemies = [give_monster(x) for x in ROOMS[target_room_id][ENEMIES]]
                        fight = combat.Combat(player.Player(self.player.name, 10, self.player.weapon), enemies)
                        fight.cmdloop()
                        self.location = target_room_id
                        self.display_current_room()
                    # If user chose retreat
                    else:
                        transition(text='Retreating cowardly to ' + current_room[NAME])
                        self.display_current_room()
                # Elif room is peaceful, change location and display room
                else:
                    self.location = current_room[dir]
                    self.display_current_room()
            # If the DESTINATION is empty
            elif dir == inp and not current_room[dir]:
                self.display_current_room()
                # Customized messages for CLIMBING/DESCENDING no destination
                if dir == UP:
                    self.error_msg(self.NO_UP)
                elif dir == DOWN:
                    self.error_msg(self.NO_DOWN)
                # N/S/E/W
                else:
                    self.error_msg('{} {}'.format(self.EMPTY_DIR, dir.upper()))

    # Generates a new dungeon structure using existing rooms