Gra-SI/genetic.py

53 lines
1.3 KiB
Python

# wygenerowanie populacji polozenia mobow na mapie - Archer, Infantry, Flower, Rocks, Grass, Blank
# Fitness
# Crossover
# Mutation
import random
import pygame
TILE_SIZE = 64
TYPES = ['A', 'I', "F", 'R', 'G', 'B']
MAP_TILES_LIST = list()
population = list()
max_population = 168 - 1
population_size = 50
class Genetic():
def generate_population():
if population_size > 168:
print("GENETIC: Podana populacja przekracza limit miejsc na mapie")
pygame.quit()
for i in range(155):
MAP_TILES_LIST.append(i)
random.shuffle(MAP_TILES_LIST)
if 14 in MAP_TILES_LIST:
MAP_TILES_LIST.remove(14)
if 131 in MAP_TILES_LIST:
MAP_TILES_LIST.remove(131)
for i in range(population_size):
tile = MAP_TILES_LIST.pop()
type = random.choice(TYPES)
object = (tile,type)
population.append(object)
if type == 'A':
TYPES.remove('A')
if type == 'I':
TYPES.remove('I')
print(population)
return population
def get_cell_x_y_cord(x,y):
cell_x = x // TILE_SIZE
cell_y = y // TILE_SIZE
return cell_x, cell_y