Пример #1
0
    def showGuide(self):
        text = tk.Text(self.root, width=13, height=20)
        text.insert(tk.INSERT, "SYMBOL GUIDE:\n\n\n")
        text.insert(tk.INSERT, " Your Avatar:\n")
        text.insert(tk.INSERT, " (Off: Grey)\n")
        text.insert(tk.INSERT, " (On: Green)\n")
        text.insert(tk.INSERT, " (Error: Red)\n")
        text.insert(tk.INSERT, " (Won: Blue)\n\n")
        text.insert(tk.INSERT, " Pickup:\n\n\n")
        text.insert(tk.INSERT, " Wall:\n\n\n")
        text.insert(tk.INSERT, " Deposit:\n\n\n")
        text.insert(tk.INSERT, " Exit:\n\n\n")
        text.configure(state=tk.DISABLED)
        text.grid(row=0, column=1, sticky=tk.S+tk.W)

        canvas = tk.Canvas(self.root, height = 250, width = 220)
        canvas.grid(row=0, column=1, sticky=tk.S+tk.E)
        droid = Droid(canvas, 80)
        droid.pos = (-.20, -.20)
        droid.show()
        pickup = Pickup(canvas, 60)
        pickup.pos = (-.18, 1.0)
        pickup.show()

        canvas.create_rectangle(5, 125, 35, 155, fill = 'grey', width=0)

        canvas.create_rectangle(5, 170, 35, 200, fill = 'orange', width=0)

        canvas.create_rectangle(5, 215, 35, 250, fill = 'yellow', width=0)
Пример #2
0
def main():

    # Part one
    t0 = time.time()
    droid = Droid("../data/input.csv")
    map, output = droid.repair_oxygen()
    part_one = output[-1]
    time_part_one = round((time.time() - t0) * 1e3)
    print("Solution to part one: %s (time taken %s[ms])" %
          (part_one, time_part_one))

    t0 = time.time()
    part_two = droid.fill_oxygen(map, output[0], output[1])
    time_part_two = round((time.time() - t0) * 1e3)
    print("Solution to part two: %s (time taken %s[ms])" %
          (part_two, time_part_two))
Пример #3
0
def main():

    dir_path = dirname(realpath(__file__))
    file_location = join(dir_path, "../data/input.txt")

    # Part one
    t0 = time.time()
    droid = Droid(file_location)
    map, output = droid.repair_oxygen()
    part_one = output[-1]
    time_part_one = round((time.time() - t0) * 1e3)
    print("Solution to part one: %s (time taken %s[ms])" %
          (part_one, time_part_one))

    t0 = time.time()
    part_two = droid.fill_oxygen(map, output[0], output[1])
    time_part_two = round((time.time() - t0) * 1e3)
    print("Solution to part two: %s (time taken %s[ms])" %
          (part_two, time_part_two))
Пример #4
0
  def showGuide(self):
    text = tk.Text(self.root, width=13, height=20)
    text.insert(tk.INSERT, "SYMBOL GUIDE:\n\n\n")
    text.insert(tk.INSERT, " Your Avatar:\n")
    text.insert(tk.INSERT, "  (Off: Grey)\n")
    text.insert(tk.INSERT, "  (On: Green)\n")
    text.insert(tk.INSERT, " (Error: Red)\n")
    text.insert(tk.INSERT, "  (Won: Blue)\n\n")
    text.insert(tk.INSERT, "      Pickup:\n\n\n")
    text.insert(tk.INSERT, "        Wall:\n\n\n")
    text.insert(tk.INSERT, "     Deposit:\n\n\n")
    text.insert(tk.INSERT, "        Exit:\n\n\n")
    text.configure(state=tk.DISABLED)
    text.grid(row=0, column=1, sticky=tk.S+tk.W)

    canvas = tk.Canvas(self.root, height = 250, width = 220)
    canvas.grid(row=0, column=1, sticky=tk.S+tk.E)
    droid = Droid(canvas, 80)
    droid.pos = (-.20, -.20)
    droid.show()
    pickup = Pickup(canvas, 60)
    pickup.pos = (-.18, 1.0)
    pickup.show()

    canvas.create_rectangle(5, 125, 35, 155,
                            fill = 'grey',
                            width=0,
                            )

    canvas.create_rectangle(5, 170, 35, 200,
                            fill = 'orange',
                            width=0,
                            )

    canvas.create_rectangle(5, 215, 35, 250,
                            fill = 'yellow',
                            width=0,
                            )
