Lion4ever

chessTurtle

Sep 4th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local field=
  2. local chessFreq=4632
  3. local actions = {}
  4. actions['p']   = {"s16", "du", "ccs", "u", "du", "u", "u", "acu", "ac", "l", "ac", "l", "ac", "l", "ac", "l", "d", "d", "acu", "d", "s16", "pu"}
  5. actions['r']  = {"s16", "du", "ccs", "u", "u", "u", "f", "act", "acu", "acd", "di", "acm", "du", "u", "acu", "d", "acu", "acd", "r", "acm", "acu", "acd", "ac", "acm", "du", "u", "acu", "d", "acu", "acd", "r", "acm", "acu", "acd", "ac", "acm", "du", "u", "acu", "d", "acu", "acd", "r", "acm", "acu", "acd", "ac", "acm", "du", "u", "acu", "d", "acu", "acd", "r", "acm", "acu", "acd", "ac", "acx", "b", "d", "d", "d", "s16", "pu"}
  6. actions['h']  = {"s16", "du", "ccs", "u", "du", "u", "du", "u", "du", "u", "du", "u","tb", "ac","tb", "d", "l", "ac", "r", "r", "ac", "l", "acu", "d", "acu", "d", "ac", "acu", "l", "l", "ac", "l", "l", "d", "acu", "d", "s16", "pu"}
  7. actions['b'] = {"s16", "du", "ccs", "u", "u", "u", "u", 'acu', 'ac', 'l', 'ac', 'l', 'ac', 'l', 'ac', 'l', 'd', 'ac', 'l', 'ac', 'l', 'ac', 'l', 'ac', 'l', 'd', 'ac', 'l', 'ac', 'l', 'ac', 'l', 'ac', 'l', 'd', 'd', 's16', 'pu'}
  8. actions['k']   = {"s16", "du", "ccs", "u", 'du', 'u', 'u', 'du', 'u', 'u', 's5', 'acu', 'ccs', 'ac', 'l', 'l', 'ac', 'd', 'd', 'l', 'ac', 'l', 'l', 'ac', 'r', 'acu', 'd', 'd', 'acu', 'd', 's16', 'pu'}
  9. actions['q']  = {"s16", "du", "ccs", "u", "du", "u", "u", "du", "u", "f", "l", "acd", "f", "acu", "l", "f", "acd", "f", "acu", "l", "f", "acd", "f", "acu", "l", "f", "acd", "f", "acu", "l", "f", "r", "b", "u", "s6", "acu", "ccs", "d", "d", "acu", "d", "d", "acu", "d", "s16", "pu"}
  10.  
  11. local easyMoves={du=turtle.digUp,dd=turtle.digDown,u=function() repeat until turtle.up() end,f=function() repeat until turtle.forward() end,d=function() repeat until turtle.down() end,b=function() repeat until turtle.back() end, di=turtle.dig,l=turtle.turnLeft,r=turtle.turnRight,pu=turtle.placeUp,pl=turtle.place,pd=turtle.placeDown}
  12.  
  13. local stateRegarding={ac={"di","pl"},acu={"du","pu"},acd={"dd","pd"},act={"r","l"},acx={"l","r"},acm={"f","b"}}
  14. function doMove(move,state,isWhite)
  15.     if(move:sub(1,1) == "s")then
  16.         turtle.select(tonumber(move:sub(2)))
  17.     elseif(easyMoves[move])then
  18.         easyMoves[move]()
  19.     elseif(stateRegarding[move])then
  20.         easyMoves[stateRegarding[move][state]]()
  21.     elseif(move == "ccs")then
  22.         if(isWhite)then
  23.             turtle.select(1)
  24.         else
  25.             turtle.select(2)
  26.         end
  27.     elseif(move=="tb")then
  28.         if(isWhite) then
  29.             turtle.turnLeft()
  30.             turtle.turnLeft()
  31.         end
  32.     end
  33. end
  34.  
  35. function cls()
  36.     term.setBackgroundColor(colors.black)
  37.     term.clear()
  38.     term.setCursorPos(1,1)
  39. end
  40. modem=peripheral.wrap("right")
  41. modem.open(chessFreq)
  42. while true do
  43.     local event={os.pullEvent("modem_message")}
  44.     if event[5] and #event[5]==11 and event[5]:sub(1,2)==field then
  45.         local tempState=event[5]:sub(4,8)=="build" and 2 or 1
  46.         local color=event[5]:sub(11,11)=="w"
  47.         print(event[5])
  48.         for i=1,#actions[event[5]:sub(10,10)] do
  49.             doMove(actions[event[5]:sub(10,10)][i],tempState,color)
  50.         end
  51.         modem.transmit(chessFreq,chessFreq,field.." done")
  52.     end
  53. end
Advertisement
Add Comment
Please, Sign In to add comment