GravityFolls 21 Опубликовано: 2 декабря, 2014 (изменено) Cтандартная программа "dig" копания в виде карьера. OpenOS:mkdir /usr/binpastebin get djsxf67h quarryИспользование:quarry [x] [y] [z],где [x] — длина, [y] — ширина, которую нужно будет вскопать роботу, а [z] говорит роботу, как глубоко он должен копать. local component = require("component")local computer = require("computer")local robot = require("robot")local shell = require("shell")local sides = require("sides")if not component.isAvailable("robot") thenio.stderr:write("can only run on robots")returnendlocal args, options = shell.parse(...)if #args < 1 thenio.write("Usage: dig [-s] \n")io.write(" -s: shutdown when done.")returnendlocal size = tonumber(args[1])if not size thenio.stderr:write("invalid size")returnendlocal r = component.robotlocal x, y, z, f = 0, 0, 0, 0local dropping = false -- avoid recursing into drop()local delta = {[0] = function() x = x + 1 end, [1] = function() y = y + 1 end,[2] = function() x = x - 1 end, [3] = function() y = y - 1 end}local function turnRight()robot.turnRight()f = (f + 1) % 4endlocal function turnLeft()robot.turnLeft()f = (f - 1) % 4endlocal function turnTowards(side)if f == side - 1 thenturnRight()elsewhile f ~= side doturnLeft()endendendlocal checkedDrop -- forward declarationlocal function clearBlock(side, cannotRetry)while r.suck(side) docheckedDrop()endlocal result, reason = r.swing(side)if result thencheckedDrop()elselocal _, what = r.detect(side)if cannotRetry and what ~= "air" and what ~= "entity" thenreturn falseendendreturn trueendlocal function tryMove(side)side = side or sides.forwardlocal tries = 10while not r.move(side) dotries = tries - 1if not clearBlock(side, tries < 1) thenreturn falseendendif side == sides.down thenz = z + 1elseif side == sides.up thenz = z - 1elsedelta[f]()endreturn trueendlocal function moveTo(tx, ty, tz, backwards)local axes = {function()while z > tz dotryMove(sides.up)endwhile z < tz dotryMove(sides.down)endend,function()if y > ty thenturnTowards(3)repeat tryMove() until y == tyelseif y < ty thenturnTowards(1)repeat tryMove() until y == tyendend,function()if x > tx thenturnTowards(2)repeat tryMove() until x == txelseif x < tx thenturnTowards(0)repeat tryMove() until x == txendend}if backwards thenfor axis = 3, 1, -1 doaxes[axis]()endelsefor axis = 1, 3 doaxes[axis]()endendendfunction checkedDrop(force)local empty = 0for slot = 1, 16 doif robot.count(slot) == 0 thenempty = empty + 1endendif not dropping and empty == 0 or force and empty < 16 thenlocal ox, oy, oz, of = x, y, z, fdropping = truemoveTo(0, 0, 0)turnTowards(2)for slot = 1, 16 doif robot.count(slot) > 0 thenrobot.select(slot)local wait = 1repeatif not robot.drop() thenos.sleep(wait)wait = math.min(10, wait + 1)enduntil robot.count(slot) == 0endendrobot.select(1)dropping = falsemoveTo(ox, oy, oz, true)turnTowards(of)endendlocal function step()clearBlock(sides.down)if not tryMove() thenreturn falseendclearBlock(sides.up)return trueendlocal function turn(i)if i % 2 == 1 thenturnRight()elseturnLeft()endendlocal function digLayer()--[[ We move in zig-zag lines, clearing three layers at a time. This means wehave to differentiate at the end of the last line between even and oddsizes on which way to face for the next layer:For either size we rotate once to the right. For even sizes this willcause the next layer to be dug out rotated by ninety degrees. For oddones the return path is symmetrical, meaning we just turn around.Examples for two layers:s--x--x e--x--x s--x--x--x x--x x--x| | | | | | |x--x--x -> x--x--x x--x--x--x x x x x| | | -> | | | |x--x--e x--x--s x--x--x--x x x x x| | | | |e--x--x--x s x--x eLegend: s = start, x = a position, e = end, - = a move]]for i = 1, size dofor j = 1, size - 1 doif not step() thenreturn falseendendif i < size then-- End of a normal line, move the "cap".turn(i)if not step() thenreturn falseendturn(i)elseturnRight()if size % 2 == 1 thenturnRight()endfor i = 1, 3 doif not tryMove(sides.down) thenreturn falseendendendendreturn trueendrepeat until not digLayer()moveTo(0, 0, 0)turnTowards(0)checkedDrop(true)if options.s thencomputer.shutdown()end Изменено 11 декабря, 2014 пользователем GravityFolls 1 Цитата Поделиться сообщением Ссылка на сообщение Поделиться на других сайтах
DUIIIES 284 Опубликовано: 2 декабря, 2014 Ах... Твой англицкий шикарен. 1 Цитата Поделиться сообщением Ссылка на сообщение Поделиться на других сайтах
Fingercomp 4 409 Опубликовано: 3 декабря, 2014 (изменено) Finger.Translate: From Enhlush: Hello, I write programm for robot. You can download in minecraft pastebin get djsxf67h [name] [command] [size] [size] [your height] To English: Hi! I wrote the program for OpenComputers robot. With its help your robot will dig a hole. To install, simply insert the internet card to your computer/robot and type following to the OpenOS shell: mkdir /usr/bin/ pastebin get djsxf67h /usr/bin/ocrq Using: /usr/bin/ocrq [x] [y] [depth], where [x] is a length, [y] is a width and [depth] tells the robot how deep it must dig. To Russian: Привет всем! Я написал прогу для робота из OpenComputers, чтобы он копал яму. Чтобы её установить, просто вставьте интернет-карту в компьютер или в робота и выполните следующие команды в шелле OpenOS: mkdir /usr/bin pastebin get djsxf67h /usr/bin/ocrq Использование: /usr/bin/ocrq [x] [y] [z], где [x] — длина, [y] — ширина, которую нужно будет вскопать роботу, а [z] говорит роботу, как глубоко он должен копать. Thanks for using Finger.Translate! Изменено 3 декабря, 2014 пользователем Fingercomp 2 Цитата Поделиться сообщением Ссылка на сообщение Поделиться на других сайтах
DUIIIES 284 Опубликовано: 3 декабря, 2014 Ммм, так это был Enhlush. Фингер, дай ссылочку на переводчик, а то интернет оказался бессилен Цитата Поделиться сообщением Ссылка на сообщение Поделиться на других сайтах
Fingercomp 4 409 Опубликовано: 3 декабря, 2014 Ммм, так это был Enhlush. Фингер, дай ссылочку на переводчик, а то интернет оказался бессилен К сожалению, ОБТ планировалось провести 28 ноября, но вместо этого злой вирус украл сервер. Цитата Поделиться сообщением Ссылка на сообщение Поделиться на других сайтах
Totoro 3 563 Опубликовано: 3 декабря, 2014 Программа в первом посте - это стандартная OpenComputers Dig, которая включена в мод (ее можно найти на дискетах в сокровищнице). Написана Kenny, оригинал можно найти здесь: http://openprograms.github.io/ Была залита анонимом (GravityFolls, я полагаю) на pastebin 1 декабря. 3 Цитата Поделиться сообщением Ссылка на сообщение Поделиться на других сайтах
DUIIIES 284 Опубликовано: 3 декабря, 2014 Это зависть в тебе, Тоторо, говорит, рекурсивщику-то далеко до OpenComputer Robot Quarry. А Kenny вообще засудить можно аж по двум причинам: 1. Украл интелектуальных собственность Гравити; 2. Утаил изобретение всечеловеческой важности, а именно машины времени! Я думаю всем понятно, что не смотря на проказни Kenny, программа Гравити все равно будет "толще и длиннее". (тема на удаление в общем) Цитата Поделиться сообщением Ссылка на сообщение Поделиться на других сайтах
Stanislavich 0 Опубликовано: 6 января, 2019 Чоткий прог, но почему роботу с этой прогой насрать на глубину копания? Какую бы не ставил, он все равно копает до бедрока, мне кажется и его бы выкопал, если бы смог) Цитата Поделиться сообщением Ссылка на сообщение Поделиться на других сайтах