Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.39 KB | None | 0 0
  1. import copy
  2. import itertools
  3. import time
  4. import sys
  5. import os
  6.  
  7. f = open("work.txt")
  8. ops = list(map(int,f.readline().split(','))) + [0]*1000
  9.  
  10.  
  11.  
  12. RELBASE = 0
  13. def get(v, mode):
  14.   global RELBASE
  15.   if mode == 0:
  16.     return ops[v]
  17.   elif mode == 2:
  18.     return ops[v + RELBASE]
  19.   return v
  20.  
  21. def get_addr(v, mode):
  22.   global RELBASE
  23.   if mode == 2:
  24.     return v + RELBASE
  25.   return v
  26.  
  27. #########
  28. dx = [-1,0,1,0]
  29. dy = [0,1,0,-1]
  30. out = 0
  31. ###########
  32. color = dict()
  33. x = 0
  34. y = 0
  35. sp = 0
  36. joy = 0
  37. disp = 0
  38. ball = None
  39. paddle = None
  40. t = 0
  41. while sp < len(ops):
  42.   # print('sp=',sp)
  43.   inst = ops[sp] % 100
  44.   t1 = ( ops[sp] // 100 ) % 10
  45.   t2 = ( ops[sp] // 1000 ) % 10
  46.   t3 = ( ops[sp] // 10000 ) % 10
  47.  
  48.   if inst == 1:
  49.     a = get(ops[sp+1], t1)
  50.     b = get(ops[sp+2], t2)
  51.     c = get_addr(ops[sp+3], t3)
  52.     # print('a=',a,'b=',b)
  53.     # print('putting sum',a+b,' in ',c)
  54.     ops[c] = a+b
  55.     sp += 4
  56.   elif inst == 2:
  57.     a = get(ops[sp+1], t1)
  58.     b = get(ops[sp+2], t2)
  59.     c = get_addr(ops[sp+3], t3)
  60.     ops[c] = a*b
  61.     sp += 4
  62.   elif inst == 3:
  63.     t += 1
  64.     if t%100 == 0:
  65.       s = ''
  66.       for j in range(25):
  67.         for i in range(50):
  68.           if (i,j) not in color or color[(i,j)] == 0:
  69.             s += ' '
  70.           elif color[(i,j)] == 1:
  71.             s += '#'
  72.           elif color[(i,j)] == 2:
  73.             s += 'x'
  74.           elif color[(i,j)] == 3:
  75.             s += '_'
  76.           elif color[(i,j)] == 4:
  77.             s += '.'
  78.         s += '\n'
  79.       s += str(t)+'\n'
  80.       s += 'disp = ' + str(disp) + '\n'*13
  81.       os.system('cls')
  82.       sys.stdout.write(s)
  83.       sys.stdout.flush()
  84.      
  85.    
  86.     a = get_addr(ops[sp+1], t1)
  87.     if paddle[0] < ball[0]:
  88.       ops[a] = 1
  89.     elif paddle[0] > ball[0]:
  90.       ops[a] = -1
  91.     else:
  92.       ops[a] = 0
  93.     # ops[a] = int(input('input?'))
  94.     ####
  95.     sp += 2
  96.   elif inst == 4:
  97.     a = get(ops[sp+1], t1)
  98.    
  99.     if out == 0:
  100.       out = 1
  101.       x = a
  102.     elif out == 1:
  103.       out = 2
  104.       y = a
  105.     elif out == 2:
  106.       out = 0
  107.       if x == -1 and y == 0:
  108.         disp = a
  109.       else:
  110.         # print('set',x,y,'to',a)
  111.         color[(x,y)] = a
  112.         if a == 4:
  113.           ball = (x,y)
  114.         if a == 3:
  115.           paddle = (x,y)
  116.    
  117.     sp += 2
  118.   elif inst == 5:
  119.     a = get(ops[sp+1], t1)
  120.     b = get(ops[sp+2], t2)
  121.     if a != 0:
  122.       sp = b
  123.     else:
  124.       sp += 3
  125.   elif inst == 6:
  126.     a = get(ops[sp+1], t1)
  127.     b = get(ops[sp+2], t2)
  128.     if a == 0:
  129.       sp = b
  130.     else:
  131.       sp += 3
  132.   elif inst == 7:
  133.     a = get(ops[sp+1], t1)
  134.     b = get(ops[sp+2], t2)
  135.     c = get_addr(ops[sp+3], t3)
  136.     if a < b:
  137.       ops[c] = 1
  138.     else:
  139.       ops[c] = 0
  140.     sp += 4
  141.   elif inst == 8:
  142.     a = get(ops[sp+1], t1)
  143.     b = get(ops[sp+2], t2)
  144.     c = get_addr(ops[sp+3], t3)
  145.     if a == b:
  146.       ops[c] = 1
  147.     else:
  148.       ops[c] = 0
  149.     sp += 4
  150.   elif inst == 9:
  151.     a = get(ops[sp+1], t1)
  152.     RELBASE += a
  153.     sp += 2
  154.   elif inst == 99:
  155.     break
  156.   else:
  157.     print('got inst=',inst,'at',sp)
  158.     break
  159.  
  160. for j in range(50):
  161.   for i in range(50):
  162.     if (i,j) not in color or color[(i,j)] == 0:
  163.       print(' ',end='')
  164.     elif color[(i,j)] == 1:
  165.       print('#',end='')
  166.     elif color[(i,j)] == 2:
  167.       print('x',end='')
  168.     elif color[(i,j)] == 3:
  169.       print('_',end='')
  170.     elif color[(i,j)] == 4:
  171.       print('.',end='')
  172.   print('')
  173. print('disp =',disp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement