Advertisement
Rostom00

2048

May 20th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 25.01 KB | None | 0 0
  1. def prn():
  2.     global res, a
  3.     for f in range(28):
  4.         for g in range(68):
  5.             res[f][g] = ' '
  6.     for f in range(4):
  7.         for g in range(4):
  8.             app(f, g, a[f][g])
  9.     print('╔', end='')
  10.     for _ in range(3):
  11.         for q in range(17):
  12.             print('=', end='')
  13.         print('╦', end='')
  14.     for q in range(17):
  15.         print('=', end='')
  16.     print('╗')
  17.     for t in range(3):
  18.         for x in range(t * 7, (t + 1) * 7):
  19.             print('║', end='')
  20.             for q in range(3):
  21.                 for y in range(q * 17, (q + 1) * 17):
  22.                     print(res[x][y], end='')
  23.                 print('│', end='')
  24.             for y in range(51, 68):
  25.                 print(res[x][y], end='')
  26.             print('║', end='')
  27.             print()
  28.         print('╠', end='')
  29.         for _ in range(3):
  30.             for q in range(17):
  31.                 print('-', end='')
  32.             print('┼', end='')
  33.         for q in range(17):
  34.             print('-', end='')
  35.         print('╣')
  36.     for x in range(21, 28):
  37.         print('║', end='')
  38.         for q in range(3):
  39.             for y in range(q * 17, (q + 1) * 17):
  40.                 print(res[x][y], end='')
  41.             print('│', end='')
  42.         for y in range(51, 68):
  43.             print(res[x][y], end='')
  44.         print('║', end='')
  45.         print()
  46.     print('╚', end='')
  47.     for _ in range(3):
  48.         for q in range(17):
  49.             print('=', end='')
  50.         print('╩', end='')
  51.     for q in range(17):
  52.         print('=', end='')
  53.     print('╝')
  54.  
  55.  
  56. def app(x, y, z):
  57.     global res
  58.     temp = []
  59.     for q in range(7):
  60.         temp.append([])
  61.         for w in range(17):
  62.             temp[q].append(' ')
  63.     if z != 0:
  64.         if z == 2:
  65.             temp[0][5] = '*'
  66.             temp[0][6] = '*'
  67.             temp[0][7] = '*'
  68.             temp[0][8] = '*'
  69.             temp[0][9] = '*'
  70.             temp[0][10] = '*'
  71.             temp[0][11] = '*'
  72.             temp[1][11] = '*'
  73.             temp[2][11] = '*'
  74.             temp[3][6] = '*'
  75.             temp[3][7] = '*'
  76.             temp[3][8] = '*'
  77.             temp[3][9] = '*'
  78.             temp[3][10] = '*'
  79.             temp[4][5] = '*'
  80.             temp[5][5] = '*'
  81.             temp[6][5] = '*'
  82.             temp[6][6] = '*'
  83.             temp[6][7] = '*'
  84.             temp[6][8] = '*'
  85.             temp[6][9] = '*'
  86.             temp[6][10] = '*'
  87.             temp[6][11] = '*'
  88.         elif z == 4:
  89.             temp[0][5] = '*'
  90.             temp[0][11] = '*'
  91.             temp[1][5] = '*'
  92.             temp[1][11] = '*'
  93.             temp[2][5] = '*'
  94.             temp[2][11] = '*'
  95.             temp[3][5] = '*'
  96.             temp[3][6] = '*'
  97.             temp[3][7] = '*'
  98.             temp[3][8] = '*'
  99.             temp[3][9] = '*'
  100.             temp[3][10] = '*'
  101.             temp[3][11] = '*'
  102.             temp[4][11] = '*'
  103.             temp[5][11] = '*'
  104.             temp[6][11] = '*'
  105.         elif z == 8:
  106.             temp[0][5] = '*'
  107.             temp[0][6] = '*'
  108.             temp[0][7] = '*'
  109.             temp[0][8] = '*'
  110.             temp[0][9] = '*'
  111.             temp[0][10] = '*'
  112.             temp[0][11] = '*'
  113.             temp[1][5] = '*'
  114.             temp[1][11] = '*'
  115.             temp[2][5] = '*'
  116.             temp[2][11] = '*'
  117.             temp[3][5] = '*'
  118.             temp[3][6] = '*'
  119.             temp[3][7] = '*'
  120.             temp[3][8] = '*'
  121.             temp[3][9] = '*'
  122.             temp[3][10] = '*'
  123.             temp[3][11] = '*'
  124.             temp[4][5] = '*'
  125.             temp[4][11] = '*'
  126.             temp[5][5] = '*'
  127.             temp[5][11] = '*'
  128.             temp[6][5] = '*'
  129.             temp[6][6] = '*'
  130.             temp[6][7] = '*'
  131.             temp[6][8] = '*'
  132.             temp[6][9] = '*'
  133.             temp[6][10] = '*'
  134.             temp[6][11] = '*'
  135.         elif z == 16:
  136.             temp[0][5] = '*'
  137.             temp[1][5] = '*'
  138.             temp[2][5] = '*'
  139.             temp[3][5] = '*'
  140.             temp[4][5] = '*'
  141.             temp[5][5] = '*'
  142.             temp[6][5] = '*'
  143.             temp[1][4] = '*'
  144.             temp[2][3] = '*'
  145.             temp[3][2] = '*'
  146.             temp[0][8] = '*'
  147.             temp[0][9] = '*'
  148.             temp[0][10] = '*'
  149.             temp[0][11] = '*'
  150.             temp[0][12] = '*'
  151.             temp[0][13] = '*'
  152.             temp[0][14] = '*'
  153.             temp[1][8] = '*'
  154.             temp[2][8] = '*'
  155.             temp[3][8] = '*'
  156.             temp[3][9] = '*'
  157.             temp[3][10] = '*'
  158.             temp[3][11] = '*'
  159.             temp[3][12] = '*'
  160.             temp[3][13] = '*'
  161.             temp[3][14] = '*'
  162.             temp[4][8] = '*'
  163.             temp[4][14] = '*'
  164.             temp[5][8] = '*'
  165.             temp[5][14] = '*'
  166.             temp[6][8] = '*'
  167.             temp[6][9] = '*'
  168.             temp[6][10] = '*'
  169.             temp[6][11] = '*'
  170.             temp[6][12] = '*'
  171.             temp[6][13] = '*'
  172.             temp[6][14] = '*'
  173.         elif z == 32:
  174.             temp[0][1] = '*'
  175.             temp[0][2] = '*'
  176.             temp[0][3] = '*'
  177.             temp[0][4] = '*'
  178.             temp[0][5] = '*'
  179.             temp[0][6] = '*'
  180.             temp[0][7] = '*'
  181.             temp[1][7] = '*'
  182.             temp[2][7] = '*'
  183.             temp[3][1] = '*'
  184.             temp[3][2] = '*'
  185.             temp[3][3] = '*'
  186.             temp[3][4] = '*'
  187.             temp[3][5] = '*'
  188.             temp[3][6] = '*'
  189.             temp[3][7] = '*'
  190.             temp[4][7] = '*'
  191.             temp[5][7] = '*'
  192.             temp[6][1] = '*'
  193.             temp[6][2] = '*'
  194.             temp[6][3] = '*'
  195.             temp[6][4] = '*'
  196.             temp[6][5] = '*'
  197.             temp[6][6] = '*'
  198.             temp[6][7] = '*'
  199.             temp[0][9] = '*'
  200.             temp[0][10] = '*'
  201.             temp[0][11] = '*'
  202.             temp[0][12] = '*'
  203.             temp[0][13] = '*'
  204.             temp[0][14] = '*'
  205.             temp[0][15] = '*'
  206.             temp[1][15] = '*'
  207.             temp[2][15] = '*'
  208.             temp[3][10] = '*'
  209.             temp[3][11] = '*'
  210.             temp[3][12] = '*'
  211.             temp[3][13] = '*'
  212.             temp[3][14] = '*'
  213.             temp[4][9] = '*'
  214.             temp[5][9] = '*'
  215.             temp[6][9] = '*'
  216.             temp[6][10] = '*'
  217.             temp[6][11] = '*'
  218.             temp[6][12] = '*'
  219.             temp[6][13] = '*'
  220.             temp[6][14] = '*'
  221.             temp[6][15] = '*'
  222.         elif z == 64:
  223.             temp[0][1] = '*'
  224.             temp[0][2] = '*'
  225.             temp[0][3] = '*'
  226.             temp[0][4] = '*'
  227.             temp[0][5] = '*'
  228.             temp[0][6] = '*'
  229.             temp[0][7] = '*'
  230.             temp[1][1] = '*'
  231.             temp[2][1] = '*'
  232.             temp[3][1] = '*'
  233.             temp[3][2] = '*'
  234.             temp[3][3] = '*'
  235.             temp[3][4] = '*'
  236.             temp[3][5] = '*'
  237.             temp[3][6] = '*'
  238.             temp[3][7] = '*'
  239.             temp[4][1] = '*'
  240.             temp[4][7] = '*'
  241.             temp[5][1] = '*'
  242.             temp[5][7] = '*'
  243.             temp[6][1] = '*'
  244.             temp[6][2] = '*'
  245.             temp[6][3] = '*'
  246.             temp[6][4] = '*'
  247.             temp[6][5] = '*'
  248.             temp[6][6] = '*'
  249.             temp[6][7] = '*'
  250.             temp[0][9] = '*'
  251.             temp[0][15] = '*'
  252.             temp[1][9] = '*'
  253.             temp[1][15] = '*'
  254.             temp[2][9] = '*'
  255.             temp[2][15] = '*'
  256.             temp[3][9] = '*'
  257.             temp[3][10] = '*'
  258.             temp[3][11] = '*'
  259.             temp[3][12] = '*'
  260.             temp[3][13] = '*'
  261.             temp[3][14] = '*'
  262.             temp[3][15] = '*'
  263.             temp[4][15] = '*'
  264.             temp[5][15] = '*'
  265.             temp[6][15] = '*'
  266.         elif z == 128:
  267.             temp[1][4] = '*'
  268.             temp[2][4] = '*'
  269.             temp[3][4] = '*'
  270.             temp[4][4] = '*'
  271.             temp[5][4] = '*'
  272.             temp[2][3] = '*'
  273.             temp[3][2] = '*'
  274.             temp[1][7] = '*'
  275.             temp[1][8] = '*'
  276.             temp[1][9] = '*'
  277.             temp[2][9] = '*'
  278.             temp[3][7] = '*'
  279.             temp[3][8] = '*'
  280.             temp[3][9] = '*'
  281.             temp[4][7] = '*'
  282.             temp[5][7] = '*'
  283.             temp[5][8] = '*'
  284.             temp[5][9] = '*'
  285.             temp[1][12] = '*'
  286.             temp[1][13] = '*'
  287.             temp[1][14] = '*'
  288.             temp[2][12] = '*'
  289.             temp[2][14] = '*'
  290.             temp[3][12] = '*'
  291.             temp[3][13] = '*'
  292.             temp[3][14] = '*'
  293.             temp[4][12] = '*'
  294.             temp[4][14] = '*'
  295.             temp[5][12] = '*'
  296.             temp[5][13] = '*'
  297.             temp[5][14] = '*'
  298.         elif z == 256:
  299.             temp[1][2] = '*'
  300.             temp[1][3] = '*'
  301.             temp[1][4] = '*'
  302.             temp[2][4] = '*'
  303.             temp[3][2] = '*'
  304.             temp[3][3] = '*'
  305.             temp[3][4] = '*'
  306.             temp[4][2] = '*'
  307.             temp[5][2] = '*'
  308.             temp[5][3] = '*'
  309.             temp[5][4] = '*'
  310.             temp[1][7] = '*'
  311.             temp[1][8] = '*'
  312.             temp[1][9] = '*'
  313.             temp[2][7] = '*'
  314.             temp[3][7] = '*'
  315.             temp[3][8] = '*'
  316.             temp[3][9] = '*'
  317.             temp[4][9] = '*'
  318.             temp[5][7] = '*'
  319.             temp[5][8] = '*'
  320.             temp[5][9] = '*'
  321.             temp[1][12] = '*'
  322.             temp[1][13] = '*'
  323.             temp[1][14] = '*'
  324.             temp[2][12] = '*'
  325.             temp[3][12] = '*'
  326.             temp[3][13] = '*'
  327.             temp[3][14] = '*'
  328.             temp[4][12] = '*'
  329.             temp[4][14] = '*'
  330.             temp[5][12] = '*'
  331.             temp[5][13] = '*'
  332.             temp[5][14] = '*'
  333.         elif z == 512:
  334.             temp[1][2] = '*'
  335.             temp[1][3] = '*'
  336.             temp[1][4] = '*'
  337.             temp[2][2] = '*'
  338.             temp[3][2] = '*'
  339.             temp[3][3] = '*'
  340.             temp[3][4] = '*'
  341.             temp[4][4] = '*'
  342.             temp[5][2] = '*'
  343.             temp[5][3] = '*'
  344.             temp[5][4] = '*'
  345.             temp[1][9] = '*'
  346.             temp[2][9] = '*'
  347.             temp[3][9] = '*'
  348.             temp[4][9] = '*'
  349.             temp[5][9] = '*'
  350.             temp[2][8] = '*'
  351.             temp[3][7] = '*'
  352.             temp[1][12] = '*'
  353.             temp[1][13] = '*'
  354.             temp[1][14] = '*'
  355.             temp[2][14] = '*'
  356.             temp[3][12] = '*'
  357.             temp[3][13] = '*'
  358.             temp[3][14] = '*'
  359.             temp[4][12] = '*'
  360.             temp[5][12] = '*'
  361.             temp[5][13] = '*'
  362.             temp[5][14] = '*'
  363.         elif z == 1024:
  364.             temp[1][3] = '*'
  365.             temp[2][3] = '*'
  366.             temp[3][3] = '*'
  367.             temp[4][3] = '*'
  368.             temp[5][3] = '*'
  369.             temp[2][2] = '*'
  370.             temp[3][1] = '*'
  371.             temp[1][5] = '*'
  372.             temp[1][6] = '*'
  373.             temp[1][7] = '*'
  374.             temp[2][5] = '*'
  375.             temp[2][7] = '*'
  376.             temp[3][5] = '*'
  377.             temp[3][7] = '*'
  378.             temp[4][5] = '*'
  379.             temp[4][7] = '*'
  380.             temp[5][5] = '*'
  381.             temp[5][6] = '*'
  382.             temp[5][7] = '*'
  383.             temp[1][9] = '*'
  384.             temp[1][10] = '*'
  385.             temp[1][11] = '*'
  386.             temp[2][11] = '*'
  387.             temp[3][9] = '*'
  388.             temp[3][10] = '*'
  389.             temp[3][11] = '*'
  390.             temp[4][9] = '*'
  391.             temp[5][9] = '*'
  392.             temp[5][10] = '*'
  393.             temp[5][11] = '*'
  394.             temp[1][13] = '*'
  395.             temp[1][15] = '*'
  396.             temp[2][13] = '*'
  397.             temp[2][15] = '*'
  398.             temp[3][13] = '*'
  399.             temp[3][14] = '*'
  400.             temp[3][15] = '*'
  401.             temp[4][15] = '*'
  402.             temp[5][15] = '*'
  403.         elif z == 2048:
  404.             temp[1][1] = '*'
  405.             temp[1][2] = '*'
  406.             temp[1][3] = '*'
  407.             temp[2][3] = '*'
  408.             temp[3][1] = '*'
  409.             temp[3][2] = '*'
  410.             temp[3][3] = '*'
  411.             temp[4][1] = '*'
  412.             temp[5][1] = '*'
  413.             temp[5][2] = '*'
  414.             temp[5][3] = '*'
  415.             temp[1][5] = '*'
  416.             temp[1][6] = '*'
  417.             temp[1][7] = '*'
  418.             temp[2][5] = '*'
  419.             temp[2][7] = '*'
  420.             temp[3][5] = '*'
  421.             temp[3][7] = '*'
  422.             temp[4][5] = '*'
  423.             temp[4][7] = '*'
  424.             temp[5][5] = '*'
  425.             temp[5][6] = '*'
  426.             temp[5][7] = '*'
  427.             temp[1][9] = '*'
  428.             temp[1][11] = '*'
  429.             temp[2][9] = '*'
  430.             temp[2][11] = '*'
  431.             temp[3][9] = '*'
  432.             temp[3][10] = '*'
  433.             temp[3][11] = '*'
  434.             temp[4][11] = '*'
  435.             temp[5][11] = '*'
  436.             temp[1][13] = '*'
  437.             temp[1][14] = '*'
  438.             temp[1][15] = '*'
  439.             temp[2][13] = '*'
  440.             temp[2][15] = '*'
  441.             temp[3][13] = '*'
  442.             temp[3][14] = '*'
  443.             temp[3][15] = '*'
  444.             temp[4][13] = '*'
  445.             temp[4][15] = '*'
  446.             temp[5][13] = '*'
  447.             temp[5][14] = '*'
  448.             temp[5][15] = '*'
  449.             for q in [0, 6]:
  450.                 for w in [0, 8, 16]:
  451.                     temp[q][w] = '®'
  452.         elif z == 4096:
  453.             temp[1][1] = '*'
  454.             temp[1][3] = '*'
  455.             temp[2][1] = '*'
  456.             temp[2][3] = '*'
  457.             temp[3][1] = '*'
  458.             temp[3][2] = '*'
  459.             temp[3][3] = '*'
  460.             temp[4][3] = '*'
  461.             temp[5][3] = '*'
  462.             temp[1][5] = '*'
  463.             temp[1][6] = '*'
  464.             temp[1][7] = '*'
  465.             temp[2][5] = '*'
  466.             temp[2][7] = '*'
  467.             temp[3][5] = '*'
  468.             temp[3][7] = '*'
  469.             temp[4][5] = '*'
  470.             temp[4][7] = '*'
  471.             temp[5][5] = '*'
  472.             temp[5][6] = '*'
  473.             temp[5][7] = '*'
  474.             temp[1][9] = '*'
  475.             temp[1][10] = '*'
  476.             temp[1][11] = '*'
  477.             temp[2][9] = '*'
  478.             temp[2][11] = '*'
  479.             temp[3][9] = '*'
  480.             temp[3][10] = '*'
  481.             temp[3][11] = '*'
  482.             temp[4][11] = '*'
  483.             temp[5][9] = '*'
  484.             temp[5][10] = '*'
  485.             temp[5][11] = '*'
  486.             temp[1][13] = '*'
  487.             temp[1][14] = '*'
  488.             temp[1][15] = '*'
  489.             temp[2][13] = '*'
  490.             temp[3][13] = '*'
  491.             temp[3][14] = '*'
  492.             temp[3][15] = '*'
  493.             temp[4][13] = '*'
  494.             temp[4][15] = '*'
  495.             temp[5][13] = '*'
  496.             temp[5][14] = '*'
  497.             temp[5][15] = '*'
  498.         elif z == 8192:
  499.             temp[1][1] = '*'
  500.             temp[1][2] = '*'
  501.             temp[1][3] = '*'
  502.             temp[2][1] = '*'
  503.             temp[2][3] = '*'
  504.             temp[3][1] = '*'
  505.             temp[3][2] = '*'
  506.             temp[3][3] = '*'
  507.             temp[4][1] = '*'
  508.             temp[4][3] = '*'
  509.             temp[5][1] = '*'
  510.             temp[5][2] = '*'
  511.             temp[5][3] = '*'
  512.             temp[1][7] = '*'
  513.             temp[2][7] = '*'
  514.             temp[3][7] = '*'
  515.             temp[4][7] = '*'
  516.             temp[5][7] = '*'
  517.             temp[2][6] = '*'
  518.             temp[3][5] = '*'
  519.             temp[1][9] = '*'
  520.             temp[1][10] = '*'
  521.             temp[1][11] = '*'
  522.             temp[2][9] = '*'
  523.             temp[2][11] = '*'
  524.             temp[3][9] = '*'
  525.             temp[3][10] = '*'
  526.             temp[3][11] = '*'
  527.             temp[4][11] = '*'
  528.             temp[5][9] = '*'
  529.             temp[5][10] = '*'
  530.             temp[5][11] = '*'
  531.             temp[1][13] = '*'
  532.             temp[1][14] = '*'
  533.             temp[1][15] = '*'
  534.             temp[2][15] = '*'
  535.             temp[3][13] = '*'
  536.             temp[3][14] = '*'
  537.             temp[3][15] = '*'
  538.             temp[4][13] = '*'
  539.             temp[5][13] = '*'
  540.             temp[5][14] = '*'
  541.             temp[5][15] = '*'
  542.         for q in range(7):
  543.             for w in range(17):
  544.                 res[7 * x + q][17 * y + w] = temp[q][w]
  545.  
  546.  
  547. def step():
  548.     global gor
  549.     x = gor[0]
  550.     y = gor[1]
  551.     z = gor[2]
  552.     q = gor[3]
  553.     e = gor[4]
  554.     if q == 0:
  555.         if z == 0:
  556.             if y == 0:
  557.                 q = x
  558.                 x = 0
  559.                 if q != 0:
  560.                     e = 1
  561.             elif y == x:
  562.                 q = 2 * x
  563.                 x = 0
  564.                 y = 0
  565.                 e = 1
  566.             else:
  567.                 q = y
  568.                 z = x
  569.                 x = 0
  570.                 y = 0
  571.                 e = 1
  572.         elif y == 0:
  573.             if x == z:
  574.                 q = 2 * x
  575.                 x = 0
  576.                 z = 0
  577.                 e = 1
  578.             else:
  579.                 q = z
  580.                 z = x
  581.                 x = 0
  582.                 e = 1
  583.         elif y == z:
  584.             q = 2 * y
  585.             z = x
  586.             x = 0
  587.             e = 1
  588.         elif x == y:
  589.             q = z
  590.             z = 2 * x
  591.             y = 0
  592.             x = 0
  593.             e = 1
  594.         else:
  595.             q = z
  596.             z = y
  597.             y = x
  598.             x = 0
  599.             e = 1
  600.     elif z == 0:
  601.         if y == 0:
  602.             if x == q:
  603.                 q = 2 * x
  604.                 x = 0
  605.                 e = 1
  606.             elif x != 0:
  607.                 z = x
  608.                 x = 0
  609.                 e = 1
  610.         elif q == y:
  611.             q = 2 * y
  612.             z = x
  613.             y = 0
  614.             x = 0
  615.             e = 1
  616.         elif y == x:
  617.             z = 2 * y
  618.             y = 0
  619.             x = 0
  620.             e = 1
  621.         else:
  622.             z = y
  623.             y = x
  624.             x = 0
  625.             e = 1
  626.     elif y == 0:
  627.         if q == z:
  628.             q = 2 * z
  629.             z = x
  630.             x = 0
  631.             e = 1
  632.         elif z == x:
  633.             z = 2 * x
  634.             x = 0
  635.             e = 1
  636.         elif x != 0:
  637.             y = x
  638.             x = 0
  639.             e = 1
  640.     elif q == z:
  641.         if y == x:
  642.             q = 2 * z
  643.             z = 2 * x
  644.             y = 0
  645.             x = 0
  646.             e = 1
  647.         else:
  648.             q = 2 * z
  649.             z = y
  650.             y = x
  651.             x = 0
  652.             e = 1
  653.     elif z == y:
  654.         z = 2 * y
  655.         y = x
  656.         x = 0
  657.         e = 1
  658.     elif y == x:
  659.         y = 2 * x
  660.         x = 0
  661.         e = 1
  662.     if e == 1:
  663.         gor[0] = x
  664.         gor[1] = y
  665.         gor[2] = z
  666.         gor[3] = q
  667.         gor[4] = e
  668.  
  669.  
  670. import random
  671. a = []
  672. b = []
  673. for i in range(4):
  674.     a.append([])
  675.     b.append([])
  676.     for j in range(4):
  677.         a[i].append(0)
  678.         b[i].append(0)
  679. c = []
  680. for i in range(16):
  681.     c.append([0])
  682. res = []
  683. for i in range(28):
  684.     res.append([])
  685.     for j in range(68):
  686.         res[i].append(' ')
  687. last = []
  688. for i in range(5):
  689.     last.append('')
  690.  
  691. print('Hello!')
  692. print('This is game 2048')
  693. game = 1
  694. while game == 1:
  695.     h = random.randint(1, 6)
  696.     for i in range(4):
  697.         for j in range(4):
  698.             a[i][j] = 0
  699.     for k in range(16):
  700.         c[k] = 0
  701.     k = 1
  702.     for i in range(4):
  703.         for j in range(4):
  704.             if a[i][j] == 0:
  705.                 c[k - 1] = 10 * i + j
  706.                 k += 1
  707.     if k != 1:
  708.         k -= 1
  709.         k = random.randint(0, k - 1)
  710.         if h == 6:
  711.             h = 4
  712.         else:
  713.             h = 2
  714.         i = c[k] // 10
  715.         j = c[k] % 10
  716.         a[i][j] = h
  717.     prn()
  718.     for i in range(4):
  719.         for j in range(4):
  720.             b[i][j] = a[i][j]
  721.     print('Please press')
  722.     print(' w - for up')
  723.     print(' s - for down')
  724.     print(' a - for left')
  725.     print(' d - for right')
  726.     print('  u - for going back 1 step')
  727.     print()
  728.     print(' r - for restart')
  729.     print('And f - for finish game')
  730.     print()
  731.     possibility = 1
  732.     st = 1
  733.     last[1] = 'l'
  734.     last[2] = 'l'
  735.     last[3] = 'l'
  736.     last[4] = 'l'
  737.     while possibility == 1 and game == 1:
  738.         st = 0
  739.         if last[4] == 'u':
  740.             s = 'u'
  741.         else:
  742.             s = input()
  743.             p = 1
  744.             if last[3] == 'w':
  745.                 if s == 'w' or s == 's':
  746.                     p = 0
  747.             if last[2] == 'a':
  748.                 if s == 'a' or s == 'd':
  749.                     p = 0
  750.             if p == 1:
  751.                 if s == 'w' or s == 's' or s == 'a' or s == 'd':
  752.                     for i in range(4):
  753.                         for j in range(4):
  754.                             b[i][j] = a[i][j]
  755.             if p == 1:
  756.                 if s == 'w':
  757.                     for i in range(4):
  758.                         gor = [a[3][i], a[2][i], a[1][i], a[0][i], st]
  759.                         step()
  760.                         a[3][i] = gor[0]
  761.                         a[2][i] = gor[1]
  762.                         a[1][i] = gor[2]
  763.                         a[0][i] = gor[3]
  764.                         st = gor[4]
  765.                 elif s == 's':
  766.                     for i in range(4):
  767.                         gor = [a[0][i], a[1][i], a[2][i], a[3][i], st]
  768.                         step()
  769.                         a[0][i] = gor[0]
  770.                         a[1][i] = gor[1]
  771.                         a[2][i] = gor[2]
  772.                         a[3][i] = gor[3]
  773.                         st = gor[4]
  774.                 elif s == 'a':
  775.                     for i in range(4):
  776.                         gor = [a[i][3], a[i][2], a[i][1], a[i][0], st]
  777.                         step()
  778.                         a[i][3] = gor[0]
  779.                         a[i][2] = gor[1]
  780.                         a[i][1] = gor[2]
  781.                         a[i][0] = gor[3]
  782.                         st = gor[4]
  783.                 elif s == 'd':
  784.                     for i in range(4):
  785.                         gor = [a[i][0], a[i][1], a[i][2], a[i][3], st]
  786.                         step()
  787.                         a[i][0] = gor[0]
  788.                         a[i][1] = gor[1]
  789.                         a[i][2] = gor[2]
  790.                         a[i][3] = gor[3]
  791.                         st = gor[4]
  792.                 elif s == 'f':
  793.                     game = 0
  794.                 elif s == 'r':
  795.                     possibility = 0
  796.                 elif s == 'u':
  797.                     if last[1] == 'u':
  798.                         for i in range(4):
  799.                             for j in range(4):
  800.                                 a[i][j] = b[i][j]
  801.                         prn()
  802.                     else:
  803.                         print('Sorry, you can not do undo')
  804.                         print('Please, select another step')
  805.                 if st == 1:
  806.                     last[1] = 'u'
  807.                     for k in range(16):
  808.                         c[k] = 0
  809.                     k = 1
  810.                     for i in range(4):
  811.                         for j in range(4):
  812.                             if a[i][j] == 0:
  813.                                 c[k - 1] = 10 * i + j
  814.                                 k += 1
  815.                     if k != 1:
  816.                         k -= 1
  817.                         k = random.randint(0, k - 1)
  818.                         h = random.randint(1, 6)
  819.                         if h == 6:
  820.                             h = 4
  821.                         else:
  822.                             h = 2
  823.                         i = c[k] // 10
  824.                         j = c[k] % 10
  825.                         a[i][j] = h
  826.                     prn()
  827.                     possibility = 2
  828.                     for i in range(4):
  829.                         for j in range(3):
  830.                             if a[i][j] == 0 or a[i][j + 1] == 0 or a[i][j] == a[i][j + 1]:
  831.                                 possibility = 1
  832.                     if possibility == 2:
  833.                         last[2] = 'a'
  834.                     possibility = 2
  835.                     for i in range(4):
  836.                         for j in range(3):
  837.                             if a[j][i] == 0 or a[j + 1][i] == 0 or a[j][i] == a[j + 1][i]:
  838.                                 possibility = 1
  839.                     if possibility == 2:
  840.                         last[3] = 'w'
  841.                     possibility = 1
  842.                     if last[2] == 'a' and last[3] == 'w':
  843.                         print('Please press')
  844.                         print(' u - for undo')
  845.                         print(' f - for finish')
  846.                         print(' or any other key - for restart')
  847.                         s = input()
  848.                 if st == 1:
  849.                     if last[2] == 'a' and last[3] == 'w':
  850.                         if s == 'f':
  851.                             game = 0
  852.                         elif s == 'u':
  853.                             last[4] = 'u'
  854.                             last[2] = 'l'
  855.                             last[3] = 'l'
  856.                         else:
  857.                             possibility = 0
  858.                     else:
  859.                         last[1] = 'u'
  860.                 elif s == 'w' or s == 's' or s == 'a' or s == 'd':
  861.                     print('Your step is invalid')
  862.                     print('Please, select another step')
  863.                 elif s != 'r' and s != 'f' and s != 'u':
  864.                     print('Your step does not exist')
  865.                     print('Please, select a right step')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement