Esempio n. 1
0
 def test_border_stalin(self):
     """Упорядочиваются вершины линии фронта в сталинградском графе"""
     # Arrange
     xgml = processing.Xgml(STALIN, IOC.config.mgen)
     xgml.parse(str(IOC.config.mgen.xgml[STALIN]))
     grid = model.Grid(STALIN, xgml.nodes, xgml.edges, IOC.config.mgen)
     expected = (209, 94, 93, 96, 101, 100, 99, 137, 139, 138, 157, 186,
                 163, 164, 165, 184, 183, 182, 194, 193, 177)
     # Act
     border = grid.border
     # Assert
     self.assertCountEqual(tuple(int(x.key) for x in border), expected)
     self.assertSequenceEqual(tuple(int(x.key) for x in border), expected)
Esempio n. 2
0
 def test_border_test(self):
     """Упорядочиваются вершины линии фронта в тестовом графе"""
     # Arrange
     xgml = processing.Xgml(TEST, IOC.config.mgen)
     xgml.parse(str(IOC.config.mgen.xgml[TEST]))
     grid = model.Grid(TEST, xgml.nodes, xgml.edges, IOC.config.mgen)
     # Act
     frontline = grid.border_nodes
     border = grid.border
     # Assert
     self.assertEqual(len(frontline), 9)
     self.assertEqual(len(border), 9)
     self.assertEqual(border[0].text, 'L1')
Esempio n. 3
0
 def test_confrontation_area_stalingrad_east(self):
     """Создаётся многоугольник восточной прифронтовой полосы"""
     xgml = processing.Xgml(STALIN, MGEN)
     xgml.parse(str(MGEN.xgml[STALIN]))
     expected_keys = (192, 57, 196, 197, 185, 188, 187, 48, 110, 25, 102,
                      19, 95, 3, 191, 209, 94, 93, 96, 101, 100, 99, 137,
                      139, 138, 157, 186, 163, 164, 165, 184, 183, 182, 194,
                      193, 177)
     builder = processing.BoundaryBuilder(self.north, self.east, self.south,
                                          self.west)
     grid = model.Grid(STALIN, xgml.nodes, xgml.edges, 1)
     path = pathlib.Path(r'./tmp/{}_{}.xgml'.format(STALIN, 0))
     xgml.save_file(str(path), grid.nodes, grid.edges)
     # Act
     result = builder.confrontation_east(grid)
     # Assert
     self.assertSequenceEqual(tuple(int(x.key) for x in result),
                              expected_keys)
Esempio n. 4
0
 def test_grid_capturing_test(self):
     """Выполняется захват в тестовом графе"""
     xgml = processing.Xgml(TEST, IOC.config.mgen)
     xgml.parse(str(IOC.config.mgen.xgml[TEST]))
     grid = model.Grid(TEST, xgml.nodes, xgml.edges, IOC.config.mgen)
     path = pathlib.Path(r'./tmp/{}_{}.xgml'.format(TEST, 0))
     xgml.save_file(str(path), grid.nodes, grid.edges)
     # Act
     for i in range(1, self.iterations):
         nodes = list(grid.border_nodes)
         if len(nodes) == 0:
             break
         random.shuffle(nodes)
         for node in nodes.pop().neighbors:
             if node.country == 201:
                 node.capture(101)
                 break
         path = pathlib.Path(r'./tmp/{}_{}.xgml'.format(TEST, i))
         xgml.save_file(str(path), grid.nodes, grid.edges)
Esempio n. 5
0
 def test_constructor(self):
     grid = model.Grid()
     rep = grid.as_list()
     self.assertEqual(
         rep, [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])
Esempio n. 6
0
 def __init__(self, name: str):
     super().__init__(
         name, '', '10.11.1941', {'x': 281600, 'z': 281600}, dict(), model.Grid(name, dict(), list(), 0),
         pathlib.Path())
     self.country = 201
Esempio n. 7
0
            self.background.move(dx, dy)
            self.label.move(dx, dy)
            time.sleep(step_sleep)

    def notify(self, event: model.GameEvent):
        """Receive notification of change from a tile.
        """
        if event.kind == model.EventKind.tile_updated:
            row, col = event.tile.row, event.tile.col
            if self.row != row or self.col != col:
                self.slide_to(row, col)
            if self.value != event.tile.value:
                self.value = event.tile.value
                tile_color = RAMP[event.tile.value]
                self.background.setFill(tile_color)
                self.label.setText(str(event.tile.value))
        elif event.kind == model.EventKind.tile_removed:
            self.label.undraw()
            self.background.undraw()
        else:
            raise Exception("Unexpected event {}".format(event))


if __name__ == "__main__":
    game_view = GameView(600, 600)
    grid_view = GridView(game_view, 4)
    grid = model.Grid()
    grid.add_listener(grid_view)
    grid.place_tile()
    game_view.lose()
