Esempio n. 1
0
    def handleNewData(self):
        """ handles the asynchroneously collected sound chunks """        
        # gets the latest frames        
        frames = self.mic.get_frames()
        mouse = xaut.mouse()
        if len(frames) > 0:
            # keeps only the last frame
            current_frame = frames[-1]
            # plots the time signal
            self.line_top.set_data(self.time_vect, current_frame)
            # computes and plots the fft signal            
            fft_frame = np.fft.rfft(current_frame)   # absolute value of fft_frame will give the amplitude information
            # print max(np.abs(fft_frame)) 

            frq = np.fft.rfftfreq(len(fft_frame))
            mY = np.abs(fft_frame) # Find magnitude
            peakY = np.max(mY) # Fsaind max peak
            locY = np.argmax(mY) # Find its location
            try: 
                frqY = frq[locY]*44100#

                    # mouse.move(frqY/10,300)# maybe we can include another circuit to control y-axis
            except:
                pass
            if self.autoGainCheckBox.checkState() == QtCore.Qt.Checked:
                fft_frame /= np.abs(fft_frame).max()  
            else:  
                fft_frame *= (1 + self.fixedGainSlider.value()) / 5000000.


                #print(np.abs(fft_frame).max())
            self.line_bottom.set_data(self.freq_vect, np.abs(fft_frame))      
            
            # refreshes the plots
            self.main_figure.canvas.draw()
from SimpleCV import *
from SimpleCV.Display import Display 
import xaut
mouse = xaut.mouse()
delay = mouse.move_delay(0)
custom_red = (121.0, 41.0, 37.0)
disp = Display(resolution=(640,480))
white_img = Image((640,480)).invert()
YELLOW=(179.0, 195.0, 112.0)
cam = Camera()

while not disp.isDone():
	original_img = cam.getImage().flipHorizontal()
	red_distance_img = original_img.colorDistance(color=Color.RED)
	red_bin = red_distance_img.threshold(100).invert()
	blobs = red_bin.findBlobs(minsize=50,maxsize=10720)
	if(blobs is not None):
		blob = max(blobs)
		mouse.move(15*(blob.x-256),12.5*(blob.y-192))
	red_bin.save(disp)
	if disp.mouseLeft:
		disp.done = True
		xaut.cleanup()
Esempio n. 3
0
import xaut
import sys
import time

k = xaut.keyboard()
k.click_delay(10)

url = sys.argv[1]
w = xaut.window.find_window("Firefox")
w.activate()
w.wait_active()
#select the search box
k.down(37)
k.click(46)
k.up(37)
k.type(url)
m = xaut.mouse()
m.move_delay(1)
m.move(1920, 1000)

