コード例 #1
0
class MoveSorter():
    def __init__(self, moves: str = None):
        self._moves = VectorArray()
        self._figure_moves = {}
        if moves is not None:
            self.add_multiple_moves(moves)

    def add_multiple_moves(self, moves: str):
        moves_count = 0
        for line in moves.splitlines():
            if moves_count == 0:
                moves_count = line
                self._moves.set_vector(int(line))
            else:
                self._moves.add(line)
        self._moves.clear_unused_memory()

    def add_move(self, move: str):
        self._moves.add(move)

    def sort(self):
        self._moves.alphabetical_sort()

    def print_square_moves_table(self):
        elems_begin_with_count = {
            'a': 0,
            'b': 0,
            'c': 0,
            'd': 0,
            'e': 0,
            'f': 0,
            'g': 0,
            'h': 0
        }
        for elem_index in range(self._moves.size()):
            elem = self._moves.get(elem_index)
            for i in ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']:
                if isinstance(elem, str) and elem[0] == i:
                    elems_begin_with_count[i] += 1

        min_len = 0
        for k, v in elems_begin_with_count.items():
            if v != 0:
                if min_len == 0:
                    min_len = v
                else:
                    if min_len > v:
                        min_len = v

        res = str(self._moves.size()) + "\n"
        str_array = MatrixArray(None, min_len)
        for elem_index in range(self._moves.size() + 1):
            elem = self._moves.get(elem_index)
            if elem_index > 0 and elem_index % min_len == 0:
                res += str_array.get_row(int(elem_index / min_len) -
                                         1).join(' ')
                res += "\n"
            str_array.add(elem)
        return res[:-1]
コード例 #2
0
class AdjacencyVector:
    def __init__(self, rows_count: int):
        self.vector = VectorArray(rows_count)
        for i in range(rows_count):
            self.vector.add(VectorArray(rows_count))

    def bind(self, slaveVertexIndex: int, masterVertexIndex: int):
        self.vector.get(masterVertexIndex).add(slaveVertexIndex)
        
コード例 #3
0
class AdjacencyVector:
    def __init__(self, rows_count: int):
        self.vector = VectorArray(rows_count)
        for i in range(rows_count):
            self.vector.add(VectorArray(rows_count))

    def bind(self, slaveVertex: Vertex, masterVertex: Vertex, weight: int):
        self.vector.get(masterVertex.index).add({
            'slaveVertex': slaveVertex,
            'masterVertex': masterVertex,
            'weight': weight
        })
コード例 #4
0
 def test_vector_array(self):
     vectorArray = VectorArray()
     for i in range(30):
         vectorArray.add(i)
     print(vectorArray.get(15))
     print(vectorArray.size())
     vectorArray.insert('test', 15)
     print(vectorArray.get(15))
     print(vectorArray.size())
     print(vectorArray.remove(15))
     print(vectorArray.get(15))
     print(vectorArray.size())
コード例 #5
0
class AdjacencyVector:
    def __init__(self, rows_count: int):
        self.vector = VectorArray(rows_count)
        for i in range(rows_count):
            self.vector.add(SingleArray())

    def bind(self, slaveVertexIndex: int, masterVertexIndex: int):
        self.vector.get(masterVertexIndex).add(slaveVertexIndex)

    def getInvertedVector(self):
        invertedVector = AdjacencyVector(self.vector.size())
        for rowIndex in range(self.vector.size()):
            row = self.vector.get(rowIndex)
            for colIndex in range(row.size()):
                colVertexIndex = row.get(colIndex)
                invertedVector.bind(rowIndex, colVertexIndex)

        return invertedVector