Esempio n. 8
0
def main():
    pygame.init()

    displayWidth = 640
    displayHeight = 640

    screen = pygame.display.set_mode((displayWidth, displayHeight))
    grid = model.Grid(40, 40, model.EMPTY, 20, 20)
    bgGrid = model.Grid(40, 40, model.EMPTY, 20, 20)

    #view.loadSprites()
    img = entities.Images()
    view.imgLoad(img)

    grid.entityList = model.initialEntities(grid)
    model.placeEntities(grid)

    persistance.load(grid, bgGrid)  #Loads on startup of file.

    pygame.time.set_timer(pygame.USEREVENT, 1000)
    pendingActionList = entities.OrderedList()

    controller.initializeActions(pendingActionList, grid.entityList)

    #must be placed elsewhere

    gatherer = grid.entityList[0]
    gatherer.aim = grid.entityList[0]
    for entity in grid.entityList:
        if isinstance(entity, entities.MonsterEnergy):
            gatherer.aim = entity
            break

    resetCopy = controller.returnCopiesOf(grid.entityList)

    while 1:
        for event in pygame.event.get():
            keys = pygame.key.get_pressed()
            mouse = pygame.mouse.get_pressed()
            x, y = pygame.mouse.get_pos()
            p = controller.clickToPoint(grid, x, y)

            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            if mouse[0]:
                controller.handleLeftClicks(pendingActionList, grid, keys, p,
                                            bgGrid)
            if mouse[2]:
                controller.handleRightClicks(grid, p)

            if keys[K_0]:
                grid.keyPressed = 0
                grid = model.resetGrid(resetCopy, bgGrid)
                grid.entityList = controller.returnCopiesOf(resetCopy)
                gatherer = grid.entityList[0]
                pendingActionList = entities.OrderedList()
                controller.initializeActions(pendingActionList,
                                             grid.entityList)
                grid.spacePressed = False
                print("World reset.")
            if keys[K_s]:
                persistance.save(grid, bgGrid)
            if keys[K_l]:
                persistance.load(grid, bgGrid)
                pendingActionList.list = []
                controller.initializeActions(pendingActionList,
                                             grid.entityList)
                grid.spacePressed = False
            controller.handleHover(grid, x, y)

            controller.handleKeys(grid, keys, gatherer)

        if grid.spacePressed:
            controller.ensureMovement(grid, pendingActionList)
            controller.updateGatherers(grid)
            controller.handleTicks(grid, pendingActionList,
                                   pygame.time.get_ticks())

        model.placeEntities(grid)
        view.draw(img, screen, grid, bgGrid, grid.screenW, grid.screenH)

        controller.cleanUp(grid.entityList)
        pygame.display.flip()
Esempio n. 9
0
                 'n_ev' : 1000,
                 'other': {
                         'charging_type' : 'if_needed_sunday'}}}
#ev_data3 = {'NonCoordonne': {'type' : 'dumb',
#                 'n_ev' : 1000,
#                 'other': {
#                         'charging_type' : 'if_needed',
#                         'charging_power' : 7.2}}}
#ev_data4 = {'NonCoordonne': {'type' : 'dumb',
#                 'n_ev' : 1000,
#                 'other': {
#                         'charging_type': 'all_days',
#                         'charging_power' : 7.2}}}
#grid1 = evmodel.Grid(ev_data1, ndays=ndays, step=step)
#grid1.do_days()
grid2 = evmodel.Grid(ev_data2, ndays=ndays, step=step)
grid2.do_days()
grid3 = evmodel.Grid(ev_data3, ndays=ndays, step=step)
for i in range(1000):
    grid3.evs['EV Load'][i].dist_wd = grid2.evs['EV Load'][i].dist_wd
    grid3.evs['EV Load'][i].dist_we = grid2.evs['EV Load'][i].dist_we
grid3.do_days()
#grid3 = evmodel.Grid(ev_data3, ndays=ndays, step=step)
#grid3.do_days()
#grid4 = evmodel.Grid(ev_data4, ndays=ndays, step=step)
#grid4.do_days()
#f, ([ax1, ax2],  [ax3, ax4]) = plt.subplots(2,2)
#ylim = 7.2*1000
f, (ax1, ax2) = plt.subplots(1,2)
ylim = 3.7*1000
grid2.plot_evload(ax=ax1, ylim=ylim, title='Non Coordonnée, Tous les jours')
Esempio n. 10
0
def test_grid_init():
    """ grid can be initialized"""
    grid = model.Grid(5, 5)
    assert grid.dic[(0, 0)] == 0
Esempio n. 11
0
def test_set_alive():
    """ we can set cells to be alive """
    grid = model.Grid(5, 5)
    grid.set_alive([[0, 0], [1, 0]])
    assert grid.dic[(0, 0)] == 1
    assert grid.dic[(1, 0)] == 1