Ejemplo n.º 1
0
    def initAngLenTable(self):

        for y in range(0, 255):
            newy = y - 128
            for x in range(0, 255):
                newx = x - 128
                if (newx != 0 and newy != 0):
                    angle = float(math.atan(Decimal(newy) / Decimal(newx)))
                    if (angle == 0 or angle == math.pi):
                        length = math.fabs(newx)
                    else:
                        length = math.fabs((newy) / (math.sin(angle)))
                        self.angLenTable[x][y] = Mouse(newx, newy, angle,
                                                       length)
                else:
                    self.angLenTable[x][y] = Mouse(0, 0, 0, 0)
Ejemplo n.º 2
0
    def foo():
        angLenTable = empty((256, 256), dtype=object)

        for y in range(0, 255):
            newy = y - 128
            for x in range(0, 255):
                newx = x - 128
                if (newx != 0 and newy != 0):
                    angle = float(math.atan(Decimal(newy) / Decimal(newx)))
                    if (angle == 0 or angle == math.pi):
                        length = math.fabs(newx)
                    else:
                        length = math.fabs((newy) / (math.sin(angle)))
                        angLenTable[x][y] = Mouse(newx, newy, angle, length)
                else:
                    angLenTable[x][y] = Mouse(0, 0, 0, 0)
Ejemplo n.º 3
0
    def start(self):
        pg.init()
        cat = Cat()
        mouse = Mouse()
        screen = pg.display.set_mode((1024, 768))
        clock = pg.time.Clock()
        running = True
        sprite = pg.sprite.Group()
        sprite.add(cat)
        sprite.add(mouse)
        calcCoords = USEREVENT + 1

        pg.time.set_timer(calcCoords, 50)

        while running:

            if pg.event.get(calcCoords):
                mouse.calcCoords()
                cat.calcCoords()

            sprite.update([cat.pos, mouse.pos])
            self.AuraDetection([cat.pos, mouse.pos], cat, mouse)
            clock.tick(60)
            pg.display.set_caption("{:.2f}".format(clock.get_fps()))
            screen.fill((250, 250, 250))
            for event in pg.event.get():
                if event.type == pg.QUIT:
                    running = False

            sprite.draw(screen)
            pg.display.flip()
Ejemplo n.º 4
0
 def __init__(self, tipi_io):
     # Extend this list to register new special request handlers
     #
     self.__reg = {
         0x20: Mouse(tipi_io),
         0x21: TipiVariable(tipi_io),
         0x22: TiSocket(tipi_io),
     }
Ejemplo n.º 5
0
def main(argv):
    argv = ['', 'Labyrinths/Laby7.txt']
    labyrinth = Labyrinth.load_from_file(argv[1])
    mouse = Mouse(labyrinth)

    while not mouse.has_reached_exit():
        mouse.move()
        print(mouse)
Ejemplo n.º 6
0
 def build(self):
     self.game = Game()
     self.keyboard = Keyboard()
     self.mouse = Mouse()
     self.settings = Settings()
     # Create loop with 1/60 sec delay
     Clock.schedule_interval(self.update, 1.0 / 60.0)
     return self.game
Ejemplo n.º 7
0
def create_new_user(name, age, avatar, password):
    """
    Создает нового пользователя и присваивает ему роль
    """
    rand = random.random()
    if rand > 0.7:
        return Owl(name, age, avatar, password)
    else:
        return Mouse(name, age, avatar, password)
Ejemplo n.º 8
0
def main():
    cpuConcreta = Cpu()
    tecladoConcreto = Teclado(cpuConcreta)
    mouseConcreto = Mouse(tecladoConcreto)


    mouseConcreto.manejaProcesos("Presionar")
    mouseConcreto.manejaProcesos("Hola1")
    mouseConcreto.manejaProcesos("Escribir")
    mouseConcreto.manejaProcesos("Hola2")
    mouseConcreto.manejaProcesos("Encender")
    mouseConcreto.manejaProcesos("Hola3")
