Пример #1
0
    def post(self):
        hash = self.request.url.split("/")[3]
        
        if (self.request.get('coordinates')):
            channel.send_message(hash+'tv', self.request.get('coordinates'))
            
        if (self.request.get('playerstop')):
            GS = Game.pull(hash)
            players = GS.players
            randomkeyword = wordlist[ (random.randint(0,len(wordlist)-1)) ]
            GS.currentKeyword = randomkeyword

            if ( GS.currentIndex < GS.totalPlayer - 1):
                GS.currentIndex += 1
            else:
                GS.currentIndex = 0
            
            GS.currentPlayer = players[GS.currentIndex].split("_")[1]
            
            for playerid in players:
                playerstandby = playerid.split("_")[1]
                if( GS.currentPlayer == playerstandby):
                     logging.info("SENDING READY TO "+GS.currentPlayer)
                     channel.send_message(hash + 'mobile' + GS.currentPlayer, CMD.get("PLAYER_READY", GS.currentPlayer, {"keyword":GS.currentKeyword}))
                     channel.send_message(hash + 'tv' , CMD.get("PLAYER_READY", GS.currentPlayer, {}))
                else:
                    channel.send_message(hash + 'mobile' + playerstandby, CMD.get("PLAYER_STOP", playerstandby, {"keyword":randomkeyword}))
            

            Game.push(GS)
Пример #2
0
    def __init__(self, parent, *args, **kwargs):
        tk.Frame.__init__(self, parent, *args, **kwargs)
        self.parent = parent

        self.hand_frame_height = 315
        self.result_text = tk.StringVar()
        self.image_manager = ImageManager()
        self.result_label = tk.Label(self,
                                     font=('', 24),
                                     textvariable=self.result_text)
        self.dealer_hand_frame = HandFrame(self, bg='#f0f0f0', bd=10)
        self.player_hand_frame = HandFrame(self, bg='#f0f0f0', bd=10)
        self.hit_button = tk.Button(self,
                                    text='Hit',
                                    font=('', 16),
                                    command=self.hit_button_pressed)
        self.pass_button = tk.Button(self,
                                     text='Pass',
                                     font=('', 16),
                                     command=self.pass_button_pressed)
        self.play_button = tk.Button(self,
                                     text='Play',
                                     font=('', 20),
                                     command=self.play_button_pressed)
        self.parent = parent
        self.game = Game()
        self.resized_card_images = {}

        self.hidden_card = Card('', '', 'red_back', 0)
        self.add_card_image(self.hidden_card)

        self.play_button.place(rely=0.47, relx=0.46)
Пример #3
0
    def _initNew( self, player1, player2 ):
        ## Create empty board
        self.board = Board()
        
        ## Save player info
        self.player1 = int( player1 )
        self.player2 = int( player2 )
        
        ## Save status
        self.status = "CHALLENGE"
        self.winner = None
        self.turn = 1

        ## Create new Game instance
        self.game = Game( player1 = self.player1, player2 = self.player2,
                          status = self.status, board = self.board.serialize(),
                          turn = self.turn, winner = self.winner, parent = Game.games_key() )
        
        ## Save new game to database
        key = self.game.put()
        self.gameid = key.id()
        
        ## Send an email to player 2
        player1_name = User.get_user_name( self.player1 )
        player2_user = User.by_id( self.player2 )
        HexEmail.sendChallenge( player2_user.email, player1_name )
