def setUp(self):
        self.numberofloops = 10

        self.board = chessboard.ChessBoard()
        self.board[27] = pieces.KingPiece('white')
        self.board[45] = pieces.KingPiece('black')
        self.generator = movegenerator.MoveGenerator(self.board)
        return None
Beispiel #2
0
    def setUp(self):
        self.board = chessboard.ChessBoard()
        self.board[18] = pieces.QueenPiece('white')
        self.board[19] = pieces.PawnPiece('white')
        self.board[23] = pieces.RookPiece('black')
        self.board[42] = pieces.KnightPiece('black')

        self.generator = movegenerator.MoveGenerator(self.board)
Beispiel #3
0
def makebestmove(board):
    """Makes the best move on board."""
    print "\nThe computer is thinking...\n"
    time.sleep(SLEEP_TIME)
    movelist = movegenerator.MoveGenerator(board).generatemovelist(
        board.computercolour)
    makemove(random.choice(movelist), board)
    return board
Beispiel #4
0
def checkorcheckmatesymbol(colour, board):
    """Determines if the move requires a special symbol."""
    generator = movegenerator.MoveGenerator(board)
    oppositecolour = core.oppositecolour(colour)
    specialsymbol = ''
    if generator.kingincheck(oppositecolour):
        if len(generator.generatemovelist(oppositecolour)) == 0:  # Checkmate!
            specialsymbol += '#'
        else:  # Else just check.
            specialsymbol += '+'
    return specialsymbol
Beispiel #5
0
    def setUp(self):
        board = chessboard.ChessBoard()
        board[4] = pieces.KingPiece('white')
        board[8] = pieces.PawnPiece('white')
        board[9] = pieces.PawnPiece('white')
        board[13] = pieces.PawnPiece('white')
        board[14] = pieces.PawnPiece('white')
        board[23] = pieces.PawnPiece('white')

        board[60] = pieces.KingPiece('black')
        board[17] = pieces.RookPiece('black')
        board[30] = pieces.RookPiece('black')

        self.generator = movegenerator.MoveGenerator(board)
        return None
Beispiel #6
0
    def setUp(self):
        self.board = chessboard.ChessBoard()
        self.board[60] = pieces.KingPiece('black')
        self.board[4] = pieces.KingPiece('white')

        self.board[51] = pieces.PawnPiece('black')
        self.board[52] = pieces.PawnPiece('black')
        self.board[53] = pieces.PawnPiece('black')
        self.board[49] = pieces.PawnPiece('black')

        self.board[36] = pieces.PawnPiece('white')
        self.board[34] = pieces.PawnPiece('white')

        self.generator = movegenerator.MoveGenerator(self.board)
        return None
Beispiel #7
0
    def setUp(self):
        self.board = chessboard.ChessBoard()
        self.board[0] = pieces.RookPiece('white')
        self.board[55] = pieces.RookPiece('white')
        self.board[4] = pieces.KingPiece('white')
        self.board[10] = pieces.PawnPiece('white')
        self.board[13] = pieces.PawnPiece('white')
        self.board[15] = pieces.PawnPiece('white')
        self.board[31] = pieces.BishopPiece('black')
        self.board[56] = pieces.RookPiece('black')
        self.board[60] = pieces.KingPiece('black')
        self.board[49] = pieces.PawnPiece('black')

        self.generator = movegenerator.MoveGenerator(self.board)
        return None
Beispiel #8
0
 def mobilityscore(self, board):
     """Determines how mobile each side is and returns a net score."""
     generator = movegenerator.MoveGenerator(board)
     whitemobility = len(generator.generatemovelist('white')) * 100
     blackmobility = len(generator.generatemovelist('black')) * 100
     return whitemobility - blackmobility
 def test_initialise_and_generate(self):
     with Timer() as t:
         for x in xrange(self.numberofloops):
             movegenerator.MoveGenerator(self.board).generatemovelist('white')
     print '\n\t=> elapsed time for %i loops: %s s' % (self.numberofloops, t.secs)
     return None
Beispiel #10
0
def islegalmove(colour, movetuple, board):
    """Determine if the move is legal."""
    generator = movegenerator.MoveGenerator(board)
    allallowedmoves = generator.generatemovelist(colour)
    return movetuple in allallowedmoves