Ejemplo n.º 1
0
def GetKnightMoves(board, position, player, opponent, row):
    moves = []
    restricted = []
    for i in range(position - 2 * 8, position + 3 * 8, 8):
        if not checkers.InBoard(i) or i == position:
            continue
        elif abs(i // 8 - row) == 2:
            l, r = i - 1, i + 1
            if l // 8 == i // 8:
                if board[l] == 0 or checkers.IsPlayer(board, l, opponent):
                    sorts.InsertSort(moves, l)
                else:
                    sorts.InsertSort(restricted, l)
            if r // 8 == i // 8:
                if board[r] == 0 or checkers.IsPlayer(board, r, opponent):
                    sorts.InsertSort(moves, r)
                else:
                    sorts.InsertSort(restricted, r)
        else:
            l, r = i - 2, i + 2
            if l // 8 == i // 8:
                if board[l] == 0 or checkers.IsPlayer(board, l, opponent):
                    sorts.InsertSort(moves, l)
                else:
                    sorts.InsertSort(restricted, l)
            if r // 8 == i // 8:
                if board[r] == 0 or checkers.IsPlayer(board, r, opponent):
                    sorts.InsertSort(moves, r)
                else:
                    sorts.InsertSort(restricted, r)
    return [moves, restricted]
Ejemplo n.º 2
0
def GetBishopMoves(board, position, player, opponent, row):
    moves, directions, n, j = [], [-1, 1, -1, 1], 1, -1
    restricted = []
    while directions != [0, 0, 0, 0]:
        j += 1
        if j > 0 and j % 2 == 0:
            n *= -1
            if j == 4:
                j = 0
                n = abs(n) + 1
        if not directions[j]:
            continue
        index = position + 8 * n + directions[j] * n
        if checkers.InBoard(index) and abs(index // 8 - row) == abs(n):
            if board[index] == 0:
                sorts.InsertSort(moves, index)
                continue
            elif checkers.IsPlayer(board, index, opponent):
                sorts.InsertSort(moves, index)
            directions[j] = 0
            sorts.InsertSort(restricted, index)
        else:
            directions[j] = 0
            #InsertSort(restricted, index)
    return [moves, restricted]
Ejemplo n.º 3
0
def GetRookMoves(board, position, player, opponent, row):
    moves, directions, n, j = [], [[1, 1], [-1, 1], [0, 1], [0, 1]], 1, -1
    restricted = []
    while directions != [[1, 0], [-1, 0], [0, 0], [0, 0]]:
        j += 1
        if j == 4:
            j = 0
            n += 1
        if not directions[j][1]:
            continue
        index = position + 8 * n * directions[j][0] + n * directions[abs(3 -
                                                                         j)][0]
        if checkers.InBoard(index) and abs(index // 8 - row) == abs(
                n * directions[j][0]):
            if board[index] == 0:
                sorts.InsertSort(moves, index)
                continue
            elif checkers.IsPlayer(board, index, opponent):
                sorts.InsertSort(moves, index)
            directions[j][1] = 0
            sorts.InsertSort(restricted, index)
        else:
            directions[j][1] = 0
            #InsertSort(restricted, index)
    return [moves, restricted]
Ejemplo n.º 4
0
 def evalnext(self, q_trav, eT, s_mm):
    p_index = self.player//10 - 1
    opp = checkers.GenOpponent(self.player)
    o_index = opp//10 - 1
    for i in range(0, len(self.pd[p_index]), 1):
       if self.pd[p_index][i][2] == []:
          continue
       for j in self.pd[p_index][i][2]:
          good_take = False
          nB = list(self.board)
          npd = [[], []]
          for n1 in range(0, 2, 1):
             npd[n1] = list(self.pd[n1])
             for n2 in range(0, len(self.pd[n1]), 1):
                npd[n1][n2] = list(self.pd[n1][n2])
                npd[n1][n2][2] = list(self.pd[n1][n2][2])
                npd[n1][n2][3] = list(self.pd[n1][n2][3])
          if checkers.IsPlayer(nB, j, opp):
             delete = sorts.BinarySearchPDPos(npd[o_index], j)
             #print(npd, delete)
             #a = PieceType(self.pd[o_index][delete][0])
             #if a >= PieceType(self.pd[p_index][i][0]):
             #   good_take = True
             npd[o_index] = npd[o_index][:delete] + npd[o_index][delete + 1:]
             #print(npd)
          nM = [npd[p_index][i][0], npd[p_index][i][1], j]  # new move
          nB[npd[p_index][i][1]] = 0
          nB[j] = npd[p_index][i][0]
          moves_and_restirct =legal_moves.GetPieceLegalMoves(nB, j)
          npd[p_index][i][2] = moves_and_restirct[0]
          npd[p_index][i][3] = moves_and_restirct[1]
          npd[p_index][i][1] = j
          self.UpdatePD(nB, npd, j) 
          self.UpdatePD(nB, npd, self.pd[p_index][i][1])
          sorts.BubbleSortPDPos(npd[p_index])
          node = evalTree(nB, opp, npd, self.depth + 1, nM)
          #if (node.score - self.score) > 8888 * factor:
          #   continue
          #if good_take:
          #   node.score += PieceValue(a + GenOpponent(node.player))
          #InsertSortNodes(self.next, node)
          self.next += [node]
    #if self.depth == 2:
    #self.next = self.BestChilds()
    s_mm.push(self)
    for i in self.next:
       q_trav.put(i)
       eT.put(i.bcm)
       s_mm.push(i)
    return True
Ejemplo n.º 5
0
def GetKingMoves(board, position, player, opponent, row):
    moves = []
    factor = 1
    restricted = []
    for i in range(position + 7, position + 10, 1):
        if i // 8 != row + 1:
            continue
        for j in range(i, i - 8 * 3, -8):
            if j == position:
                continue
            elif checkers.InBoard(j):
                if checkers.IsPlayer(board, j, player):
                    sorts.InsertSort(restricted, j)
                else:
                    sorts.InsertSort(moves, j)
    return [moves, restricted]
Ejemplo n.º 6
0
def GetPawnMoves(board, position, player, opponent, row):
    moves = []
    restricted = []
    if player == 10:
        factor = 1
    else:
        factor = -1
    for i in range(position + 7 * factor, position + 10 * factor, 1 * factor):
        if not checkers.InBoard(i) or i // 8 != row + factor:
            continue
        elif i == position + 8 * factor:
            if board[i] == 0:
                sorts.InsertSort(moves, i)
            else:
                sorts.InsertSort(restricted, i)
            continue
        elif checkers.IsPlayer(board, i, opponent):
            sorts.InsertSort(moves, i)
        else:
            sorts.InsertSort(restricted, i)
    return [moves, restricted]