def test_nearby_hex_6_odd(self): '''Test 6-hex adjacency odd''' sector = Sector('Sector') radius = 6 hex_id = '1120' nearby_hexes = [ '0517', '0518', '0519', '0520', '0521', '0522', '0523', '0616', '0617', '0618', '0619', '0620', '0621', '0622', '0623', '0716', '0717', '0718', '0719', '0720', '0721', '0722', '0723', '0724', '0815', '0816', '0817', '0818', '0819', '0820', '0821', '0822', '0823', '0824', '0915', '0916', '0917', '0918', '0919', '0920', '0921', '0922', '0923', '0924', '0925', '1014', '1015', '1016', '1017', '1018', '1019', '1020', '1021', '1022', '1023', '1024', '1025', '1114', '1115', '1116', '1117', '1118', '1119', '1121', '1122', '1123', '1124', '1125', '1126', '1214', '1215', '1216', '1217', '1218', '1219', '1220', '1221', '1222', '1223', '1224', '1225', '1315', '1316', '1317', '1318', '1319', '1320', '1321', '1322', '1323', '1324', '1325', '1415', '1416', '1417', '1418', '1419', '1420', '1421', '1422', '1423', '1424', '1516', '1517', '1518', '1519', '1520', '1521', '1522', '1523', '1524', '1616', '1617', '1618', '1619', '1620', '1621', '1622', '1623', '1717', '1718', '1719', '1720', '1721', '1722', '1723' ] print('hex_id:', hex_id) print('actual:', set(sorted(nearby_hexes))) print('result:', set(sector.find_nearby_hexes(hex_id, radius))) self.assertTrue( set(nearby_hexes) == set(sector.find_nearby_hexes(hex_id, radius)))
def test_nearby_hex_6_even(self): '''Test 6-hex adjacency even''' sector = Sector('Sector') radius = 6 hex_id = '1213' nearby_hexes = [ '0610', '0611', '0612', '0613', '0614', '0615', '0616', '0710', '0711', '0712', '0713', '0714', '0715', '0716', '0717', '0809', '0810', '0811', '0812', '0813', '0814', '0815', '0816', '0817', '0909', '0910', '0911', '0912', '0913', '0914', '0915', '0916', '0917', '0918', '1008', '1009', '1010', '1011', '1012', '1013', '1014', '1015', '1016', '1017', '1018', '1108', '1109', '1110', '1111', '1112', '1113', '1114', '1115', '1116', '1117', '1118', '1119', '1207', '1208', '1209', '1210', '1211', '1212', '1214', '1215', '1216', '1217', '1218', '1219', '1308', '1309', '1310', '1311', '1312', '1313', '1314', '1315', '1316', '1317', '1318', '1319', '1408', '1409', '1410', '1411', '1412', '1413', '1414', '1415', '1416', '1417', '1418', '1509', '1510', '1511', '1512', '1513', '1514', '1515', '1516', '1517', '1518', '1609', '1610', '1611', '1612', '1613', '1614', '1615', '1616', '1617', '1710', '1711', '1712', '1713', '1714', '1715', '1716', '1717', '1810', '1811', '1812', '1813', '1814', '1815', '1816' ] print('hex_id:', hex_id) print('actual:', set(sorted(nearby_hexes))) print('result:', set(sector.find_nearby_hexes(hex_id, radius))) self.assertTrue( set(nearby_hexes) == set(sector.find_nearby_hexes(hex_id, radius)))
def test_nearby_hex_1_odd(self): '''Test 1-hex adjacency odd''' sector = Sector('Sector') radius = 1 hex_id = '1120' nearby_hexes = ['1019', '1020', '1119', '1121', '1219', '1220'] print('hex_id:', hex_id) print('actual:', set(sorted(nearby_hexes))) print('result:', set(sector.find_nearby_hexes(hex_id, radius))) self.assertTrue( set(nearby_hexes) == set(sector.find_nearby_hexes(hex_id, radius)))
def test_nearby_hex_1_even(self): '''Test 1-hex adjacency even''' sector = Sector('Sector') radius = 1 hex_id = '1213' nearby_hexes = ['1113', '1114', '1212', '1214', '1313', '1314'] print('hex_id:', hex_id) print('actual:', set(sorted(nearby_hexes))) print('result:', set(sector.find_nearby_hexes(hex_id, radius))) self.assertTrue( set(nearby_hexes) == set(sector.find_nearby_hexes(hex_id, radius)))
def test_nearby_hex_corner_case(self): '''Test corner case adjacency''' sector = Sector('Sector') radius = 3 hex_id = '0202' nearby_hexes = [ '0101', '0102', '0103', '0104', '0105', '0201', '0203', '0204', '0205', '0301', '0302', '0303', '0304', '0305', '0401', '0402', '0403', '0404', '0501', '0502', '0503', '0504' ] print('hex_id:', hex_id) print('actual:', set(sorted(nearby_hexes))) print('result:', set(sector.find_nearby_hexes(hex_id, radius))) self.assertTrue( set(nearby_hexes) == set(sector.find_nearby_hexes(hex_id, radius)))
def test_nearby_hex_3_odd(self): '''Test 3-hex adjacency odd''' sector = Sector('Sector') radius = 3 hex_id = '1120' nearby_hexes = [ '0818', '0819', '0820', '0821', '0918', '0919', '0920', '0921', '0922', '1017', '1018', '1019', '1020', '1021', '1022', '1117', '1118', '1119', '1121', '1122', '1123', '1217', '1218', '1219', '1220', '1221', '1222', '1318', '1319', '1320', '1321', '1322', '1418', '1419', '1420', '1421' ] print('hex_id:', hex_id) print('actual:', set(sorted(nearby_hexes))) print('result:', set(sector.find_nearby_hexes(hex_id, radius))) self.assertTrue( set(nearby_hexes) == set(sector.find_nearby_hexes(hex_id, radius)))
def test_nearby_hex_3_even(self): '''Test 3-hex adjacency even''' sector = Sector('Sector') radius = 3 hex_id = '1213' nearby_hexes = [ '0912', '0913', '0914', '0915', '1011', '1012', '1013', '1014', '1015', '1111', '1112', '1113', '1114', '1115', '1116', '1210', '1211', '1212', '1214', '1215', '1216', '1311', '1312', '1313', '1314', '1315', '1316', '1411', '1412', '1413', '1414', '1415', '1512', '1513', '1514', '1515' ] print('hex_id:', hex_id) print('actual:', set(sorted(nearby_hexes))) print('result:', set(sector.find_nearby_hexes(hex_id, radius))) self.assertTrue( set(nearby_hexes) == set(sector.find_nearby_hexes(hex_id, radius)))
def test_subsectorhex_to_sectorhex(self): '''Test subsector hex to sector hex transform''' sctr = Sector('Sector') self.assertTrue( sctr.subsector_hex_to_sector_hex('0105', 'A') == '0105') self.assertTrue( sctr.subsector_hex_to_sector_hex('0105', 'B') == '0905') print(sctr.subsector_hex_to_sector_hex('0810', 'A')) self.assertTrue( sctr.subsector_hex_to_sector_hex('0810', 'A') == '0810') print(sctr.subsector_hex_to_sector_hex('0810', 'B')) self.assertTrue( sctr.subsector_hex_to_sector_hex('0810', 'B') == '1610')
def test_sectorhex_to_subsectorhex(self): '''Test sector hex to subsector hex transform''' sctr = Sector('Sector') self.assertTrue(sctr.sector_hex_to_subsector_hex('0105') == '0105') self.assertTrue(sctr.sector_hex_to_subsector_hex('0905') == '0105') print('Sector hex = {} subsector hex = {}'.format( '0810', sctr.sector_hex_to_subsector_hex('0810'))) self.assertTrue(sctr.sector_hex_to_subsector_hex('0810') == '0810') print('Sector hex = {} subsector hex = {}'.format( '0820', sctr.sector_hex_to_subsector_hex('0820'))) self.assertTrue(sctr.sector_hex_to_subsector_hex('0820') == '0810')
def test_owning_system_sector(self): '''Test owning system (sector)''' # Sector data - 0105 is the owned world, 0308 should be the owning world sector = Sector('Test sector') sector.hexes = {} s_data = [ '{"mainworld": "{\\"trade_codes\\": [\\"Ni\\", \\"O:0101\\"],' + \ '\\"travel_code\\": \\"\\",' + \ '\\"is_mainworld\\": true,' + \ '\\"mainworld_type\\": \\"Planet\\",' + \ '\\"parent_type\\": null,' + \ '\\"orbit_around_parent\\": null,' + \ '\\"uwp\\": \\"E9D8665-7\\",' + \ '\\"orbit\\": 3,' + \ '\\"bases\\": \\"\\"}",' + \ '"worlds": 4,' + \ '"allegiance": "Na",' + \ '"stellar": "{\\"decimal\\": 3,' + \ '\\"companion\\": null,' + \ '\\"habitable_zone\\": 3,' + \ '\\"spectral_type\\": \\"G\\",' + \ '\\"secondaries\\": {},' + \ '\\"size\\": \\"V\\"}",' + \ '"Ix": "{-3}",' + \ '"name": "Name-0105A",' + \ '"zone": "",' + \ '"Cx": "[5349]",' + \ '"hex": "0105",' + \ '"pbg": "202",' + \ '"bases": "",' + \ '"Ex": "(753+1)",' + \ '"nobility": "B"}', '{"mainworld": "{\\"trade_codes\\": [\\"De\\", \\"Hi\\",' + \ '\\"In\\", \\"Po\\", \\"Tz\\"],' + \ '\\"travel_code\\": \\"\\",' + \ '\\"is_mainworld\\": true,' + \ '\\"mainworld_type\\": \\"Planet\\",' + \ '\\"parent_type\\": null,' + \ '\\"orbit_around_parent\\": null,' + \ '\\"uwp\\": \\"B140987-A\\",' + \ '\\"orbit\\": 0,' + \ '\\"bases\\": \\"\\"}",' + \ '"worlds": 5,' + \ '"allegiance": "Na",' + \ '"stellar": "{\\"decimal\\": 0,' + \ '\\"companion\\": null,' + \ '\\"habitable_zone\\": 0,' + \ '\\"spectral_type\\": \\"M\\",' + \ '\\"secondaries\\": {},' + \ '\\"size\\": \\"III\\"}",' + \ '"Ix": "{+4}",' + \ '"name": "Name-0308A",' + \ '"zone": "",' + \ '"Cx": "[ED17]",' + \ '"hex": "0308",' + \ '"pbg": "103",' + \ '"bases": "",' + \ '"Ex": "(A8A+1)",' + \ '"nobility": "BEf"}', '{"mainworld": "{\\"trade_codes\\": [\\"Hi\\", \\"In\\"],' + \ '\\"travel_code\\": \\"\\",' + \ '\\"is_mainworld\\": true,' + \ '\\"mainworld_type\\": \\"Planet\\",' + \ '\\"parent_type\\": null,' + \ '\\"orbit_around_parent\\": null,' + \ '\\"uwp\\": \\"A54598A-C\\",' + \ '\\"orbit\\": 2,' + \ '\\"bases\\": \\"\\"}",' + \ '"worlds": 5,' + \ '"allegiance": "Na",' + \ '"stellar": "{\\"decimal\\": 0,' + \ '\\"companion\\": null,' + \ '\\"habitable_zone\\": 2,' + \ '\\"spectral_type\\": \\"K\\",' + \ '\\"secondaries\\": {},' + \ '\\"size\\": \\"V\\"}",' + \ '"Ix": "{+4}",' + \ '"name": "Name-0805A",' + \ '"zone": "",' + \ '"Cx": "[5D4C]",' + \ '"hex": "0805",' + \ '"pbg": "403",' + \ '"bases": "N",' + \ '"Ex": "(98A+3)",' + \ '"nobility": "BEf"}', '{"mainworld": "{\\"trade_codes\\": [\\"Ni\\", \\"Ag\\", \\"Pr\\"],' + \ '\\"travel_code\\": \\"\\",' + \ '\\"is_mainworld\\": true,' + \ '\\"mainworld_type\\": \\"Planet\\",' + \ '\\"parent_type\\": null,' + \ '\\"orbit_around_parent\\": null,' + \ '\\"uwp\\": \\"B588510-8\\",' + \ '\\"orbit\\": 3,' + \ '\\"bases\\": \\"\\"}",' + \ '"worlds": 9,' + \ '"allegiance": "Na",' + \ '"stellar": "{\\"decimal\\": 7,' + \ '\\"companion\\": null,' + \ '\\"habitable_zone\\": 3,' + \ '\\"spectral_type\\": \\"G\\",' + \ '\\"secondaries\\": {},' + \ '\\"size\\": \\"V\\"}",' + \ '"Ix": "{+0}",' + \ '"name":' + \ '"Name-0702A",' + \ '"zone": "",' + \ '"Cx": "[7567]",' + \ '"hex": "0702",' + \ '"pbg": "802",' + \ '"bases": "",' + \ '"Ex": "(B41-1)",' + \ '"nobility": "BcC"}' ] for dta in s_data: system = System() system.json_import(dta) sector.hexes[system.hex] = system self.assertTrue(sector.find_owning_system('0105') == '0308') sector.trade_code_owning_system() self.assertTrue('O:0308' in sector.hexes['0105'].mainworld.trade_codes) for _ in sector.t5_tab(): print(_)
def test_is_odd(self): '''Test _is_even returns False for odd''' sector = Sector('sector') self.assertFalse(sector._is_even(3))
def test_is_even(self): '''Test _is_even returns True for even''' sector = Sector('sector') self.assertTrue(sector._is_even(2))
#! /usr/bin/env python from __future__ import print_function from T5_worldgen.mapping_region import Sector import os sector_name = 'Test_Sector_Sparse' sector = Sector(sector_name, 'Sparse') # sector.display() for _ in sector.t5_tab(): print(_) # Save JSON data in ./tmp/sector_name/subsector_name.json try: os.makedirs('/tmp/{}/'.format(sector_name)) except OSError: if not os.path.isdir('/tmp/{}/'.format(sector_name)): raise for ss_id in sector.subsectors.keys(): with open( '/tmp/{}/Subsector-{}.json'.format(sector_name, ss_id), 'w') as jout: for hex_id in sector.subsectors[ss_id].hexes.keys(): jout.write( sector.subsectors[ss_id].hexes[hex_id].as_json() + "\n" )