当前位置: 首页>>代码示例>>Python>>正文


Python GameState.getBuildings方法代码示例

本文整理汇总了Python中GameState.GameState.getBuildings方法的典型用法代码示例。如果您正苦于以下问题:Python GameState.getBuildings方法的具体用法?Python GameState.getBuildings怎么用?Python GameState.getBuildings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GameState.GameState的用法示例。


在下文中一共展示了GameState.getBuildings方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Controller

# 需要导入模块: from GameState import GameState [as 别名]
# 或者: from GameState.GameState import getBuildings [as 别名]

#.........这里部分代码省略.........
            self.state.phase = 'ended'
            self.state.phaseinfo = 'stalemate'
            return True
        else:
            return False


    def turnEnded(self):
        return self.state.phase == 'endturn'

    def roll(self):
        self.state.lastroll = random.randint(1,6) + random.randint(1,6)
        #self.updateView()
        if self.state.lastroll == 7:
            turn = self.state.turn
            #resource discard
            for i in range(0, self.nplayers):
                self.state.turn = i
                nresources = self.state.countResources(i)
                if nresources > 7:
                    reqresources = (nresources+1)/2
                    self.state.phase = "discard"
                    while nresources > reqresources:
                        # number you need to discard
                        self.state.phaseinfo = nresources - reqresources
                        # should we change whose turn it is in state?
                        move = self.getValidMove(i)
                        self.doMove(move)
                        nresources = self.state.countResources(i)
            self.state.turn = turn
            #robber movement
            self.moveRobber()
        else: #resource collection
            for (r,p,b) in self.state.getBuildings(self.state.lastroll):
                mult = 1 if b == 'settlement' else 2
                self.state.addResource(p, r, mult)
            #self.updateView()
        self.state.phase = 'standard'

    def moveRobber(self):
        self.state.phase = 'moverobber'
        move = self.getValidMove(self.state.turn)
        self.doMove(move)
        #list of playerid's next to robber
        adjplayers = self.state.getAdjacentPlayers(self.state.getRobberTile())
        if self.state.turn in adjplayers:
            adjplayers.remove(self.state.turn)
        #remove players who have no cards from adjacent list
        for i in xrange(len(adjplayers) - 1, -1, -1):
            if self.state.countResources(adjplayers[i]) == 0:
                del adjplayers[i]

        # Davis says to make code concise, use empty list as test for this
        # if statement otherwise he will hit irakli. I like irakli, so this list
        # is now the test for this if statement.
        if adjplayers:
            self.state.phaseinfo = adjplayers
            self.state.phase = 'chooseplayer'
            move = self.getValidMove(self.state.turn)
            self.doMove(move)

    def getValidMove(self, player):
        self.updateView()
        move = self.players[player].getMove(self.state)
        # loop until valid move receied
        while not self.isValid(move):
开发者ID:minorl,项目名称:hackcu,代码行数:70,代码来源:controller.py


注:本文中的GameState.GameState.getBuildings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。