Пример #4
0
    def post(self):
        
        hash = self.request.url.split("/")[3]
        player = self.request.url.split("/")[5]

        GS = Game.pull(hash)
        
        if (self.request.get('coordinates')):
            channel.send_message(hash+'tv', CMD.get("DRAW", player, self.request.get("coordinates"))) 

        if (self.request.get('readyAck')):
        # Notify Tv of player connection
            logging.info(GS.currentPlayer)

            if (GS.currentPlayer == player):
                randomkeyword = wordlist[random.randint(0,len(wordlist)-1)]
                GS.currentKeyword = randomkeyword
                channel.send_message(hash + 'tv', CMD.get("PLAYER_READY", player, {}))
               
                # defer sending event to mobile
                time.sleep(0.5)
                channel.send_message(hash + 'mobile' + player, CMD.get("PLAYER_READY", player, {"keyword":randomkeyword}))
                logging.info("SENDING PLAYER READY TO "+player);
                
            else:
                for playerid in GS.players:
                    playerstandby = playerid.split("_")[1]
                    if (not playerstandby == GS.currentPlayer):
                        channel.send_message(hash + 'mobile' + playerstandby, CMD.get("PLAYER_STOP", playerstandby, {"keyword":GS.currentKeyword}))
                        logging.info("SENDING PLAYER STOP TO "+playerstandby);
        if (self.request.get('playerstart')):
            channel.send_message(hash + 'tv', CMD.get("PLAYER_START", player, {}))
            
        if (player != GS.currentPlayer and self.request.get('playerattack')):
            channel.send_message(hash + 'mobile' + GS.currentPlayer, CMD.get("PLAYER_ATTACKED", GS.currentPlayer, {}))
            
        if (self.request.get('playerfound')):
            """players = GS.players
            randomkeyword = wordlist[random.randrange(0,len(wordlist))]
            GS.currentKeyword = randomkeyword
            
            for playerid in players:
                playerstandby = playerid.split("_")[1]
                channel.send_message(hash + 'mobile' + playerstandby, CMD.get("PLAYER_STOP", playerstandby, {"keyword":randomkeyword}))
            
            if ( not GS.currentIndex == GS.totalPlayer - 2):
                GS.currentIndex += 1
            else:
                GS.currentIndex = 0
            
            GS.currentPlayer = players[GS.currentIndex].split("_")[1]"""
            channel.send_message(hash + 'tv', CMD.get("PLAYER_FOUND", player, {}))
            #channel.send_message(hash + 'mobile' + GS.currentPlayer, CMD.get("PLAYER_READY", GS.currentPlayer, {"keyword":GS.currentKeyword}))
        
        Game.push(GS)
Пример #5
0
Файл: Home.py Проект: rywit/Hex
 def _get_pending( self, user_id ):
     parent = Game.games_key()
     waiting = Game.all().filter('player1 =', user_id ).filter( "status =", "CHALLENGE" ).ancestor( parent ).fetch( limit = 10 )
     waiting = list( waiting )
     waiting_games = self._build_game_set( waiting )
     
     pending = Game.all().filter('player2 =', user_id ).filter( "status =", "CHALLENGE" ).ancestor( parent ).fetch( limit = 10 )
     pending = list( pending )
     pending_games = self._build_game_set( pending )
     
     return waiting_games, pending_games 
Пример #6
0
 def post(self):
     # Generate Hash
     hash = hashlib.sha1()
     hash.update(str(time.time()))
     hash = hash.hexdigest()[:4]
     
     # Create GameState to store data info
     GS = GameState(key_name = hash,
                        currentPlayer = "-1",
                        currentIndex = 0,
                        currentKeyword = "",
                        totalPlayer = 0,
                        scorePlayers = ["0"]
                        )
     Game.push(GS)
     
     # redirect to /hash/tv
     self.redirect("/"+hash+"/tv")
