python类Game()的实例源码

TBG.py 文件源码 项目:ThatBeanGame 作者: tuchfarber 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def draw_for_hand(game: Game, player: Player) -> Dict:
    '''Draws three cards and places them in players hand'''
    result: Dict = game.deck_to_hand(player)
    error_check(result)
    update_client(game)
    return jsonify(result)
TBG.py 文件源码 项目:ThatBeanGame 作者: tuchfarber 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def create_trade(game: Game, player: Player) -> Dict:
    '''Creates new trade'''
    post_data: Dict = request.get_json()
    try:
        card_ids: List[str] = post_data['card_ids']
        other_player_name: str = post_data['other_player']
        wants: List[str] = post_data['wants'] # List of card names
    except KeyError:
        abort(400, util.error('Incorrect JSON data'))

    result = game.create_trade(player, other_player_name, card_ids, wants)
    error_check(result)
    update_client(game)
    return jsonify(result)
TBG.py 文件源码 项目:ThatBeanGame 作者: tuchfarber 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def accept_trade(game: Game, player: Player) -> Dict:
    '''Accepts a trade'''
    post_data: Dict = request.get_json()
    try:
        trade_id: str = post_data['trade_id']
        card_ids: List[str] = post_data['card_ids']
    except KeyError:
        abort(400, util.error('Incorrect JSON data'))
    result = game.accept_trade(player, trade_id, card_ids)
    error_check(result)
    update_client(game)
    return jsonify(result)
TBG.py 文件源码 项目:ThatBeanGame 作者: tuchfarber 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def reject_trade(game: Game, player: Player) -> Dict:
    '''Rejects a trade'''
    post_data: Dict = request.get_json()
    try:
        trade_id: str = post_data['trade_id']
    except KeyError:
        abort(400, util.error('Incorrect JSON data'))
    result = game.reject_trade(player, trade_id)
    error_check(result)
    update_client(game)
    return jsonify(result)
TBG.py 文件源码 项目:ThatBeanGame 作者: tuchfarber 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def buy_field(game: Game, player: Player) -> Dict:
    '''Buys third field for 3 coins'''
    result = game.buy_field(player)
    error_check(result)
    update_client(game)
    return jsonify(result)
heuristics.py 文件源码 项目:Chess-AI 作者: lamesjim 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_piece_moves_heuristics(self):
            player_points_1 = {'w': 0, 'b': 0}
            new_game = Game()
            self.assertEqual(piece_moves(new_game, player_points_1, 0.50)['w'], 16, "Should return white player's sum of total weighted legal moves")
            player_points_2 = {'w': 0, 'b': 0}
            new_game.apply_move("d2d3")
            new_game.apply_move("e7e6")
            self.assertEqual(piece_moves(new_game, player_points_2, 0.50)['w'], 29, "Should return white player's sum of total weighted legal moves after pawn moves d2d3")
heuristics.py 文件源码 项目:Chess-AI 作者: lamesjim 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_center_squares(self):
            player_points = {'w': 0, 'b': 0}
            #Initialized board
            situation_a = Game()
            center_squares(situation_a, player_points, 1)
            self.assertEqual(player_points['b'], 0, "Should not have value since no piece is in any of the center squares")
            self.assertEqual(player_points['w'], 0, "Should not have value since no piece is in any of the center squares")
            situation_b = Game("r1bqkb1r/ppp1pppp/2n2n2/3p4/3PP3/2PQ4/PP3PPP/RNB1KBNR b KQkq e3 0 4")
            center_squares(situation_b, player_points, 1)
            self.assertEqual(player_points['b'], 5, "Should have points for 2 pieces in the outer square and 1 in the inner (5)")
            self.assertEqual(player_points['w'], 8, "Should have points for 2 pieces in the outer square and 2 in the inner (8)")
multi_chess_ai.py 文件源码 项目:Chess-AI 作者: lamesjim 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __init__(self):
        self.game = Game()
        self.computer = AI(self.game, 4)
chess_ai.py 文件源码 项目:Chess-AI 作者: lamesjim 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __init__(self, board_state):
        self.game = Game(board_state)
        self.computer = AI(self.game, 5)
chess_ai.py 文件源码 项目:Chess-AI 作者: lamesjim 项目源码 文件源码 阅读 64 收藏 0 点赞 0 评论 0
def get_moves(self, board_state=None):
        if board_state == None:
            board_state = str(self.game)
        possible_moves = []
        for move in Game(board_state).get_moves():
            if (len(move) < 5 or move[4] == "q"):
                clone = Game(board_state)
                clone.apply_move(move)
                node = Node(str(clone))
                node.algebraic_move = move
                possible_moves.append(node)
        return possible_moves
twitter.py 文件源码 项目:relocaliser 作者: very-scary-scenario 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def start_new_game():
    game = Game()
    listener = TwitterGame(api, game, api.update_status(game.clue).id)
    return listener