Ejemplo n.º 9
0
    def __init__(self, boardLayoutFile):
        # Defined Class Variables
        self.cols, self.rows = None, None
        self.startCol, self.startRow = None, None
        self.endCol, self.endRow = None, None

        # 2d arrays. To be initialized later when length is known.
        self.gridVals = None
        self.obstacles = None

        # Read in file.
        self.readIn(boardLayoutFile)

        # Create the has-a mouse.
        self.mouse = Mouse(self.startCol, self.startRow)
    def generate_resources(self):
        unique_random_positions = self.generate_unique_random_positions()
        self.cheese_pos = []

        # self.cheese_pos = [[16, 21], [16, 5], [7, 18]]
        # self.cat = Cat([21, 8])
        # self.mouse = Mouse([21, 16])

        # self.cheese_pos = [[7, 11], [20, 14], [11, 27]]
        # self.cat = Cat([4, 20])
        # self.mouse = Mouse([4, 6])

        for i in range(self.num_of_cheese + 2):

            if i < self.num_of_cheese:
                self.cheese_pos.append(unique_random_positions[i])
            elif i < self.num_of_cheese + 1:
                self.cat = Cat(unique_random_positions[i])
            else:
                self.mouse = Mouse(unique_random_positions[i])
linkLength1 *= multiplier
linkLength2 *= multiplier
linkLength3 *= multiplier
linkLength4 *= multiplier
linkLength5 *= multiplier
linkLengthhip *= multiplier

screen = Screen(screen_dim_pix, screen_dim_inch)

leg1 = Leg(screen, linkLength1, linkLength2, linkLength3, linkLength4,
           linkLength5, linkLengthhip)

csvWriter = CsvWriter(screen, fileWriteName, leg1)
csvReader = CsvReader(screen, fileReadName)

mouse = Mouse(screen)

Point(screen, screen.inches_to_pixels(screen.origin_x),
      screen.inches_to_pixels(screen.origin_y + 3), 0, screen.points)

run = True
test = False
while run:
    screen.initialize()

    # Mouse Position
    keys = py.key.get_pressed()
    mouse_press = py.mouse.get_pressed()
    mouse_pos = py.mouse.get_pos()
    mouse.function(mouse_pos, mouse_press, leg1.lhipz)
Ejemplo n.º 12
0
from Tkinter  import *                  # Import everything from Tkinter
from Arena    import Arena              # Import our Arena
from Cat      import Cat                # Import our Cat
from Mouse    import Mouse              # Import our Statue
from Statue   import Statue             # Import our Statue
from Vector   import *                  # Import everything from our Vector
from globalVars import *                # Import everything from globalVars
from random   import random             # Import random

tk = Tk()                               # Create a Tk top-level widget
arena = Arena(tk, 800, 600, padx=12, pady=6) # Create an Arena widget, arena
arena.pack()                            # Tell arena to pack itself on screen

midX = arena.width/2                    # Horizontal center of window
midY = arena.height/2                   # Vertical center of window
mouseAngle = random()*360*scaleRad      # Random mouse angle to initialize
catAngle = random()*360*scaleRad        # Random cat angle to initialize
catRadius = 5                           # Random cat radius to initialize

statue = Statue(Vector(midX,midY), 0)   # Create a statue in center of arena, arbitrary heading
arena.add(statue)                       # Add statue

mouse = Mouse(Vector(midX + statue.radius*scalePixel*cos(mouseAngle), midY - statue.radius*scalePixel*sin(mouseAngle)), 0, arena, statue) # Create a mouse at right edge of statue, arbitrary heading since it will be overwritten in initialization
arena.add(mouse)                        # Add mouse
 
cat = Cat(Vector(midX + catRadius*scalePixel*cos(catAngle), midY - catRadius*scalePixel*sin(catAngle)), 0, arena, statue, mouse) # Create a cat at given angle and radius, arbitrary heading since it will be overwritten in initialization
arena.add(cat, "cat")                   # Add cat and specify that it's a cat as extra argument

tk.mainloop()                           # Enter the Tkinter event loop
Ejemplo n.º 13
0
    cat_angle = 150.000
    cat_heading = cat_angle - 90
    cat_radius = 8.100
    '''
    '''
    # case 5
    mouse_angle = -57.000
    mouse_heading = mouse_angle - 90
    cat_angle = 0.000
    cat_heading = cat_angle - 90
    cat_radius = 4.000
    # stoptime = 30*10**3
    '''

    statue = Statue(Vector(200, 200), 0, radius * 100)
    mouse = Mouse(Vector(200, 200), mouse_heading, radius * 100, 1,
                  mouse_angle, arena)
    cat = Cat(Vector(200, 200), cat_heading, radius * 100, cat_radius * 100,
              1.25, 1, cat_angle, mouse_angle, mouse, arena,
              updatetime.callback())

    #########################################
    # DO NOT CHANGE ANY CODE BELOW THIS LINE
    #########################################

    arena.add(statue)
    arena.add(cat)
    arena.add(mouse)
    if args.no_gui:
        arena.run()
    tk.mainloop()
Ejemplo n.º 14
0
 def __init__(self):
     self.__parts = [Mouse(), Keyboard(), Monitor()]
Ejemplo n.º 15
0
 def set_type(self):
     self.type = Mouse()
     self.key_set = self.type.key_set
     self.del_key_set = self.type.del_key_set
Ejemplo n.º 16
0
import pyautogui
import os
import time
import random
from Looter import Looter
from Mouse import Mouse
from ScreenGrab import ScreenGrab

m = Mouse()
l = Looter(m)


def check_creatures_present():
    s2 = ScreenGrab()
    s2.b_box = (0, 0) + (1176, 91)
    s2.grab_screen()
    return s2.is_creature_present()


i = 1
coords = None

while (True):

    s = ScreenGrab()
    s.set_map_bb()
    time.sleep(1 + random.random())
    pyautogui.press('space')
    time.sleep(3 + random.random())
    if i % 3 == 0:
        pyautogui.press('1')
Ejemplo n.º 17
0
def creat_image():
    print("create image")
    mn = Mouse()
    mn.create_image()
Ejemplo n.º 18
0
    turns each String into a List of two coordinates
    and returns a List of Integers as a result.'''
    coordinates = []
    final = []
    with open(filename) as myfile:
        for line in myfile.readlines():
            xy = list(map(int, line.split()))
            coordinates.append(xy)

    for item in coordinates:
        for item2 in item:
            final.append(item2)
    return final


mice = [Mouse(animalFromFile("mice.txt"), n) for n in range(0, 15)]
kittens = [Kitten(animalFromFile("kittens.txt"), n) for n in range(0, 6)]
middleCats = [
    MiddleCat(animalFromFile("middleCats.txt"), n) for n in range(0, 4)
]  # initialize each Animal
lazyCats = [LazyCat(animalFromFile("lazyCats.txt"), n)
            for n in range(0, 4)]  # in a list of instances
bigCats = [BigCat(animalFromFile("bigCats.txt"), n) for n in range(0, 3)]


def simulate(iterations):
    '''Takes a number of iterations as an argument and simulates
    movement of each Animal from the list. Starts with mice and
    checks for interaction with each Cat type object.'''
    frames = 0
    while frames < iterations:
Ejemplo n.º 19
0
from Cat import Cat
from Mouse import Mouse
from Humans import Humans

person = Humans()
tom = Cat("tom")
jerry = Mouse("jerry")
'''
person.feedCat(tom,"fish")
person.feedMouse(jerry,"coin")
'''
person.feedAniaml(tom, 'fish')
person.feedAniaml(jerry, 'jam')
Ejemplo n.º 20
0
from random import randint
from Mouse import Mouse
from Cat import Cat
from Cheese import Cheese
from BFS import BFS
from DFS import DFS
from AStar import AStarSearch
import copy

# Initialize items' position, not used for random map
cheese1 = Cheese([1,10])
cheese2 = Cheese([11, 1])
cheese3 = Cheese([4,8])

cheeseList = [cheese1, cheese2, cheese3]
mouse = Mouse([6, 4])
cat = Cat([10, 7])

MAP_HEIGHT = 12
MAP_WIDTH = 12
searchMethod = BFS()


myMap = MapState(None, cheeseList, mouse, cat, MAP_WIDTH, MAP_HEIGHT)
# set random positions
myMap.setInitState()

# ------------------For random map---------------
while(searchMethod.ifCatWin == False):
    print("Generating a random map...")
    searchMethod = BFS()
Ejemplo n.º 21
0
 def __init__(self, tipi_io):
     # Extend this list to register new special request handlers
     self.__reg = {0x20: Mouse(tipi_io)}
Ejemplo n.º 22
0
# Screen title
pygame.display.set_caption("Colorindo Cenarios")

# Create an object to help track time
clock = pygame.time.Clock()

# All buttons
draw_button = Button(STANDARD_COLOR, 815, 5, 225, 400, "DRAW")
clear_button = Button(GREY, 815, 410, 225, 400, "CLEAR")

gold_button = Button(GOLD, 1095, 5, 225, 200, "GOLD")
brown_button = Button(BROWN, 1330, 5, 225, 200, "BROWN")
red_button = Button(RED, 1095, 210, 225, 200, "RED")
green_button = Button(GREEN, 1330, 210, 225, 200, "GREEN")
yellow_button = Button(YELLOW, 1095, 410, 225, 200, "YELLOW")
blue_button = Button(BLUE, 1330, 410, 225, 200, "BLUE")
purple_button = Button(PURPLE, 1095, 610, 225, 200, "PURPLE")
pink_button = Button(PINK, 1330, 610, 225, 200, "PINK")
buttons = [
    draw_button, clear_button, brown_button, gold_button, green_button,
    red_button, yellow_button, blue_button, purple_button, pink_button
]

# Objects
board = Board(25, 25, 5, STANDARD_COLOR)
mouse = Mouse()

# Controls mouse color
new_color = WALL
Ejemplo n.º 23
0
linkLength1 *= multiplier
linkLength2 *= multiplier
linkLength3 *= multiplier
linkLength4 *= multiplier
linkLength5 *= multiplier
linkLengthhip *= multiplier

screen = Screen(screen_dim_pix, screen_dim_inch)

leg1 = Leg(screen, linkLength1, linkLength2, linkLength3,
           linkLength4, linkLength5, linkLengthhip)

csvWriter = CsvWriter(screen, fileWriteName, leg1)
csvReader = CsvReader(screen, fileReadName)

mouse = Mouse(screen, 0, 0)

Point(screen, screen.inches_to_pixels(screen.origin_x), screen.inches_to_pixels(screen.origin_y + 3), 0, screen.points)

run = True
test = False
while run:
    screen.initialize()

    # Mouse Position
    keys = py.key.get_pressed()
    mouse_press = py.mouse.get_pressed()
    mouse_pos = py.mouse.get_pos()
    mouse.function(mouse_pos, mouse_press, leg1.lhipz)

    screen.check_key_commands(keys)
Ejemplo n.º 24
0
    def run(self, myMap):
        catPossibleMoveList = [[2, 1], [-2, -1], [-2, 1], [-1, -2], [-1, 2], [1, -2], [1, 2], [2, -1]]
        # catPossibleMoveList = [[-1, -2], [1, -2], [2, -1], [2, 1], [-1, 2], [1, 2], [-2, -1], [-2, 1]]

        mouseMoveTrackingList = []
        moveTrackingState = []
        stateStack = []
        catSearchedList = []
        remainingCheeseNum = 0
        stateStack.append(myMap)
        solution = None
        mouseMoveTrackingList.append(myMap.mouse.getPos())
        while(solution == None):
            if(len(stateStack) != 0):
                # FILO stack for DFS
                currentState = stateStack.pop(len(stateStack) - 1)
                # if with the same step moved, and mouse have no more cheese to eat, stop finding more successors, go backtracking
                if(len(currentState.cheeseList) != 0):
                    # Found the goal state
                    if(currentState.mouse.mousePos == currentState.cat.catPos):
                        solution = currentState
                        break

                    closestCheese = self.getClosestCheese(currentState.mouse.getPos(), currentState.cheeseList)
                    nextMouseMove = self.mouseMove(currentState.mouse.getPos(), closestCheese.getPos())
                    # add mouseMove to list
                    if(nextMouseMove not in mouseMoveTrackingList):
                        mouseMoveTrackingList.append(nextMouseMove)
                    # Generate current node's successors
                    for possibleMoves in catPossibleMoveList:
                        newCheeseList = []
                        for cheese in currentState.cheeseList:
                            cheese1 = Cheese(cheese.cheesePos)
                            newCheeseList.append(cheese1)
                        nextCatMove = [currentState.cat.catPos[0] + possibleMoves[1], currentState.cat.catPos[1] + possibleMoves[0]]
                        # generate a successor and set its parent to currentState
                        nextState = MapState(currentState, newCheeseList, Mouse(nextMouseMove), Cat(nextCatMove), currentState.mapWidth, currentState.mapHeight)
                        # set current state as its parent
                        nextState.parentState = currentState
                        # make sure nextCatMove is in boundary and the state is not in visited state list
                        if (nextCatMove[0] >= 0 and nextCatMove[0] < nextState.mapWidth and nextCatMove[1] < nextState.mapHeight and nextCatMove[1] >= 0 and (nextState not in catSearchedList)):
                            nextState.updateMousePos(nextMouseMove)
                            nextState.updateCatPos(nextCatMove)
                            catSearchedList.append(nextState)
                            # add the state to stack
                            stateStack.append(nextState)

                # count for iterations
                self.searchCount += 1
                print(self.searchCount)
                # print(self.searchCount)
                if(self.searchCount > 10000):
                    print("Having more than 10000 searchs, generating a new map...")
                    self.ifCatWin = False
                    break

            # cannot find a solution
            else:
                solution = currentState
                self.ifCatWin = False
                break
        if(solution != None and len(solution.cheeseList) != 0):
            self.ifCatWin = True
            remainingCheeseNum = len(solution.cheeseList)
            # add solution to tracking list one by one
            while(solution != None):
                moveTrackingState.append(solution)
                solution = solution.parentState
            moveTrackingState.reverse()

            for state in moveTrackingState:
                state.updateCatPos(state.cat.catPos)
                state.updateMousePos(state.mouse.mousePos)
                time.sleep(1)
                state.covertMapToUI()
            print("Cat Win!")
            print("Search Count:", self.searchCount)
            print("Total Move:", len(moveTrackingState) - 1)
            print("Number of cheeses remaining:", remainingCheeseNum)
Ejemplo n.º 25
0
def animalFromFile(filename):
    coordinates = []
    final = []
    with open(filename) as myfile:
        for line in myfile.readlines():
            xy = list(map(int, line.split()))
            coordinates.append(xy)

    for item in coordinates:
        for item2 in item:
            final.append(item2)
    return final


mice = [Mouse(animalFromFile("mysz.txt"), n) for n in range(0,8)]
middleCats = [MiddleCat(animalFromFile("middleCat.txt"), n) for n in range(0,8)]
lazyCats = [LazyCat(animalFromFile("leniuch.txt"), n) for n in range(0,8)]
kittens = [Kitten(animalFromFile("kociaki.txt"), n) for n in range(0,8)]


print(middleCats[3].x, middleCats[3].y)
print(lazyCats[3].x, middleCats[3].y)
print(kittens[3].x, kittens[3].y)
print(mice[3].x, mice[3].y)
print("--------------")

iterations = 0
while iterations < 199:
    for mouse in mice:
        mouse.move()
Ejemplo n.º 26
0
def main():
    c = Cat("Tom")
    m = Mouse("jerry")
    p = Person()
    p.feedAnima(c)
    p.feedAnima(m)
Ejemplo n.º 27
0
import board
import time
from Mouse import Mouse

bob = Mouse([board.D12, board.D11, board.D10])
bob.moveForward(0.25)
time.sleep(1)
bob.stop()
time.sleep(1)
bob.turn("right")
time.sleep(1)
bob.turn("right")
time.sleep(1)
bob.turn("left")
time.sleep(1)
bob.turn("right")
time.sleep(1)
bob.moveForward(0.25)
time.sleep(1)
bob.stop()
Ejemplo n.º 28
0
def main():
    maze = Maze(API.mazeWidth(), API.mazeHeight())
    mouse = Mouse(0, 0, Direction.NORTH)
    while not maze.inCenter(mouse.getPosition()):
        updateWalls(maze, mouse)
        moveOneCell(maze, mouse)
Ejemplo n.º 29
0
Created on Sun Nov 18 15:44:25 2018

@author: Morten
"""

from tkinter import *  # Import everything from Tkinter
from Arena import Arena  # Import our Arena
from Turtle import Turtle  # Import our Turtle
from Vector import *  # Import everything from our Vector
from Statue import Statue
from Mouse import Mouse
from Cat import Cat
from globalVariables import *

statueRadius = 1
statuePosition = Vector(200, 200)
mouseAngle = -57.0
catAngle = 0.0
catRadius = 4.0

tk = Tk()  # Create a Tk top-level widget
arena = Arena(tk)  # Create an Arena widget, arena
arena.pack()  # Tell arena to pack itself on screen
s = Statue(statuePosition,
           statueRadius)  # Add a turtle at (200,200) heading 0=up
m = Mouse(statue=s, angle=mouseAngle, arena=arena)
c = Cat(arena=arena, mouse=m, angle=catAngle, radius=catRadius)
arena.add(s)
arena.add(m)
arena.add(c)
tk.mainloop()
Ejemplo n.º 30
0
	def __init__(self,mouse=Mouse(),rec_k='c',quit_k='q'):
		self.mouse = mouse
		self.rec_k = rec_k
		self.quit_k = quit_k
		self.records = []