本文整理汇总了Python中Board.addPiece方法的典型用法代码示例。如果您正苦于以下问题:Python Board.addPiece方法的具体用法?Python Board.addPiece怎么用?Python Board.addPiece使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Board
的用法示例。
在下文中一共展示了Board.addPiece方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: checkersTest
# 需要导入模块: import Board [as 别名]
# 或者: from Board import addPiece [as 别名]
def checkersTest():
game = Checkers()
print(game.evaluate("Player"))
print(game.evaluate("AI"))
print(game.getTurn())
game.turnEnd()
print(game.getTurn())
game.printGame()
board = Board(8)
board.addPiece("Player",0,1,1)
game.loadBoard(board)
game.printGame()
print(game.checkWin(), game.isOver())
board = Board(8)
board.addPiece("AI",0,1,1)
game.loadBoard(board)
game.printGame()
print(game.checkWin(), game.isOver())
"""
board = Board(8)
board.addPiece("Player",0,1,0)
board.addPiece("Player",0,4,4)
board.addPiece("AI",0,5,3)
board.addPiece("Player",0,2,2)
board.addPiece("AI",0,0,7)
board.addPiece("AI",0,3,3)
board.addPiece("AI",0,1,6)
game.loadBoard(board)
print("validMove from 2,2 to 1,1",game.validMove(1,1))
print("Movable","2,2",game.pieceMovable(2, 2) )
print("Movable","0,7",game.pieceMovable(1, 6) )
print("King", game.isKing(3,3))
print("King", game.isKing(1,6))
print("King", game.isKing(1,0))
print("King", game.isKing(0,7))
print("CAN 4,4 Jump?", game.canJump(4, 4))
print("ForceJump Player", game.forceJump("Player"))
print("CAN 5,3 Jump?", game.canJump(5, 3))
print("ForceJump AI", game.forceJump("AI"))
board = Board(8)
board.addPiece("Player",0,1,0)
board.addPiece("Player",0,5,4)
board.addPiece("AI",0,0,7)
board.addPiece("AI",0,4,3)
board.addPiece("AI",0,7,0)
board.addPiece("Player",0,1,6)
board.addPiece("Player",0,6,7)
board.updatePiece(1, 0, 7)
board.updatePiece(1, 1, 0)
game.loadBoard(board)
print(game.movePiece("Player",1, 0, 0, 1))
print(game.movePiece("AI",7, 0, 6, 1))
print(game.movePiece("AI",0, 7, 2, 5))
print(game.movePiece("Player",5, 4, 3, 2))
board2 = Board(8)
board2.addPiece("Player",0,1,0)
board2.addPiece("Player",0,5,4)
board2.addPiece("AI",0,0,7)
board2.addPiece("AI",0,4,3)
board2.addPiece("AI",0,7,0)
board2.addPiece("Player",0,1,6)
board2.addPiece("Player",0,6,7)
board2.updatePiece(1, 0, 7)
board2.updatePiece(1, 1, 0)
game2 = Checkers()
game2.printGame()
game2.loadBoard(board2)
game2.printGame()
print(game.movePiece("AI",0, 7, 2, 5))
print(game.movePiece("Player",5, 4, 3, 2))
print(game.movePiece("AI",7, 0, 6, 1))
print(game.movePiece("Player",1, 0, 0, 1))
"""
"""while not game.isOver():
示例2: BoardTest
# 需要导入模块: import Board [as 别名]
# 或者: from Board import addPiece [as 别名]
class BoardTest(unittest.TestCase):
def setUp(self):
self.board = Board(8)
self.board2 = Board(3)
self.board3 = Board(4)
def testBoardSize(self):
self.assertEqual(8,self.board.getSize())
self.assertEqual(3,self.board2.getSize())
self.assertEqual(4,self.board3.getSize())
def test_Remove_From_Board(self):
self.board.removePiece(2,1)
self.assertEqual(0,self.board.countAiPieces())
self.board.removePiece(6,6)
self.assertEqual(0,self.board.countPlayerPieces())
def test_Add_To_Board(self):
# board 1
self.board.addPiece("AI",0,1,1)
self.board.addPiece("Player",0,6,6)
self.assertEqual(1,self.board.countPlayerPieces())
self.assertEqual(1,self.board.countAiPieces())
self.assertTrue(self.board.pieceAt(1, 1))
self.assertTrue(self.board.pieceAt(6, 6))
# board 2
self.board2.addPiece("test",0,1,1)
self.board2.addPiece("AI",3,1,2)
self.assertEqual(0,self.board2.countPlayerPieces())
self.assertEqual(0,self.board2.countAiPieces())
self.assertFalse(self.board2.pieceAt(1, 1))
self.assertFalse(self.board2.pieceAt(1, 2))
self.board2.addPiece("AI",1,2,1)
self.assertEqual(0,self.board2.countPlayerPieces())
self.assertEqual(1,self.board2.countAiPieces())
self.assertTrue(self.board2.pieceAt(2, 1))
# board 3
self.board3.addPiece("AI",0,1,1)
self.assertEqual(0,self.board3.countPlayerPieces())
self.assertEqual(1,self.board3.countAiPieces())
self.assertTrue(self.board3.pieceAt(1, 1))
def test_Get_Piece_Info(self):
# board 1
self.piece = self.board.getPieceAt(6, 6)
self.assertEqual("Player", self.piece.getOwner())
self.assertEqual(1, self.piece.getType())
# board 2
self.piece = self.board2.getPieceAt(2, 1)
self.assertEqual("AI", self.piece.getOwner())
self.assertEqual(1, self.piece.getType())
self.piece = self.board2.getPieceAt(1, 2)
self.assertIsNone(self.piece)
self.piece = self.board2.getPieceAt(1, 1)
self.assertIsNone(self.piece)
# board 3
self.piece = self.board3.getPieceAt(1, 1)
self.assertEqual("AI", self.piece.getOwner())
self.assertEqual(0, self.piece.getType())
def test_Move_Piece(self):
self.assertTrue(self.board.pieceAt(1, 1))
self.board.movePiece(1, 1, 2, 1)
self.assertFalse(self.board.pieceAt(1, 1))
self.assertTrue(self.board.pieceAt(2, 1))
self.assertTrue(self.board2.pieceAt(2, 1))
self.board2.movePiece(2, 1, 2, 2)
self.assertFalse(self.board2.pieceAt(2, 1))
self.assertTrue(self.board2.pieceAt(2, 2))
self.assertTrue(self.board3.pieceAt(1, 1))
self.board3.movePiece(1, 1, 2, 1)
self.assertFalse(self.board3.pieceAt(1, 1))
self.assertTrue(self.board3.pieceAt(2, 1))
def test_Update_Piece(self):
self.board.updatePieceType(1,6,6)
self.piece = self.board.getPieceAt(6, 6)
self.assertEqual("Player", self.piece.getOwner())
self.assertEqual(1, self.piece.getType())
def tearDown(self):
self.board = None
self.board2 = None
self.board3 = None
def main(self):
self.setUp()
self.testBoardSize()
self.test_Add_To_Board()
self.test_Update_Piece()
self.test_Get_Piece_Info()
#.........这里部分代码省略.........
示例3: __init__
# 需要导入模块: import Board [as 别名]
# 或者: from Board import addPiece [as 别名]
class Checkers:
"""
default constructor creates the board and populates
the board with pieces
"""
def __init__(self):
self.board = Board(8)
self.size = self.board.getSize()
self.turn = 0
self.best_move = None
self.game_over = False
self.jumpAgain = (False,None,None)
for y in range(0,3):
for x in range(self.size):
if(y%2 ==0 and x%2 ==1 ):
self.board.addPiece("AI", 0, x, y)
if(y%2==1 and x%2 ==0):
self.board.addPiece("AI", 0, x, y)
for y in range(5,self.size):
for x in range(self.size):
if(y%2 ==0 and x%2 ==1 ):
self.board.addPiece("Player", 0, x, y)
if(y%2==1 and x%2 ==0):
self.board.addPiece("Player", 0, x, y)
def loadBoard(self,board):
self.board = board
# returns the number of Ai pieces
def getAI(self):
return self.board.countAiPieces()
# returns the number of player pieces
def getPlayer(self):
return self.board.countPlayerPieces()
# ends the game
def resign(self):
self.game_over = True
# returns piece at position X Y on the Board
def getPiece(self,x,y):
return self.board.getPieceAt(int(x),int (y))
"""
gets if any of the players pieces can jump and adds it to
the array, and returns it
"""
def forceJump(self,player):
moves = []
for i in range (self.size):
for j in range (self.size):
tmp = self.board.getPieceAt(i, j)
# checks if tmp is not none and player == the piece
if tmp and player == tmp.getOwner() :
jumpF = self.canJump(i, j)
# if jumpF array is not empty append i , j and each value in the array
# for that piece
if jumpF :
for n in jumpF:
moves.append(n)
return moves
# prints the game.
def printGame(self):
count = 0
tmp = " |0|1|2|3|4|5|6|7|\n"
for y in range (self.board.getSize()):
tmp += str(y) +"|"
for x in range (self.board.getSize()):
if(self.board.pieceAt(x, y)== True):
count+=1
pi = Piece()
pi =self.board.getPieceAt(x, y)
if(pi.getOwner() == "AI"):
tmp = tmp + "0|"
else:
tmp = tmp + "X|"
else:
tmp = tmp + " |"
tmp += "\n"
print (str(tmp))
# returns if the game is over
def isOver(self):
return self.game_over
# checks to see if the game has ended and sets game_over to true
def checkWin(self):
if self.board.countPlayerPieces ==0 or len(self.getMoves("Player")) == 0:
self.game_over = True
return "AI"
elif self.board.countAiPieces ==0 or len(self.getMoves("AI")) == 0:
self.game_over = True
return "Player"
"""
validates if piece at X,Y can move to x1 , y1
#.........这里部分代码省略.........