本文整理汇总了Python中board.Board.getBoard方法的典型用法代码示例。如果您正苦于以下问题:Python Board.getBoard方法的具体用法?Python Board.getBoard怎么用?Python Board.getBoard使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类board.Board
的用法示例。
在下文中一共展示了Board.getBoard方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: genRandomBoard
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import getBoard [as 别名]
def genRandomBoard(xSize, ySize):
board = Board(xSize, ySize)
print board.getBoard()
for i in xrange(xSize):
for j in xrange(ySize):
state = random.choice([True, False])
board.setState(i,j,state)
return board
示例2: __init__
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import getBoard [as 别名]
class Board_administrator: #Means the dealer
players = [] #array of Player
def __init__(self):
self.board = Board()
self.deck = Deck()
self.evaluator = Evaluator()
def cleanBoard(self):
self.board = Board()
def randomFullBoard(self):
self.deck.shuffle()
self.board.clean()
for i in range(5):
self.board.addCard(self.deck.draw(1))
def printBoard(self):
print self.board.printBoard()
def dealPlayer(self,player):
player.setHand(self.deck.draw(2))
def getEquityOnePlayer(self,pairCards):
return self.evaluator.evaluate(self.board.getBoard(),pairCards)
def addPlayer(self,player):
self.players.append(player)
def dealPlayers(self):
for player in self.players:
self.dealPlayer(player)
示例3: __init__
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import getBoard [as 别名]
class Game:
def __init__(self):
self.setBoard()
def setBoard(self):
self.board = Board()
self.nextPlayer = '#'
self.lastDrop = 'A1'
def nextDrop(self, col):
if self.nextPlayer == '#':
self.nextHash(col)
elif self.nextPlayer == '@':
self.nextAt(col)
def nextHash(self, col):
self.lastDrop = self.board.drop(self.nextPlayer, col)
self.nextPlayer = '@'
def nextAt(self, col):
self.lastDrop = self.board.drop(self.nextPlayer, col)
self.nextPlayer = '#'
def isWin(self):
board = self.board.getGroup(self.lastDrop)
for group in board:
if self.hasFour(group):
return True
return False
def isDraw(self):
for row in self.board.getBoard():
for item in row:
if (item != '#') and (item != '@'):
return False
return True
def hasFour(self, group):
for four in self.fours(group):
if four.count('#') == 4 or four.count('@') == 4:
return True
def fours(self, group):
return [group[place:place + 4] for place in range(len(group) - 3)]
def valid(self, c):
return self.board.valid(c)
def showBoard(self):
return self.board.makeBoard()
示例4: test_get_board
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import getBoard [as 别名]
def test_get_board(self):
from board import Board
b = Board()
self.assertEqual(b.getBoard(), ChessTest.STARTING_BOARD)
示例5: __init__
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import getBoard [as 别名]
class Player:
def __init__(self, name=''):
self._name = name
self._board = Board('Player Board')
self._listOfShips = []
self._guesses = []
def getName(self):
return self._name
def getBoard(self):
return self._board
def getLife(self):
return len(self._listOfShips)
# Remove a ship from listOfShips (called when a ship is sunk); returns true if ship is found and removed, false otherwise
def removeShip(self, ship):
if ship in self._listOfShips:
self._listOfShips.remove(ship)
return true
else:
return false
# Prompt user to guess a coordinate until valid, un-guessed coordinate is entered; return validated coordinate
def makeGuess(self):
# Prompt the user to guess a coordinate until a valid coordinate is entered
prompt = self._name + ", pick a target."
while True:
# Prompt the user
guess = requestString(prompt)
# Verify that the coordinate input is valid
if guess == None:
# Cancel was clicked, return None
return None
elif self._board.validateCoordinate(guess) == False:
# Coodinate is invalid, reprompt
prompt = "That target is invalid. Pick a target."
elif guess in self._guesses:
# Coordinate was already guessed, reprompt
prompt = "You have already fired at that target."
else:
# Coordinate is valid and not already guessed, return validated coordinate
self._guesses.append(guess)
return guess.upper()
# Prompt user to select locations to place ships on board
def setupLocalBoard(self, listOfShips):
# Save list of ships
self._listOfShips = listOfShips
# Show player's board
show(self._board.getBoard())
# Loop through ships to place
i = 0
while i < len(self._listOfShips):
ship = self._listOfShips[i]
# Prompt user to enter starting coordinate for placement
coordinate = false
while not coordinate:
coordinate = requestString('On what square will the bow of your %s (length: %s) be? ' % (ship.getDescription(),ship.getSize()))
# Cancel was clicked; clear list of ships and return to exit
if coordinate == None:
self._listOfShips[:] = []
return
# Validate coordinate input
coordinate = self._board.validateCoordinate(coordinate)
if not coordinate:
showInformation('That coordinate does not exist on the board. Please try again.')
# Prompt user to select direction in which to fill ship from starting coordinate
directionChoices = ['Up', 'Down', 'Left', 'Right']
direction = getOption("", "In which direction is the stern of your %s?" % ship.getDescription(), directionChoices)
# Translate option dialog return value
if direction == 0:
direction = 'up'
elif direction == 1:
direction = 'down'
elif direction == 2:
direction = 'left'
elif direction == 3:
direction = 'right'
# Check if there is space in provided location, then place the ship; else reprompt if ship cannot be placed
if self._board.validateSpaceForShip(ship, coordinate, direction):
if self._board.placeShip(ship, coordinate, direction):
repaint(self._board.getBoard())
showInformation('Your %s has been placed on the board.' % ship.getDescription())
i += 1 # Incremement listOfShips index
else:
showInformation('There is an existing ship in the way. Please try a different location.')
continue
#.........这里部分代码省略.........