コード例 #1
0
ファイル: query.py プロジェクト: LKarel/subdl
    def parse(filename):
        filename = filename.lower()
        filename = os.path.splitext(filename)[0]

        name = filename
        pointer_str = Pointer.read_str(filename)

        if pointer_str:
            name = filename.split(pointer_str)[0]

        name = re.sub(r"[.-]", " ", name)
        name = re.sub(r"\s+", " ", name)
        name = name.strip()

        # It is a movie
        if not pointer_str:
            name = re.sub(r"^(.+\d{4}).*$", r"\1", name)

        query = Query(name)
        query.filename = filename

        if pointer_str:
            query.pointer = Pointer.parse(pointer_str)

        return query
コード例 #2
0
    def __init__(self, player_key):

        self.level = None
        self.player = None
        self.player_key = player_key
        self.objects = []

        self.ui = UI(self)

        self.turn_tracker = TurnTracker(self)
        self.turn = 'player'
        self.active_ability = None

        self.effect_tracker = EffectTracker(self)

        self.clock = pygame.time.Clock()
        self.tick = 0

        self.pointer = Pointer(self)
        self.highlighter = Highlighter(self)

        self.sub_screen = pygame.Surface((720, 720)).convert()

        self.game_display = GameDisplay(self)
        self.screen_mode = 'zoomed'

        self.zoomed_sub_screen = pygame.Surface((19 * 16, 15 * 24)).convert()
        self.zoomed_sub_screen_scale = pygame.Surface(
            (19 * 16 * 2, 15 * 24 * 2)).convert()
        self.zoomed_sub_screen_scale_rect = self.zoomed_sub_screen_scale.get_rect(
        )
        self.zoomed_sub_screen_scale_rect.topleft = (56, 0)
コード例 #3
0
    def __init__(self, storage) -> None:
        self.storage = storage
        self.pointer = Pointer(x=48, y=16)
        self.inp = InputEx()
        self.finish = False
        self.stack: ItemsStack = None
        self.MIN_LEFT = 48
        self.MIN_TOP = 16

        self.bar_draw = BatteryBarDrawable()
コード例 #4
0
 def __init__(self, value, size=8):
     self.in_init = True
     self.size = size
     super().__init__(value, size)
     Pointer(self, 0, size).write_int(value)
     self.name = "const"
     self.in_init = False
コード例 #5
0
    def __init__(self,
                 static_size,
                 dynamic_size,
                 hidden_size,
                 update_fn=None,
                 mask_fn=None,
                 num_layers=1,
                 dropout=0.):
        super(DRL4TSP, self).__init__()

        if dynamic_size < 1:
            raise ValueError(':param dynamic_size: must be > 0, even if the '
                             'problem has no dynamic elements')

        self.update_fn = update_fn
        self.mask_fn = mask_fn

        # Define the encoder & decoder models
        self.static_encoder = Encoder(static_size, hidden_size)
        self.dynamic_encoder = Encoder(dynamic_size, hidden_size)
        self.decoder = Encoder(static_size, hidden_size)
        self.pointer = Pointer(hidden_size, num_layers, dropout)

        for p in self.parameters():
            if len(p.shape) > 1:
                nn.init.xavier_uniform_(p)

        # Used as a proxy initial state in the decoder when not specified
        self.x0 = torch.zeros((1, static_size, 1),
                              requires_grad=True,
                              device=device)
コード例 #6
0
import sys
import time
import pickle
from collections import deque
from pointer import Pointer
from ipcamera2 import CCamera

STEP = 10
DELAY = 0.1
FILE = 'servo_map.data'
RES = (736, 480)

p = Pointer()
c = CCamera(resolution=RES)
q = deque()
visited = set()
datamap = {}

pan = sys.argv[1] if len(sys.argv)>1 else 1700
tilt = sys.argv[2] if len(sys.argv)>2 else 1700
p.position(pan, tilt)

time.sleep(3) # warmup
if c.detect_pointer():
	q.append((pan, tilt))
else:
	raise Exception("Cannot detect laser pointer at initial pan={} tilt={}".format(pan, tilt))

print("starting from {}".format((pan, tilt)))
while q:
	print("enqued: {}, visited: {}, collected: {}".format(len(q), len(visited), len(datamap)))
