pawnStartBlack = deepcopy(board) pawnStartBlack.board[6][6] = P.Pawn(0, P.BLACK) pawnCPBlack= deepcopy(board) pawnCPBlack.board[4][3] = P.Pawn(0, P.BLACK) pawnCPBlack.board[3][3] = P.Pawn(1, P.WHITE) pawnCPBlack.board[5][2] = P.Pawn(2, P.WHITE) pawnCPBlack.passentable = (3, 3) pawnCPBlack.unmoved.remove(0) pawnCPBlack.unmoved.remove(1) pawnCPBlack.unmoved.remove(2) pawnStartMoves = [ P.Move((1,2), P.NON_CAPTURE), P.Move((1,3), P.NON_CAPTURE) ] pSB1Moves = [] pSB2Moves = [P.Move((1,2), P.NON_CAPTURE)] pCPMoves = [ P.Move((4,5), P.NON_CAPTURE), P.Move((3,5), P.EN_PASSENT), P.Move((5,5)) ] pawnStartBlackMoves = [ P.Move((6,5), P.NON_CAPTURE), P.Move((6,4), P.NON_CAPTURE) ] pCPBMoves = [ P.Move((4,2), P.NON_CAPTURE),
import pytest import Board as B import Pieces as P import Logic testCase1 = B.Board() testCase1 = Logic.move_piece(testCase1, 4, 1, P.Move((4, 3), P.NON_CAPTURE)) testCase1 = Logic.move_piece(testCase1, 2, 6, P.Move((2, 5), P.NON_CAPTURE)) testCase1 = Logic.move_piece(testCase1, 5, 1, P.Move((5, 3), P.NON_CAPTURE)) testCase1 = Logic.move_piece(testCase1, 3, 6, P.Move((3, 5), P.NON_CAPTURE)) testCase1 = Logic.move_piece(testCase1, 6, 1, P.Move((6, 3), P.NON_CAPTURE)) testCase1 = Logic.move_piece(testCase1, 4, 6, P.Move((3, 4), P.NON_CAPTURE)) testCase1 = Logic.move_piece(testCase1, 6, 0, P.Move((4, 1))) testCase1 = Logic.move_piece(testCase1, 3, 7, P.Move((7, 3))) testCase2 = B.Board() testCase2 = Logic.move_piece(testCase2, 0, 1, P.Move((0, 3), P.NON_CAPTURE)) testCase2 = Logic.move_piece(testCase2, 4, 6, P.Move((4, 4), P.NON_CAPTURE)) testCase2 = Logic.move_piece(testCase2, 1, 1, P.Move((1, 3), P.NON_CAPTURE)) testCase2 = Logic.move_piece(testCase2, 7, 6, P.Move((7, 4), P.NON_CAPTURE)) testCase2 = Logic.move_piece(testCase2, 2, 1, P.Move((2, 3), P.NON_CAPTURE)) testCase2 = Logic.move_piece(testCase2, 3, 7, P.Move((5, 5))) testCase2 = Logic.move_piece(testCase2, 0, 3, P.Move((0, 4), P.NON_CAPTURE)) testCase2 = Logic.move_piece(testCase2, 7, 7, P.Move((7, 5))) testCase2 = Logic.move_piece(testCase2, 1, 3, P.Move((1, 4), P.NON_CAPTURE)) testCase2 = Logic.move_piece(testCase2, 5, 5, P.Move((5, 4))) testCase2 = Logic.move_piece(testCase2, 2, 3, P.Move((2, 4), P.NON_CAPTURE)) testCase2 = Logic.move_piece(testCase2, 7, 5, P.Move((5, 5))) testCase2 = Logic.move_piece(testCase2, 0, 4, P.Move((0, 5), P.NON_CAPTURE)) testCase2 = Logic.move_piece(testCase2, 5, 4, P.Move((5, 1)))
from DecisionTree import aiSearch, endStateCheck, Node stalemate = B.Board(True) stalemate.board[3][3] = P.King(stalemate.whiteKingId, P.WHITE) stalemate.board[0][4] = P.Rook(100, P.BLACK) stalemate.board[2][0] = P.Queen(101, P.BLACK) stalemate.board[5][1] = P.Knight(102, P.BLACK) stalemate.board[7][2] = P.Rook(103, P.BLACK) stalemate.board[7][7] = P.King(stalemate.blackKingId, P.BLACK) stalemate.unmoved = [] stalemate.initializePosVals() unknownError = B.Board() unknownError = Logic.move_piece(unknownError, 4, 1, P.Move((4, 3), P.NON_CAPTURE)) unknownError = Logic.move_piece(unknownError, 6, 6, P.Move((6, 4), P.NON_CAPTURE)) unknownError = Logic.move_piece(unknownError, 3, 0, P.Move((5, 2))) unknownError = Logic.move_piece(unknownError, 5, 7, P.Move((6, 6))) unknownError = Logic.move_piece(unknownError, 5, 0, P.Move((2, 3))) unknownError = Logic.move_piece(unknownError, 0, 6, P.Move((0, 4), P.NON_CAPTURE)) unknownError = Logic.move_piece(unknownError, 5, 2, P.Move((5, 6))) unknownError.initializePosVals() crash = B.Board(True) crash.board[5][0] = P.Bishop(100, P.WHITE) crash.board[2][1] = P.Pawn(101, P.WHITE) crash.board[4][1] = P.Pawn(102, P.WHITE) crash.board[5][1] = P.King(crash.whiteKingId, P.WHITE)
def __init__(self, color, state, depth, depthLim, heuristic, space = (0,0), move = P.Move((-1, -1))): global totalNodes totalNodes += 1 self.state = state # board state of the node self.color = color # whether the AI controls the white or black pieces. self.depth = depth # current depth of node self.depthLim = depthLim # depth of how far the tree can evaluate self.heuristic = heuristic self.alpha = 0 # alpha and beta are values for pruning the tree self.beta = 0 if (self.heuristic == HASH or self.heuristic == HASH_SORT or self.heuristic == HASH_SORT_POS): self.nextMoves = {} else: self.nextMoves = [] self.weight = 0 # How good of a move is current node self.space = space # The coordinates of the piece being moved self.move = move # The coordinates that the piece is being moved to self._equalWeights = True if depth == depthLim or self.heuristic == BASIC_SORT or self.heuristic == HASH_SORT or self.heuristic == BASIC_SORT_POS or self.heuristic == HASH_SORT_POS: self.setWeight() if depth < depthLim: global maxNodeDepth if (depth > maxNodeDepth): maxNodeDepth = depth