Пример #7
0
    def get(self):
        hash = self.request.url.split("/")[3]
        player_str = self.request.url.split("/")[5]
        GS = Game.pull(hash)

        
        if len(GS.players) == 0 or (hash+"_"+player_str) not in GS.players:
            logging.info("creating channel");
            token = channel.create_channel( hash + 'mobile' + player_str,ChannelTimeout)
            
            #Create a player and push it in the DB
            playerDb = Player(key_name = hash + "_" + player_str, player_name = player_str, player_token = token)
            
            GS.players.append(hash+"_"+player_str)
            GS.totalPlayer += 1
            PlayerManager.push(playerDb)
        else:
            logging.info("player already existing, restoring token")
            #TODO : Token are expiring so they shouldn't be stored
            token = PlayerManager.pull( (hash+"_"+player_str) ).player_token
        
        logging.info("____TOKEN "+token)

        if (self.request.get('message')):
            channel.send_message(hash+'tv', self.request.get('message'))
        
        #TODO: update with next version
        if (GS.currentPlayer == "-1"):
            GS.currentPlayer = player_str
        
        Game.push(GS)

        channel.send_message(hash+'tv', CMD.get("JOIN", player_str, {}))
        
        template2handler(self,'mobile','mobile-game.html',{
                                                   'client': 'mobile',
                                                   'title': 'You are the '+player_str+' !',
                                                   'token': token
                                                   })
Пример #8
0
 def start_new_game(self):
     users = [
         User.get_or_create(display_name=self.black_name,
                            defaults={'token': '1'})[0],
         User.get_or_create(display_name=self.white_name,
                            defaults={'token': '2'})[0]
     ]
     timer = Timer()
     players = {Color.black: users[0], Color.white: users[1]}
     self.game = Game.new_game(size=9,
                               rule_set=get_japanese_rule_set(),
                               players=players,
                               timer=timer)
     self.game.save()
     self.api.start_game(self.game)
     return self.game
Пример #9
0
def main():
    app = QtWidgets.QApplication([])

    gameMessage = QtWidgets.QLabel('Welcome to Number Guess')

    guess = Guess(gameMessage)
    difficulty = Difficulty(gameMessage)
    previous_guesses = PreviousGuesses()

    highscores = Highscores(db, 'chris', difficulty)
    game = Game(guess, previous_guesses, highscores, difficulty, gameMessage)
    # username_window = UsernameWindow()
    # username_window.show()
    game_window = GameWindow(game, gameMessage)
    game_window.show()
    sys.exit(app.exec_())
Пример #10
0
    def _initExisting( self, gameid ):
        
        self.gameid = gameid
        
        ## Retrieve game from database
        self.game = Game.by_id( int( gameid ) )

        ## Load up player info
        self.player1 = self.game.player1
        self.player2 = self.game.player2
        self.status = self.game.status
        self.turn = self.game.turn
        self.winner = self.game.winner

        ## Create a new board instance        
        self.board = Board( self.game.board )