コード例 #7
0
import time
import random
from pointer import Pointer

print("Starting")
def randpan():
    return random.randrange(1400, 1600)

def randtilt():
    return random.randrange(1800, 2000)

def randsleep():
    time.sleep(random.uniform(0.5, 3))

pointer = Pointer()
try:
    while True:
        pointer.position(randpan(), randtilt())
        randsleep()
except KeyboardInterrupt:
    pass # it's ok
finally:
    print("Clean up and exit.")
    pointer.cleanup()

print("Done")
コード例 #8
0
class Game(object):

    FPS = 60

    zoom_screen_w = 9
    zoom_screen_h = 7

    def __init__(self, player_key):

        self.level = None
        self.player = None
        self.player_key = player_key
        self.objects = []

        self.ui = UI(self)

        self.turn_tracker = TurnTracker(self)
        self.turn = 'player'
        self.active_ability = None

        self.effect_tracker = EffectTracker(self)

        self.clock = pygame.time.Clock()
        self.tick = 0

        self.pointer = Pointer(self)
        self.highlighter = Highlighter(self)

        self.sub_screen = pygame.Surface((720, 720)).convert()

        self.game_display = GameDisplay(self)
        self.screen_mode = 'zoomed'

        self.zoomed_sub_screen = pygame.Surface((19 * 16, 15 * 24)).convert()
        self.zoomed_sub_screen_scale = pygame.Surface(
            (19 * 16 * 2, 15 * 24 * 2)).convert()
        self.zoomed_sub_screen_scale_rect = self.zoomed_sub_screen_scale.get_rect(
        )
        self.zoomed_sub_screen_scale_rect.topleft = (56, 0)

    def load_level(self):

        self.level = LevelGen.generate_level(self)

        self.player = self.level.map_object_generator.add_player(
            self.player_key, self.level.player_start)
        self.level.load_player(self.player)

        # bind ui panels to player
        self.ui.panels['crystal'].load_player()
        self.ui.panels['character'].load_player()
        self.ui.panels['ability'].load_player()

    def increment_tick(self):
        self.tick += 1
        if self.tick > 60:
            self.tick = 0

    def draw(self):

        self.level.map_image.draw(self.sub_screen, self.tick)

        for obj in self.objects:
            obj.draw(self.sub_screen, self.tick)

        for effect in self.effect_tracker.effects:
            effect.draw(self.sub_screen, self.tick)

        self.highlighter.draw(self.sub_screen)

        if self.game_display.screen_mode == 'full':
            self.draw_full()
        elif self.game_display.screen_mode == 'zoomed':
            self.draw_zoomed()

        self.ui.draw(pygame.display.get_surface(), self.tick)

    def draw_full(self):
        screen = pygame.display.get_surface()
        screen.blit(self.sub_screen, self.sub_screen.get_rect())

    def draw_zoomed(self):
        screen = pygame.display.get_surface()
        sw = self.zoomed_sub_screen_scale.get_width()
        sh = self.zoomed_sub_screen_scale.get_height()

        sub_screen_offset = self.get_screen_coord()
        rect = self.sub_screen.get_rect()
        rect.topleft = sub_screen_offset

        self.zoomed_sub_screen.fill((0, 0, 0))
        self.zoomed_sub_screen.blit(self.sub_screen, rect)

        pygame.transform.scale(self.zoomed_sub_screen, (sw, sh),
                               self.zoomed_sub_screen_scale)
        screen.blit(self.zoomed_sub_screen_scale,
                    self.zoomed_sub_screen_scale_rect)

    def get_screen_coord(self):
        x, y = self.player.coord

        sx = x - Game.zoom_screen_w
        sy = y - Game.zoom_screen_h

        return sx * -16, sy * -24

    def switch_screen_mode(self):
        self.game_display.switch_screen_mode()

    def handle_input(self):

        # returns true to exit game

        for event in pygame.event.get():

            if event.type == QUIT:
                return True

            elif event.type == KEYDOWN:

                if event.key == K_ESCAPE:
                    return True

                elif event.key == K_SLASH:
                    self.switch_screen_mode()

                if self.turn == 'player' and self.effect_tracker.effects_clear(
                ):
                    if self.active_ability is not None and event.key in self.active_ability.valid_keys:

                        self.active_ability.handle_player_input(
                            self.pointer, event)

                    else:
                        self.handle_player_input(event)

            elif event.type == MOUSEBUTTONDOWN:

                if event.button == 1:  # left click
                    if not self.ui.click(
                            pygame.mouse.get_pos()):  # no icon clicked
                        if self.active_ability is not None:
                            coord = self.pointer.coord
                            self.active_ability.click_map(coord)

                elif event.button == 3:  # right click
                    if not self.ui.right_click(pygame.mouse.get_pos()):
                        if self.active_ability is not None:
                            self.player.ability_inventory.cancel_ability()
                        pass  # handle right clicking the screen

            elif event.type == MOUSEMOTION:

                self.pointer.mouse_moved()

        return False

    def handle_player_input(self, event):
        if event.key == K_UP:
            self.player.move_player('up')
        elif event.key == K_DOWN:
            self.player.move_player('down')
        elif event.key == K_RIGHT:
            self.player.move_player('right')
        elif event.key == K_LEFT:
            self.player.move_player('left')
        elif event.key == K_SPACE:
            self.end_player_turn()
            pass  # player.pass

    def start_player_turn(self):
        self.turn = 'player'
        self.player.ability_inventory.update()

    def end_player_turn(self):
        self.turn = 'monster'

    def end_monster_turn(self):
        self.start_player_turn()

    def run(self):

        self.level.redraw_manager.run()

        if self.turn == 'monster' and self.effect_tracker.effects_clear():
            self.turn_tracker.run()
        # run effects

        self.effect_tracker.run()

    def main(self):

        while True:

            if self.handle_input():
                break

            self.run()

            self.draw()
            pygame.display.update()

            self.clock.tick(Game.FPS)
            self.increment_tick()
            # print self.clock.get_fps()

    def set_active_ability(self, ability):
        self.active_ability = ability

    def clear_active_ability(self):
        self.active_ability = None