Esempio n. 4
0
def main():
	#print OCRperformOCRPlayerBalance(1,2,3,4)
	#exit(1);
	
	#subprocess.call(['/usr/bin/canberra-gtk-play','--id','bell'])
	#Getting window name from command line options
	windowName = ''
	nextOne = 0
	for arg in sys.argv:
		if(arg == "-t"):
			nextOne = 1
		elif(nextOne ==1):
			windowName=arg
			break
	if(windowName == ""):
		print "usage: -t window name part"
		sys.exit(2)
	#Locating opened game window for control
	win = xaut.window.find_window(windowName)
	time.sleep(0.5)
	if win is None:
		print "Window name not found !!!"
		sys.exit(2)
	#Retrieve game window details for control
	details = win.info()
	mouse = xaut.mouse()
	
	#Resizing window for specified size for OCR to work
	if(details[2] != 491 and details[3] != 363):
		controlResizeWithMouse(win,mouse,491,363)
		time.sleep(1)
		details = win.info();
	"""Screen must be 491/363!!"""
	win.activate()
	
	#Ready to play
	#Game state
	#0 - pre
	#1 - flop
	#2 - turn
	#3 - river
	gameState = -1;
	#Game play loop
	playerDetails = []
	firstRun = True;
	dealIs = tableDealerIs(details);
	waitingForNewHand = True;
	
	myTotalChipsInPot = 0
	#win is not None
	while(True):
		if(firstRun):
			firstRun = False
			for i in range(1,10):
				playerDetails.append(tableGetPlayerDetails(0,i,details,tableHasCard(i,details)))
			playerDetails.sort(key=lambda tup: tup[4])
		#Waiting for new hand
		hand = tableGetPositionHand(5,details)
		if(waitingForNewHand or hand[0] == ('X','H') or tableGetPot(details) <= 0):
			waitingForNewHand = False
			myTotalChipsInPot = 0
			handCleared = False
			while(hand[0] == ('X','H') or tableGetPot(details) <= 0):
				handCleared = True
				hand = tableGetPositionHand(5,details)
				time.sleep(0.1)
			if(handCleared):
				print 'clearing data out for a new hand'
				for i in range(1,10):
					playerDetails[i-1] = tableGetPlayerDetails(playerDetails[i-1][5],i,details,tableHasCard(i,details),False)
				playerDetails.sort(key=lambda tup: tup[4])
		#Check until it is my turn
		while controlWaitForMyTurn(details):
			time.sleep(0.1)
			hand = tableGetPositionHand(5,details)
			if(hand[0] == ('X','H')):
				break
			#Update gamestate changes
			tableCards = tableGetTableCards(details)
			if(tableCards[0][0] == 0 and tableCards[3][0] == 0 and tableCards[4][0] == 0 and gameState != 0):
				gameState = 0
				for i in range(1,10):
					playerDetails[i-1] = tableGetPlayerDetails(playerDetails[i-1][5],i,details,tableHasCard(i,details),False, playerDetails[i-1][1])
				playerDetails.sort(key=lambda tup: tup[4])
			elif(tableCards[0][0] != 0 and tableCards[3][0] == 0 and tableCards[4][0] == 0  and gameState != 1):
				gameState = 1
				for i in range(1,10):
					playerDetails[i-1] = tableGetPlayerDetails(playerDetails[i-1][5],i,details,tableHasCard(i,details),False,playerDetails[i-1][1])
				playerDetails.sort(key=lambda tup: tup[4])
			elif(tableCards[0][0] != 0 and tableCards[3][0] != 0 and tableCards[4][0] == 0  and gameState != 2):
				gameState = 2
				for i in range(1,10):
					playerDetails[i-1] = tableGetPlayerDetails(playerDetails[i-1][5],i,details,tableHasCard(i,details),False,playerDetails[i-1][1])
				playerDetails.sort(key=lambda tup: tup[4])
			elif(tableCards[0][0] != 0 and tableCards[3][0] != 0 and tableCards[4][0] != 0  and gameState != 3):
				gameState = 3
				for i in range(1,10):
					playerDetails[i-1] = tableGetPlayerDetails(playerDetails[i-1][5],i,details,tableHasCard(i,details),False,playerDetails[i-1][1])
				playerDetails.sort(key=lambda tup: tup[4])
			#TODO If more than one hand is visible and full table and more than one hand is visible snapshot to mysql
			#Hands
			#Table
			#Nicks
			#Balances
		#Once my turn
		#Table cards
		print "--------------------------------------"
		for i in range(1,10):
			playerDetails[i-1] = tableGetPlayerDetails(playerDetails[i-1][5],i,details,tableHasCard(i,details),False,playerDetails[i-1][1])
			print tableGetPositionHand(i,details)
			#print playerDetails[i-1][4],'\t',playerDetails[i-1][0],'\t',playerDetails[i-1][2],'   \t   ',playerDetails[i-1][1],'   \t'   ,playerDetails[i-1][3],'   \t'   ,playerDetails[i-1][5]
		playerDetails.sort(key=lambda tup: tup[4])
		print "-------------------------------",gameState,"----------------------------"
		action = statsTakeAction(tableGetTableCards(details),tableGetPot(details),playerDetails,gameState,tableGetPositionHand(5,details),myTotalChipsInPot)
		myTotalChipsInPot = myTotalChipsInPot + action[1]
		#Fold
		if(action[0] == 1):
			controlFold(win,mouse)	
			waitingForNewHand = True
		#Check/call
		elif(action[0] == 2):
			if(controlPresentCheck(details)):
				controlCheck(win,mouse)
			else:
				#All in call
		#		print 'not present'
				controlRaise(win,mouse)
		#Raise
		elif(action[0] == 3):
			#TODO enter amount to raise by
			controlRaise(win,mouse)
		#TODO
		#controlJoinGame(win,mouse)
		#controlImBack(win,mouse)
	return 0
