Untitled
unknown
python
2 years ago
1.5 kB
3
Indexable
import random # Format: # All cells 3x3, pointer starts at center, wraps # Read string left to right # 0 - Place next character # 1-4 - Move pointer up/right/down/left def Create_Creature(c_string): grid = [[' ',' ',' '],[' ',' ',' '],[' ',' ',' ']] pointer = [1,1] place = False for i in c_string: if place: grid[pointer[0]][pointer[1]] = i place = False else: if i == '0': place = True elif i == '1': pointer[1] = (pointer[1] + 2) % 3 elif i == '2': pointer[0] = (pointer[0] + 1) % 3 elif i == '3': pointer[1] = (pointer[1] + 1) % 3 elif i == '4': pointer[0] = (pointer[0] + 2) % 3 for i in grid: print(''.join(i)) base_string = "00101330312024404" Create_Creature(base_string) for i in range(5): print('--') s = list(base_string) mutation_index = random.randint(0,len(base_string)-1) mutation_number = str(random.randint(0,4)) print(f'Position {mutation_index} replaced with {mutation_number}, was {base_string[mutation_index]}') s[mutation_index] = mutation_number s = ''.join(s) Create_Creature(s) ### # 4 #103 # 2 #-- #Position 8 replaced with 2, was 3 # 4 #102 # 2 #-- #Position 4 replaced with 2, was 1 # 4 #203 # 2 #-- #Position 0 replaced with 4, was 0 #31 # 2 # 4 #-- #Position 16 replaced with 4, was 4 # 4 #103 # 2 #-- #Position 7 replaced with 1, was 0 # 4 #10 # 2
Editor is loading...