local turn = require("turn")
local reset = require("reset")
local drop = require("drop")
local sensor = require("sensor")
local back = require("back")
local color = require("color")
local take = require("take")

tasks = {}
curr = 1
tables = {0, 1, 2}

for i = 2, #tables do
    table.insert(tasks, { main = take, delay = 2, context = {} })
    for _, j in pairs(buildRoute(graph, tables[i - 1], tables[i])) do
        table.insert(tasks, { main = turn, delay = 0, context = { idx = j, up = true } })
        table.insert(tasks, { main = color, delay = 0, context = { idx = j } })
    end
    table.insert(tasks, { main = sensor, delay = 0, context = { idx = 1 } })
    table.insert(tasks, { main = drop, delay = 0.5, context = {} })
    table.insert(tasks, { main = back, delay = 5, context = {} })

    for _, j in pairs(buildRoute(graph, tables[i], 0)) do
        table.insert(tasks, { main = turn, delay = 0, context = { idx = j, up = true } })
    end

    table.insert(tasks, { main = reset, delay = 0, context = {} })
end