menu.py 文件源码 项目:PyPong 作者: Starlight42 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, screen: pygame.Surface):
        super(MainMenu, self).__init__(screen)
        self.game = Game(self.screen)
        screen_portion = (self.screen.get_width() / 2, self.screen.get_height() / 3)
        screen_portion1 = (screen_portion[0], screen_portion[1] * 1.5)
        screen_portion2 = (screen_portion[0], screen_portion[1] * 2)

        self.menu = [MenuItem(self.screen, '1 PLAYER', screen_portion),
                     MenuItem(self.screen, '2 PLAYER', screen_portion1),
                     MenuItem(self.screen, 'QUIT MENU', screen_portion2)]
multiAgent.py 文件源码 项目:xiao_multiagent 作者: namidairo777 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def generateSuccessor(self, action, agentIndex):
        """
        Returns the successor state after the specified pursuer takes action
        """
        # Check that successors exist
        if self.isWin() or self.isLose(): 
            # time.sleep(2)
            raise Exception('Game over')

        # Copy current state
        state = GameState(self)

        # Let agent's logic deal with its action's effects on the board
        if agentIndex == 0:  # Pacman is moving
            # state.data._eaten = [False for i in range(state.getNumAgents())]
            TargetRules.applyAction( state, action )
        else:                # A ghost is moving
            PursuerRules.applyAction( state, action, agentIndex )


        # Book keeping
        #state.data._agentMoved = agentIndex
        state.data.score += state.data.scoreChange
        GameState.explored.add(self)
        GameState.explored.add(state)
        return state
multiAgent.py 文件源码 项目:xiao_multiagent 作者: namidairo777 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def newGame(self, layout, targetAgent, pursuerAgents, display, catchExceptions = False):

        agents = [targetAgent] + pursuerAgents[:layout.getNumPursuers()]

        initState = GameState()
        initState.initialize(layout, len(pursuerAgents))
        game = Game(agents, display, self, catchExceptions = catchExceptions)
        game.state = initState
        self.initialState = initState.deepCopy()
        return game
test_player.py 文件源码 项目:mau_mau_bot 作者: jh0ker 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def setUp(self):
        self.game = Game(None)
pacman.py 文件源码 项目:Berkeley-AI-PacMan-Lab-1 作者: jrios6 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def newGame( self, layout, pacmanAgent, ghostAgents, display, quiet = False, catchExceptions=False):
    agents = [pacmanAgent] + ghostAgents[:layout.getNumGhosts()]
    initState = GameState()
    initState.initialize( layout, len(ghostAgents) )
    game = Game(agents, display, self, catchExceptions=catchExceptions)
    game.state = initState
    self.initialState = initState.deepCopy()
    self.quiet = quiet
    return game
pacman.py 文件源码 项目:AI_MinMax_AlphaBetaPruning 作者: astraey 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def newGame( self, layout, pacmanAgent, ghostAgents, display, quiet = False, catchExceptions=False):
        agents = [pacmanAgent] + ghostAgents[:layout.getNumGhosts()]
        initState = GameState()
        initState.initialize( layout, len(ghostAgents) )
        game = Game(agents, display, self, catchExceptions=catchExceptions)
        game.state = initState
        self.initialState = initState.deepCopy()
        self.quiet = quiet
        return game
scenarios.py 文件源码 项目:Colony 作者: DeflatedPickle 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def start_game(self, *args):
        if self.treeview.focus() != "":
            if not self.treeview.item(self.treeview.focus())["text"].startswith("-"):
                self.parent.canvas.delete("all")

                self.parent.canvas.unbind("<Configure>")
                self.parent.canvas.bind("<Configure>", self.parent.canvas.on_resize)

                self.game = Game(self.parent)
                self.spawn(self.scenario_list[self.selected_scenario])
                self.game.update_families()

                self.game.recreate_taskbar()

        del args
pacman.py 文件源码 项目:2017-planning-with-simulators 作者: aig-upf 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def newGame( self, layout, pacmanAgent, ghostAgents, display, quiet = False, catchExceptions=False):
        agents = [pacmanAgent] + ghostAgents[:layout.getNumGhosts()]
        initState = GameState()
        initState.initialize( layout, len(ghostAgents) )
        game = Game(agents, display, self, catchExceptions=catchExceptions)
        game.state = initState
        self.initialState = initState.deepCopy()
        self.quiet = quiet
        return game
test.py 文件源码 项目:Tiger-Problem-POMDP 作者: malayandi 项目源码 文件源码 阅读 13 收藏 0 点赞 0 评论 0
def testStateAfterListen(self):
        game = Game()
        # testing 10 times to account for uncertainty
        for i in range(10):
            old_state = game.getState()
            game.respond("listen")
            new_state = game.getState()
            self.assertFalse(old_state != new_state)


问题


面经


文章

微信
公众号

扫码关注公众号