Пример #11
0
class GameFrame(tk.Frame):
    def __init__(self, parent, *args, **kwargs):
        tk.Frame.__init__(self, parent, *args, **kwargs)
        self.parent = parent

        self.hand_frame_height = 315
        self.result_text = tk.StringVar()
        self.image_manager = ImageManager()
        self.result_label = tk.Label(self,
                                     font=('', 24),
                                     textvariable=self.result_text)
        self.dealer_hand_frame = HandFrame(self, bg='#f0f0f0', bd=10)
        self.player_hand_frame = HandFrame(self, bg='#f0f0f0', bd=10)
        self.hit_button = tk.Button(self,
                                    text='Hit',
                                    font=('', 16),
                                    command=self.hit_button_pressed)
        self.pass_button = tk.Button(self,
                                     text='Pass',
                                     font=('', 16),
                                     command=self.pass_button_pressed)
        self.play_button = tk.Button(self,
                                     text='Play',
                                     font=('', 20),
                                     command=self.play_button_pressed)
        self.parent = parent
        self.game = Game()
        self.resized_card_images = {}

        self.hidden_card = Card('', '', 'red_back', 0)
        self.add_card_image(self.hidden_card)

        self.play_button.place(rely=0.47, relx=0.46)

    def update_hands(self, dealer_hand, player_hand, hidden_card=True):
        self.dealer_hand_frame.place(rely=0.10, relheight=0.35, relwidth=1)
        self.dealer_hand_frame.show_cards(dealer_hand, hidden_card)
        self.player_hand_frame.place(rely=0.55, relheight=0.35, relwidth=1)
        self.player_hand_frame.show_cards(player_hand, False)

    def end_game(self, result):
        if result == 'win':
            self.result_text.set('You won')
        elif result == 'tie':
            self.result_text.set("It's a tie")
        elif result == 'lose':
            self.result_text.set('You lost')
        self.result_label.pack(side='top', pady=(10, 0))
        self.hit_button.place_forget()
        self.pass_button.place_forget()
        self.update_hands(self.game.dealer_hand, self.game.player_hand, False)
        self.game.put_cards_back()

        self.play_button.place(rely=0.47, relx=0.46)

    def hit_button_pressed(self):
        self.game.player_hand.add_card(self.game.deck.deal())
        self.add_card_image(self.game.player_hand.cards[-1])
        self.update_hands(self.game.dealer_hand, self.game.player_hand, True)
        if self.game.player_hand.is_hand_over():
            self.end_game('lose')

    def pass_button_pressed(self):
        while (self.game.dealer_hand.value < self.game.player_hand.value) and \
                self.game.dealer_hand.value < 17:
            self.game.dealer_hand.add_card(self.game.deck.deal())
            self.add_card_image(self.game.dealer_hand.cards[-1])

        if self.game.dealer_hand.is_hand_over():
            self.end_game('win')
        elif self.game.player_hand.value > self.game.dealer_hand.value:
            self.end_game('win')
        elif self.game.player_hand.value == self.game.dealer_hand.value:
            self.end_game('tie')
        else:
            self.end_game('lose')

    def play_button_pressed(self):
        self.result_label.pack_forget()
        self.hit_button.place(rely=0.48, relx=0.32)
        self.pass_button.place(rely=0.48, relx=0.65)
        self.play_button.place_forget()

        self.game.start()

        for card in self.game.dealer_hand.cards:
            self.add_card_image(card)
        for card in self.game.player_hand.cards:
            self.add_card_image(card)

        self.update_hands(self.game.dealer_hand, self.game.player_hand, True)

    def add_card_image(self, card):
        card_code_suit = card.code + card.suit[
            0] if card.code != 'red_back' else card.code
        if card_code_suit not in self.resized_card_images:
            card_name = card_code_suit + '.png'
            self.resized_card_images[
                card_code_suit] = self.image_manager.add_image(
                    card_name, self.hand_frame_height * 0.8)
Пример #12
0
class OptionsFrame(tk.Frame):
    def __init__(self, parent, *args, **kwargs):
        tk.Frame.__init__(self, parent, *args, **kwargs)
        self.parent = parent
        self.games_amount = tk.IntVar(value=100)
        self.use_decision_table_value = tk.BooleanVar()
        self.dealer_threshold = tk.IntVar(value=17)
        self.player_threshold = tk.IntVar(value=17)
        self.result_percentage = tk.StringVar()
        self.decision_table_value = tk.BooleanVar()

        self.games_amount_label = tk.Label(
            self, text='Number of rounds to play (max 10000):', bg='#cccccc')
        self.games_amount_entry = tk.Entry(self,
                                           width=5,
                                           textvariable=self.games_amount)
        self.use_decision_table_checkbox = tk.Checkbutton(
            self,
            text='Use decision table for player',
            command=self.use_decision_table_checkbox_clicked,
            variable=self.use_decision_table_value,
            bg='#cccccc')
        self.dealer_threshold_label = tk.Label(
            self, text='Dealer\'s threshold for hitting:', bg='#cccccc')
        self.dealer_threshold_entry = tk.Entry(
            self, width=2, textvariable=self.dealer_threshold)
        self.player_threshold_label = tk.Label(
            self, text='Player\'s threshold for hitting:', bg='#cccccc')
        self.player_threshold_entry = tk.Entry(
            self, width=2, textvariable=self.player_threshold)
        self.simulation_button = tk.Button(
            self,
            text='Simulate',
            command=self.simulate_button_pressed,
            bg='#cccccc')
        self.log_text = tk.Text(self, height=10, width=32, cursor="arrow")
        self.log_scrollbar = tk.Scrollbar(self)
        self.result_percentage_label = tk.Label(
            self, textvariable=self.result_percentage, bg='#cccccc')
        self.decision_table_frame = DecisionTableFrame(self, bg='#cccccc')
        self.decision_table_aces_frame = DecisionTableAcesFrame(self,
                                                                bg='#cccccc')

        self.games_amount_label.grid(row=0,
                                     column=0,
                                     sticky='w',
                                     padx=2,
                                     pady=(6, 0))
        self.games_amount_entry.grid(row=0, column=1, sticky='w', padx=2)
        self.use_decision_table_checkbox.grid(row=1,
                                              column=0,
                                              sticky='w',
                                              padx=2)
        self.dealer_threshold_label.grid(row=2, column=0, sticky='w', padx=2)
        self.dealer_threshold_entry.grid(row=2, column=1, sticky='w', padx=2)
        self.player_threshold_label.grid(row=3, column=0, sticky='w', padx=2)
        self.player_threshold_entry.grid(row=3, column=1, sticky='w', padx=2)
        self.simulation_button.grid(row=5,
                                    column=0,
                                    sticky='s',
                                    padx=(50, 0),
                                    pady=(12, 0))
        self.log_text.grid(row=6, columnspan=2, column=0, sticky='nsw', padx=2)
        self.log_scrollbar.grid(row=6, column=2, sticky='nsw')
        self.log_scrollbar.config(command=self.log_text.yview)
        self.log_text.configure(yscrollcommand=self.log_scrollbar.set,
                                state='disabled')

        self.simulation_game = Game()

    def use_decision_table_checkbox_clicked(self):
        if self.use_decision_table_value.get():
            self.player_threshold_label.configure(foreground='gray')
            self.player_threshold_entry.grid_forget()

            self.decision_table_frame.grid(row=8,
                                           column=0,
                                           columnspan=2,
                                           sticky='s')
            self.decision_table_aces_frame.grid(row=9,
                                                column=0,
                                                columnspan=2,
                                                sticky='s')

        else:
            self.player_threshold_label.configure(foreground='black')
            self.player_threshold_entry.grid(row=3, column=1, sticky='w')

            self.decision_table_frame.grid_forget()
            self.decision_table_aces_frame.grid_forget()

    def simulate_button_pressed(self):
        if self.games_amount.get() > 10_000:
            self.games_amount.set(10_000)
        self.log_text.configure(state='normal')
        self.log_text.delete('1.0', tk.END)
        self.log_text.configure(state='disabled')
        win_counter = 0
        tie_counter = 0
        loss_counter = 0

        for i in range(self.games_amount.get()):
            self.simulation_game.start()

            result = self.play_simulation(self.dealer_threshold.get(),
                                          self.player_threshold.get(),
                                          self.use_decision_table_value.get())
            if result == 'WIN':
                win_counter += 1
            if result == 'TIE':
                tie_counter += 1
            if result == 'LOSS':
                loss_counter += 1
            round_summary = 'Dealer: {'
            cards_code = []

            for card in self.simulation_game.dealer_hand.cards:
                cards_code.append(str(card.code + card.suit[0]))
            round_summary += ' '.join(cards_code) + '} (' + str(
                self.simulation_game.dealer_hand.value) + ')\nPlayer: {'
            cards_code = []
            for card in self.simulation_game.player_hand.cards:
                cards_code.append(str(card.code + card.suit[0]))
            round_summary += ' '.join(cards_code) + '} (' + str(
                self.simulation_game.player_hand.value) + ')\n'
            round_summary += result + '\n***\n'
            self.simulation_game.put_cards_back()
            self.log_text.configure(state='normal')
            self.log_text.insert(tk.END, round_summary + '\n')
            self.log_text.configure(state='disabled')

        win_percentage = round(win_counter / self.games_amount.get() * 100, 3)
        tie_percentage = round(tie_counter / self.games_amount.get() * 100, 3)
        loss_percentage = round(loss_counter / self.games_amount.get() * 100,
                                3)
        self.result_percentage.set('Win percentage: ' + str(win_percentage) +
                                   '%' + '| Tie: ' + str(tie_percentage) +
                                   '%' + '| Lose: ' + str(loss_percentage) +
                                   '%')
        self.result_percentage_label.grid(row=7,
                                          column=0,
                                          columnspan=2,
                                          sticky='w')

    def play_simulation(self,
                        dealer_threshold=17,
                        player_threshold=17,
                        use_decision_table=False):

        player_hand_value = self.simulation_game.player_hand.value
        dealer_hand_value = self.simulation_game.dealer_hand.value
        dealer_visible_card_value = self.simulation_game.dealer_hand.cards[
            1].value

        if player_hand_value != 21:
            if use_decision_table:
                if self.simulation_game.player_hand.aces > 0:
                    decision_table = self.decision_table_aces_frame.decision_table_aces_value_list
                else:
                    decision_table = self.decision_table_frame.decision_table_value_list
                decision = decision_table[20 - player_hand_value][
                    dealer_visible_card_value - 2]
                while decision != 'S':
                    self.simulation_game.player_hand.add_card(
                        self.simulation_game.deck.deal())
                    player_hand_value = self.simulation_game.player_hand.value
                    if player_hand_value > 20:
                        decision = 'S'
                    else:
                        decision = decision_table[20 - player_hand_value][
                            dealer_visible_card_value - 2]

            else:
                while player_hand_value < player_threshold:
                    self.simulation_game.player_hand.add_card(
                        self.simulation_game.deck.deal())
                    player_hand_value = self.simulation_game.player_hand.value

        if player_hand_value > 21:
            return 'LOSS'

        while (dealer_hand_value <
               player_hand_value) and dealer_hand_value < dealer_threshold:
            self.simulation_game.dealer_hand.add_card(
                self.simulation_game.deck.deal())
            dealer_hand_value = self.simulation_game.dealer_hand.value

        if dealer_hand_value > 21:
            return 'WIN'
        if dealer_hand_value == player_hand_value:
            return 'TIE'
        if dealer_hand_value > player_hand_value:
            return 'LOSS'
        else:
            return 'WIN'
