예제 #1
0
 def checkMovesEndPosition(self,moves, expectedFen):
     board = Board()
     for move in moves:
         san = board.performMove(move)
         if debug:
             print ("%s %s" % (str(move),san))
     self.checkEndPosition(board, expectedFen)
예제 #2
0
 def test_PixelListGenerators(self):
     board = Board()
     field = Field(board, 0, 0)
     field.width = 100
     field.height = 100
     field.pcx = 50
     field.pcy = 50
     field.step = 7
     field.distance = 3
     fieldGrid = Grid(1, field.step, field.step)
     roi = FieldROI(
         field, fieldGrid, 0, lambda grid, roiIndex, xstep, ystep:
         (grid.xstep(xstep), grid.ystep(ystep)))
     #print (list(roi.pixelList()))
     assert list(
         roi.pixelList()) == [(13, 13), (13, 25), (13, 38), (13, 50),
                              (13, 63), (13, 75), (13, 88), (25, 13),
                              (25, 25), (25, 38), (25, 50), (25, 63),
                              (25, 75), (25, 88), (38, 13), (38, 25),
                              (38, 38), (38, 50), (38, 63), (38, 75),
                              (38, 88), (50, 13), (50, 25), (50, 38),
                              (50, 50), (50, 63), (50, 75), (50, 88),
                              (63, 13), (63, 25), (63, 38), (63, 50),
                              (63, 63), (63, 75), (63, 88), (75, 13),
                              (75, 25), (75, 38), (75, 50), (75, 63),
                              (75, 75), (75, 88), (88, 13), (88, 25),
                              (88, 38), (88, 50), (88, 63), (88, 75),
                              (88, 88)]
     grid = Grid(1, 2, 2, 10, 10)
     assert grid.shiftSafety(1, 1) == (0.9, 0.9)
     assert grid.shiftSafety(0, 0) == (0.1, 0.1)
     assert grid.shiftSafety(0.5, 0.5) == (0.5, 0.5)
예제 #3
0
 def test_Pieces(self):
     board = Board()
     assert board.piecesOfColor(chess.WHITE) == 16
     assert board.piecesOfColor(chess.BLACK) == 16
     counts = board.fieldStateCounts()
     assert len(counts) == 6
     assert counts[FieldState.WHITE_EMPTY] == 16
     assert counts[FieldState.WHITE_BLACK] == 8
     assert counts[FieldState.WHITE_WHITE] == 8
 
     assert counts[FieldState.BLACK_EMPTY] == 16
     assert counts[FieldState.BLACK_BLACK] == 8
     assert counts[FieldState.BLACK_WHITE] == 8
     if debug:
         print (board.unicode())
     bstr = ""
     for row in range(0, 8):
         for col in range(0, 8):
             field = board.fieldAt(row, col)
             piece = field.getPiece()
             bstr = bstr + field.an
             # print (row,col,piece)
             if piece is not None:
                 bstr += piece.symbol()
                 if piece.symbol().upper == "Q":
                     assert piece.color == field.fieldColor
     #print(bstr)
     assert bstr == "a8rb8nc8bd8qe8kf8bg8nh8ra7pb7pc7pd7pe7pf7pg7ph7pa6b6c6d6e6f6g6h6a5b5c5d5e5f5g5h5a4b4c4d4e4f4g4h4a3b3c3d3e3f3g3h3a2Pb2Pc2Pd2Pe2Pf2Pg2Ph2Pa1Rb1Nc1Bd1Qe1Kf1Bg1Nh1R"
     board.chessboard.clear()
     assert board.piecesOfColor(chess.WHITE) == 0
     assert board.piecesOfColor(chess.BLACK) == 0
예제 #4
0
 def test_FieldAlgebraicNotation(self):
     board = Board()
     anstr = ""
     for row in range(0, 8):
         for col in range(0, 8):
             field = Field(board, row, col)
             anstr = anstr + field.an
     #print (anstr)
     assert anstr == "a8b8c8d8e8f8g8h8a7b7c7d7e7f7g7h7a6b6c6d6e6f6g6h6a5b5c5d5e5f5g5h5a4b4c4d4e4f4g4h4a3b3c3d3e3f3g3h3a2b2c2d2e2f2g2h2a1b1c1d1e1f1g1h1"
예제 #5
0
 def test_ValidMove(self):
     board = Board()
     board.debug=debug
     changes=[("e4","e2"),("e5","e7")]
     for change in changes:
         move=board.changeToMove(change)
         assert move is not None
         board.move(move)
 def __init__(self,args,board=None):
     self.device=args.input
     self.title=Video.title(self.device)
     self.video=Video(self.title)
     self.args=args
     self.showDebug=args.debug
     self.start=None
     self.quitWanted=False
     self.hasImage=False
     self.timestamps=[]
     self.debug=args.debug
     if board is None:
         board=Board(args=args)
     self.board = board
     if self.args.fen is not None:
         self.board.updatePieces(self.args.fen)
     self.warp = Warp(args.warpPointList)
     self.warp.rotation = args.rotation
     if self.args.nowarp:
         self.warp.warping=True
     self.firstFrame=True    
     self.speedup=args.speedup
     pass
예제 #7
0
 def test_BoardPgn(self):
     pgn = "1. d4 Nf6 2. c4 e6 3. c5 Bd6 4. Qa4 b5 5. cxb6 O-O 6. bxc7"
     board = Board()
     board.setPgn(pgn)
     expectedFen = "rnbq1rk1/p1Pp1ppp/3bpn2/8/Q2P4/8/PP2PPPP/RNB1KBNR"
     self.checkEndPosition(board, expectedFen)
예제 #8
0
 def test_PGN(self):
     board=Board()
     pgn=board.game.pgn
     if debug:
         print (pgn)
     assert '[Result "*"]' in pgn