Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import copy
- import itertools
- import time
- import sys
- import os
- f = open("work.txt")
- ops = list(map(int,f.readline().split(','))) + [0]*1000
- RELBASE = 0
- def get(v, mode):
- global RELBASE
- if mode == 0:
- return ops[v]
- elif mode == 2:
- return ops[v + RELBASE]
- return v
- def get_addr(v, mode):
- global RELBASE
- if mode == 2:
- return v + RELBASE
- return v
- #########
- dx = [-1,0,1,0]
- dy = [0,1,0,-1]
- out = 0
- ###########
- color = dict()
- x = 0
- y = 0
- sp = 0
- joy = 0
- disp = 0
- ball = None
- paddle = None
- t = 0
- while sp < len(ops):
- # print('sp=',sp)
- inst = ops[sp] % 100
- t1 = ( ops[sp] // 100 ) % 10
- t2 = ( ops[sp] // 1000 ) % 10
- t3 = ( ops[sp] // 10000 ) % 10
- if inst == 1:
- a = get(ops[sp+1], t1)
- b = get(ops[sp+2], t2)
- c = get_addr(ops[sp+3], t3)
- # print('a=',a,'b=',b)
- # print('putting sum',a+b,' in ',c)
- ops[c] = a+b
- sp += 4
- elif inst == 2:
- a = get(ops[sp+1], t1)
- b = get(ops[sp+2], t2)
- c = get_addr(ops[sp+3], t3)
- ops[c] = a*b
- sp += 4
- elif inst == 3:
- t += 1
- if t%100 == 0:
- s = ''
- for j in range(25):
- for i in range(50):
- if (i,j) not in color or color[(i,j)] == 0:
- s += ' '
- elif color[(i,j)] == 1:
- s += '#'
- elif color[(i,j)] == 2:
- s += 'x'
- elif color[(i,j)] == 3:
- s += '_'
- elif color[(i,j)] == 4:
- s += '.'
- s += '\n'
- s += str(t)+'\n'
- s += 'disp = ' + str(disp) + '\n'*13
- os.system('cls')
- sys.stdout.write(s)
- sys.stdout.flush()
- a = get_addr(ops[sp+1], t1)
- if paddle[0] < ball[0]:
- ops[a] = 1
- elif paddle[0] > ball[0]:
- ops[a] = -1
- else:
- ops[a] = 0
- # ops[a] = int(input('input?'))
- ####
- sp += 2
- elif inst == 4:
- a = get(ops[sp+1], t1)
- if out == 0:
- out = 1
- x = a
- elif out == 1:
- out = 2
- y = a
- elif out == 2:
- out = 0
- if x == -1 and y == 0:
- disp = a
- else:
- # print('set',x,y,'to',a)
- color[(x,y)] = a
- if a == 4:
- ball = (x,y)
- if a == 3:
- paddle = (x,y)
- sp += 2
- elif inst == 5:
- a = get(ops[sp+1], t1)
- b = get(ops[sp+2], t2)
- if a != 0:
- sp = b
- else:
- sp += 3
- elif inst == 6:
- a = get(ops[sp+1], t1)
- b = get(ops[sp+2], t2)
- if a == 0:
- sp = b
- else:
- sp += 3
- elif inst == 7:
- a = get(ops[sp+1], t1)
- b = get(ops[sp+2], t2)
- c = get_addr(ops[sp+3], t3)
- if a < b:
- ops[c] = 1
- else:
- ops[c] = 0
- sp += 4
- elif inst == 8:
- a = get(ops[sp+1], t1)
- b = get(ops[sp+2], t2)
- c = get_addr(ops[sp+3], t3)
- if a == b:
- ops[c] = 1
- else:
- ops[c] = 0
- sp += 4
- elif inst == 9:
- a = get(ops[sp+1], t1)
- RELBASE += a
- sp += 2
- elif inst == 99:
- break
- else:
- print('got inst=',inst,'at',sp)
- break
- for j in range(50):
- for i in range(50):
- if (i,j) not in color or color[(i,j)] == 0:
- print(' ',end='')
- elif color[(i,j)] == 1:
- print('#',end='')
- elif color[(i,j)] == 2:
- print('x',end='')
- elif color[(i,j)] == 3:
- print('_',end='')
- elif color[(i,j)] == 4:
- print('.',end='')
- print('')
- print('disp =',disp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement