Advertisement
VikeStep

Rubiks Main

Jun 14th, 2013
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 26.93 KB | None | 0 0
  1. -- Rubik's Cube made by VikeStep
  2. -- 1: Blue, 2: Red, 3: Green, 4: Orange, 5: Yellow, 6: White
  3. -- f: front, r: right, b: back, l: left, u: up, d: down
  4. -- id 117 is replaced with 220 due to accidental breakage
  5.  
  6. local f, r, b, l, u, d = {}, {}, {}, {}, {}, {}
  7. local rubiksvars
  8. local nomove = false
  9.  
  10. function split(pString, pPattern)
  11. numchanged = 0
  12.    local Table = {}  -- NOTE: use {n = 0} in Lua-5.0
  13.    local fpat = "(.-)" .. pPattern
  14.    local last_end = 1
  15.    local s, e, cap = pString:find(fpat, 1)
  16.    while s do
  17.           if s ~= 1 or cap ~= "" then
  18.          table.insert(Table,cap)
  19. numchanged = numchanged +1
  20.           end
  21.           last_end = e+1
  22.           s, e, cap = pString:find(fpat, last_end)
  23.    end
  24.    if last_end <= #pString then
  25.           cap = pString:sub(last_end)
  26.           table.insert(Table, cap)
  27.           numchanged = numchanged +1
  28.    end
  29.    return Table
  30. end
  31.  
  32. function loadCube()
  33.     if fs.exists("rubiksvariables") then
  34.         loadVariables()
  35.         for i = 1,9 do
  36.             f[i] = rubiksvars[i]
  37.             r[i] = rubiksvars[i+9]
  38.             b[i] = rubiksvars[i+18]
  39.             l[i] = rubiksvars[i+27]
  40.             u[i] = rubiksvars[i+36]
  41.             d[i] = rubiksvars[i+45]
  42.         end
  43.     else
  44.         for i = 1,9 do
  45.             f[i] = 1
  46.             r[i] = 2
  47.             b[i] = 3
  48.             l[i] = 4
  49.             u[i] = 5
  50.             d[i] = 6
  51.         end
  52.     end
  53. end
  54.  
  55. function loadVariables()
  56.     local file = fs.open("rubiksvariables","r")
  57.     rubiksvars = split(file.readLine(), "@")
  58.     file.close()
  59. end
  60.  
  61. function saveVariables(variables)
  62.     local file = fs.open("rubiksvariables","w")
  63.     file.writeLine(variables)
  64.     file.close()
  65. end
  66.  
  67. function positionToID(position)
  68.     local id
  69.     if position == "f" then
  70.     id = "0,1,2,3"
  71.     elseif position == "fl" then
  72.     id = "4,5,6,7"
  73.     elseif position == "fr" then
  74.     id = "8,9,10,11"
  75.     elseif position == "fu" then
  76.     id = "12,13,14,15"
  77.     elseif position == "fd" then
  78.     id = "16,17,18,19"
  79.     elseif position == "fru" then
  80.     id = "20,21,22,23"
  81.     elseif position == "flu" then
  82.     id = "24,25,26,27"
  83.     elseif position == "fdr" then
  84.     id = "28,29,30,31"
  85.     elseif position == "fdl" then
  86.     id = "32,33,34,35"
  87.     elseif position == "r" then
  88.     id = "36,37,38,39"
  89.     elseif position == "rf" then
  90.     id = "40,41,42,43"
  91.     elseif position == "rb" then
  92.     id = "44,45,46,47"
  93.     elseif position == "ru" then
  94.     id = "48,49,50,51"
  95.     elseif position == "rd" then
  96.     id = "52,53,54,55"
  97.     elseif position == "rbu" then
  98.     id = "56,57,58,59"
  99.     elseif position == "rfu" then
  100.     id = "60,61,62,63"
  101.     elseif position == "rbd" then
  102.     id = "64,65,66,67"
  103.     elseif position == "rdf" then
  104.     id = "68,69,70,71"
  105.     elseif position == "b" then
  106.     id = "72,73,74,75"
  107.     elseif position == "br" then
  108.     id = "76,77,78,79"
  109.     elseif position == "bl" then
  110.     id = "80,81,82,83"
  111.     elseif position == "bu" then
  112.     id = "84,85,86,87"
  113.     elseif position == "bd" then
  114.     id = "88,89,90,91"
  115.     elseif position == "blu" then
  116.     id = "92,93,94,95"
  117.     elseif position == "bru" then
  118.     id = "96,97,98,99"
  119.     elseif position == "bdl" then
  120.     id = "100,101,102,103"
  121.     elseif position == "bdr" then
  122.     id = "104,105,106,107"
  123.     elseif position == "l" then
  124.     id = "108,109,110,111"
  125.     elseif position == "lb" then
  126.     id = "112,113,114,115"
  127.     elseif position == "lf" then
  128.     id = "116,117,220,119"
  129.     elseif position == "lu" then
  130.     id = "120,121,122,123"
  131.     elseif position == "ld" then
  132.     id = "124,125,126,127"
  133.     elseif position == "lfu" then
  134.     id = "128,129,130,131"
  135.     elseif position == "lbu" then
  136.     id = "132,133,134,135"
  137.     elseif position == "ldf" then
  138.     id = "136,137,138,139"
  139.     elseif position == "lbd" then
  140.     id = "140,141,142,143"
  141.     elseif position == "u" then
  142.     id = "144,145,146,147"
  143.     elseif position == "ul" then
  144.     id = "148,149,150,151"
  145.     elseif position == "ur" then
  146.     id = "152,153,154,155"
  147.     elseif position == "ub" then
  148.     id = "156,157,158,159"
  149.     elseif position == "uf" then
  150.     id = "160,161,162,163"
  151.     elseif position == "ubr" then
  152.     id = "164,165,166,167"
  153.     elseif position == "ubl" then
  154.     id = "168,169,170,171"
  155.     elseif position == "ufr" then
  156.     id = "172,173,174,175"
  157.     elseif position == "ufl" then
  158.     id = "176,177,178,179"
  159.     elseif position == "d" then
  160.     id = "180,181,182,183"
  161.     elseif position == "dl" then
  162.     id = "184,185,186,187"
  163.     elseif position == "dr" then
  164.     id = "188,189,190,191"
  165.     elseif position == "df" then
  166.     id = "192,193,194,195"
  167.     elseif position == "db" then
  168.     id = "196,197,198,199"
  169.     elseif position == "dfr" then
  170.     id = "200,201,202,203"
  171.     elseif position == "dfl" then
  172.     id = "204,205,206,207"
  173.     elseif position == "dbr" then
  174.     id = "208,209,210,211"
  175.     elseif position == "dbl" then
  176.     id = "212,213,214,215"
  177.     else
  178.     print("error, incorrect position")
  179.     end
  180.     return split(id,",")
  181. end
  182.  
  183. function setup()
  184.     loadCube()
  185.     rednet.open("right")
  186. end
  187.  
  188. function saveCube()
  189.     local tempsave = tostring(f[1]).."@"
  190.     for i = 2,9 do
  191.         tempsave = tempsave..tostring(f[i]).."@"
  192.     end
  193.     for i = 1,9 do
  194.         tempsave = tempsave..tostring(r[i]).."@"
  195.     end
  196.     for i = 1,9 do
  197.         tempsave = tempsave..tostring(b[i]).."@"
  198.     end
  199.     for i = 1,9 do
  200.         tempsave = tempsave..tostring(l[i]).."@"
  201.     end
  202.     for i = 1,9 do
  203.         tempsave = tempsave..tostring(u[i]).."@"
  204.     end
  205.     for i = 1,8 do
  206.         tempsave = tempsave..tostring(d[i]).."@"
  207.     end
  208.     tempsave = tempsave..tostring(d[9])
  209.     saveVariables(tempsave)
  210. end
  211.  
  212. function send(id, colour)
  213.     local side
  214.     id = tonumber(id)
  215.     if id <= 143 then
  216.         side = "f"
  217.     elseif id >= 144 and id <=179 then
  218.         side = "t"
  219.     elseif id >=180 and id <=215 then
  220.         side = "d"
  221.     elseif id == 220 then
  222.         side = "f"
  223.     else
  224.         print("type in the side this id is facing: u, f or d")
  225.         side = read()
  226.     end
  227.     rednet.send(id, side..","..tostring(colour))
  228. end
  229.  
  230. function resetCube()
  231.     for i = 0, 35 do
  232.         send(i, 1)
  233.     end
  234.     for i = 36, 71 do
  235.         send(i, 2)
  236.     end
  237.     for i = 72, 107 do
  238.         send(i, 3)
  239.     end
  240.     for i = 108, 143 do
  241.         send(i, 4)
  242.     end
  243.     for i = 144, 179 do
  244.         send(i, 5)
  245.     end
  246.     for i = 180, 215 do
  247.         send(i, 6)
  248.     end
  249.     send(220, 4)
  250.     for i = 1,9 do
  251.         f[i] = 1
  252.         r[i] = 2
  253.         b[i] = 3
  254.         l[i] = 4
  255.         u[i] = 5
  256.         d[i] = 6
  257.     end
  258. end
  259.  
  260. function sendSquare(side, colour)
  261.     local ids
  262.     if nomove == false then
  263.         ids = positionToID(side)
  264.         for i = 1, 4 do
  265.             send(ids[i], colour)
  266.         end
  267.     end
  268.     saveColour(side, colour)
  269. end
  270.  
  271. function readInput()
  272.     while true do
  273.         local id, msg = rednet.receive()
  274.         if msg == "reset" then
  275.             resetCube()
  276.         elseif msg == "F" then
  277.             moveF()
  278.         elseif msg == "R" then
  279.             moveR()
  280.         elseif msg == "B" then
  281.             moveB()
  282.         elseif msg == "L" then
  283.             moveL()
  284.         elseif msg == "U" then
  285.             moveU()
  286.         elseif msg == "D" then
  287.             moveD()
  288.         elseif msg == "F'" then
  289.             nomove = true
  290.             moveF()
  291.             moveF()
  292.             nomove = false
  293.             moveF()
  294.         elseif msg == "R'" then
  295.             nomove = true
  296.             moveR()
  297.             moveR()
  298.             nomove = false
  299.             moveR()
  300.         elseif msg == "B'" then
  301.             nomove = true
  302.             moveB()
  303.             moveB()
  304.             nomove = false
  305.             moveB()
  306.         elseif msg == "L'" then
  307.             nomove = true
  308.             moveL()
  309.             moveL()
  310.             nomove = false
  311.             moveL()
  312.         elseif msg == "U'" then
  313.             nomove = true
  314.             moveU()
  315.             moveU()
  316.             nomove = false
  317.             moveU()
  318.         elseif msg == "D'" then
  319.             nomove = true
  320.             moveD()
  321.             moveD()
  322.             nomove = false
  323.             moveD()
  324.         elseif msg == "randomise" then
  325.             randomise()
  326.         end
  327.     end
  328. end
  329.  
  330. function getColour(position)
  331.     local colour
  332.     if position == "f" then
  333.         colour = f[5]
  334.     elseif position == "fl" then
  335.         colour = f[4]
  336.     elseif position == "fr" then
  337.         colour = f[6]
  338.     elseif position == "fu" then
  339.         colour = f[2]
  340.     elseif position == "fd" then
  341.         colour = f[8]
  342.     elseif position == "fru" then
  343.         colour = f[3]
  344.     elseif position == "flu" then
  345.         colour = f[1]
  346.     elseif position == "fdr" then
  347.         colour = f[9]
  348.     elseif position == "fdl" then
  349.         colour = f[7]
  350.     elseif position == "r" then
  351.         colour = r[5]
  352.     elseif position == "rf" then
  353.         colour = r[4]
  354.     elseif position == "rb" then
  355.         colour = r[6]
  356.     elseif position == "ru" then
  357.         colour = r[2]
  358.     elseif position == "rd" then
  359.         colour = r[8]
  360.     elseif position == "rbu" then
  361.         colour = r[3]
  362.     elseif position == "rfu" then
  363.         colour = r[1]
  364.     elseif position == "rbd" then
  365.         colour = r[9]
  366.     elseif position == "rdf" then
  367.         colour = r[7]
  368.     elseif position == "b" then
  369.         colour = b[5]
  370.     elseif position == "br" then
  371.         colour = b[4]
  372.     elseif position == "bl" then
  373.         colour = b[6]
  374.     elseif position == "bu" then
  375.         colour = b[2]
  376.     elseif position == "bd" then
  377.         colour = b[8]
  378.     elseif position == "blu" then
  379.         colour = b[3]
  380.     elseif position == "bru" then
  381.         colour = b[1]
  382.     elseif position == "bdl" then
  383.         colour = b[9]
  384.     elseif position == "bdr" then
  385.         colour = b[7]
  386.     elseif position == "l" then
  387.         colour = l[5]
  388.     elseif position == "lb" then
  389.         colour = l[4]
  390.     elseif position == "lf" then
  391.         colour = l[6]
  392.     elseif position == "lu" then
  393.         colour = l[2]
  394.     elseif position == "ld" then
  395.         colour = l[8]
  396.     elseif position == "lfu" then
  397.         colour = l[3]
  398.     elseif position == "lbu" then
  399.         colour = l[1]
  400.     elseif position == "ldf" then
  401.         colour = l[9]
  402.     elseif position == "lbd" then
  403.         colour = l[7]
  404.     elseif position == "u" then
  405.         colour = u[5]
  406.     elseif position == "ul" then
  407.         colour = u[4]
  408.     elseif position == "ur" then
  409.         colour = u[6]
  410.     elseif position == "ub" then
  411.         colour = u[2]
  412.     elseif position == "uf" then
  413.         colour = u[8]
  414.     elseif position == "ubr" then
  415.         colour = u[3]
  416.     elseif position == "ubl" then
  417.         colour = u[1]
  418.     elseif position == "ufr" then
  419.         colour = u[9]
  420.     elseif position == "ufl" then
  421.         colour = u[7]
  422.     elseif position == "d" then
  423.         colour = d[5]
  424.     elseif position == "dl" then
  425.         colour = d[4]
  426.     elseif position == "dr" then
  427.         colour = d[6]
  428.     elseif position == "df" then
  429.         colour = d[2]
  430.     elseif position == "db" then
  431.         colour = d[8]
  432.     elseif position == "dfr" then
  433.         colour = d[3]
  434.     elseif position == "dfl" then
  435.         colour = d[1]
  436.     elseif position == "dbr" then
  437.         colour = d[9]
  438.     elseif position == "dbl" then
  439.         colour = d[7]
  440.     else
  441.         print("incorrect side")
  442.     end
  443.     return colour
  444. end
  445.  
  446. function saveColour(position, colour)
  447.     if position == "f" then
  448.         f[5] = colour
  449.     elseif position == "fl" then
  450.         f[4] = colour
  451.     elseif position == "fr" then
  452.         f[6] = colour
  453.     elseif position == "fu" then
  454.         f[2] = colour
  455.     elseif position == "fd" then
  456.         f[8] = colour
  457.     elseif position == "fru" then
  458.         f[3] = colour
  459.     elseif position == "flu" then
  460.         f[1] = colour
  461.     elseif position == "fdr" then
  462.         f[9] = colour
  463.     elseif position == "fdl" then
  464.         f[7] = colour
  465.     elseif position == "r" then
  466.         r[5] = colour
  467.     elseif position == "rf" then
  468.         r[4] = colour
  469.     elseif position == "rb" then
  470.         r[6] = colour
  471.     elseif position == "ru" then
  472.         r[2] = colour
  473.     elseif position == "rd" then
  474.         r[8] = colour
  475.     elseif position == "rbu" then
  476.         r[3] = colour
  477.     elseif position == "rfu" then
  478.         r[1] = colour
  479.     elseif position == "rbd" then
  480.         r[9] = colour
  481.     elseif position == "rdf" then
  482.         r[7] = colour
  483.     elseif position == "b" then
  484.         b[5] = colour
  485.     elseif position == "br" then
  486.         b[4] = colour
  487.     elseif position == "bl" then
  488.         b[6] = colour
  489.     elseif position == "bu" then
  490.         b[2] = colour
  491.     elseif position == "bd" then
  492.         b[8] = colour
  493.     elseif position == "blu" then
  494.         b[3] = colour
  495.     elseif position == "bru" then
  496.         b[1] = colour
  497.     elseif position == "bdl" then
  498.         b[9] = colour
  499.     elseif position == "bdr" then
  500.         b[7] = colour
  501.     elseif position == "l" then
  502.         l[5] = colour
  503.     elseif position == "lb" then
  504.         l[4] = colour
  505.     elseif position == "lf" then
  506.         l[6] = colour
  507.     elseif position == "lu" then
  508.         l[2] = colour
  509.     elseif position == "ld" then
  510.         l[8] = colour
  511.     elseif position == "lfu" then
  512.         l[3] = colour
  513.     elseif position == "lbu" then
  514.         l[1] = colour
  515.     elseif position == "ldf" then
  516.         l[9] = colour
  517.     elseif position == "lbd" then
  518.         l[7] = colour
  519.     elseif position == "u" then
  520.         u[5] = colour
  521.     elseif position == "ul" then
  522.         u[4] = colour
  523.     elseif position == "ur" then
  524.         u[6] = colour
  525.     elseif position == "ub" then
  526.         u[2] = colour
  527.     elseif position == "uf" then
  528.         u[8] = colour
  529.     elseif position == "ubr" then
  530.         u[3] = colour
  531.     elseif position == "ubl" then
  532.         u[1] = colour
  533.     elseif position == "ufr" then
  534.         u[9] = colour
  535.     elseif position == "ufl" then
  536.         u[7] = colour
  537.     elseif position == "d" then
  538.         d[5] = colour
  539.     elseif position == "dl" then
  540.         d[4] = colour
  541.     elseif position == "dr" then
  542.         d[6] = colour
  543.     elseif position == "df" then
  544.         d[2] = colour
  545.     elseif position == "db" then
  546.         d[8] = colour
  547.     elseif position == "dfr" then
  548.         d[3] = colour
  549.     elseif position == "dfl" then
  550.         d[1] = colour
  551.     elseif position == "dbr" then
  552.         d[9] = colour
  553.     elseif position == "dbl" then
  554.         d[7] = colour
  555.     else
  556.         print("incorrect side")
  557.     end
  558.     return colour
  559. end
  560.  
  561. function moveF()
  562.     oldcolourfl = getColour("fl")
  563.     oldcolourfr = getColour("fr")
  564.     oldcolourfu = getColour("fu")
  565.     oldcolourfd = getColour("fd")
  566.     oldcolourflu = getColour("flu")
  567.     oldcolourfru = getColour("fru")
  568.     oldcolourfdl = getColour("fdl")
  569.     oldcolourfdr = getColour("fdr")
  570.     oldcolourlf = getColour("lf")
  571.     oldcolouruf = getColour("uf")
  572.     oldcolourrf = getColour("rf")
  573.     oldcolourdf = getColour("df")
  574.     oldcolourlfu = getColour("lfu")
  575.     oldcolourufl = getColour("ufl")
  576.     oldcolourrfu = getColour("rfu")
  577.     oldcolourufr = getColour("ufr")
  578.     oldcolourdfl = getColour("dfl")
  579.     oldcolourldf = getColour("ldf")
  580.     oldcolourdfr = getColour("dfr")
  581.     oldcolourrdf = getColour("rdf")
  582.     newcolourfl = oldcolourfd
  583.     newcolourfr = oldcolourfu
  584.     newcolourfu = oldcolourfl
  585.     newcolourfd = oldcolourfr
  586.     newcolourflu = oldcolourfdl
  587.     newcolourfru = oldcolourflu
  588.     newcolourfdl = oldcolourfdr
  589.     newcolourfdr = oldcolourfru
  590.     newcolourlf = oldcolourdf
  591.     newcolouruf = oldcolourlf
  592.     newcolourrf = oldcolouruf
  593.     newcolourdf = oldcolourrf
  594.     newcolourlfu = oldcolourdfl
  595.     newcolourufl = oldcolourldf
  596.     newcolourrfu = oldcolourufl
  597.     newcolourufr = oldcolourlfu
  598.     newcolourdfl = oldcolourrdf
  599.     newcolourldf = oldcolourdfr
  600.     newcolourdfr = oldcolourrfu
  601.     newcolourrdf = oldcolourufr
  602.     sendSquare("fl", newcolourfl)
  603.     sendSquare("fr", newcolourfr)
  604.     sendSquare("fu", newcolourfu)
  605.     sendSquare("fd", newcolourfd)
  606.     sendSquare("flu", newcolourflu)
  607.     sendSquare("fru", newcolourfru)
  608.     sendSquare("fdl", newcolourfdl)
  609.     sendSquare("fdr", newcolourfdr)
  610.     sendSquare("lf", newcolourlf)
  611.     sendSquare("uf", newcolouruf)
  612.     sendSquare("rf", newcolourrf)
  613.     sendSquare("df", newcolourdf)
  614.     sendSquare("lfu", newcolourlfu)
  615.     sendSquare("ufl", newcolourufl)
  616.     sendSquare("rfu", newcolourrfu)
  617.     sendSquare("ufr", newcolourufr)
  618.     sendSquare("dfl", newcolourdfl)
  619.     sendSquare("ldf", newcolourldf)
  620.     sendSquare("dfr", newcolourdfr)
  621.     sendSquare("rdf", newcolourrdf)
  622.     saveCube()
  623. end
  624.  
  625. function moveR()
  626.     oldcolourrf = getColour("rf")
  627.     oldcolourrb = getColour("rb")
  628.     oldcolourru = getColour("ru")
  629.     oldcolourrd = getColour("rd")
  630.     oldcolourrfu = getColour("rfu")
  631.     oldcolourrbu = getColour("rbu")
  632.     oldcolourrdf = getColour("rdf")
  633.     oldcolourrbd = getColour("rbd")
  634.     oldcolourfr = getColour("fr")
  635.     oldcolourur = getColour("ur")
  636.     oldcolourbr = getColour("br")
  637.     oldcolourdr = getColour("dr")
  638.     oldcolourfru = getColour("fru")
  639.     oldcolourufr = getColour("ufr")
  640.     oldcolourbru = getColour("bru")
  641.     oldcolourubr = getColour("ubr")
  642.     oldcolourdfr = getColour("dfr")
  643.     oldcolourfdr = getColour("fdr")
  644.     oldcolourdbr = getColour("dbr")
  645.     oldcolourbdr = getColour("bdr")
  646.     newcolourrf = oldcolourrd
  647.     newcolourrb = oldcolourru
  648.     newcolourru = oldcolourrf
  649.     newcolourrd = oldcolourrb
  650.     newcolourrfu = oldcolourrdf
  651.     newcolourrbu = oldcolourrfu
  652.     newcolourrdf = oldcolourrbd
  653.     newcolourrbd = oldcolourrbu
  654.     newcolourfr = oldcolourdr
  655.     newcolourur = oldcolourfr
  656.     newcolourbr = oldcolourur
  657.     newcolourdr = oldcolourbr
  658.     newcolourfru = oldcolourdfr
  659.     newcolourufr = oldcolourfdr
  660.     newcolourbru = oldcolourufr
  661.     newcolourubr = oldcolourfru
  662.     newcolourdfr = oldcolourbdr
  663.     newcolourfdr = oldcolourdbr
  664.     newcolourdbr = oldcolourbru
  665.     newcolourbdr = oldcolourubr
  666.     sendSquare("rf", newcolourrf)
  667.     sendSquare("rb", newcolourrb)
  668.     sendSquare("ru", newcolourru)
  669.     sendSquare("rd", newcolourrd)
  670.     sendSquare("rfu", newcolourrfu)
  671.     sendSquare("rbu", newcolourrbu)
  672.     sendSquare("rdf", newcolourrdf)
  673.     sendSquare("rbd", newcolourrbd)
  674.     sendSquare("fr", newcolourfr)
  675.     sendSquare("ur", newcolourur)
  676.     sendSquare("br", newcolourbr)
  677.     sendSquare("dr", newcolourdr)
  678.     sendSquare("fru", newcolourfru)
  679.     sendSquare("ufr", newcolourufr)
  680.     sendSquare("bru", newcolourbru)
  681.     sendSquare("ubr", newcolourubr)
  682.     sendSquare("dfr", newcolourdfr)
  683.     sendSquare("fdr", newcolourfdr)
  684.     sendSquare("dbr", newcolourdbr)
  685.     sendSquare("bdr", newcolourbdr)
  686.     saveCube()
  687. end
  688.  
  689. function moveB()
  690.     oldcolourbr = getColour("br")
  691.     oldcolourbl = getColour("bl")
  692.     oldcolourbu = getColour("bu")
  693.     oldcolourbd = getColour("bd")
  694.     oldcolourbru = getColour("bru")
  695.     oldcolourblu = getColour("blu")
  696.     oldcolourbdr = getColour("bdr")
  697.     oldcolourbdl = getColour("bdl")
  698.     oldcolourrb = getColour("rb")
  699.     oldcolourub = getColour("ub")
  700.     oldcolourlb = getColour("lb")
  701.     oldcolourdb = getColour("db")
  702.     oldcolourrbu = getColour("rbu")
  703.     oldcolourubr = getColour("ubr")
  704.     oldcolourlbu = getColour("lbu")
  705.     oldcolourubl = getColour("ubl")
  706.     oldcolourdbr = getColour("dbr")
  707.     oldcolourrbd = getColour("rbd")
  708.     oldcolourdbl = getColour("dbl")
  709.     oldcolourlbd = getColour("lbd")
  710.     newcolourbr = oldcolourbd
  711.     newcolourbl = oldcolourbu
  712.     newcolourbu = oldcolourbr
  713.     newcolourbd = oldcolourbl
  714.     newcolourbru = oldcolourbdr
  715.     newcolourblu = oldcolourbru
  716.     newcolourbdr = oldcolourbdl
  717.     newcolourbdl = oldcolourblu
  718.     newcolourrb = oldcolourdb
  719.     newcolourub = oldcolourrb
  720.     newcolourlb = oldcolourub
  721.     newcolourdb = oldcolourlb
  722.     newcolourrbu = oldcolourdbr
  723.     newcolourubr = oldcolourrbd
  724.     newcolourlbu = oldcolourubr
  725.     newcolourubl = oldcolourrbu
  726.     newcolourdbr = oldcolourlbd
  727.     newcolourrbd = oldcolourdbl
  728.     newcolourdbl = oldcolourlbu
  729.     newcolourlbd = oldcolourubl
  730.     sendSquare("br", newcolourbr)
  731.     sendSquare("bl", newcolourbl)
  732.     sendSquare("bu", newcolourbu)
  733.     sendSquare("bd", newcolourbd)
  734.     sendSquare("bru", newcolourbru)
  735.     sendSquare("blu", newcolourblu)
  736.     sendSquare("bdr", newcolourbdr)
  737.     sendSquare("bdl", newcolourbdl)
  738.     sendSquare("rb", newcolourrb)
  739.     sendSquare("ub", newcolourub)
  740.     sendSquare("lb", newcolourlb)
  741.     sendSquare("db", newcolourdb)
  742.     sendSquare("rbu", newcolourrbu)
  743.     sendSquare("ubr", newcolourubr)
  744.     sendSquare("lbu", newcolourlbu)
  745.     sendSquare("ubl", newcolourubl)
  746.     sendSquare("dbr", newcolourdbr)
  747.     sendSquare("rbd", newcolourrbd)
  748.     sendSquare("dbl", newcolourdbl)
  749.     sendSquare("lbd", newcolourlbd)
  750.     saveCube()
  751. end
  752.  
  753. function moveL()
  754.     oldcolourlb = getColour("lb")
  755.     oldcolourlf = getColour("lf")
  756.     oldcolourlu = getColour("lu")
  757.     oldcolourld = getColour("ld")
  758.     oldcolourlbu = getColour("lbu")
  759.     oldcolourlfu = getColour("lfu")
  760.     oldcolourlbd = getColour("lbd")
  761.     oldcolourldf = getColour("ldf")
  762.     oldcolourbl = getColour("bl")
  763.     oldcolourul = getColour("ul")
  764.     oldcolourfl = getColour("fl")
  765.     oldcolourdl = getColour("dl")
  766.     oldcolourblu = getColour("blu")
  767.     oldcolourubl = getColour("ubl")
  768.     oldcolourflu = getColour("flu")
  769.     oldcolourufl = getColour("ufl")
  770.     oldcolourdbl = getColour("dbl")
  771.     oldcolourbdl = getColour("bdl")
  772.     oldcolourdfl = getColour("dfl")
  773.     oldcolourfdl = getColour("fdl")
  774.     newcolourlb = oldcolourld
  775.     newcolourlf = oldcolourlu
  776.     newcolourlu = oldcolourlb
  777.     newcolourld = oldcolourlf
  778.     newcolourlbu = oldcolourlbd
  779.     newcolourlfu = oldcolourlbu
  780.     newcolourlbd = oldcolourldf
  781.     newcolourldf = oldcolourlfu
  782.     newcolourbl = oldcolourdl
  783.     newcolourul = oldcolourbl
  784.     newcolourfl = oldcolourul
  785.     newcolourdl = oldcolourfl
  786.     newcolourblu = oldcolourdbl
  787.     newcolourubl = oldcolourbdl
  788.     newcolourflu = oldcolourubl
  789.     newcolourufl = oldcolourblu
  790.     newcolourdbl = oldcolourfdl
  791.     newcolourbdl = oldcolourdfl
  792.     newcolourdfl = oldcolourflu
  793.     newcolourfdl = oldcolourufl
  794.     sendSquare("lb", newcolourlb)
  795.     sendSquare("lf", newcolourlf)
  796.     sendSquare("lu", newcolourlu)
  797.     sendSquare("ld", newcolourld)
  798.     sendSquare("lbu", newcolourlbu)
  799.     sendSquare("lfu", newcolourlfu)
  800.     sendSquare("lbd", newcolourlbd)
  801.     sendSquare("ldf", newcolourldf)
  802.     sendSquare("bl", newcolourbl)
  803.     sendSquare("ul", newcolourul)
  804.     sendSquare("fl", newcolourfl)
  805.     sendSquare("dl", newcolourdl)
  806.     sendSquare("blu", newcolourblu)
  807.     sendSquare("ubl", newcolourubl)
  808.     sendSquare("flu", newcolourflu)
  809.     sendSquare("ufl", newcolourufl)
  810.     sendSquare("dbl", newcolourdbl)
  811.     sendSquare("bdl", newcolourbdl)
  812.     sendSquare("dfl", newcolourdfl)
  813.     sendSquare("fdl", newcolourfdl)
  814.     saveCube()
  815. end
  816.  
  817. function moveU()
  818.     oldcolourul = getColour("ul")
  819.     oldcolourur = getColour("ur")
  820.     oldcolourub = getColour("ub")
  821.     oldcolouruf = getColour("uf")
  822.     oldcolourubl = getColour("ubl")
  823.     oldcolourubr = getColour("ubr")
  824.     oldcolourufl = getColour("ufl")
  825.     oldcolourufr = getColour("ufr")
  826.     oldcolourlu = getColour("lu")
  827.     oldcolourbu = getColour("bu")
  828.     oldcolourru = getColour("ru")
  829.     oldcolourfu = getColour("fu")
  830.     oldcolourlbu = getColour("lbu")
  831.     oldcolourblu = getColour("blu")
  832.     oldcolourrbu = getColour("rbu")
  833.     oldcolourbru = getColour("bru")
  834.     oldcolourflu = getColour("flu")
  835.     oldcolourlfu = getColour("lfu")
  836.     oldcolourfru = getColour("fru")
  837.     oldcolourrfu = getColour("rfu")
  838.     newcolourul = oldcolouruf
  839.     newcolourur = oldcolourub
  840.     newcolourub = oldcolourul
  841.     newcolouruf = oldcolourur
  842.     newcolourubl = oldcolourufl
  843.     newcolourubr = oldcolourubl
  844.     newcolourufl = oldcolourufr
  845.     newcolourufr = oldcolourubr
  846.     newcolourlu = oldcolourfu
  847.     newcolourbu = oldcolourlu
  848.     newcolourru = oldcolourbu
  849.     newcolourfu = oldcolourru
  850.     newcolourlbu = oldcolourflu
  851.     newcolourblu = oldcolourlfu
  852.     newcolourrbu = oldcolourblu
  853.     newcolourbru = oldcolourlbu
  854.     newcolourflu = oldcolourrfu
  855.     newcolourlfu = oldcolourfru
  856.     newcolourfru = oldcolourrbu
  857.     newcolourrfu = oldcolourbru
  858.     sendSquare("ul", newcolourul)
  859.     sendSquare("ur", newcolourur)
  860.     sendSquare("ub", newcolourub)
  861.     sendSquare("uf", newcolouruf)
  862.     sendSquare("ubl", newcolourubl)
  863.     sendSquare("ubr", newcolourubr)
  864.     sendSquare("ufl", newcolourufl)
  865.     sendSquare("ufr", newcolourufr)
  866.     sendSquare("lu", newcolourlu)
  867.     sendSquare("bu", newcolourbu)
  868.     sendSquare("ru", newcolourru)
  869.     sendSquare("fu", newcolourfu)
  870.     sendSquare("lbu", newcolourlbu)
  871.     sendSquare("blu", newcolourblu)
  872.     sendSquare("rbu", newcolourrbu)
  873.     sendSquare("bru", newcolourbru)
  874.     sendSquare("flu", newcolourflu)
  875.     sendSquare("lfu", newcolourlfu)
  876.     sendSquare("fru", newcolourfru)
  877.     sendSquare("rfu", newcolourrfu)
  878.     saveCube()
  879. end
  880.  
  881. function moveD()
  882.     oldcolourdl = getColour("dl")
  883.     oldcolourdr = getColour("dr")
  884.     oldcolourdf = getColour("df")
  885.     oldcolourdb = getColour("db")
  886.     oldcolourdfl = getColour("dfl")
  887.     oldcolourdfr = getColour("dfr")
  888.     oldcolourdbl = getColour("dbl")
  889.     oldcolourdbr = getColour("dbr")
  890.     oldcolourld = getColour("ld")
  891.     oldcolourfd = getColour("fd")
  892.     oldcolourrd = getColour("rd")
  893.     oldcolourbd = getColour("bd")
  894.     oldcolourldf = getColour("ldf")
  895.     oldcolourfdl = getColour("fdl")
  896.     oldcolourrdf = getColour("rdf")
  897.     oldcolourfdr = getColour("fdr")
  898.     oldcolourbdl = getColour("bdl")
  899.     oldcolourlbd = getColour("lbd")
  900.     oldcolourbdr = getColour("bdr")
  901.     oldcolourrbd = getColour("rbd")
  902.     newcolourdl = oldcolourdb
  903.     newcolourdr = oldcolourdf
  904.     newcolourdf = oldcolourdl
  905.     newcolourdb = oldcolourdr
  906.     newcolourdfl = oldcolourdbl
  907.     newcolourdfr = oldcolourdfl
  908.     newcolourdbl = oldcolourdbr
  909.     newcolourdbr = oldcolourdfr
  910.     newcolourld = oldcolourbd
  911.     newcolourfd = oldcolourld
  912.     newcolourrd = oldcolourfd
  913.     newcolourbd = oldcolourrd
  914.     newcolourldf = oldcolourbdl
  915.     newcolourfdl = oldcolourlbd
  916.     newcolourrdf = oldcolourfdl
  917.     newcolourfdr = oldcolourldf
  918.     newcolourbdl = oldcolourrbd
  919.     newcolourlbd = oldcolourbdr
  920.     newcolourbdr = oldcolourrdf
  921.     newcolourrbd = oldcolourfdr
  922.     sendSquare("dl", newcolourdl)
  923.     sendSquare("dr", newcolourdr)
  924.     sendSquare("df", newcolourdf)
  925.     sendSquare("db", newcolourdb)
  926.     sendSquare("dfl", newcolourdfl)
  927.     sendSquare("dfr", newcolourdfr)
  928.     sendSquare("dbl", newcolourdbl)
  929.     sendSquare("dbr", newcolourdbr)
  930.     sendSquare("ld", newcolourld)
  931.     sendSquare("fd", newcolourfd)
  932.     sendSquare("rd", newcolourrd)
  933.     sendSquare("bd", newcolourbd)
  934.     sendSquare("ldf", newcolourldf)
  935.     sendSquare("fdl", newcolourfdl)
  936.     sendSquare("rdf", newcolourrdf)
  937.     sendSquare("fdr", newcolourfdr)
  938.     sendSquare("bdl", newcolourbdl)
  939.     sendSquare("lbd", newcolourlbd)
  940.     sendSquare("bdr", newcolourbdr)
  941.     sendSquare("rbd", newcolourrbd)
  942.     saveCube()
  943. end
  944.  
  945. function randomise()
  946.     local randommoves = math.random(10,20)
  947.     nomove = true
  948.     for i=1, randommoves do
  949.         local move = math.random(1,12)
  950.         if move == 1 then
  951.             moveF()
  952.         elseif move == 2 then
  953.             moveR()
  954.         elseif move == 3 then
  955.             moveB()
  956.         elseif move == 4 then
  957.             moveL()
  958.         elseif move == 5 then
  959.             moveU()
  960.         elseif move == 6 then
  961.             moveD()
  962.         elseif move == 7 then
  963.             moveF()
  964.             moveF()
  965.             moveF()
  966.         elseif move == 8 then
  967.             moveR()
  968.             moveR()
  969.             moveR()
  970.         elseif move == 9 then
  971.             moveB()
  972.             moveB()
  973.             moveB()
  974.         elseif move == 10 then
  975.             moveL()
  976.             moveL()
  977.             moveL()
  978.         elseif move == 11 then
  979.             moveU()
  980.             moveU()
  981.             moveU()
  982.         elseif move == 12 then
  983.             moveD()
  984.             moveD()
  985.             moveD()
  986.         end
  987.     end
  988.     nomove = false
  989.     refresh()
  990. end
  991.  
  992. function refresh()
  993.     for i = 0, 35 do
  994.         local init = (math.floor(i/4))+1
  995.         if init == 1 then
  996.             a = 5
  997.         elseif init == 2 then
  998.             a = 4
  999.         elseif init == 3 then
  1000.             a = 6
  1001.         elseif init == 4 then
  1002.             a = 2
  1003.         elseif init == 5 then
  1004.             a = 8
  1005.         elseif init == 6 then
  1006.             a = 3
  1007.         elseif init == 7 then
  1008.             a = 1
  1009.         elseif init == 8 then
  1010.             a = 9
  1011.         elseif init == 9 then
  1012.             a = 7
  1013.         end
  1014.         send(i, f[a])
  1015.     end
  1016.     for i = 36, 71 do
  1017.         local init = (math.floor((i-36)/4))+1
  1018.         if init == 1 then
  1019.             a = 5
  1020.         elseif init == 2 then
  1021.             a = 4
  1022.         elseif init == 3 then
  1023.             a = 6
  1024.         elseif init == 4 then
  1025.             a = 2
  1026.         elseif init == 5 then
  1027.             a = 8
  1028.         elseif init == 6 then
  1029.             a = 3
  1030.         elseif init == 7 then
  1031.             a = 1
  1032.         elseif init == 8 then
  1033.             a = 9
  1034.         elseif init == 9 then
  1035.             a = 7
  1036.         end
  1037.         send(i, r[a])
  1038.     end
  1039.     for i = 72, 107 do
  1040.         local init = (math.floor((i-72)/4))+1
  1041.         if init == 1 then
  1042.             a = 5
  1043.         elseif init == 2 then
  1044.             a = 4
  1045.         elseif init == 3 then
  1046.             a = 6
  1047.         elseif init == 4 then
  1048.             a = 2
  1049.         elseif init == 5 then
  1050.             a = 8
  1051.         elseif init == 6 then
  1052.             a = 3
  1053.         elseif init == 7 then
  1054.             a = 1
  1055.         elseif init == 8 then
  1056.             a = 9
  1057.         elseif init == 9 then
  1058.             a = 7
  1059.         end
  1060.         send(i, b[a])
  1061.     end
  1062.     for i = 108, 143 do
  1063.         local init = (math.floor((i-108)/4))+1
  1064.         if init == 1 then
  1065.             a = 5
  1066.         elseif init == 2 then
  1067.             a = 4
  1068.         elseif init == 3 then
  1069.             a = 6
  1070.         elseif init == 4 then
  1071.             a = 2
  1072.         elseif init == 5 then
  1073.             a = 8
  1074.         elseif init == 6 then
  1075.             a = 3
  1076.         elseif init == 7 then
  1077.             a = 1
  1078.         elseif init == 8 then
  1079.             a = 9
  1080.         elseif init == 9 then
  1081.             a = 7
  1082.         end
  1083.         send(i, l[a])
  1084.     end
  1085.     for i = 144, 179 do
  1086.         local init = (math.floor((i-144)/4))+1
  1087.         if init == 1 then
  1088.             a = 5
  1089.         elseif init == 2 then
  1090.             a = 4
  1091.         elseif init == 3 then
  1092.             a = 6
  1093.         elseif init == 4 then
  1094.             a = 2
  1095.         elseif init == 5 then
  1096.             a = 8
  1097.         elseif init == 6 then
  1098.             a = 3
  1099.         elseif init == 7 then
  1100.             a = 1
  1101.         elseif init == 8 then
  1102.             a = 9
  1103.         elseif init == 9 then
  1104.             a = 7
  1105.         end
  1106.         send(i, u[a])
  1107.     end
  1108.     for i = 180, 215 do
  1109.         local init = (math.floor((i-180)/4))+1
  1110.         if init == 1 then
  1111.             a = 5
  1112.         elseif init == 2 then
  1113.             a = 4
  1114.         elseif init == 3 then
  1115.             a = 6
  1116.         elseif init == 4 then
  1117.             a = 2
  1118.         elseif init == 5 then
  1119.             a = 8
  1120.         elseif init == 6 then
  1121.             a = 3
  1122.         elseif init == 7 then
  1123.             a = 1
  1124.         elseif init == 8 then
  1125.             a = 9
  1126.         elseif init == 9 then
  1127.             a = 7
  1128.         end
  1129.         send(i, d[a])
  1130.     end
  1131.     send(220, l[6])
  1132. end
  1133.  
  1134. setup()
  1135. readInput()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement