def rightStrike(startSquare, data, mySet): endSquare = Square(startSquare.row + 1, startSquare.column + 1) if(isInbounds(endSquare.row, endSquare.column) and \ data.isDifferentSides(startSquare, endSquare)): mySet.add(endSquare)
def knightAt(row, column, side, data): if not isInbounds(row, column): return False if data.isEmpty(row, column): return False if data.getSide(row, column) == side: return False if data.getPiece(row, column).pieceType != "knight": return False return True
def right(startSquare, data, mySet): """Adds all possible destinations in the horizontal right direction to a set""" row = startSquare.row columnIt = startSquare.column + 1 while (isInbounds(row, columnIt)): potentialDestination = Square(row, columnIt) if (data.isEmpty(row, columnIt)): mySet.add(potentialDestination) columnIt = columnIt + 1 else: if (data.isDifferentSides(startSquare, potentialDestination)): mySet.add(potentialDestination) break
def up(startSquare, data, mySet): """Adds all possible destinations in the vertical up direction to a set""" rowIt = startSquare.row - 1 column = startSquare.column while (isInbounds(rowIt, column)): potentialDestination = Square(rowIt, column) if (data.isEmpty(rowIt, column)): mySet.add(potentialDestination) rowIt = rowIt - 1 else: if (data.isDifferentSides(startSquare, potentialDestination)): mySet.add(potentialDestination) break
def upRight(startSquare, data, mySet): """Adds all possible destinations in the diagonal up right direction to a set""" rowIt = startSquare.row - 1 columnIt = startSquare.column + 1 while (isInbounds(rowIt, columnIt)): potentialDestination = Square(rowIt, columnIt) if (data.isEmpty(rowIt, columnIt)): mySet.add(potentialDestination) rowIt = rowIt - 1 columnIt = columnIt + 1 else: if (data.isDifferentSides(startSquare, potentialDestination)): mySet.add(potentialDestination) break
def checkedFromUp(kingLocation, side, data): rowIt = kingLocation.row - 1 column = kingLocation.column while isInbounds(rowIt, column): iteratorPiece = data.getPiece(rowIt, column) if (iteratorPiece == 0): #empty pass #continue to look at next row elif (iteratorPiece.side == side): return False #friendly unit found elif(iteratorPiece.pieceType == "rook" or \ iteratorPiece.pieceType == "queen"): return True rowIt = rowIt - 1 return False