Пример #13
0
def game_started(sid, data):
    game = Game.from_sgf(data['game_sgf'])
    game.save()
Пример #14
0
 def setUp(self):
     self.game = Game()
     self.player = Player("Jake")
     self.deck = Deck()
     self.deck.populate()
Пример #15
0
class GameView():
    
    def __init__( self, **kwargs ):
        
        ## If a game id was provided, initialize the existing game
        if "gameid" in kwargs:
            self._initExisting( kwargs[ "gameid" ] )
        ## Otherwise, intialize a new game between the two given players
        else:
            self._initNew( kwargs[ "player1" ], kwargs[ "player2" ] )

    def _initNew( self, player1, player2 ):
        ## Create empty board
        self.board = Board()
        
        ## Save player info
        self.player1 = int( player1 )
        self.player2 = int( player2 )
        
        ## Save status
        self.status = "CHALLENGE"
        self.winner = None
        self.turn = 1

        ## Create new Game instance
        self.game = Game( player1 = self.player1, player2 = self.player2,
                          status = self.status, board = self.board.serialize(),
                          turn = self.turn, winner = self.winner, parent = Game.games_key() )
        
        ## Save new game to database
        key = self.game.put()
        self.gameid = key.id()
        
        ## Send an email to player 2
        player1_name = User.get_user_name( self.player1 )
        player2_user = User.by_id( self.player2 )
        HexEmail.sendChallenge( player2_user.email, player1_name )
                
    def _initExisting( self, gameid ):
        
        self.gameid = gameid
        
        ## Retrieve game from database
        self.game = Game.by_id( int( gameid ) )

        ## Load up player info
        self.player1 = self.game.player1
        self.player2 = self.game.player2
        self.status = self.game.status
        self.turn = self.game.turn
        self.winner = self.game.winner

        ## Create a new board instance        
        self.board = Board( self.game.board )
        
    def update_game( self, user, row, col ):
        
        ## Make sure the correct user is making the move
        player_to_move = self.player_to_move()
        
        ## If the wrong player moved, raise an exception
        if str( user.key().id() ) != str( player_to_move ):
            raise WrongTurnException( "It is not your turn to move" )
        
        ## If this game is already complete, raise an exception
        if self.status == "COMPLETE":
            raise AlreadyCompleteException( "The game is already finished" )
        
        ## Update the board
        self.board.update_board( row, col, self.turn )
        
        ## Check if game is now finished
        if self.board.is_finished( self.turn ):
            self.winner = self.player_to_move()
            self.status = "COMPLETE"
        else:
            ## Flip who's turn it is to move
            self.turn = ( self.turn % 2 ) + 1
    
        ## Update the underlying Game
        self.game.update_state( self.turn, self.board.serialize(), self.status, self.winner )
        
        ## Save underlying Game to the database
        self.game.put()
        
        
    def update_status( self, new_status ):
        self.status = new_status
        self.game.status = new_status
        self.game.put()
        
    def player_to_move( self ):
        ## Make sure the correct user is making the move
        return self.player1 if self.turn == 1 else self.player2
    
    def is_my_turn( self, user_id ):
        to_move = self.player_to_move()
        return self.status == "ACTIVE" and to_move == user_id
        
    def get_detailed_status( self, user_id ):

        ## Pending games
        if self.status == "CHALLENGE":
            player2_name = User.get_user_name( self.player2 )
            return "Waiting for %s to accept challenge" % player2_name
        
        ## Active games
        if self.is_my_turn( user_id ):
            return "My move"
        if self.status == "ACTIVE":
            return "Opponent's turn"

        ## Completed games
        if self.status == "COMPLETE":
            winner_name = User.get_user_name( self.winner )
            return "%s has won" % winner_name
