Best Python code snippet using Kiwi_python
world.py
Source:world.py
...31 self.tickers = []32 self.difficulty = difficulty33 self.pathfinding = None34 self.visited = consts.DEBUG_ALL_EXPLORED35 def add_link(self, cell, direction):36 self.links.append((direction, cell))37 cell.links.append((opposite(direction), self))38 def add_object(self, object):39 if not isinstance(object, main.GameObject):40 raise ValueError("{} is not a game object!".format(object))41 self.objects.append(object)42 if object.fighter:43 self.fighters.append(object)44def opposite(direction):45 if direction == 'north':46 return 'south'47 elif direction == 'south':48 return 'north'49 elif direction == 'east':50 return 'west'51 elif direction == 'west':52 return 'east'53 elif direction == 'up':54 return 'down'55 elif direction == 'down':56 return 'up'57 else:58 return None59def get_map(map_name):60 if map_name not in world_maps.keys():61 raise Exception('Map not found: %s' % map_name)62 return world_maps[map_name]63def get_branch_scaling():64 import dungeon65 scaling = {}66 for branch in dungeon.branches.keys():67 scaling[branch] = dungeon.branches[branch]['scaling']68 return scaling69def set_branch_scaling(scaling):70 import dungeon71 for branch in scaling.keys():72 dungeon.branches[branch]['scaling'] = scaling[branch]73def initialize_world():74 import dungeon75 import npc76 global world_maps77 for branch in dungeon.branches.values():78 branch['scaling'] = 079 npc.npcs = {}80 world_maps = {}81 world_maps['beach'] = Map('beach')82 # Make Pilgrim's Grotto and connect to beach83 if dungeon.branches['grotto'].get('enabled', False):84 new_map = Map('grotto')85 world_maps['grotto'] = new_map86 world_maps['beach'].add_link(new_map, 'north')87 # Add marsh maps and link back to beach88 if dungeon.branches['marsh'].get('enabled', False):89 for y in range(2):90 for x in range(2):91 new_map = Map('marsh', coord=(x, y))92 if x > 0:93 new_map.add_link(world_maps['marsh_' + str(x - 1) + '_' + str(y)], 'west')94 if y > 0:95 new_map.add_link(world_maps['marsh_' + str(x) + '_' + str(y - 1)], 'north')96 world_maps[new_map.name] = new_map97 world_maps['marsh_1_1'].add_link(world_maps['beach'], 'east')98 # Make bog at a random marsh room and link back to the marsh99 if dungeon.branches['bog'].get('enabled', False):100 new_map = Map('bog')101 world_maps['marsh_0_%d' % libtcod.random_get_int(0, 0, 1)].add_link(new_map, 'down')102 world_maps[new_map.name] = new_map103 # Add badlands maps and link back to beach104 if dungeon.branches['badlands'].get('enabled', False):105 for y in range(2):106 for x in range(2):107 new_map = Map('badlands', coord=(x, y))108 if x > 0:109 new_map.add_link(world_maps['badlands_' + str(x - 1) + '_' + str(y)], 'west')110 if y > 0:111 new_map.add_link(world_maps['badlands_' + str(x) + '_' + str(y - 1)], 'north')112 world_maps[new_map.name] = new_map113 world_maps['badlands_0_1'].add_link(world_maps['beach'], 'west')114 # Make crypt at a random badlands room and link back to the badlands115 if dungeon.branches['crypt'].get('enabled', False):116 new_map = Map('crypt')117 world_maps['badlands_%d_1' % libtcod.random_get_int(0, 0, 1)].add_link(new_map, 'down')118 world_maps[new_map.name] = new_map119 # Make lines of goblin tunnels and link them below the badlands and marshes120 if dungeon.branches['gtunnels'].get('enabled', False):121 for x in range(3):122 y = 2123 new_map = Map('gtunnels', coord=(x, y))124 if x > 0:125 new_map.add_link(world_maps['gtunnels_' + str(x - 1) + '_' + str(y)], 'west')126 world_maps[new_map.name] = new_map127 for y in range(2):128 x = 1129 new_map = Map('gtunnels', coord=(x, y))130 if y > 0:131 new_map.add_link(world_maps['gtunnels_' + str(x) + '_' + str(y - 1)], 'north')132 world_maps[new_map.name] = new_map133 world_maps['gtunnels_1_1'].add_link(world_maps['gtunnels_1_2'], 'south')134 new_map = Map('gtunnels', coord=(0, 1))135 new_map.add_link(world_maps['gtunnels_1_1'], 'east')136 world_maps[new_map.name] = new_map137 new_map = Map('gtunnels', coord=(0, 3))138 new_map.add_link(world_maps['gtunnels_0_2'], 'north')139 if dungeon.branches['marsh'].get('enabled', False):140 new_map.add_link(world_maps['marsh_1_0'], 'up')141 world_maps[new_map.name] = new_map142 new_map = Map('gtunnels', coord=(2, 3))143 new_map.add_link(world_maps['gtunnels_2_2'], 'north')144 if dungeon.branches['badlands'].get('enabled', False):145 new_map.add_link(world_maps['badlands_0_0'], 'up')146 world_maps[new_map.name] = new_map147 # Make river148 if dungeon.branches['river'].get('enabled', False):149 new_map = Map('river', depth=0)150 if dungeon.branches['marsh'].get('enabled', False):151 new_map.add_link(world_maps['marsh_1_0'], 'south')152 world_maps[new_map.name] = new_map153 new_map = Map('river', depth=1)154 if dungeon.branches['badlands'].get('enabled', False):155 new_map.add_link(world_maps['badlands_0_0'], 'south')156 world_maps[new_map.name] = new_map157 if dungeon.branches['crossing'].get('enabled', False):158 new_map = Map('crossing')159 new_map.add_link(world_maps['river_0'], 'west')160 new_map.add_link(world_maps['river_1'], 'east')161 world_maps[new_map.name] = new_map162 # Add Frozen Forest maps and link back to river/goblin tunnels163 if dungeon.branches['forest'].get('enabled', False):164 for y in range(2):165 for x in range(2):166 new_map = Map('forest', coord=(x, y))167 if x > 0:168 new_map.add_link(world_maps['forest_' + str(x - 1) + '_' + str(y)], 'west')169 if y > 0:170 new_map.add_link(world_maps['forest_' + str(x) + '_' + str(y - 1)], 'north')171 world_maps[new_map.name] = new_map172 if dungeon.branches['river'].get('enabled', False):173 world_maps['forest_1_1'].add_link(world_maps['river_1'], 'south')174 if dungeon.branches['gtunnels'].get('enabled', False):175 world_maps['forest_0_1'].add_link(world_maps['gtunnels_1_1'], 'down')176 # Make eolith caverns at a random forest room and link back to the forest177 if dungeon.branches['eolith'].get('enabled', False):178 new_map = Map('eolith')179 world_maps['forest_%d_%d' % (libtcod.random_get_int(0, 0, 1), libtcod.random_get_int(0, 0, 1))].add_link(new_map, 'down')180 world_maps[new_map.name] = new_map181 # Add Garden maps and link back to river/goblin tunnels182 if dungeon.branches['garden'].get('enabled', False):183 for y in range(3):184 x = 1185 new_map = Map('garden', coord=(x, y))186 if y > 0:187 new_map.add_link(world_maps['garden_' + str(x) + '_' + str(y - 1)], 'north')188 world_maps[new_map.name] = new_map189 new_map = Map('garden', coord=(0, 1))190 new_map.add_link(world_maps['garden_1_1'], 'east')191 world_maps[new_map.name] = new_map192 if dungeon.branches['river'].get('enabled', False):193 world_maps['garden_1_2'].add_link(world_maps['river_0'], 'south')194 if dungeon.branches['gtunnels'].get('enabled', False):195 world_maps['garden_1_2'].add_link(world_maps['gtunnels_0_1'], 'down')196 if dungeon.branches['garden'].get('enabled', False) and dungeon.branches['forest'].get('enabled', False):197 # Link gardens and forest198 world_maps['garden_1_1'].add_link(world_maps['forest_0_0'], 'east')199 # Add catacombs map and link back to gtunnels200 if dungeon.branches['catacombs'].get('enabled', False):201 for x in range(4):202 new_map = Map('catacombs', coord=(x, 0))203 world_maps[new_map.name] = new_map204 if x > 0:205 new_map.add_link(world_maps['catacombs_' + str(x - 1) + '_0'], 'west')206 if dungeon.branches['gtunnels'].get('enabled', False):207 world_maps['catacombs_3_0'].add_link(world_maps['gtunnels_1_0'], 'up')208 if dungeon.branches['bone'].get('enabled', False):209 for x in range(4):210 new_map = Map('bone', coord=(x, 0))211 world_maps[new_map.name] = new_map212 if x > 0:213 new_map.add_link(world_maps['bone_' + str(x - 1) + '_0'], 'west')214 if dungeon.branches['catacombs'].get('enabled', False):215 world_maps['bone_3_0'].add_link(world_maps['catacombs_3_0'], 'up')216 # Add unnamed tomb217 if dungeon.branches['tomb'].get('enabled', False):218 new_map = Map('tomb')219 world_maps['tomb'] = new_map220 world_maps['catacombs_0_0'].add_link(new_map, 'up')221 # Add tower of mages and link back to forest222 if dungeon.branches['tower'].get('enabled', False):223 for z in range(4):224 new_map = Map('tower', depth=z)225 if z > 0:226 new_map.add_link(world_maps['tower_' + str(z - 1)], 'down')227 world_maps[new_map.name] = new_map228 if dungeon.branches['forest'].get('enabled', False):229 world_maps['tower_0'].add_link(world_maps['forest_1_1'], 'west')230 # Add lava lake231 if dungeon.branches['lavalake'].get('enabled', False):232 new_map = Map('lavalake')233 world_maps['lavalake'] = new_map234 if dungeon.branches['badlands'].get('enabled', False):235 world_maps['badlands_1_0'].add_link(new_map, 'north')236 # Add slagfields maps and link back to lava/tower237 if dungeon.branches['slagfields'].get('enabled', False):238 for y in range(2):239 for x in range(2):240 new_map = Map('slagfields', coord=(x, y))241 if x > 0:242 new_map.add_link(world_maps['slagfields_' + str(x - 1) + '_' + str(y)], 'west')243 if y > 0:244 new_map.add_link(world_maps['slagfields_' + str(x) + '_' + str(y - 1)], 'north')245 world_maps[new_map.name] = new_map246 if dungeon.branches['tower'].get('enabled', False):247 world_maps['slagfields_0_0'].add_link(world_maps['tower_0'], 'west')248 if dungeon.branches['lavalake'].get('enabled', False):249 world_maps['slagfields_0_1'].add_link(world_maps['lavalake'], 'west')250 # Add foundry of war maps and link back to slagfields251 if dungeon.branches['foundry'].get('enabled', False):252 for y in range(2):253 for x in range(2):254 new_map = Map('foundry', coord=(x, y), depth=0)255 if x > 0:256 new_map.add_link(world_maps['foundry_' + str(x - 1) + '_' + str(y) + '_0'], 'west')257 if y > 0:258 new_map.add_link(world_maps['foundry_' + str(x) + '_' + str(y - 1) + '_0'], 'north')259 world_maps[new_map.name] = new_map260 new_map = Map('foundry', coord=(1, 0), depth=1)261 new_map.add_link(world_maps['foundry_1_0_0'], 'down')262 world_maps[new_map.name] = new_map263 if dungeon.branches['slagfields'].get('enabled', False):264 world_maps['foundry_0_1_0'].add_link(world_maps['slagfields_1_0'], 'west')265 # Add giant woods/canopy maps and link back to gardens266 if dungeon.branches['giantwoods'].get('enabled', False):267 for y in range(2):268 for x in range(2):269 new_map = Map('giantwoods', coord=(x, y))270 if x > 0:271 new_map.add_link(world_maps['giantwoods_' + str(x - 1) + '_' + str(y)], 'west')272 if y > 0:273 new_map.add_link(world_maps['giantwoods_' + str(x) + '_' + str(y - 1)], 'north')274 world_maps[new_map.name] = new_map275 if dungeon.branches['garden'].get('enabled', False):276 world_maps['giantwoods_1_0'].add_link(world_maps['garden_0_1'], 'north')277 if dungeon.branches['canopy'].get('enabled', False):278 for y in range(2):279 for x in range(2):280 new_map = Map('canopy', coord=(x, y))281 if x > 0:282 new_map.add_link(world_maps['canopy_' + str(x - 1) + '_' + str(y)], 'west')283 if y > 0:284 new_map.add_link(world_maps['canopy_' + str(x) + '_' + str(y - 1)], 'north')285 if dungeon.branches['giantwoods'].get('enabled', False):286 new_map.add_link(world_maps['giantwoods_' + str(x) + '_' + str(y)], 'down')287 world_maps[new_map.name] = new_map288 # Add sunken temple and link back to tomb/giant woods289 if dungeon.branches['temple'].get('enabled', False):290 for x in range(2):291 for z in range(2):292 new_map = Map('temple', coord=(x, 1), depth=z)293 if x > 0:294 new_map.add_link(world_maps['temple_' + str(x - 1) + '_1_' + str(z)], 'west')295 if z > 0:296 new_map.add_link(world_maps['temple_' + str(x) + '_1_' + str(z - 1)], 'up')297 world_maps[new_map.name] = new_map298 new_map = Map('temple', coord=(0, 0), depth=1)299 new_map.add_link(world_maps['temple_0_1_1'], 'south')300 world_maps[new_map.name] = new_map301 if dungeon.branches['giantwoods'].get('enabled', False):302 world_maps['temple_1_1_0'].add_link(world_maps['giantwoods_0_0'], 'up')303 if dungeon.branches['tomb'].get('enabled', False):304 world_maps['temple_1_1_0'].add_link(world_maps['tomb'], 'north')305 # Add mines maps and link back to gtunnels/bone pits306 if dungeon.branches['mines'].get('enabled', False):307 for z in range(3):308 new_map = Map('mines', coord=(0, 1), depth=z)309 if z > 0:310 new_map.add_link(world_maps['mines_0_1_' + str(z - 1)], 'up')311 world_maps[new_map.name] = new_map312 new_map = Map('mines', coord=(0, 0), depth=1)313 new_map.add_link(world_maps['mines_0_1_1'], 'south')314 if dungeon.branches['bone'].get('enabled', False):315 new_map.add_link(world_maps['bone_3_0'], 'north')316 world_maps[new_map.name] = new_map317 if dungeon.branches['gtunnels'].get('enabled', False):318 world_maps['mines_0_1_0'].add_link(world_maps['gtunnels_1_2'], 'up')319 # Add depths maps and link back to mines320 if dungeon.branches['depths'].get('enabled', False):321 for y in range(2):322 for x in range(2):323 new_map = Map('depths', coord=(x, y))324 if x > 0:325 new_map.add_link(world_maps['depths_' + str(x - 1) + '_' + str(y)], 'west')326 if y > 0 and x == 0:327 new_map.add_link(world_maps['depths_' + str(x) + '_' + str(y - 1)], 'north')328 world_maps[new_map.name] = new_map329 if dungeon.branches['mines'].get('enabled', False):330 world_maps['depths_1_1'].add_link(world_maps['mines_0_1_2'], 'up')331 # Add menagerie332 if dungeon.branches['menagerie'].get('enabled', False):333 new_map = Map('menagerie')334 world_maps['menagerie'] = new_map335 if dungeon.branches['garden'].get('enabled', False):336 world_maps['garden_1_0'].add_link(new_map, 'west')337 # Add gatehouse338 if dungeon.branches['gatehouse'].get('enabled', False):339 new_map = Map('gatehouse')340 world_maps['gatehouse'] = new_map341 if dungeon.branches['garden'].get('enabled', False):342 world_maps['garden_1_0'].add_link(new_map, 'east')343 if dungeon.branches['forest'].get('enabled', False):344 world_maps['forest_0_0'].add_link(new_map, 'north')345 # Add battlements maps and link back to gatehouse346 if dungeon.branches['battlements'].get('enabled', False):347 for x in range(3):348 new_map = Map('battlements', coord=(x, 0))349 world_maps[new_map.name] = new_map350 if x > 0:351 new_map.add_link(world_maps['battlements_' + str(x - 1) + '_0'], 'west')352 new_map = Map('battlements', coord=(2, 1))353 new_map.add_link(world_maps['battlements_2_0'], 'north')354 if dungeon.branches['gatehouse'].get('enabled', False):355 new_map.add_link(world_maps['gatehouse'], 'west')356 world_maps[new_map.name] = new_map357 # Add city maps and link back to the battlements358 if dungeon.branches['city'].get('enabled', False):359 for x in range(3):360 new_map = Map('city', coord=(x, 1))361 world_maps[new_map.name] = new_map362 if x > 0:363 new_map.add_link(world_maps['city_' + str(x - 1) + '_1'], 'west')364 new_map = Map('city', coord=(1, 0))365 new_map.add_link(world_maps['city_1_1'], 'south')366 world_maps[new_map.name] = new_map367 new_map = Map('city', coord=(1, 2))368 new_map.add_link(world_maps['city_1_1'], 'north')369 if dungeon.branches['battlements'].get('enabled', False):370 new_map.add_link(world_maps['battlements_0_0'], 'south')371 world_maps[new_map.name] = new_map372 # Add cathedral373 if dungeon.branches['cathedral'].get('enabled', False):374 new_map = Map('cathedral')375 world_maps['cathedral'] = new_map376 if dungeon.branches['city'].get('enabled', False):377 world_maps['city_1_2'].add_link(new_map, 'west')378 # Add cursed path maps and link back to the citadel/tomb379 if dungeon.branches['cursed'].get('enabled', False):380 for y in range(2):381 new_map = Map('cursed', coord=(1, y))382 world_maps[new_map.name] = new_map383 if y > 0:384 new_map.add_link(world_maps['cursed_1_' + str(y - 1)], 'north')385 for y in range(1, 3):386 new_map = Map('cursed', coord=(0, y))387 world_maps[new_map.name] = new_map388 if y > 1:389 new_map.add_link(world_maps['cursed_0_' + str(y - 1)], 'north')390 world_maps['cursed_1_1'].add_link(world_maps['cursed_0_1'], 'west')391 if dungeon.branches['cathedral'].get('enabled', False):392 world_maps['cursed_1_0'].add_link(world_maps['cathedral'], 'up')393 if dungeon.branches['tomb'].get('enabled', False):394 world_maps['tomb'].add_link(world_maps['cursed_0_2'], 'north')395 # Make test map396 world_maps['test'] = Map('test')...
demo_slicing.py
Source:demo_slicing.py
...27 add_table(s, 1, [101, 102])28 add_table(s, 2, [201, 202])29 add_table(s, 3, [301, 302])30 # add links31 add_link(s, 0, 101)32 add_link(s, 0, 201)33 add_link(s, 0, 301)34 add_link(s, 102, 103)35 add_link(s, 202, 203)36 add_link(s, 302, 303)37 # add rules38 add_rule(s, 1, 1, [101], [102], '100xxxxx', 'xxxxxxxx', None)39 add_rule(s, 2, 1, [201], [202], '101xxxxx', 'xxxxxxxx', None)40 add_rule(s, 3, 1, [301], [302], 'xxxxxxxx', 'xxxxxxxx', None)41 # add universal source and source probe42 add_source(s, ['xxxxxxxx'], None, [0])43 # add probes44 add_source_probe(s, [103], 'existential', {'type':'false'}, {'type':'true'})45 add_source_probe(s, [203], 'existential', {'type':'false'}, {'type':'true'})46 add_source_probe(s, [303], 'existential', {'type':'false'}, {'type':'true'})47def demo_overlap(s):48 reset_plumbing_network(s)49 add_slice(s, 1, ['10xxxxxx'], None)50 add_slice(s, 2, ['101xxxxx'], None)51def demo_base(s):52 reset_plumbing_network(s)53 54 # add slices55 add_slice(s, 1, ['000xxxxx'], None)56 add_slice(s, 2, ['001xxxxx'], None)57 add_slice(s, 3, ['010xxxxx'], None)58 add_slice(s, 4, ['011xxxxx'], None)59 add_slice(s, 5, ['100xxxxx'], None)60 add_slice(s, 6, ['101xxxxx'], None)61 # add forwarding tables62 add_table(s, 1, (101,102))63 add_table(s, 2, (201,202))64 add_table(s, 3, (301,302))65 add_table(s, 4, (401,402))66 add_table(s, 5, (501,502))67 add_table(s, 6, (601,602))68 add_table(s, 7, (1,11,12,13,14,15,16))69 # add links70 add_link(s, 0, 1)71 add_link(s, 11, 101)72 add_link(s, 12, 201)73 add_link(s, 13, 301)74 add_link(s, 14, 401)75 add_link(s, 15, 501)76 add_link(s, 16, 601)77 add_link(s, 102, 103)78 add_link(s, 202, 203)79 add_link(s, 302, 303)80 add_link(s, 402, 403)81 add_link(s, 502, 503)82 add_link(s, 602, 603)83 84 # add rules85 add_rule(s, 7, 1, [1], [11], '000xxxxx', 'xxxxxxxx', None)86 add_rule(s, 7, 2, [1], [12], '001xxxxx', 'xxxxxxxx', None)87 add_rule(s, 7, 3, [1], [13], '010xxxxx', 'xxxxxxxx', None)88 add_rule(s, 7, 4, [1], [14], '011xxxxx', 'xxxxxxxx', None)89 add_rule(s, 7, 5, [1], [15], '100xxxxx', 'xxxxxxxx', None)90 add_rule(s, 7, 6, [1], [16], '101xxxxx', 'xxxxxxxx', None)91 # add dummy in rules in slice tables92 add_rule(s, 1, 1, [101], [102], '000xxxxx', 'xxxxxxxx', None)93 add_rule(s, 2, 1, [201], [202], '001xxxxx', 'xxxxxxxx', None)94 add_rule(s, 3, 1, [301], [302], '010xxxxx', 'xxxxxxxx', None)95 add_rule(s, 4, 1, [401], [402], '011xxxxx', 'xxxxxxxx', None)96 add_rule(s, 5, 1, [501], [502], '100xxxxx', 'xxxxxxxx', None)97 add_rule(s, 6, 1, [601], [602], '101xxxxx', 'xxxxxxxx', None)98 # add universal source and source probe99 add_source(s, ['xxxxxxxx'], None, [0])100 # add probes101 add_source_probe(s, [103], 'existential', {'type':'false'}, {'type':'true'})102 add_source_probe(s, [203], 'existential', {'type':'false'}, {'type':'true'})103 add_source_probe(s, [303], 'existential', {'type':'false'}, {'type':'true'})104 add_source_probe(s, [403], 'existential', {'type':'false'}, {'type':'true'})105 add_source_probe(s, [503], 'existential', {'type':'false'}, {'type':'true'})106 add_source_probe(s, [603], 'existential', {'type':'false'}, {'type':'true'})107def demo_leak1(s):108 reset_plumbing_network(s)109 110 # add slices111 add_slice(s, 1, ['000xxxxx'], None)112 add_slice(s, 2, ['001xxxxx'], None)113 add_slice(s, 3, ['010xxxxx'], None)114 add_slice(s, 4, ['011xxxxx'], None)115 add_slice(s, 5, ['100xxxxx'], None)116 add_slice(s, 6, ['101xxxxx'], None)117 # add slice matrix118 add_slice_matrix(s, ",0,1,2,3,4,5,6\n" +119 "0,x,x,x,x,x,x,x\n" +120 "1,x,,,,,,\n" +121 "2,x,,,,,,\n" +122 "3,x,,,,,,\n" +123 "4,x,,,,,,\n" +124 "5,x,,,,,,\n" +125 "6,x,,,,,,\n")126 127 # add forwarding tables128 add_table(s, 1, (101,102))129 add_table(s, 2, (201,202))130 add_table(s, 3, (301,302))131 add_table(s, 4, (401,402))132 add_table(s, 5, (501,502))133 add_table(s, 6, (601,602,603,604))134 add_table(s, 7, (1,11,12,13,14,15,16))135 # add links136 add_link(s, 0, 1)137 add_link(s, 11, 101)138 add_link(s, 12, 201)139 add_link(s, 13, 301)140 add_link(s, 14, 401)141 add_link(s, 15, 501)142 add_link(s, 16, 601)143 add_link(s, 2, 603)144 add_link(s, 604, 501)145 add_link(s, 102, 103)146 add_link(s, 202, 203)147 add_link(s, 302, 303)148 add_link(s, 402, 403)149 add_link(s, 502, 503)150 add_link(s, 602, 605)151 # add rules152 add_rule(s, 7, 1, [1], [11], '000xxxxx', 'xxxxxxxx', None)153 add_rule(s, 7, 2, [1], [12], '001xxxxx', 'xxxxxxxx', None)154 add_rule(s, 7, 3, [1], [13], '010xxxxx', 'xxxxxxxx', None)155 add_rule(s, 7, 4, [1], [14], '011xxxxx', 'xxxxxxxx', None)156 add_rule(s, 7, 5, [1], [15], '100xxxxx', 'xxxxxxxx', None)157 add_rule(s, 7, 6, [1], [16], '101xxxxx', 'xxxxxxxx', None)158 # add dummy in rules in slice tables159 add_rule(s, 1, 1, [101], [102], '000xxxxx', 'xxxxxxxx', None)160 add_rule(s, 2, 1, [201], [202], '001xxxxx', 'xxxxxxxx', None)161 add_rule(s, 3, 1, [301], [302], '010xxxxx', 'xxxxxxxx', None)162 add_rule(s, 4, 1, [401], [402], '011xxxxx', 'xxxxxxxx', None)163 add_rule(s, 5, 1, [501], [502], '100xxxxx', 'xxxxxxxx', None)164 add_rule(s, 6, 1, [601], [602], '101xxxxx', 'xxxxxxxx', None)165 add_rule(s, 6, 2, [603], [604], '101xxxxx', '000xxxxx', '100xxxxx')166 # add universal source and source probe167 add_source(s, ['xxxxxxxx'], None, [0])168 add_source(s, ['101xxxxx'], None, [2])169 # add probes170 add_source_probe(s, [103], 'existential', {'type':'false'}, {'type':'true'})171 add_source_probe(s, [203], 'existential', {'type':'false'}, {'type':'true'})172 add_source_probe(s, [303], 'existential', {'type':'false'}, {'type':'true'})173 add_source_probe(s, [403], 'existential', {'type':'false'}, {'type':'true'})174 add_source_probe(s, [503], 'existential', {'type':'false'}, {'type':'true'})175 add_source_probe(s, [605], 'existential', {'type':'false'}, {'type':'true'})176def demo_leak2(s):177 reset_plumbing_network(s)178 179 # add slices180 add_slice(s, 1, ['000xxxxx'], None)181 add_slice(s, 2, ['001xxxxx'], None)182 add_slice(s, 3, ['010xxxxx'], None)183 add_slice(s, 4, ['011xxxxx'], None)184 add_slice(s, 5, ['100xxxxx'], None)185 add_slice(s, 6, ['101xxxxx'], None)186 # add slice matrix187 add_slice_matrix(s, ",0,1,2,3,4,5,6\n" +188 "0,x,x,x,x,x,x,x\n" +189 "1,x,x,x,x,x,x,x\n" +190 "2,x,x,,,,x,x\n" +191 "3,x,x,,x,,x,x\n" +192 "4,x,x,,,,x,x\n" +193 "5,x,x,x,x,x,x,x\n" +194 "6,x,x,x,x,x,x,\n")195 print_slice_matrix(s)196 # add forwarding tables197 add_table(s, 1, (101,102))198 add_table(s, 2, (201,202))199 add_table(s, 3, (301,302))200 add_table(s, 4, (401,402))201 add_table(s, 5, (501,502))202 add_table(s, 6, (601,602,603,604))203 add_table(s, 7, (1,11,12,13,14,15,16))204 # add links205 add_link(s, 0, 1)206 add_link(s, 11, 101)207 add_link(s, 12, 201)208 add_link(s, 13, 301)209 add_link(s, 14, 401)210 add_link(s, 15, 501)211 add_link(s, 16, 601)212 add_link(s, 2, 603)213 add_link(s, 604, 501)214 add_link(s, 102, 103)215 add_link(s, 202, 203)216 add_link(s, 302, 303)217 add_link(s, 402, 403)218 add_link(s, 502, 503)219 add_link(s, 602, 605)220 221 # add rules222 add_rule(s, 7, 1, [1], [11], '000xxxxx', 'xxxxxxxx', None)223 add_rule(s, 7, 2, [1], [12], '001xxxxx', 'xxxxxxxx', None)224 add_rule(s, 7, 3, [1], [13], '010xxxxx', 'xxxxxxxx', None)225 add_rule(s, 7, 4, [1], [14], '011xxxxx', 'xxxxxxxx', None)226 add_rule(s, 7, 5, [1], [15], '100xxxxx', 'xxxxxxxx', None)227 add_rule(s, 7, 6, [1], [16], '101xxxxx', 'xxxxxxxx', None)228 # add dummy in rules in slice tables229 add_rule(s, 1, 1, [101], [102], '000xxxxx', 'xxxxxxxx', None)230 add_rule(s, 2, 1, [201], [202], '001xxxxx', 'xxxxxxxx', None)231 add_rule(s, 3, 1, [301], [302], '010xxxxx', 'xxxxxxxx', None)232 add_rule(s, 4, 1, [401], [402], '011xxxxx', 'xxxxxxxx', None)233 add_rule(s, 5, 1, [501], [502], '100xxxxx', 'xxxxxxxx', None)234 add_rule(s, 6, 1, [601], [602], '101xxxxx', 'xxxxxxxx', None)235 add_rule(s, 6, 2, [603], [604], '101xxxxx', '000xxxxx', 'xxxxxxxx')236 237 # add universal source and source probe238 add_source(s, ['xxxxxxxx'], None, [0])239 add_source(s, ['101xxxxx'], None, [2])240 # add probes241 add_source_probe(s, [103], 'existential', {'type':'false'}, {'type':'true'})242 add_source_probe(s, [203], 'existential', {'type':'false'}, {'type':'true'})243 add_source_probe(s, [303], 'existential', {'type':'false'}, {'type':'true'})244 add_source_probe(s, [403], 'existential', {'type':'false'}, {'type':'true'})245 add_source_probe(s, [503], 'existential', {'type':'false'}, {'type':'true'})246 add_source_probe(s, [605], 'existential', {'type':'false'}, {'type':'true'})247def demo_leak3(s):248 reset_plumbing_network(s)249 250 # add slices251 add_slice(s, 1, ['000xxxxx'], None)252 add_slice(s, 2, ['001xxxxx'], None)253 add_slice(s, 3, ['010xxxxx'], None)254 add_slice(s, 4, ['011xxxxx'], None)255 add_slice(s, 5, ['100xxxxx'], None)256 add_slice(s, 6, ['101xxxxx'], None)257 # add slice matrix258 add_slice_matrix(s,",0,1,2,3,4,5,6\n"+259 "0,x,x,x,x,x,x,x\n"+260 "1,x,x,x,x,x,x,x\n"+261 "2,x,x,x,,,x,x\n"+262 "3,x,x,,x,,x,x\n"+263 "4,x,x,,,x,x,x\n"+264 "5,x,x,x,x,x,x,x\n"+265 "6,x,x,x,x,x,x,x")266 # add forwarding tables267 add_table(s, 1, (101,102,103,104))268 add_table(s, 2, (201,202,203,204))269 add_table(s, 3, (301,302,303,304))270 add_table(s, 4, (401,402,403,404))271 add_table(s, 5, (501,502,503,504))272 add_table(s, 6, (601,602,603,604))273 add_table(s, 7, (1,11,12,13,14,15,16))274 # add links275 add_link(s, 0, 1)276 add_link(s, 11, 101)277 add_link(s, 12, 201)278 add_link(s, 13, 301)279 add_link(s, 14, 401)280 add_link(s, 15, 501)281 add_link(s, 16, 601)282 # add source links for slices283 add_link(s, 2, 103)284 add_link(s, 3, 203)285 add_link(s, 4, 303)286 add_link(s, 5, 403)287 add_link(s, 6, 503)288 add_link(s, 7, 603)289 # add sink links290 add_link(s, 102, 105)291 add_link(s, 202, 205)292 add_link(s, 302, 305)293 add_link(s, 402, 405)294 add_link(s, 502, 505)295 add_link(s, 602, 605)296 # add links between slices297 add_link(s, 104, 201)298 add_link(s, 104, 301)299 add_link(s, 104, 401)300 add_link(s, 104, 501)301 add_link(s, 104, 601)302 add_link(s, 204, 101)303 add_link(s, 204, 501)304 add_link(s, 204, 601)305 add_link(s, 304, 101)306 add_link(s, 304, 501)307 add_link(s, 304, 601)308 add_link(s, 404, 101)309 add_link(s, 404, 501)310 add_link(s, 404, 601)311 add_link(s, 504, 101)312 add_link(s, 504, 201)313 add_link(s, 504, 301)314 add_link(s, 504, 401)315 add_link(s, 504, 601)316 add_link(s, 604, 101)317 add_link(s, 604, 201)318 add_link(s, 604, 301)319 add_link(s, 604, 401)320 add_link(s, 604, 501)321 322 # add rules323 add_rule(s, 7, 1, [1], [11], '000xxxxx', 'xxxxxxxx', None)324 add_rule(s, 7, 2, [1], [12], '001xxxxx', 'xxxxxxxx', None)325 add_rule(s, 7, 3, [1], [13], '010xxxxx', 'xxxxxxxx', None)326 add_rule(s, 7, 4, [1], [14], '011xxxxx', 'xxxxxxxx', None)327 add_rule(s, 7, 5, [1], [15], '100xxxxx', 'xxxxxxxx', None)328 add_rule(s, 7, 6, [1], [16], '101xxxxx', 'xxxxxxxx', None)329 # add dummy in rules in slice tables330 add_rule(s, 1, 1, [101], [102], '000xxxxx', 'xxxxxxxx', None)331 add_rule(s, 2, 1, [201], [202], '001xxxxx', 'xxxxxxxx', None)332 add_rule(s, 3, 1, [301], [302], '010xxxxx', 'xxxxxxxx', None)333 add_rule(s, 4, 1, [401], [402], '011xxxxx', 'xxxxxxxx', None)334 add_rule(s, 5, 1, [501], [502], '100xxxxx', 'xxxxxxxx', None)335 add_rule(s, 6, 1, [601], [602], '101xxxxx', 'xxxxxxxx', None)336 # add outgoing rules from slices to other slices337 add_rule(s, 1, 2, [103], [104], '000xxxxx', '000xxxxx', 'xxxxxxxx')338 add_rule(s, 2, 2, [203], [204], '001xxxxx', '000xxxxx', 'xxxxxxxx')339 add_rule(s, 3, 2, [303], [304], '010xxxxx', '000xxxxx', 'xxxxxxxx')340 add_rule(s, 4, 2, [403], [404], '011xxxxx', '000xxxxx', 'xxxxxxxx')341 add_rule(s, 5, 2, [503], [504], '100xxxxx', '000xxxxx', 'xxxxxxxx')342 add_rule(s, 6, 2, [603], [604], '101xxxxx', '000xxxxx', 'xxxxxxxx') 343 # add universal source and source probe344 add_source(s, ['xxxxxxxx'], None, [0])345 add_source(s, ['xxxxxxxx'], None, [2])346 add_source(s, ['xxxxxxxx'], None, [3])347 add_source(s, ['xxxxxxxx'], None, [4])348 add_source(s, ['xxxxxxxx'], None, [5])349 add_source(s, ['xxxxxxxx'], None, [6])350 add_source(s, ['xxxxxxxx'], None, [7])351 352 # add probes353 add_source_probe(s, [105], 'existential', {'type':'false'}, {'type':'true'})354 add_source_probe(s, [205], 'existential', {'type':'false'}, {'type':'true'})355 add_source_probe(s, [305], 'existential', {'type':'false'}, {'type':'true'})356 add_source_probe(s, [405], 'existential', {'type':'false'}, {'type':'true'})357 add_source_probe(s, [505], 'existential', {'type':'false'}, {'type':'true'})358 add_source_probe(s, [605], 'existential', {'type':'false'}, {'type':'true'})359def demo_leak4(s):360 reset_plumbing_network(s)361 362 # add slices363 add_slice(s, 1, ['000xxxxx'], None)364 add_slice(s, 2, ['001xxxxx'], None)365 add_slice(s, 3, ['010xxxxx'], None)366 add_slice(s, 4, ['011xxxxx'], None)367 add_slice(s, 5, ['100xxxxx'], None)368 add_slice(s, 6, ['101xxxxx'], None)369 # add slice matrix370 add_slice_matrix(s,",0,1,2,3,4,5,6\n"+371 "0,x,x,x,x,x,x,x\n"+372 "1,x,x,x,x,x,x,x\n"+373 "2,x,x,x,,,x,x\n"+374 "3,x,x,,x,,x,x\n"+375 "4,x,x,,,x,x,x\n"+376 "5,x,x,x,x,x,x,x\n"+377 "6,x,x,x,x,x,x,x")378 # add forwarding tables379 add_table(s, 1, (101,102,103,104))380 add_table(s, 2, (201,202,203,204))381 add_table(s, 3, (301,302,303,304))382 add_table(s, 4, (401,402,403,404))383 add_table(s, 5, (501,502,503,504))384 add_table(s, 6, (601,602,603,604))385 add_table(s, 7, (1,11,12,13,14,15,16))386 # add links387 add_link(s, 0, 1)388 add_link(s, 11, 101)389 add_link(s, 12, 201)390 add_link(s, 13, 301)391 add_link(s, 14, 401)392 add_link(s, 15, 501)393 add_link(s, 16, 601)394 # add source links for slices395 add_link(s, 2, 103)396 add_link(s, 3, 203)397 add_link(s, 4, 303)398 add_link(s, 5, 403)399 add_link(s, 6, 503)400 add_link(s, 7, 603)401 # add sink links402 add_link(s, 102, 105)403 add_link(s, 202, 205)404 add_link(s, 302, 305)405 add_link(s, 402, 405)406 add_link(s, 502, 505)407 add_link(s, 602, 605)408 409 # add links between slices410 add_link(s, 104, 201)411 add_link(s, 104, 301)412 add_link(s, 104, 401)413 add_link(s, 104, 501)414 add_link(s, 104, 601)415 add_link(s, 204, 101)416 add_link(s, 204, 501)417 add_link(s, 204, 601)418 add_link(s, 304, 101)419 add_link(s, 304, 501)420 add_link(s, 304, 601)421 add_link(s, 404, 101)422 add_link(s, 404, 501)423 add_link(s, 404, 601)424 add_link(s, 504, 101)425 add_link(s, 504, 201)426 add_link(s, 504, 301)427 add_link(s, 504, 401)428 add_link(s, 504, 601)429 add_link(s, 604, 101)430 add_link(s, 604, 201)431 add_link(s, 604, 301)432 add_link(s, 604, 401)433 add_link(s, 604, 501)434 # not allowed435 add_link(s, 404, 201)436 437 # add rules438 add_rule(s, 7, 1, [1], [11], '000xxxxx', 'xxxxxxxx', None)439 add_rule(s, 7, 2, [1], [12], '001xxxxx', 'xxxxxxxx', None)440 add_rule(s, 7, 3, [1], [13], '010xxxxx', 'xxxxxxxx', None)441 add_rule(s, 7, 4, [1], [14], '011xxxxx', 'xxxxxxxx', None)442 add_rule(s, 7, 5, [1], [15], '100xxxxx', 'xxxxxxxx', None)443 add_rule(s, 7, 6, [1], [16], '101xxxxx', 'xxxxxxxx', None)444 # add dummy in rules in slice tables445 add_rule(s, 1, 1, [101], [102], '000xxxxx', 'xxxxxxxx', None)446 add_rule(s, 2, 1, [201], [202], '001xxxxx', 'xxxxxxxx', None)447 add_rule(s, 3, 1, [301], [302], '010xxxxx', 'xxxxxxxx', None)448 add_rule(s, 4, 1, [401], [402], '011xxxxx', 'xxxxxxxx', None)449 add_rule(s, 5, 1, [501], [502], '100xxxxx', 'xxxxxxxx', None)450 add_rule(s, 6, 1, [601], [602], '101xxxxx', 'xxxxxxxx', None)451 # add outgoing rules from slices to other slices452 add_rule(s, 1, 2, [103], [104], '000xxxxx', '000xxxxx', 'xxxxxxxx')453 add_rule(s, 2, 2, [203], [204], '001xxxxx', '000xxxxx', 'xxxxxxxx')454 add_rule(s, 3, 2, [303], [304], '010xxxxx', '000xxxxx', 'xxxxxxxx')455 add_rule(s, 4, 2, [403], [404], '011xxxxx', '000xxxxx', 'xxxxxxxx')456 add_rule(s, 5, 2, [503], [504], '100xxxxx', '000xxxxx', 'xxxxxxxx')457 add_rule(s, 6, 2, [603], [604], '101xxxxx', '000xxxxx', 'xxxxxxxx') 458 # add universal source and source probe459 add_source(s, ['xxxxxxxx'], None, [0])460 add_source(s, ['xxxxxxxx'], None, [2])461 add_source(s, ['xxxxxxxx'], None, [3])462 add_source(s, ['xxxxxxxx'], None, [4])463 add_source(s, ['xxxxxxxx'], None, [5])464 add_source(s, ['xxxxxxxx'], None, [6])465 add_source(s, ['xxxxxxxx'], None, [7])466 467 # add probes468 add_source_probe(s, [105], 'existential', {'type':'false'}, {'type':'true'})469 add_source_probe(s, [205], 'existential', {'type':'false'}, {'type':'true'})470 add_source_probe(s, [305], 'existential', {'type':'false'}, {'type':'true'})471 add_source_probe(s, [405], 'existential', {'type':'false'}, {'type':'true'})472 add_source_probe(s, [505], 'existential', {'type':'false'}, {'type':'true'})473 add_source_probe(s, [605], 'existential', {'type':'false'}, {'type':'true'})474def simpleslice(s):475 reset_plumbing_network(s)476 add_table(s, 1, (1,2,3,4))477 add_link(s, 0, 1)478 add_link(s, 0, 2)479 add_link(s, 3, 5)480 add_link(s, 4, 5)481 add_rule(s, 1, 1, [1], [3], '10xxxxxx', 'xxxxxxxx', None)482 add_rule(s, 1, 2, [2], [4], '11xxxxxx', 'xxxxxxxx', None)483 add_source(s, ['xxxxxxxx'], None, [0])484 add_source_probe(s, [5], 'existential', {'type':'false'}, {'type':'true'})485 add_slice(s, 1, ['10xxxxxx'], None)486 add_slice(s, 2, ['11xxxxxx'], None)487 print_plumbing_network(s)488def dump(s):489 dump_plumbing_network(s, '.')490 dump_flows(s, '.')491 dump_pipes(s, '.')492 dump_slices(s, '.')...
tramline2.py
Source:tramline2.py
2from transportnet import net3from transportnet import vehicle4n = net.Net()5# Struga - Chelmonskiego Osiedle6n.add_link(1, 2, 0.73, True)7n.add_link(2, 3, 0.43, True)8n.add_link(3, 4, 0.41, True)9n.add_link(4, 5, 0.44, True)10n.add_link(5, 6, 0.94, True)11n.add_link(6, 7, 1.23, True)12n.add_link(7, 8, 0.92, True)13n.add_link(8, 9, 1.59, True)14n.add_link(9, 10, 0.78, True)15n.add_link(10, 11, 2.35, True)16n.add_link(11, 12, 0.46, True)17n.add_link(12, 13, 0.69, True)18n.add_link(13, 14, 1.01, True)19n.add_link(14, 15, 0.89, True)20n.add_link(15, 16, 0.48, True)21n.add_link(16, 17, 1.27, True)22n.add_link(17, 18, 0.58, True)23n.add_link(18, 19, 1.23, True)24n.add_link(19, 20, 0.41, True)25n.add_link(20, 21, 0.85, True)26n.add_link(21, 22, 1.30, True)27# Chelmonskiego Osiedle - Struga28n.add_link(3, 1, 0.96, True)29n.add_link(4, 3, 0.62, True)30n.add_link(5, 4, 0.35, True)31n.add_link(6, 5, 0.92, True)32n.add_link(7, 6, 1.32, True)33n.add_link(8, 7, 0.88, True)34n.add_link(9, 8, 1.55, True)35n.add_link(10, 9, 0.87, True)36n.add_link(11, 10, 2.17, True)37n.add_link(12, 11, 0.89, True)38n.add_link(13, 12, 0.81, True)39n.add_link(14, 13, 0.71, True)40n.add_link(15, 14, 0.92, True)41n.add_link(16, 15, 0.57, True)42n.add_link(17, 16, 1.26, True)43n.add_link(18, 17, 0.54, True)44n.add_link(19, 18, 1.30, True)45n.add_link(20, 19, 0.55, True)46n.add_link(21, 20, 0.58, True)47n.add_link(23, 21, 0.80, True)48n.add_link(22, 23, 0.55, True)49# name the stops50n.get_node(1).name = "Struga"51n.get_node(2).name = "Aleja Roz"52n.get_node(3).name = "Zeromskiego"53n.get_node(4).name = "Teatr Ludowy"54n.get_node(5).name = "Arka"55n.get_node(6).name = "Rondo Hipokratesa"56n.get_node(7).name = "Os.Na Lotnisku"57n.get_node(8).name = "Wislicka"58n.get_node(9).name = "Bora-Komorowskiego"59n.get_node(10).name = "Miechowity"60n.get_node(11).name = "Rondo Mogilskie"61n.get_node(12).name = "Uniwersytet Ekonomiczny"62n.get_node(13).name = "Politechnika"...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!