def menu(): print('1. Fractal H') print('2. Sierpinski Carpet') print('3. Sierpinski Sieve') print('4. Patrón: Squares') print('5. Patrón: Circles') print('6. Patrón: Spiral') print('7. Salir') answer = int(input('> ')) if answer == 7: return elif answer == 1: FractalH.fractal() elif answer == 2: Sierpinski_Carpet.fractal() elif answer == 3: Sierpinski_Sieve.fractal() elif answer == 4: Squares.fractal() elif answer == 5: Circles.fractal() elif answer == 6: Spiral.fractal() else: print('Ingrese un número valido\n') menu() print('Presione enter para continuar') input() menu()
def get_Occupancy_and_Coordinates(img): ######################################################## #this part needs to take in an image when Mission Planner tells it to #ergo it needs to be changed, or does mission planenr pass in a #ready to go image? # #filename = 'img' #img = cv2.imread(filename) #gray = cv2.imread(filename, 0) ######################################################## #Get the angle of rotation needed and rotate #rotated image is really the thing we need because it will be the best final image to use theta = baseLine.findAngle(img) rotatedImage = Rotate.rotateImage(theta) #Find all the lines of the squares imgWithEdges = edgechesshc.addEdges(rotatedImage) #Get all the coordinates of the keypoints coordinates = findCoordinates.getCoordinates(imgWithEdges) #Pass coordinates on to Squares squares = Squares.populateSquares(coordinates) #believe this step is no longer necessary because of the architecture #Load squares with their starting state #Squares.loadPieces(squares, pieceTypeArray) squaresCropped = Squares.getSquaresCropped(squares, rotatedImage) new_occupancy_grid, array_of_coordinates = FindPiece.main(squaresCropped) return new_occupancy_grid, array_of_coordinates
def writeStats(dtype, results): # determine draw type if dtype == '777': max_num = 70 else: max_num = 37 k=0 # count number of lines ################### # Write draw statistics lines = csv.writer(open('draw_stats.csv','wb'),delimiter=',') first_line = ['Draw','Ticket','OddEven','LowHigh','Sum','SumOddEven','SumRoot','SumOENums','SumLHNums','SumLastDig','DigitSum','StdDev'] lines.writerow(first_line) for line in results: a = results[k][1:] draw_num = results[k][0] b =[draw_num, a, oddEven(a), lowHigh(a, max_num), sumRange(a), sumRangeOddEven(a), sumRoot(a), sumOddEvenNums(a), sumlowHighNums(a, max_num), sumLastDig(a), digitsSum(a), stdDev(a)] lines.writerow(b) # write statistics to draw_stats k+=1 # last iteration will be the maximum line number ################### # Write ball statistics skipper = Skips.skipCtr(max_num, results, k) #create skip object lines = csv.writer(open('ball_stats.csv','wb'),delimiter=',') first_line = ['Ball','Skip 1','Skip 2','Skip 3','Skip 4','Skip 5','5 Skips Sum','Skip Average'] lines.writerow(first_line) ball = 1 skp = skipper.skip for key in skp: avg = (sum(skp[key])/len(skp[key])) # skip average lst5skps = sum(skp[key][0:5]) # skip sum if len(skp[key]) < 5: # check for empty indexes length = len(skp[key]) while length < 5: skp[key].append(None) length += 1 balls = [ball, skp[key][0], skp[key][1], skp[key][2], skp[key][3], skp[key][4], lst5skps,avg] lines.writerow(balls) ball+=1 #################### # look for ball appearance in each square if dtype == '777': # Special 777 algorithm fname = open('777_numbers.txt','wb') sqr = Squares.square(results, max_num, k) # create square object sqr_list, sqr_length = kenoSqrFilter(sqr) fname.write(sqr_list) print 'A total of %d possible numbers has been written to 777_numbers.txt' % sqr_length
def makeSquareObjects(self, img): #######################initialize############################## #Take in image file ''' take in file img to initialize then run it throught the same ''' #somehow filename needs to take in a new image work through tomorrow filename = 'img' img = cv2.imread(filename) gray = cv2.imread(filename, 0) #Get the angle of rotation needed and rotate #rotated image is really the thing we need because it will be the best final image to use theta = baseLine.findAngle(filename) rotatedImage = Rotate.rotateImage(theta) #Save the rotated image cv2.imwrite('lib/rotated.jpg', rotatedImage) #Find all the lines of the squares imgWithEdges = edgechesshc.addEdges('lib/rotated.jpg') #Get all the coordinates of the keypoints coordinates = findCoordinates.getCoordinates(imgWithEdges) #Pass coordinates on to Squares squares = Squares.populateSquares(coordinates) #Load squares with their starting state Squares.loadPieces(squares, pieceTypeArray) squaresCropped = Squares.getSquaresCropped(squares, rotatedImage) self.new_piece_attribute, array_of_coordinates = FindPiece.main(squaresCropped) return squares
def makeSquareObjects(self, img): #######################initialize############################## #Take in image file ''' take in file img to initialize then run it throught the same ''' #somehow filename needs to take in a new image work through tomorrow filename = 'img' img = cv2.imread(filename) gray = cv2.imread(filename, 0) #Get the angle of rotation needed and rotate #rotated image is really the thing we need because it will be the best final image to use theta = baseLine.findAngle(filename) rotatedImage = Rotate.rotateImage(theta) #Save the rotated image cv2.imwrite('lib/rotated.jpg', rotatedImage) #Find all the lines of the squares imgWithEdges = edgechesshc.addEdges('lib/rotated.jpg') #Get all the coordinates of the keypoints coordinates = findCoordinates.getCoordinates(imgWithEdges) #Pass coordinates on to Squares squares = Squares.populateSquares(coordinates) #Load squares with their starting state Squares.loadPieces(squares, self.pieceTypeArray) squaresCropped = Squares.getSquaresCropped(squares, rotatedImage) self.new_piece_attribute, array_of_coordinates = FindPiece.main(squaresCropped) return squares
def makeFE(self, currentPieceType_board, w_or_b_turn): finalFE = Squares.giveForsythEdwardsNotation(currentPieceType_board, w_or_b_turn) return finalFE
def main(): #######################initialize############################## #Take in image file ''' take in file img to initialize then run it throught the same ''' filename = 'lib/chessanglesmall.jpg' img = cv2.imread(filename) #newimage = cv2.resize(img, (640,480)) showImage('img', img) cv2.waitKey(0) #gray = cv2.imread(filename, 0) #Get the angle of rotation needed and rotate theta = baseLine.findAngle(filename) rotatedImage = Rotate.rotateImage(theta, img) showImage('rotated image', rotatedImage) cv2.waitKey(0) cv2.destroyAllWindows() #Save the rotated image cv2.imwrite('lib/rotated.jpg', rotatedImage) #Find all the lines of the squares imgWithEdges = edgechesshc.addEdges('lib/rotated.jpg') #Get all the coordinates of the keypoints coordinates = findCoordinates.getCoordinates(imgWithEdges) #Pass coordinates on to Squares squares = Squares.populateSquares(coordinates) #Load squares with their starting state Squares.loadPieces(squares, new_piece_attribute, pieceTypeArray) ########################repeatedProcess############################ #at the end of all repeated processes we need to shift all the "new" #stuff into the "old" stuff we are using for reference and comparison #Find where the peices lie on the board #replace with updated image newImage = cv2.imread('lib/rotated.jpg') squaresCropped = Squares.getSquaresCropped(squares, newImage) print type(squaresCropped) piece_attribute_array, centerOfPiece = FindPiece.main(squaresCropped) #the arrayOfBooleans is T or F if there is a piece in a square #centerofpeice is an array of coordinates for the cetner of each piece (catch is it has to be perfectly centered on top of the piece) #print arrayOfBooleans #print centerOfPiece #print array_of_colors print piece_attribute_array print pieceTypeArray #Manage old and new images first #pieceTypeArray = findDifferencesArrays(oldBool, newBool, pieceType) ####################################finalProcess to start up again####################################3 ####We have to come up with a way to determine who moved, white or balck so that we can send it to AI ###########we will have to constantly update piecetype array as well and boolAray finalFE = Squares.giveForsythEdwardsNotation(pieceTypeArray, w_or_b_turn) ai_move = chess_ai.get_chess_move(finalFE, ROBOTCOLOR) ''' ##############How to do this##################################### if (w_or_b_turn == 'w'): w_or_b_turn == 'b' elif(w_or_b_turn == 'b'): w_or_b_turn == 'w' ''' print ai_move ############################Testing############################## #Show all the important images showImage('original', img) showImage('rotated', rotatedImage) showImage('image with edges', imgWithEdges) #Show all the cropped images #Squares.printCroppedSquares(squaresCropped) cv2.waitKey(0) cv2.destroyAllWindows()
def main(): pygame.init() screen = pygame.display.set_mode((848, 848)) pygame.display.set_caption("Chess") #Size of squares size = 106 white = (255, 255, 255) black = (161, 96, 43) board = chess.Board() board_squares = chess.SquareSet() squares = [] # method for drawing chess board obtained from stack overflow, link lost somewhere in history count = 0 # this fen has no slashes, you must remove slashes for any fen to work, you also must remove the ending material that says "3 - 0" or something startingFen = 'rnbkqbnrpppppppp8888PPPPPPPPRNBKQBNR' fenCount = len(startingFen)- 1 for i in range(8): for j in range(8): if count % 2 == 0: # rectangle = pygame.rect.Rect(size*j,size*i,size,size) rectangle = pygame.draw.rect(screen, white, (size*j,size*i,size,size)) if startingFen[fenCount].isdigit() and int(startingFen[fenCount]) > 0: squares.append(Squares.Squares(chr((j + 97)) + str(int(8 - i)), "", rectangle, False)) f = str(int(startingFen[fenCount]) - 1) startingFen = startingFen[:fenCount] + f + startingFen[fenCount + 1:] if int(startingFen[fenCount]) == 0: fenCount -= 1 else: squares.append(Squares.Squares(chr((j + 97)) + str(int(8 - i)), startingFen[fenCount], rectangle, False)) pieceImg = squares[len(squares) - 1].image screen.blit(pieceImg, (size*j, size*i)) fenCount -= 1 else: rectangle = pygame.draw.rect(screen, white, (size*j,size*i,size,size)) # rectangle = pygame.rect.Rect(size*j,size*i,size,size) if startingFen[fenCount].isdigit() and int(startingFen[fenCount]) > 0: squares.append(Squares.Squares(chr((j + 97)) + str(int(8 - i)), "", rectangle, False)) f = str(int(startingFen[fenCount]) - 1) startingFen = startingFen[:fenCount] + f + startingFen[fenCount + 1:] if int(startingFen[fenCount]) == 0: fenCount -= 1 else: squares.append(Squares.Squares(chr((j + 97)) + str(int(8 - i)), startingFen[fenCount], rectangle, False)) pieceImg = squares[len(squares) - 1].image screen.blit(pieceImg, (size*j, size*i)) fenCount -= 1 count +=1 count-=1 movedThing = None x, y = 0, 0 while True: screen = drawBoard(screen, squares) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: for i in squares: if i.rectangle.collidepoint(event.pos) and i.image != None: i.dragging = True mouse_x, mouse_y = event.pos offset_x = i.posx - mouse_x offset_y = i.posy - mouse_y x, y = event.pos[0], event.pos[1] elif event.type == pygame.MOUSEBUTTONUP and event.button == 1: for i in range(len(squares)): if squares[i].dragging: squares[i].dragging = False print(event.pos) for x in range(len(squares)): if squares[x].rectangle.collidepoint(event.pos) and squares[x] != squares[i]: # We use a try except because it will raise ValueError on illegal move or on Game Over try: print(squares[i].pos + squares[x].pos) playHumanMove(board, squares, i, x) playAIMove(board, squares) except (ValueError, TypeError, NameError) as e: if board.is_game_over() or board.is_stalemate(): print("Game Over!") else: print("Invalid Move. \n{0}".format(e)) elif event.type == pygame.MOUSEMOTION: for i in squares: if i.image == None: continue if i.dragging: mouse_x, mouse_y = event.pos x = mouse_x + offset_x y = mouse_y + offset_y screen.blit(i.image, (x, y)) # place the piece that is currently being moved. for i in squares: if i.dragging: screen.blit(i.image, (x, y)) # loop through squares and place each piece accordingly each update. pygame.display.update()