コード例 #1
0
 def clean_up_dead_python(self, old_tail_x, old_tail_y):
     """
     The Python has dead and we have to clean up his body.
     We ignore the head because it has hit something or gone out of bounds
     """
     for part in self.python.body[1:]:
         self.world[part.x][part.y] = Cell()
     self.world[old_tail_x][old_tail_y] = Cell()
コード例 #2
0
    def update_world(self, old_tail_coords: tuple = None):
        """
        After the Python's movement, update the cells in the world
        :param old_tail_coords: The coordinates of the python's tail before he moved, which should now be freed
        """
        if old_tail_coords is not None:
            tail_x, tail_y = old_tail_coords
            self.world[tail_x][tail_y] = Cell()

        for part in self.python.body:
            self.world[part.x][part.y] = Cell(part)
コード例 #3
0
def test_update_value(start, neighbors, expected):
        # The state of the local cell doesn't matter, it's the mirror cell that matters.
        c = Cell(start, Cell(start))

        c.set_source_neighbors(neighbors)
        c.update_value()

        assert expected == c.state
コード例 #4
0
    def build_world(self) -> list:
        world: [[Cell]] = []

        for row in range(self.size):
            new_row: [Cell] = []

            for col in range(self.size):
                new_row.append(Cell())

            world.append(new_row)

        return world
コード例 #5
0
    def add_cell(self, cell_type: WorldObject, x, y):
        try:
            if not self.world[x][y].is_empty():
                raise ConstructionError(
                    'You cannot overwrite a cell that is not empty!')

            if isinstance(cell_type, Food):
                self.food_count += 1

            cell = Cell(cell_type)
            self.world[x][y] = cell
        except (ConstructionError, IndexError) as e:
            print(e.message)
コード例 #6
0
import unittest
import pytest

from world import World, Cell

# Cell tests


@pytest.mark.parametrize("start,neighbors,expected",  [
    # Empty, 1 neighbor
    ('E', [Cell('1')], 'E'),
    ('E', [Cell('E')], 'E'),
    # Empty, 2 neighbors
    ('E', [Cell('E'), Cell('1')], 'E'),
    ('E', [Cell('1'), Cell('1')], 'E'),
    # Empty, 3 neighbors
    ('E', [Cell('1'), Cell('1'), Cell('1')], '1'),
    ('E', [Cell('1'), Cell('1'), Cell('F')], '1'),
    # Empty, 4 neighbors
    ('E', [Cell('1'), Cell('1'), Cell('1'), Cell('E')], '1'), # Born from 3 neighbors
    ('E', [Cell('1'), Cell('2'), Cell('1'), Cell('R')], 'E'), # Hostile neighbor prevents birth
    # Living, 1 neighbor
    ('1', [Cell('1')], 'E'),
    # Living, 2 neighbors
    ('1', [Cell('1'), Cell('1')], '1'),
    ('1', [Cell('1'), Cell('F')], '1'),
    # Living, 3 neighbors
    ('1', [Cell('1'), Cell('1'), Cell('1')], '1'),
    ('1', [Cell('1'), Cell('1'), Cell('F')], '1'),
    ('1', [Cell('1'), Cell('1'), Cell('2')], '1'), # Still 2 friendly neighbors
    # Living, 4 neighbors
コード例 #7
0
ファイル: tests.py プロジェクト: Syntox32/VacuumAI
    def test_contains_modifier(self):
        c = Cell(0, 0)
        c.add_modifier("hello", 15)

        self.assertIs(c.contains_modifier("hello"), True)
        self.assertIs(c.contains_modifier("not"), False)
コード例 #8
0
ファイル: tests.py プロジェクト: Syntox32/VacuumAI
 def test_add_modifier(self):
     c = Cell(0, 0)
     c.add_modifier("hello", 15)
     self.assertIs(c.modifiers["hello"], 15)