SHARE
TWEET

Untitled

a guest Nov 8th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2.  
  3. Block1 = [0, 0, 0, 0]
  4. Block2 = [0, 0, 0, 0]
  5. Block3 = [0, 0, 0, 0]
  6. Block4 = [0, 0, 0, 0]
  7. blocks = [Block1, Block2, Block3, Block4]
  8. Blockt1 = [Block1.copy(), Block2.copy(), Block3.copy(), Block4.copy()]
  9. inducerlist = [0, 1, 2, 3]
  10.  
  11. #Succesful: Revert, display, combine, reposition
  12. #not combining random numbers
  13.  
  14.  
  15.  
  16.  
  17. def is_FULL():
  18.     flag = True
  19.     for i in range(len(blocks)):
  20.         for j in blocks[i]:
  21.             if j == 0:
  22.                 flag = False
  23.     return flag
  24.  
  25.  
  26. def spawn_number():
  27.     global blocks
  28.     global Blockt1
  29.     if is_FULL() is False:
  30.         random_row = random.choice(inducerlist)
  31.         random_col = random.choice(inducerlist)
  32.         print(random_row, random_col)
  33.         if Blockt1[random_row][random_col] == 0:
  34.             Blockt1[random_row][random_col] = 2
  35.             blocks[random_row][random_col] = 2
  36.  
  37.             print(random_row, random_col)
  38.         else:
  39.             spawn_number()
  40.     else:
  41.         exit(0)
  42.  
  43.  
  44.  
  45. def display_board():
  46.     for i in range(len(blocks)):
  47.         for j in blocks[i]:
  48.             print(f"{j}", end = " ")
  49.         print()
  50.  
  51.  
  52.  
  53.  
  54. def repositionBoard():
  55.     global action
  56.     Blockt1 = [Block1.copy(), Block2.copy(), Block3.copy(), Block4.copy()]
  57.     if action == ('w' or 'W'):
  58.         Block1[:] = [Blockt1[3][0], Blockt1[2][0], Blockt1[1][0], Blockt1[0][0]]
  59.         Block2[:] = [Blockt1[3][1], Blockt1[2][1], Blockt1[1][1], Blockt1[0][1]]
  60.         Block3[:] = [Blockt1[3][2], Blockt1[2][2], Blockt1[1][2], Blockt1[0][2]]
  61.         Block4[:] = [Blockt1[3][3], Blockt1[2][3], Blockt1[1][3], Blockt1[0][3]]
  62.         blocks[:] = [Block1, Block2, Block3, Block4]
  63.     elif action == ('s' or 'S'):
  64.         Block1[:] = [Blockt1[0][0], Blockt1[1][0], Blockt1[2][0], Blockt1[3][0]]
  65.         Block2[:] = [Blockt1[0][1], Blockt1[1][1], Blockt1[2][1], Blockt1[3][1]]
  66.         Block3[:] = [Blockt1[0][2], Blockt1[1][2], Blockt1[2][2], Blockt1[3][2]]
  67.         Block4[:] = [Blockt1[0][3], Blockt1[1][3], Blockt1[2][3], Blockt1[3][3]]
  68.         blocks[:] = [Block1, Block2, Block3, Block4]
  69.     elif action == ('d' or 'D'):
  70.         Block1[:] = [Blockt1[0][0], Blockt1[0][1], Blockt1[0][2], Blockt1[0][3]]
  71.         Block2[:] = [Blockt1[1][0], Blockt1[1][1], Blockt1[1][2], Blockt1[1][3]]
  72.         Block3[:] = [Blockt1[2][0], Blockt1[2][1], Blockt1[2][2], Blockt1[2][3]]
  73.         Block4[:] = [Blockt1[3][0], Blockt1[3][1], Blockt1[3][2], Blockt1[3][3]]
  74.         blocks[:] = [Block1, Block2, Block3, Block4]
  75.     elif action == ('a' or 'A'):
  76.         Block1[:] = [Blockt1[0][3], Blockt1[0][2], Blockt1[0][1], Blockt1[0][0]]
  77.         Block2[:] = [Blockt1[1][3], Blockt1[1][2], Blockt1[1][1], Blockt1[1][0]]
  78.         Block3[:] = [Blockt1[2][3], Blockt1[2][2], Blockt1[2][1], Blockt1[2][0]]
  79.         Block4[:] = [Blockt1[3][3], Blockt1[3][2], Blockt1[3][1], Blockt1[3][0]]
  80.         blocks[:] = [Block1, Block2, Block3, Block4]
  81.  
  82. def revertBoard():
  83.     global action
  84.     global Blockt1
  85.     if action == ('w' or 'W'):
  86.         Block1[:] = [Blockt1[0][3], Blockt1[1][3], Blockt1[2][3], Blockt1[3][3]]
  87.         Block2[:] = [Blockt1[0][2], Blockt1[1][2], Blockt1[2][2], Blockt1[3][2]]
  88.         Block3[:] = [Blockt1[0][1], Blockt1[1][1], Blockt1[2][1], Blockt1[3][1]]
  89.         Block4[:] = [Blockt1[0][0], Blockt1[1][0], Blockt1[2][0], Blockt1[3][0]]
  90.         blocks[:] = [Block1, Block2, Block3, Block4]
  91.     elif action == ('s' or 'S'):
  92.         Block1[:] = [Blockt1[0][0], Blockt1[1][0], Blockt1[2][0], Blockt1[3][0]]
  93.         Block2[:] = [Blockt1[0][1], Blockt1[1][1], Blockt1[2][1], Blockt1[3][1]]
  94.         Block3[:] = [Blockt1[0][2], Blockt1[1][2], Blockt1[2][2], Blockt1[3][2]]
  95.         Block4[:] = [Blockt1[0][3], Blockt1[1][3], Blockt1[2][3], Blockt1[3][3]]
  96.         blocks[:] = [Block1, Block2, Block3, Block4]
  97.     elif action == ('d' or 'D'):
  98.         Block1[:] = [Blockt1[0][0], Blockt1[0][1], Blockt1[0][2], Blockt1[0][3]]
  99.         Block2[:] = [Blockt1[1][0], Blockt1[1][1], Blockt1[1][2], Blockt1[1][3]]
  100.         Block3[:] = [Blockt1[2][0], Blockt1[2][1], Blockt1[2][2], Blockt1[2][3]]
  101.         Block4[:] = [Blockt1[3][0], Blockt1[3][1], Blockt1[3][2], Blockt1[3][3]]
  102.         blocks[:] = [Block1, Block2, Block3, Block4]
  103.     elif action == ('a' or 'A'):
  104.         Block1[:] = [Blockt1[0][3], Blockt1[0][2], Blockt1[0][1], Blockt1[0][0]]
  105.         Block2[:] = [Blockt1[1][3], Blockt1[1][2], Blockt1[1][1], Blockt1[1][0]]
  106.         Block3[:] = [Blockt1[2][3], Blockt1[2][2], Blockt1[2][1], Blockt1[2][0]]
  107.         Block4[:] = [Blockt1[3][3], Blockt1[3][2], Blockt1[3][1], Blockt1[3][0]]
  108.         blocks[:] = [Block1, Block2, Block3, Block4]
  109.  
  110.  
  111. def reposition_Block1():
  112.  
  113.     global Blockt1
  114.     Blockt1 = [Block1.copy(), Block2.copy(), Block3.copy(), Block4.copy()]
  115.     for j in range(2):
  116.         for i in reversed(range(0, 4)):
  117.             if i == 3:
  118.                 if Blockt1[0][i] == 0:
  119.                     Blockt1[0][i] = Blockt1[0][i-1]
  120.                     Blockt1[0][i-1] = Blockt1[0][i-2]
  121.                     Blockt1[0][i-2] = Blockt1[0][i-3]
  122.                     Blockt1[0][i-3] = 0
  123.             elif i == 2:
  124.                 if Blockt1[0][i] == 0:
  125.                     Blockt1[0][i] = Blockt1[0][i - 1]
  126.                     Blockt1[0][i - 1] = Blockt1[0][i - 2]
  127.                     Blockt1[0][i - 2] = 0
  128.             elif i == 1:
  129.                 if Blockt1[0][i] == 0:
  130.                     Blockt1[0][i] = Blockt1[0][i - 1]
  131.                     Blockt1[0][i - 1] = 0
  132.  
  133.  
  134.  
  135. def reposition_Block2():
  136.  
  137.     for j in range(2):
  138.         for i in reversed(range(0, 4)):
  139.             if i == 3:
  140.                 if Blockt1[1][i] == 0:
  141.                     Blockt1[1][i] = Blockt1[1][i-1]
  142.                     Blockt1[1][i-1] = Blockt1[1][i-2]
  143.                     Blockt1[1][i-2] = Blockt1[1][i-3]
  144.                     Blockt1[1][i-3] = 0
  145.             elif i == 2:
  146.                 if Blockt1[1][i] == 0:
  147.                     Blockt1[1][i] = Blockt1[1][i - 1]
  148.                     Blockt1[1][i - 1] = Blockt1[1][i - 2]
  149.                     Blockt1[1][i - 2] = 0
  150.             elif i == 1:
  151.                 if Blockt1[1][i] == 0:
  152.                     Blockt1[1][i] = Blockt1[1][i - 1]
  153.                     Blockt1[1][i - 1] = 0
  154.  
  155.  
  156.  
  157.  
  158. def reposition_Block3():
  159.  
  160.     for j in range(2):
  161.         for i in reversed(range(0, 4)):
  162.             if i == 3:
  163.                 if Blockt1[2][i] == 0:
  164.                     Blockt1[2][i] = Blockt1[2][i-1]
  165.                     Blockt1[2][i-1] = Blockt1[2][i-2]
  166.                     Blockt1[2][i-2] = Blockt1[2][i-3]
  167.                     Blockt1[2][i-3] = 0
  168.             elif i == 2:
  169.                 if Blockt1[2][i] == 0:
  170.                     Blockt1[2][i] = Blockt1[2][i - 1]
  171.                     Blockt1[2][i - 1] = Blockt1[2][i - 2]
  172.                     Blockt1[2][i - 2] = 0
  173.             elif i == 1:
  174.                 if Blockt1[2][i] == 0:
  175.                     Blockt1[2][i] = Blockt1[2][i - 1]
  176.                     Blockt1[2][i - 1] = 0
  177.  
  178.  
  179. def reposition_Block4():
  180.  
  181.     for j in range(2):
  182.         for i in reversed(range(0, 4)):
  183.             if i == 3:
  184.                 if Blockt1[3][i] == 0:
  185.                     Blockt1[3][i] = Blockt1[3][i-1]
  186.                     Blockt1[3][i-1] = Blockt1[3][i-2]
  187.                     Blockt1[3][i-2] = Blockt1[3][i-3]
  188.                     Blockt1[3][i-3] = 0
  189.             elif i == 2:
  190.                 if Blockt1[3][i] == 0:
  191.                     Blockt1[3][i] = Blockt1[3][i - 1]
  192.                     Blockt1[3][i - 1] = Blockt1[3][i - 2]
  193.                     Blockt1[3][i - 2] = 0
  194.             elif i == 1:
  195.                 if Blockt1[3][i] == 0:
  196.                     Blockt1[3][i] = Blockt1[3][i - 1]
  197.                     Blockt1[3][i - 1] = 0
  198.  
  199.  
  200. def reposition_blocks():
  201.     reposition_Block1()
  202.     Blockt1[:] = [Blockt1[0], Block2.copy(), Block3.copy(), Block4.copy()]
  203.     reposition_Block2()
  204.     Blockt1[:] = [Blockt1[0], Blockt1[1], Block3.copy(), Block4.copy()]
  205.     reposition_Block3()
  206.     Blockt1[:] = [Blockt1[0], Blockt1[1], Blockt1[2], Block4.copy()]
  207.     reposition_Block4()
  208.  
  209.  
  210.  
  211. def Block1_combine():
  212.     global Blockt1
  213.  
  214.     for i in reversed(range(0, 4)):
  215.         if i == 3:
  216.             if (Blockt1[0][i] == Blockt1[0][i - 1]) and Blockt1[0][i] != 0:
  217.                 Blockt1[0][i] = Blockt1[0][i] + Blockt1[0][i - 1]
  218.                 Blockt1[0][i - 1] = Blockt1[0][i - 2]
  219.                 Blockt1[0][i - 2] = Blockt1[0][i - 3]
  220.                 Blockt1[0][i - 3] = 0
  221.         elif i == 2:
  222.             if (Blockt1[0][i] == Blockt1[0][i - 1]) and Blockt1[0][i] != 0:
  223.                 Blockt1[0][i] = Blockt1[0][i] + Blockt1[0][i - 1]
  224.                 Blockt1[0][i - 1] = Blockt1[0][i - 2]
  225.                 Blockt1[0][i - 2] = 0
  226.         elif i == 1:
  227.             if (Blockt1[0][i] == Blockt1[0][i - 1]) and Blockt1[0][i] != 0:
  228.                 Blockt1[0][i] = Blockt1[0][i] + Blockt1[0][i - 1]
  229.                 Blockt1[0][i - 1] = 0
  230.  
  231.  
  232. def Block2_combine():
  233.     for i in reversed(range(0, 4)):
  234.         if i == 3:
  235.             if (Blockt1[1][i] == Blockt1[1][i - 1]) and Blockt1[1][i] != 0:
  236.                 Blockt1[1][i] = Blockt1[1][i] + Blockt1[1][i - 1]
  237.                 Blockt1[1][i - 1] = Blockt1[1][i - 2]
  238.                 Blockt1[1][i - 2] = Blockt1[1][i - 3]
  239.                 Blockt1[1][i - 3] = 0
  240.         elif i == 2:
  241.             if (Blockt1[1][i] == Blockt1[1][i - 1]) and Blockt1[1][i] != 0:
  242.                 Blockt1[1][i] = Blockt1[1][i] + Blockt1[1][i - 1]
  243.                 Blockt1[1][i - 1] = Blockt1[1][i - 2]
  244.                 Blockt1[1][i - 2] = 0
  245.         elif i == 1:
  246.             if (Blockt1[1][i] == Blockt1[1][i - 1]) and Blockt1[1][i] != 0:
  247.                 Blockt1[1][i] = Blockt1[1][i] + Blockt1[1][i - 1]
  248.                 Blockt1[1][i - 1] = 0
  249.  
  250.  
  251. def Block3_combine():
  252.     for i in reversed(range(0, 4)):
  253.         if i == 3:
  254.             if (Blockt1[2][i] == Blockt1[2][i - 1]) and Blockt1[2][i] != 0:
  255.                 Blockt1[2][i] = Blockt1[2][i] + Blockt1[2][i - 1]
  256.                 Blockt1[2][i - 1] = Blockt1[2][i - 2]
  257.                 Blockt1[2][i - 2] = Blockt1[2][i - 3]
  258.                 Blockt1[2][i - 3] = 0
  259.         elif i == 2:
  260.             if (Blockt1[2][i] == Blockt1[2][i - 1]) and Blockt1[2][i] != 0:
  261.                 Blockt1[2][i] = Blockt1[2][i] + Blockt1[2][i - 1]
  262.                 Blockt1[2][i - 1] = Blockt1[2][i - 2]
  263.                 Blockt1[2][i - 2] = 0
  264.         elif i == 1:
  265.             if (Blockt1[2][i] == Blockt1[2][i - 1]) and Blockt1[2][i] != 0:
  266.                 Blockt1[2][i] = Blockt1[2][i] + Blockt1[2][i - 1]
  267.                 Blockt1[2][i - 1] = 0
  268.  
  269.  
  270. def Block4_combine():
  271.     for i in reversed(range(0, 4)):
  272.         if i == 3:
  273.             if (Blockt1[3][i] == Blockt1[3][i - 1]) and Blockt1[3][i] != 0:
  274.                 Blockt1[3][i] = Blockt1[3][i] + Blockt1[3][i - 1]
  275.                 Blockt1[3][i - 1] = Blockt1[3][i - 2]
  276.                 Blockt1[3][i - 2] = Blockt1[3][i - 3]
  277.                 Blockt1[3][i - 3] = 0
  278.         elif i == 2:
  279.             if (Blockt1[3][i] == Blockt1[3][i - 1]) and Blockt1[3][i] != 0:
  280.                 Blockt1[3][i] = Blockt1[3][i] + Blockt1[3][i - 1]
  281.                 Blockt1[3][i - 1] = Blockt1[3][i - 2]
  282.                 Blockt1[3][i - 2] = 0
  283.         elif i == 1:
  284.             if (Blockt1[3][i] == Blockt1[3][i - 1]) and Blockt1[3][i] != 0:
  285.                 Blockt1[3][i] = Blockt1[3][i] + Blockt1[3][i - 1]
  286.                 Blockt1[3][i - 1] = 0
  287.  
  288.  
  289. def combine_blocks():
  290.  
  291.     Block1_combine()
  292.     Blockt1[:] = [Blockt1[0], Blockt1[1].copy(), Blockt1[2].copy(), Blockt1[3].copy()]
  293.  
  294.     Block2_combine()
  295.     Blockt1[:] = [Blockt1[0], Blockt1[1], Blockt1[2].copy(), Blockt1[3].copy()]
  296.  
  297.     Block3_combine()
  298.     Blockt1[:] = [Blockt1[0], Blockt1[1].copy(), Blockt1[2], Blockt1[3].copy()]
  299.  
  300.     Block4_combine()
  301.  
  302.     blocks[:] = Blockt1
  303.  
  304.  
  305. spawn_number()
  306. while True:
  307.     display_board()
  308.     action = input()
  309.     repositionBoard()
  310.     reposition_blocks()
  311.     combine_blocks()
  312.     spawn_number()
  313.     revertBoard()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top