コード例 #1
0
ファイル: atom.py プロジェクト: avinayak/quark_minmax
 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
コード例 #2
0
 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, ')'
コード例 #3
0
ファイル: atom.py プロジェクト: avinayak/quark_minmax
 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
コード例 #4
0
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
コード例 #5
0
ファイル: main.py プロジェクト: jawadcode/ASCII_art_RLE
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')
コード例 #6
0
 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"))
コード例 #7
0
ファイル: main.py プロジェクト: jawadcode/ASCII_art_RLE
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')
コード例 #8
0
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
コード例 #9
0
def test_decode_simple():
    assert decode('123') == '333333333333'
コード例 #10
0
ファイル: test_rle.py プロジェクト: pstallworth/python-rle
	def test_single_decode(self):
		self.assertEqual("a",decode("a"))
コード例 #11
0
ファイル: test_rle.py プロジェクト: pstallworth/python-rle
	def test_decoder(self):
		self.assertEqual("aaaaaaaabbbbbcccd", decode("8a5b3cd"))
コード例 #12
0
ファイル: atom.py プロジェクト: avinayak/quark_minmax
 def isTerminal(self):
     return quark.is_gameover(rle.decode(self.board, (10, 8)))
コード例 #13
0
ファイル: test_rle.py プロジェクト: rikke14/E3SWE
def test_decode_empty():
    assert decode('') == ""
コード例 #14
0
ファイル: atom.py プロジェクト: avinayak/quark_minmax
 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]
コード例 #15
0
def test_enkod_dekod_tal():
    x = '1111'
    assert decode(rle(x)) == x
コード例 #16
0
    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()
コード例 #17
0
ファイル: test_rle.py プロジェクト: rikke14/E3SWE
def test_decode():
    assert decode('2k') == 'kk'
コード例 #18
0
def test_decode():
    assert decode([(3, 'b'), (4, ','), (19, ' ')]) == 'bbb,,,,' + ' ' * 19
コード例 #19
0
def test_decode_simple():
    assert decode('41') == '1111'
コード例 #20
0
def test_decode_simple():
    assert decode('') == ''
コード例 #21
0
def test_decode_simple():
    assert decode('2k3a') == 'kkaaa'
コード例 #22
0
ファイル: test_rle.py プロジェクト: rikke14/E3SWE
def test_hypo(x):
    print(x)
    decode(encode(x)) == x
コード例 #23
0
def test_enkod_dekod():
    x = 'assssassssassssaaaaaaasssassasfegrhjyuki'
    assert decode(rle(x)) == x
コード例 #24
0
def test_enkod_dekod_empty():
    x = ''
    assert decode(rle(x)) == x
コード例 #25
0
def test_encode_decode(s):
    #s = '2222aaaaaaaaafffffuuuu9999'
    print(s)
    assert decode(encode(s)) == s
コード例 #26
0
def test_enkod_dekod_hypo(x):
    assert decode(rle(x)) == x
コード例 #27
0
ファイル: test_rle.py プロジェクト: jenslawl/SWE2020
def test_decode():
    assert decode('2a') == 'aa'
    assert decode('3k2y') == 'kkkyy'
    assert decode('3k1y') == 'kkky'
    assert decode('4k5b1y3h') == 'kkkkbbbbbyhhh'
コード例 #28
0
def test_decode():
    assert decode('3b4,19 ') == 'bbb,,,,' + ' ' * 19