本文整理汇总了Python中board.Board.print方法的典型用法代码示例。如果您正苦于以下问题:Python Board.print方法的具体用法?Python Board.print怎么用?Python Board.print使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类board.Board
的用法示例。
在下文中一共展示了Board.print方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import print [as 别名]
class Game:
def __init__(self, x=10, y=10, mines=10):
self.board = Board(x, y, mines)
self.players = []
def play(self):
if self.players == []:
print("No players")
return
line = ""
action = ""
playing = True
while playing:
for player in self.players:
player.printState()
move = player.getMove()
action = move[0]
if action == "quit":
sys.exit()
else:
x, y = move[1:3]
try:
if x < 0 or y < 0:
raise IndexError
elif action == "quit":
sys.exit()
elif action == "flag":
self.board.flag(x,y)
player.sendState([(x, y)], "flag")
elif action == "autopick":
tiles = self.board.autopick(x,y)
player.sendState(tiles)
else:
tiles = self.board.pick(x,y)
player.sendState(tiles)
except GotMineError:
print("Got a mine!")
self.board.print(showMines=True)
playing = False
break
except IndexError:
print("That is not on the board.", sep='')
if self.board.minesLeft == 0:
playing = False
print("You won!")
self.board.print()
def addPlayer(self, player):
player.setBoard(self.board.rows, self.board.cols, self.board.numMines)
self.players.append(player)
示例2: __init__
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import print [as 别名]
class Game:
def __init__(self, x=10, y=10, r=0.1):
self.board = Board(x, y)
def play(self):
line = ""
action = ""
playing = True
while playing:
print(self.board.guessNumLeft(), "mines left")
self.board.print()
while True:
try:
action = ""
line = input("> ")
args = line.split(" ")
if args[0] == "f":
x,y = [int(i) for i in args[1:]]
action = "flag"
elif args[0] == "a":
x,y = [int(i) for i in args[1:]]
action = "autopick"
else:
x,y = [int(i) for i in args]
break
except EOFError:
sys.exit()
except ValueError:
if line == "quit":
sys.exit()
else:
print("Invalid input.")
try:
if action == "flag":
self.board.flag(x,y)
elif action == "autopick":
self.board.autopick(x,y)
else:
self.board.pick(x,y)
except GotMineError:
print("Got a mine!")
self.board.print(showMines=True)
break
except IndexError:
print(x, ", ", y, " is not on the board.", sep='')
if self.board.minesLeft == 0:
playing = False
print("You won!")
示例3: play
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import print [as 别名]
def play(width, height, inarow, players):
gameboard = Board((width, height), allowed=players, clearval=' ')
turns = cycle(players)
while True:
player = next(turns)
print("'{}' turn. Choose coordinates 'x,y':".format(player))
x,y = get_tuple_int(0, 0, width, height)
while not gameboard.isClear(x,y):
print("Square is taken, please choose free coordinates 'x,y':")
x,y = get_tuple_int(0, 0, width, height)
gameboard.setValue(x,y,player)
gameboard.print()
if in_a_row(gameboard, inarow):
print("Winner is: {}".format(player))
break;
if gameboard.isFilled():
print("Draw")
break;
示例4: __init__
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import print [as 别名]
class Player:
def __init__(self, name):
self.gamestate = Board(0, 0, 0)
self.name = name
def setBoard(self, x, y, mines):
self.gamestate = Board(x, y, 0)
self.gamestate.numMines = mines
def getMove(self):
return ["pick", 0, 0]
def sendState(self, tiles, type="reveal"):
for t in tiles:
if type == "flag":
self.gamestate.flag(t[0], t[1])
else:
self.gamestate.grid[t[0]][t[1]].value = t[2]
self.gamestate.grid[t[0]][t[1]].isVisible = True
def printState(self):
print(self.name, ":", sep='')
print(self.gamestate.guessNumLeft(), "mines left")
self.gamestate.print()
示例5: Data
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import print [as 别名]
return True
if __name__ == '__main__':
# initialize objects
d = Data("rowdata.txt", "coldata.txt")
b = Board('starter_board.txt')
# create lists of all possible configurations for rows/columns
generate_all_possible(b, d)
print('Generated all possibles from rules in %.3f sec' % s.get_elapsed())
# start game loop
solved_this_round = -1 # start with non-zero
while solved_this_round != 0:
b.print()
s.iterate()
filter_possibles(b)
solved_this_round = apply_certainties(b)
print('== COMPLETE ==')
count = 0
for index, possibles in enumerate(b.possiblerows):
if len(possibles) > 1:
count += 1
print("Unsolved for row %d, number of possibilities: %d" % (index, len(possibles)))
for index, possibles in enumerate(b.possiblecols):
if len(possibles) > 1:
count += 1
print("Unsolved for column %d, number of possibilities: %d" % (index, len(possibles)))