Пример #16
0
def move_made(sid, data):
    move = Move.from_sgf(data['move_sgf'])
    move.save()

    GameMove(game=Game.get(uuid=data['game_uuid']), move=move).save()
Пример #17
0
os.environ['http_proxy'] = proxy
os.environ['HTTP_PROXY'] = proxy
os.environ['https_proxy'] = proxy
os.environ['HTTPS_PROXY'] = proxy

# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
                    level=logging.INFO)

max_len=4

logger = logging.getLogger(__name__)

SUGGEST_CARD, GENDER, PHOTO, LOCATION, BIO = range(5)

game = Game(-1001390724742)
conversation_handler = None

for i in range(0, 10):
    game.add_player(Player(i, "user " + str(i)))
game.add_player(Player(237713674, "mikaeel"))


def start(update, context):
    reply_keyboard = [['Boy', 'Girl', 'Other']]
    keyboard = [
        [InlineKeyboardButton("0", callback_data=str(0)),
         InlineKeyboardButton("4", callback_data=str(5)),
         InlineKeyboardButton("4", callback_data=str(0))]
    ]
    reply_markup = InlineKeyboardMarkup(keyboard)
Пример #18
0
    def __init__(self, parent, *args, **kwargs):
        tk.Frame.__init__(self, parent, *args, **kwargs)
        self.parent = parent
        self.games_amount = tk.IntVar(value=100)
        self.use_decision_table_value = tk.BooleanVar()
        self.dealer_threshold = tk.IntVar(value=17)
        self.player_threshold = tk.IntVar(value=17)
        self.result_percentage = tk.StringVar()
        self.decision_table_value = tk.BooleanVar()

        self.games_amount_label = tk.Label(
            self, text='Number of rounds to play (max 10000):', bg='#cccccc')
        self.games_amount_entry = tk.Entry(self,
                                           width=5,
                                           textvariable=self.games_amount)
        self.use_decision_table_checkbox = tk.Checkbutton(
            self,
            text='Use decision table for player',
            command=self.use_decision_table_checkbox_clicked,
            variable=self.use_decision_table_value,
            bg='#cccccc')
        self.dealer_threshold_label = tk.Label(
            self, text='Dealer\'s threshold for hitting:', bg='#cccccc')
        self.dealer_threshold_entry = tk.Entry(
            self, width=2, textvariable=self.dealer_threshold)
        self.player_threshold_label = tk.Label(
            self, text='Player\'s threshold for hitting:', bg='#cccccc')
        self.player_threshold_entry = tk.Entry(
            self, width=2, textvariable=self.player_threshold)
        self.simulation_button = tk.Button(
            self,
            text='Simulate',
            command=self.simulate_button_pressed,
            bg='#cccccc')
        self.log_text = tk.Text(self, height=10, width=32, cursor="arrow")
        self.log_scrollbar = tk.Scrollbar(self)
        self.result_percentage_label = tk.Label(
            self, textvariable=self.result_percentage, bg='#cccccc')
        self.decision_table_frame = DecisionTableFrame(self, bg='#cccccc')
        self.decision_table_aces_frame = DecisionTableAcesFrame(self,
                                                                bg='#cccccc')

        self.games_amount_label.grid(row=0,
                                     column=0,
                                     sticky='w',
                                     padx=2,
                                     pady=(6, 0))
        self.games_amount_entry.grid(row=0, column=1, sticky='w', padx=2)
        self.use_decision_table_checkbox.grid(row=1,
                                              column=0,
                                              sticky='w',
                                              padx=2)
        self.dealer_threshold_label.grid(row=2, column=0, sticky='w', padx=2)
        self.dealer_threshold_entry.grid(row=2, column=1, sticky='w', padx=2)
        self.player_threshold_label.grid(row=3, column=0, sticky='w', padx=2)
        self.player_threshold_entry.grid(row=3, column=1, sticky='w', padx=2)
        self.simulation_button.grid(row=5,
                                    column=0,
                                    sticky='s',
                                    padx=(50, 0),
                                    pady=(12, 0))
        self.log_text.grid(row=6, columnspan=2, column=0, sticky='nsw', padx=2)
        self.log_scrollbar.grid(row=6, column=2, sticky='nsw')
        self.log_scrollbar.config(command=self.log_text.yview)
        self.log_text.configure(yscrollcommand=self.log_scrollbar.set,
                                state='disabled')

        self.simulation_game = Game()
from Models.Game import Game

game = Game()
game.start()
Пример #20
0
Файл: Home.py Проект: rywit/Hex
 def _get_finished( self, user_id ):
     parent = Game.games_key()
     games1 = Game.all().filter('player1 =', user_id ).filter( "status =", "COMPLETE" ).ancestor( parent ).fetch( limit = 10 )
     games2 = Game.all().filter('player2 =', user_id ).filter( "status =", "COMPLETE" ).ancestor( parent ).fetch( limit = 10 )
     games = list( games1 ) + list( games2 )
     return self._build_game_set( games ) 
Пример #21
0
import threading
import time

from Models.Game import Game
from Models.Player import Player

game = Game(0)
for i in range(0, 10):
    game.add_player(Player(i, "user " + str(i)))


def run_game():
    while len(game.players) > 2:
        print("number of players in this turn: " + str(len(game.players)))
        print("turn started, you can suggest cards")
        time.sleep(20)
        game.start_vote_time()
        print("vote time started, you can vote")
        time.sleep(20)
        print("turn ended")
        game.end_turn()
        game.start_new_turn()


th = threading.Thread(target=run_game)
th.start()

while True:
    print("you can perform query")
    query = input()
    if query.split()[0] == 'suggest_card':