Пример #5
0
def main():
    data = sys.stdin.readline()
    d = Droid(Program(data))

    threads = [
        threading.Thread(target=d.execute),
        threading.Thread(target=lambda: play(d)),
    ]

    for thread in threads:
        thread.start()

    for thread in threads:
        thread.join()
Пример #6
0
    def __init__(self, game, states, resultStr, stepTime):
        self.game = game
        self.divs = game['size']
        self.root = root = tk.Tk(className = " SYCS 100 Robots! ")
        self.root.geometry(newGeometry = str(WIDTH)+'x'+str(HEIGHT)+'+100+0')
        # Initialize the parent class.
        tk.Frame.__init__(self, master=root, cnf={})
        self.grid(sticky=tk.N+tk.S+tk.E+tk.W)

        canvas = tk.Canvas(self.root, height = BOARD_SIZE, width = BOARD_SIZE, bg = 'white')
        self.canvas = canvas
        canvas.grid(row=0, column=0, sticky=tk.N+tk.S+tk.E+tk.W)

        self.makeBoard()
        self.showResults(resultStr)
        self.showGuide()
        self.droid = Droid(canvas, BOARD_SIZE/self.divs)
        self.states = states
        self.stateIndex = 0
        self.pickups = []

        global STEP_TIME
        STEP_TIME = max(100, stepTime)
        STEP_TIME = min(3000, STEP_TIME)
Пример #7
0
  def __init__(self, game, states, resultStr, stepTime):
    self.game = game
    self.divs = game['size']
    self.root = root = tk.Tk(className = " SYCS 100 Robots! ")
    self.root.geometry(newGeometry = str(WIDTH)+'x'+str(HEIGHT)+'+100+0')
    # Initialize the parent class.
    tk.Frame.__init__(self, master=root, cnf={})
    self.grid(sticky=tk.N+tk.S+tk.E+tk.W)

    canvas = tk.Canvas(self.root, height = BOARD_SIZE, width = BOARD_SIZE, bg = 'white')
    self.canvas = canvas
    canvas.grid(row=0, column=0, sticky=tk.N+tk.S+tk.E+tk.W)

    self.makeBoard()
    self.showResults(resultStr)
    self.showGuide()
    self.droid = Droid(canvas, BOARD_SIZE/self.divs)
    self.states = states
    self.stateIndex = 0
    self.pickups = []

    global STEP_TIME
    STEP_TIME = max(100, stepTime)
    STEP_TIME = min(3000, STEP_TIME)
Пример #8
0
import os

from droid import Droid
from droid.jobs import JobType


class TestJob(JobType):
    pass


bot = Droid(
    name="bot",
    environment=os.environ.get("BOT_ENV", "development"),
    timezone="America/Chicago",
    jobs={
        "config_path": os.path.join(os.path.dirname(__file__), "jobs"),
        "types": (TestJob, ),
        "default_job_settings": {
            "github_access_token": "test",
        },
    },
)

if __name__ == "__main__":
    bot.cli()
Пример #9
0
"""Droid exploring an area running an intcode program."""

import sys
from droid import Droid

if __name__ == '__main__':
    code = [int(i) for i in sys.stdin.readline().split(',')]
    droid = Droid(code)
    droid.explore()
    position, path = droid.find_oxygen()

    print('part 1', len(path) - 1)
    print('part 2', droid.find_max_dist_from(position))

Пример #10
0
def part1():
    droid = Droid(code)
    # droid.update_feed()
    print(droid)
    print(f"Alignment: {droid.get_alignment()}")
Пример #11
0
def part2():
    droid = Droid(code, 2)
    droid.program("A,B,B,C,C,A,A,B,B,C", "L,12,R,4,R,4", "R,12,R,4,L,12",
                  "R,12,R,4,L,6,L,8,L,8", False)
Пример #12
0
class World(tk.Frame):
    def __init__(self, game, states, resultStr, stepTime):
        self.game = game
        self.divs = game['size']
        self.root = root = tk.Tk(className = " SYCS 100 Robots! ")
        self.root.geometry(newGeometry = str(WIDTH)+'x'+str(HEIGHT)+'+100+0')
        # Initialize the parent class.
        tk.Frame.__init__(self, master=root, cnf={})
        self.grid(sticky=tk.N+tk.S+tk.E+tk.W)

        canvas = tk.Canvas(self.root, height = BOARD_SIZE, width = BOARD_SIZE, bg = 'white')
        self.canvas = canvas
        canvas.grid(row=0, column=0, sticky=tk.N+tk.S+tk.E+tk.W)

        self.makeBoard()
        self.showResults(resultStr)
        self.showGuide()
        self.droid = Droid(canvas, BOARD_SIZE/self.divs)
        self.states = states
        self.stateIndex = 0
        self.pickups = []

        global STEP_TIME
        STEP_TIME = max(100, stepTime)
        STEP_TIME = min(3000, STEP_TIME)

    def draw(self):
        self.updateState()
        self.droid.show()
        self.drawPickups()

        if len(self.states) > self.stateIndex:
            self.after(STEP_TIME, self.draw)

    def drawPickups(self):
        for pickup in self.pickups:
            pickup.destroy()

        for pickupSpot in self.pickupSpots:
            pickup = Pickup(self.canvas, BOARD_SIZE/self.divs)
            pickup.pos = pickupSpot
            pickup.show()
            self.pickups.append(pickup)

    def updateState(self):
        state = self.states[self.stateIndex]

        self.droid.pos = state[0]
        self.droid.status = state[1]
        self.droid.dir = state[2]
        self.droid.pickups = state[3]

        self.pickupSpots = state[5]
        self.stateIndex += 1

    def makeBoard(self):
        canvas = self.canvas
        divSize = BOARD_SIZE/self.divs

        board = self.game['board']
        for i in range(len(board)):
            x = i % self.divs * divSize
            y = i / self.divs * divSize
            if board[i] == END:
                # Draw the Finish
                self.canvas.create_rectangle(x, y, x + divSize, y + divSize,
                                             outline = 'white',
                                             fill = 'yellow',
                                             width=divSize/2)
            elif board[i] == DEPOSIT:
                # Draw the Walls
                self.canvas.create_rectangle(x, y, x + divSize, y + divSize,
                                             outline = 'white',
                                             fill = 'orange',
                                             width=divSize/2)
            elif board[i] == WALL:
                # Draw the Walls
                self.canvas.create_rectangle(x, y, x + divSize, y + divSize,
                                             outline = 'white',
                                             fill = 'grey',
                                             width=divSize/2)
        # Draw the Border walls
        self.canvas.create_rectangle(0, 0, BOARD_SIZE, BOARD_SIZE,
                                     outline = 'grey',
                                     # fill = 'clear',
                                     width=divSize/4)

        for i in range(divSize/2, BOARD_SIZE, divSize):
            canvas.create_line(i, 0, i, BOARD_SIZE, width = 2)
            canvas.create_line(0, i, BOARD_SIZE, i, width = 2)

    def showResults(self, resultStr):
        text = tk.Text(self.root, width=48, height=16, bg='grey')
        if resultStr.find('Error'):
            text.configure(fg='red')

        text.insert(tk.INSERT, "Resutls: (scroll down)\n\n")
        text.insert(tk.END, resultStr)

        text.configure(state=tk.DISABLED)
        text.grid(row=0, column=1, sticky=tk.N+tk.W)

    def showGuide(self):
        text = tk.Text(self.root, width=13, height=20)
        text.insert(tk.INSERT, "SYMBOL GUIDE:\n\n\n")
        text.insert(tk.INSERT, " Your Avatar:\n")
        text.insert(tk.INSERT, " (Off: Grey)\n")
        text.insert(tk.INSERT, " (On: Green)\n")
        text.insert(tk.INSERT, " (Error: Red)\n")
        text.insert(tk.INSERT, " (Won: Blue)\n\n")
        text.insert(tk.INSERT, " Pickup:\n\n\n")
        text.insert(tk.INSERT, " Wall:\n\n\n")
        text.insert(tk.INSERT, " Deposit:\n\n\n")
        text.insert(tk.INSERT, " Exit:\n\n\n")
        text.configure(state=tk.DISABLED)
        text.grid(row=0, column=1, sticky=tk.S+tk.W)

        canvas = tk.Canvas(self.root, height = 250, width = 220)
        canvas.grid(row=0, column=1, sticky=tk.S+tk.E)
        droid = Droid(canvas, 80)
        droid.pos = (-.20, -.20)
        droid.show()
        pickup = Pickup(canvas, 60)
        pickup.pos = (-.18, 1.0)
        pickup.show()

        canvas.create_rectangle(5, 125, 35, 155, fill = 'grey', width=0)

        canvas.create_rectangle(5, 170, 35, 200, fill = 'orange', width=0)

        canvas.create_rectangle(5, 215, 35, 250, fill = 'yellow', width=0)

    def start(self, *pargs):
        mainThread = threading.Thread(target = self.draw, args=pargs)
        mainThread.start()
        self.mainloop()
Пример #13
0
class World(tk.Frame):
  def __init__(self, game, states, resultStr, stepTime):
    self.game = game
    self.divs = game['size']
    self.root = root = tk.Tk(className = " SYCS 100 Robots! ")
    self.root.geometry(newGeometry = str(WIDTH)+'x'+str(HEIGHT)+'+100+0')
    # Initialize the parent class.
    tk.Frame.__init__(self, master=root, cnf={})
    self.grid(sticky=tk.N+tk.S+tk.E+tk.W)

    canvas = tk.Canvas(self.root, height = BOARD_SIZE, width = BOARD_SIZE, bg = 'white')
    self.canvas = canvas
    canvas.grid(row=0, column=0, sticky=tk.N+tk.S+tk.E+tk.W)

    self.makeBoard()
    self.showResults(resultStr)
    self.showGuide()
    self.droid = Droid(canvas, BOARD_SIZE/self.divs)
    self.states = states
    self.stateIndex = 0
    self.pickups = []

    global STEP_TIME
    STEP_TIME = max(100, stepTime)
    STEP_TIME = min(3000, STEP_TIME)

  def draw(self):
    self.updateState()
    self.droid.show()
    self.drawPickups()

    if len(self.states) > self.stateIndex:
      self.after(STEP_TIME, self.draw)

  def drawPickups(self):
    for pickup in self.pickups:
      pickup.destroy()

    for pickupSpot in self.pickupSpots:
      pickup = Pickup(self.canvas, BOARD_SIZE/self.divs)
      pickup.pos = pickupSpot
      pickup.show()
      self.pickups.append(pickup)

  def updateState(self):
    state = self.states[self.stateIndex]

    self.droid.pos = state[0]
    self.droid.status = state[1]
    self.droid.dir = state[2]
    self.droid.pickups = state[3]

    self.pickupSpots = state[5]
    self.stateIndex += 1

  def makeBoard(self):
    canvas = self.canvas
    divSize = BOARD_SIZE/self.divs

    board = self.game['board']
    for i in range(len(board)):
      x = i % self.divs * divSize
      y = i / self.divs * divSize
      if board[i] == END:
        # Draw the Finish
        self.canvas.create_rectangle(x, y, x + divSize, y + divSize,
                                outline = 'white',
                                fill = 'yellow',
                                width=divSize/2,
                                )
      elif board[i] == DEPOSIT:
        # Draw the Walls
        self.canvas.create_rectangle(x, y, x + divSize, y + divSize,
                                outline = 'white',
                                fill = 'orange',
                                width=divSize/2,
                                )
      elif board[i] == WALL:
        # Draw the Walls
        self.canvas.create_rectangle(x, y, x + divSize, y + divSize,
                                outline = 'white',
                                fill = 'grey',
                                width=divSize/2,
                                )
    # Draw the Border walls
    self.canvas.create_rectangle(0, 0, BOARD_SIZE, BOARD_SIZE,
                            outline = 'grey',
                            # fill = 'clear',
                            width=divSize/4,
                            )

    for i in range(divSize/2, BOARD_SIZE, divSize):
      canvas.create_line(i, 0, i, BOARD_SIZE, width = 2)
      canvas.create_line(0, i, BOARD_SIZE, i, width = 2)

  def showResults(self, resultStr):
    text = tk.Text(self.root, width=48, height=16, bg='grey')
    if resultStr.find('Error'):
      text.configure(fg='red')

    text.insert(tk.INSERT, "Resutls: (scroll down)\n\n")
    text.insert(tk.END, resultStr)

    text.configure(state=tk.DISABLED)
    text.grid(row=0, column=1, sticky=tk.N+tk.W)

  def showGuide(self):
    text = tk.Text(self.root, width=13, height=20)
    text.insert(tk.INSERT, "SYMBOL GUIDE:\n\n\n")
    text.insert(tk.INSERT, " Your Avatar:\n")
    text.insert(tk.INSERT, "  (Off: Grey)\n")
    text.insert(tk.INSERT, "  (On: Green)\n")
    text.insert(tk.INSERT, " (Error: Red)\n")
    text.insert(tk.INSERT, "  (Won: Blue)\n\n")
    text.insert(tk.INSERT, "      Pickup:\n\n\n")
    text.insert(tk.INSERT, "        Wall:\n\n\n")
    text.insert(tk.INSERT, "     Deposit:\n\n\n")
    text.insert(tk.INSERT, "        Exit:\n\n\n")
    text.configure(state=tk.DISABLED)
    text.grid(row=0, column=1, sticky=tk.S+tk.W)

    canvas = tk.Canvas(self.root, height = 250, width = 220)
    canvas.grid(row=0, column=1, sticky=tk.S+tk.E)
    droid = Droid(canvas, 80)
    droid.pos = (-.20, -.20)
    droid.show()
    pickup = Pickup(canvas, 60)
    pickup.pos = (-.18, 1.0)
    pickup.show()

    canvas.create_rectangle(5, 125, 35, 155,
                            fill = 'grey',
                            width=0,
                            )

    canvas.create_rectangle(5, 170, 35, 200,
                            fill = 'orange',
                            width=0,
                            )

    canvas.create_rectangle(5, 215, 35, 250,
                            fill = 'yellow',
                            width=0,
                            )

  def start(self, *pargs):
    mainThread = threading.Thread(target = self.draw, args=pargs)
    mainThread.start()
    self.mainloop()
# coding=utf-8

from droid import Droid

# Crie uma classe Pessoa e uma Classe Robo e finalmente uma classe Droid que
# herda das duas anteriores.

c3p0 = Droid("C3P0", 46)
c3p0.falar("Oh my goodness!!!")
c3p0.dormir()
c3p0.andar()
Пример #15
0
from droid import Droid

fp = "day15/in.txt"
with open(fp) as fd:
    droid = Droid([int(w) for w in fd.read().split(",")], 50)


def part1():
    # droid.explore_ai(1337)
    droid.explore_man()


part1()

print(droid)