Exemple #1
0
    def static_eval(self):
        win_ai = CellState.to_char(CellState.AI) * self._win_length
        win_enemy = CellState.to_char(CellState.AI) * self._win_length

        rows = self.get_rows()
        cols = self.get_cols()
        diagonals = self.get_diagonals()
        antidiagonals = self.get_antidiagonals()

        if win_ai in rows or win_ai in cols or win_ai in diagonals or win_ai in antidiagonals:
            return inf
        elif win_enemy in rows or win_enemy in cols or win_enemy in diagonals or win_enemy in antidiagonals:
            return -inf

        total = 0
        # Make it extremely slow
        for p in patterns.patterns:
            for row in rows:
                total += row.count(p["pattern"]) * p["weight"]
            for col in cols:
                total += col.count(p["pattern"]) * p["weight"]
            for diagonal in diagonals:
                total += diagonal.count(p["pattern"]) * p["weight"]
            for antidiagonal in antidiagonals:
                total += antidiagonal.count(p["pattern"]) * p["weight"]

        return total
Exemple #2
0
 def addCell(self, cellType=0, **kwargs):
     cid = self.next_id()
     cs = CellState(cid)
     cs.idx = self.next_idx()
     cs.cellType = cellType
     self.idToIdx[cid] = cs.idx
     self.cellStates[cid] = cs
     if self.integ:
         self.integ.addCell(cs)
     self.reg.addCell(cs)
     if self.sig:
         self.sig.addCell(cs)
     self.phys.addCell(cs, **kwargs)
Exemple #3
0
    def who_won(self):
        rows = self.get_rows()
        cols = self.get_cols()
        diagonals = self.get_diagonals()
        antidiagonals = self.get_antidiagonals()
        win_ai = CellState.to_char(CellState.AI) * self._win_length
        win_enemy = CellState.to_char(CellState.ENEMY) * self._win_length

        if win_ai in rows or win_ai in cols or win_ai in diagonals or win_ai in antidiagonals:
            return CellState.AI
        if win_enemy in rows or win_enemy in cols or win_enemy in diagonals or win_enemy in antidiagonals:
            return CellState.ENEMY
        return CellState.EMPTY
    def __init__(self,
                 eq_index,
                 z_coordinate,
                 is_boundary_x=False,
                 is_boundary_y=False,
                 has_well=False,
                 well_index=None):
        self.is_boundary_y = is_boundary_y
        self.is_boundary_x = is_boundary_x
        self.cell_states = [CellState(), CellState()]  # n, n + 1 layers
        self.eq_index = eq_index
        self.has_well = has_well
        self.well = Well(self, well_index,
                         horizontal=Layer.horizontal) if has_well else None
        self.z_coordinate = z_coordinate

        self.flow_array_x = np.array(
            [Flow() for _ in range(Layer.components_count)], dtype=Flow
        )  # Поток минус(для oil и water) Поток плюс(для oil и water)
        self.flow_array_y = np.array(
            [Flow() for _ in range(Layer.components_count)], dtype=Flow)
        self.flow_array_z = np.array(
            [Flow() for _ in range(Layer.components_count)], dtype=Flow)
 def addCell(self, cellType=0, cellAdh=0.0, length=3.5, **kwargs):
     cid = self.next_id()
     cs = CellState(cid)
     cs.length = length
     cs.oldLen = length
     cs.cellType = cellType
     cs.cellAdh = cellAdh
     cs.idx = self.next_idx()
     self.idToIdx[cid] = cs.idx
     self.cellStates[cid] = cs
     if self.integ:
         self.integ.addCell(cs)
     self.reg.addCell(cs)
     if self.sig:
         self.sig.addCell(cs)
     self.phys.addCell(cs, **kwargs)
Exemple #6
0
 def addCell(self, cellType=0, cellAdh=0.0, length=3.5, **kwargs):
     cid = self.next_id()
     cs = CellState(cid)
     cs.length = length
     cs.oldLen = length
     cs.cellType = cellType
     cs.cellAdh = cellAdh
     cs.idx = self.next_idx()
     self.idToIdx[cid] = cs.idx
     self.cellStates[cid] = cs
     if self.integ:
         self.integ.addCell(cs)
     self.reg.addCell(cs)
     if self.sig:
         self.sig.addCell(cs)
     self.phys.addCell(cs, **kwargs)
Exemple #7
0
 def to_string(row):
     return ''.join(CellState.to_char(cell) for cell in row)
Exemple #8
0
    def from_string(string, size, win_length=5):
        board = Board(size, win_length)
        board._board = [CellState.from_char(c) for c in string]

        return board