
from abc import ABC, abstractmethod

from Color import RandomColor


class Algo(ABC):

    def __init__(self, population_size):
        self.population_size = population_size
        self.set_random_population()

    def set_random_population(self):
        self.population = []
        for i in range(self.population_size):
            self.population.append(RandomColor())

    def dump(self):
        for color in self.population:
            print('{} '.format(color), end='')
        print(flush=True)

    @abstractmethod
    def tick(self, deltas):
        pass


from abc import ABC, abstractmethod

from Color import RandomColor


class Algo(ABC):

    def __init__(self, population_size):

        assert population_size % 2 == 0

        self.half_population_size = population_size // 2
        self.population_size = population_size

        self.set_random_population()

    def set_random_population(self):
        self.population = []
        for i in range(self.population_size):
            self.population.append(RandomColor())

    def dump(self):
        for color in self.population:
            print('{} '.format(color), end='')
        print(flush=True)

    @abstractmethod
    def tick(self, deltas):
        pass

Check that population_size is even, and set half_population_size.
Check that population_size is even, and set half_population_size.

This will be used by genetic algorithms.

  
  from abc import ABC, abstractmethod
  
  from Color import RandomColor
  
  
  class Algo(ABC):
  
      def __init__(self, population_size):
+ 
+         assert population_size % 2 == 0
+ 
+         self.half_population_size = population_size // 2
          self.population_size = population_size
+ 
          self.set_random_population()
  
      def set_random_population(self):
          self.population = []
          for i in range(self.population_size):
              self.population.append(RandomColor())
  
      def dump(self):
          for color in self.population:
              print('{} '.format(color), end='')
          print(flush=True)
  
      @abstractmethod
      def tick(self, deltas):
          pass
  
Check that population_size is even, and set half_population_size.
## Code Before:

from abc import ABC, abstractmethod

from Color import RandomColor


class Algo(ABC):

    def __init__(self, population_size):
        self.population_size = population_size
        self.set_random_population()

    def set_random_population(self):
        self.population = []
        for i in range(self.population_size):
            self.population.append(RandomColor())

    def dump(self):
        for color in self.population:
            print('{} '.format(color), end='')
        print(flush=True)

    @abstractmethod
    def tick(self, deltas):
        pass

## Instruction:
Check that population_size is even, and set half_population_size.
## Code After:

from abc import ABC, abstractmethod

from Color import RandomColor


class Algo(ABC):

    def __init__(self, population_size):

        assert population_size % 2 == 0

        self.half_population_size = population_size // 2
        self.population_size = population_size

        self.set_random_population()

    def set_random_population(self):
        self.population = []
        for i in range(self.population_size):
            self.population.append(RandomColor())

    def dump(self):
        for color in self.population:
            print('{} '.format(color), end='')
        print(flush=True)

    @abstractmethod
    def tick(self, deltas):
        pass