Esempio n. 5
0
def main():
	windowName = ''
	nextOne = 0
	for arg in sys.argv:
		if(arg == "-t"):
			nextOne = 1
		elif(nextOne ==1):
			windowName=arg
			break
	if(windowName == ""):
		print "usage: -t window name part"
		sys.exit(2)
	win = xaut.window.find_window(windowName)
	time.sleep(0.5)
	details = win.info();
	mouse = xaut.mouse()
	if(details[2] != 491 and details[3] != 363):
		resizeWithMouse(win,mouse)
		time.sleep(1)
		details = win.info();
	"""Screen must be 491/363!!"""
	win.activate()
	
	
	print "--------------hands-------------------"
	print 1,getPositionHand(1,details)
	print 2,getPositionHand(2,details)
	print 3,getPositionHand(3,details)
	print 4,getPositionHand(4,details)
	print 5,getPositionHand(5,details)
	print 6,getPositionHand(6,details)
	print 7,getPositionHand(7,details)
	print 8,getPositionHand(8,details)
	print 9,getPositionHand(9,details)
	print "---------------------------------"
		
	cardID = ((170,138),(170+32,138),(170+32*2,138),(170+32*3,138),(170+32*4,138))
	cardSign = ((170,158),(170+32,158),(170+32*2,158),(170+32*3,158),(170+32*4,158))
	
	"""When cards are removed -> new hand is being played, 5 points to check color
	while (isNewHand(mouse,details) == 0):
		time.sleep(0.1)
	TODO: table position find"""
	"""I am one who has a pair of cards after new dealing"""
	cardmap = {237:2,183:4,234:5,171:7,240:8,279:10,153:11,273:12,243:13,576:0}

	print "--------------table-------------------"
	print getCard(cardmap,details[0]+cardID[0][0],details[1]+cardID[0][1],12,16), getSign(details[0]+cardSign[0][0],details[1]+cardSign[0][1],12,10)
	print getCard(cardmap,details[0]+cardID[1][0],details[1]+cardID[1][1],12,16), getSign(details[0]+cardSign[1][0],details[1]+cardSign[1][1],12,10)
	print getCard(cardmap,details[0]+cardID[2][0],details[1]+cardID[2][1],12,16), getSign(details[0]+cardSign[2][0],details[1]+cardSign[2][1],12,10)
	print getCard(cardmap,details[0]+cardID[3][0],details[1]+cardID[3][1],12,16), getSign(details[0]+cardSign[3][0],details[1]+cardSign[3][1],12,10)
	print getCard(cardmap,details[0]+cardID[4][0],details[1]+cardID[4][1],12,16), getSign(details[0]+cardSign[4][0],details[1]+cardSign[4][1],12,10)
	
	print "--------------Dealer is-------------------"
	print dealerIs(details)
	
	print "-----------------Player nicknames hex---------------------"
	print "1: ",getNickname(1,details)
	print "2: ",getNickname(2,details)
	print "3: ",getNickname(3,details)
	print "4: ",getNickname(4,details)
	print "5: ",getNickname(5,details)
	print "6: ",getNickname(6,details)
	print "7: ",getNickname(7,details)
	print "8: ",getNickname(8,details)
	print "9: ",getNickname(9,details)
	print "-----------------Player balances-----------------------"
	print "1: ",getBalance(1,details)
	print "2: ",getBalance(2,details)
	print "3: ",getBalance(3,details)
	print "4: ",getBalance(4,details)
	print "5: ",getBalance(5,details)
	print "6: ",getBalance(6,details)
	print "7: ",getBalance(7,details)
	print "8: ",getBalance(8,details)
	print "9: ",getBalance(9,details)


	print "-----------------Has cards still-----------------------"
	"""Check who still has cards"""
	print "1 " + str(hasCard(1,details))
	print "2 " + str(hasCard(2,details))
	print "3 " + str(hasCard(3,details))
	print "4 " + str(hasCard(4,details))
	print "5 " + str(hasCard(5,details))
	print "6 " + str(hasCard(6,details))
	print "7 " + str(hasCard(7,details))
	print "8 " + str(hasCard(8,details))
	print "9 " + str(hasCard(9,details))
	
	return 0
Esempio n. 6
0
import sys
import xaut
import time
import threading
import thread

mouse = xaut.mouse()
sensitivity = 5
keyboard = xaut.keyboard()
par = False  #ignoro las pulsaciones pares.
pipe = open('/dev/input/js0', 'r')
action = []


class mousemanipulator(threading.Thread):
    def run(self):
        self.reset()
        global mouse
        while True:
            time.sleep(.02)  # Just so we don't hog CPU waiting around
            if self.coords != (0, 0):
                mouse.move(mouse.x() + self.coords[0],
                           mouse.y() + self.coords[1])

    def updatex(self, coord):
        self.coords = (coord, self.coords[1])

    def updatey(self, coord):
        self.coords = (self.coords[0], coord)

    def reset(self):