本文整理汇总了Python中Board.placeNewCoinIfNothingOnBoard方法的典型用法代码示例。如果您正苦于以下问题:Python Board.placeNewCoinIfNothingOnBoard方法的具体用法?Python Board.placeNewCoinIfNothingOnBoard怎么用?Python Board.placeNewCoinIfNothingOnBoard使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Board
的用法示例。
在下文中一共展示了Board.placeNewCoinIfNothingOnBoard方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import Board [as 别名]
# 或者: from Board import placeNewCoinIfNothingOnBoard [as 别名]
def main():
### debug options (see https://docs.python.org/2/howto/logging.html) ###
if debugMode:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.ERROR)
#logging.basicConfig(filename='Debug.log', level=logging.DEBUG)
### initialization part ###
logging.debug( "Initialization" )
logging.debug( "Parsed file paths\n%s\n%s\n%s\n%s\nCreate History=%s" % (pathToInitialBoard, pathToPlayerFile, pathToConfigFile, pathToOutputDirectory, history) )
# parse config file
configs = parseConfigFile( pathToConfigFile )
logging.debug("Parsed config file %s\nParameters are stopCriterion:%s\tNoOfCoins:%s\tWaitingTime:%s\n" % (pathToConfigFile,configs.stopCriterion,configs.numberOfCoins,configs.waitingTime))
# construct initial board by reading in board and player files
board = Board()
board.init( pathToInitialBoard, configs, pathToPlayerFile)
rememberedBoards = list()
# init gui
if displayGUI:
guiGame = GUI(onGridInitialized)
guiGame.Map = board.matrix
guiGame.start()
# waiting for gui to be initialized
print("waiting for gui to be initialized...")
while(not IsGridInitialized):
time.sleep(0.1)
#draw legend
guiGame.updateCoinsRemaining(int(configs.numberOfCoins))
else:
# guiGame should be None, such that we can call the update functions of the module board
guiGame = None
for i in range(len(board.players)):
playerName = board.players[i][1]
playerName = os.path.basename(playerName)
if guiGame != None:
guiGame.addPlayerToLegend(i,playerName)
#add players to gui
#draw player
for k in board.playerInfo.keys():
player = board.playerInfo[k]
playerIndex = board.players.index((player.Name,player.FilePath))
position = player.Position
if guiGame != None:
guiGame.addPlayerToCell(position, playerIndex)
# set first coin on board and draw it to gui
board.placeNewCoinIfNothingOnBoard(guiGame)
#set outputPaths
boardFile = os.path.join(pathToOutputDirectory, "boardCurrent.txt")
historyFile = os.path.join(pathToOutputDirectory, "history.txt")
### iteratitive rounds part ###
logging.debug( "Iterative rounds" )
while( not gameIsFinished( configs, board ) ):
logging.debug( "nextRound")
board.initRound()
# determine order of players in this round
playersSequence = [player for player, path in board.getPlayersSequence()]
logging.debug( "Player sequence: " + ','.join(playersSequence) )
# write out current board with all information (board, players, player sequence, coins per player, remaining coins, general playing configs)
writeCurrentBoard(boardFile, board, configs)
#f=raw_input()
# forget last history
#del rememberedBoards[:] # why should we forget the last history, ji would suggest we store every board until the game is finished in rememberedBoards
for aPlayer in playersSequence:
board.placeNewCoinIfNothingOnBoard(guiGame)
logging.debug( "Player\n " + str(aPlayer) )
# remember start time of this round
start = time.time()
# ask player for her move
move = board.requestPlayersMove( aPlayer, configs, boardFile, historyFile)
logging.debug( "Move\n " + str(move) )
# perform player's move and consider all possible cases: moving to empty field, water, mountain, other player, coin
board.movePlayer( aPlayer, move, guiGame)
# remember updated board for writing it to history file after the round is finished
rememberedBoards.append( board.copy() )
# draw updated board
if not displayGUI:
clearScreen()
#.........这里部分代码省略.........