コード例 #9
0
ファイル: rom.py プロジェクト: Atari2/WhiteSnake
 def pointer_pc(self, address: int, size: int = 3, bank: int = 0x00):
     return Pointer.from_snes(
         get_pointer(self.fulldata, address, size, bank))
コード例 #10
0
 def pop(self, size):
     ret = Pointer(self.mem, self.pos, size).read()
     self.pos += size
     return ret
コード例 #11
0
class BuildScene(Scene):
    def __init__(self, storage) -> None:
        self.storage = storage
        self.pointer = Pointer(x=48, y=16)
        self.inp = InputEx()
        self.finish = False
        self.stack: ItemsStack = None
        self.MIN_LEFT = 48
        self.MIN_TOP = 16

        self.bar_draw = BatteryBarDrawable()

    def on_activate(self):
        if self.storage['level'] >= len(LEVELS):
            print("Reset levels")
            self.storage['level'] = 0
        print("LEVEL {}".format(self.storage['level']))
        self.stack = ItemsStack(self.storage['level'])
        setup_tiles(self.storage, self.storage['level'])

    def update(self, dt):
        self.draw_back(dt)
        self.inp.update(dt)
        self.stack.update(dt)
        self.draw_tiles(dt)
        self.pointer.update(dt)
        self.bar_draw.draw(0, 0, dt)

        if self.inp.btnp(jvcr.BTN_UP, 0):
            self.pointer.move_up()
        if self.inp.btnp(jvcr.BTN_DOWN, 0):
            self.pointer.move_down()
        if self.inp.btnp(jvcr.BTN_LEFT, 0):
            self.pointer.move_left()
        if self.inp.btnp(jvcr.BTN_RIGHT, 0):
            self.pointer.move_right()
        if self.inp.btnp(jvcr.BTN_A, 0):
            return self._put_item()
        if self.inp.btnp(jvcr.BTN_X, 0):
            suffle_palette()

    def draw_tiles(self, dt):
        for j, line in enumerate(get_tiles(self.storage)):
            for i, tile in enumerate(line):
                x = i * tile.width + self.MIN_LEFT
                y = j * tile.height + self.MIN_TOP
                tile.draw(x, y, dt)

    def draw_back(self, dt):
        px, py = LEVELS[self.storage['level']]['spr']
        jvcr.spr(32, 0, px, py, 240, 144, 0, 0, 0)

    def _put_item(self):
        if can_store_tile(self.storage, self.pointer.get_x(), self.pointer.get_y()):
            print("PUT ITEM")
            item = self.stack.pop()
            if item is not None:
                store_tile(self.storage, item, self.pointer.get_x(), self.pointer.get_y())
            else:
                return "next"
        else:
            print("Can't put item at [{}, {}]".format(self.pointer.get_x(), self.pointer.get_y()))
        return None
