def takeAction(self, action): newState = deepcopy(self) newBoard = rle.decode(newState.board, (10, 8)) newBoard = quark.play(newBoard, action.x, action.y, action.player) newState.currentPlayer = self.currentPlayer * -1 newState.board = rle.encode(newBoard) return newState
def pic_from_data(self, data): self.width, self.height, self.mode = unpack('HHB', data[0:5]) rle_data = lzw.decompress(map(ord, data[5:]), self.mode) data = rle.decode(rle_data) self.pic = [] for y in xrange(0, self.height): self.pic.append(data[y*self.width:y*self.width + self.width]) print 'Pic read', self.width, 'x', self.height, '(', self.mode, ')'
def getReward(self): newBoard = rle.decode(self.board, (10, 8)) if quark.is_gameover(newBoard): degrees = quark.get_total_degrees_by_color(newBoard) if degrees[1] == 0: return -1*(320 - degrees[-1])**2 else: return 1*(320-degrees[1])**2 return False
def decompress(values, counts, decompressed_file_name): array_decompress = rle.decode(values, counts) string_decompress = "" for word in array_decompress: string_decompress = string_decompress + str(word) f = open(decompressed_file_name, 'w') f.write(string_decompress) f.close() return string_decompress
def convert_to_ASCII_art(): filename = './files/' + input( 'Please enter the filename for the encoded data: ') try: with open(filename, 'r') as file: print('\n') for line in rle.decode(file): print(line.strip()) except FileNotFoundError: print('Error: File not found :(') print('\n')
def test_simple_rle(self): self.assertEquals("ADVENT", rle.decode("ADVENT")) self.assertEquals("ABBBBBC", rle.decode("A(1x5)BC")) self.assertEquals("XYZXYZXYZ", rle.decode("(3x3)XYZ")) self.assertEquals("ABCBCDEFEFG", rle.decode("A(2x2)BCD(2x2)EFG")) self.assertEquals("(1x3)A", rle.decode("(6x1)(1x3)A")) self.assertEquals("X(3x3)ABC(3x3)ABCY", rle.decode("X(8x2)(3x3)ABCY"))
def enter_RLE(): try: linesofinput = int(input('How many lines of data will you enter: ')) except ValueError: print('That is not a valid integer\n') return enter_RLE() if linesofinput <= 2: print('You must input more than 2 lines\n') return enter_RLE() data = input_data(linesofinput) for line in rle.decode(data): print(line) print('\n')
def decode(text): values = [x for x in text if x.isalpha()] counts = [] idx = 0 while True: if are_lens_equal(counts, values): break el = text[idx] idx = (idx + 1) % len(text) next_el = text[idx] counts.append(take_count(el, next_el)) counts = [c for c in counts if not c == 0] result = rle.decode(values, counts) result = "".join(result) return result
def test_decode_simple(): assert decode('123') == '333333333333'
def test_single_decode(self): self.assertEqual("a",decode("a"))
def test_decoder(self): self.assertEqual("aaaaaaaabbbbbcccd", decode("8a5b3cd"))
def isTerminal(self): return quark.is_gameover(rle.decode(self.board, (10, 8)))
def test_decode_empty(): assert decode('') == ""
def getPossibleActions(self): newBoard = rle.decode(self.board, (10, 8)) moves = quark.get_legal_cell_locs(newBoard, self.currentPlayer) return [Action(player=self.currentPlayer, x=x, y=y) for x,y in moves]
def test_enkod_dekod_tal(): x = '1111' assert decode(rle(x)) == x
archivo = open(path) contenido = archivo.read(128) aux1 = time.perf_counter() cod = rle.encode(contenido) aux2 = time.perf_counter() tiempo = aux2 - aux1 print(tiempo) print(cod) archivo.close() arch = open("./comprimido.txt", "w") for i in cod: parseo = str(i) arch.write(parseo) arch.close() aux1 = time.perf_counter() decod = rle.decode(cod[0], cod[1]) aux2 = time.perf_counter() tiempo = aux2 - aux1 print(tiempo) print(decod) elif opcion == 3: archivo = open(path) contenido = archivo.read(128) archivo.close() probs = get_probabilities(contenido) tree = make_tree(probs) dic = make_dictionary(tree) compressed = compress(dic, contenido) aux1 = time.perf_counter() store(compressed, dic, "comprimido.txt") aux2 = time.perf_counter()
def test_decode(): assert decode('2k') == 'kk'
def test_decode(): assert decode([(3, 'b'), (4, ','), (19, ' ')]) == 'bbb,,,,' + ' ' * 19
def test_decode_simple(): assert decode('41') == '1111'
def test_decode_simple(): assert decode('') == ''
def test_decode_simple(): assert decode('2k3a') == 'kkaaa'
def test_hypo(x): print(x) decode(encode(x)) == x
def test_enkod_dekod(): x = 'assssassssassssaaaaaaasssassasfegrhjyuki' assert decode(rle(x)) == x
def test_enkod_dekod_empty(): x = '' assert decode(rle(x)) == x
def test_encode_decode(s): #s = '2222aaaaaaaaafffffuuuu9999' print(s) assert decode(encode(s)) == s
def test_enkod_dekod_hypo(x): assert decode(rle(x)) == x
def test_decode(): assert decode('2a') == 'aa' assert decode('3k2y') == 'kkkyy' assert decode('3k1y') == 'kkky' assert decode('4k5b1y3h') == 'kkkkbbbbbyhhh'
def test_decode(): assert decode('3b4,19 ') == 'bbb,,,,' + ' ' * 19