コード例 #12
0
ファイル: web_server.py プロジェクト: pshabunia/experimental
from urllib.parse import urlparse, parse_qs
from http.server import HTTPServer, BaseHTTPRequestHandler
from os import curdir, sep
from pointer import Pointer
from servo_map import ServoMap

HOSTNAME = '192.168.0.11'
PORT = 1337

POINTER = Pointer()
SERVO_MAP = ServoMap()


class RequestHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        if (self.path == '/'):
            self.play()
        elif self.path.startswith('/position'):
            self.position()
        else:
            self.not_found()

    # TODO remove
    def end_headers(self):
        # CORS
        self.send_header('Access-Control-Allow-Origin', '*')
        self.send_header('Access-Control-Allow-Methods', 'GET')
        self.send_header('Cache-Control',
                         'no-store, no-cache, must-revalidate')
        return super(RequestHandler, self).end_headers()
コード例 #13
0
ファイル: main.py プロジェクト: snndmr/Tubitak-UAV
#     time.sleep(5)
#     pwm.ChangeDutyCycle(7)

if __name__ == '__main__':
    # # Initialize of Servo
    # servoPIN = 18
    # GPIO.setwarnings(False)
    # GPIO.setmode(GPIO.BOARD)
    # GPIO.setup(servoPIN, GPIO.OUT)
    # pwm = GPIO.PWM(servoPIN, 50)
    # pwm.start(7)

    print('\n Connecting to vehicle on: {}'.format(args.connect))
    vehicle = connect(args.connect, wait_ready=True)

    pointer = Pointer()
    pointer.read_from_file()

    # First lap
    #
    #    (o)                                   (o)
    #       6N....5D................4N........3T
    #     .                 |                   .
    #   7T                  |                     2T
    #     .                 |                   .
    #       8T...........H..|................1N
    #                       |

    # # For SITL.
    # if not bool(pointer.get_data()):
    #     print(' Data file not found for the flight, data generator will be started.')
コード例 #14
0
flags = tf.app.flags
FLAGS = flags.FLAGS

flags.DEFINE_integer('batch_size', 1024, '')

import numpy as np

import melt
logging = melt.logging
import gezi

from pointer import Pointer

from util import *

p = Pointer()

loss = p.build()

ops = [loss]

eval_ops = [loss]

train_feed_dict = {}
test_feed_dict = {}


def gen_feed_dict(inputs,
                  actual_index_dists,
                  segment_lengths,
                  max_length=60,
コード例 #15
0
 def push(self, data):
     self.pos -= len(data)
     Pointer(self.mem, self.pos, len(data)).write(data)
コード例 #16
0
ファイル: game.py プロジェクト: andrelrg/x-game
from screen import Screen
from pointer import Pointer
from player import Player
# import threading

if __name__ == "__main__":
    t = Screen()
    p = Pointer(t)
    player = Player(p)
    player.Walk()
コード例 #17
0
import sys
from pointer import Pointer

pan = sys.argv[1] if len(sys.argv)>1 else 1600
tilt = sys.argv[2] if len(sys.argv)>2 else 1800
p = Pointer()
p.position(pan, tilt)
コード例 #18
0
ファイル: rom.py プロジェクト: Atari2/WhiteSnake
 def pointer_snes(self,
                  address: int,
                  size: int = 3,
                  bank: int = 0x00) -> Pointer:
     return Pointer.from_snes(
         get_pointer(self.fulldata, self.snes_to_pc(address), size, bank))
コード例 #19
0
 def read_pointer(self, size):
     res = Pointer(self.mem, self.pos, size)
     self.pos += size
     return res
コード例 #20
0
 def syscall_return_int(self, value):
     Pointer(self.cpu.register[0], 0, 8).write_int(value)
コード例 #21
0
 def ptr(self):
     return Pointer(self, 0, self.size)