def test_parse_admit(): t = ''' admit 1933 zb1 1001 1002 2001 3001 admit 8738 qm9 ez0 ''' ret = [['1933', to_int('zb1'), '1001', '1002', '2001', '3001'], ['8738', to_int('qm9'), to_int('ez0')]] assert turnparser.parse_admit(t) == ret
def check_where(data, unit, loc): ''' Used by other tests to verify that unit is in loc and vice-versa. Does not work for unique items. ''' unitint = to_int(str(unit)) locint = to_int(str(loc)) assert ' item ' not in data[unitint].get('firstline', '') assert data[unitint]['LI']['wh'] == [locint] # this will throw ValueError if it fails assert data[locint]['LI']['hl'].index(unitint) >= 0
def test_parse_faction(): t = ''' Admit permissions: admit 4256 ja1 ad3 admit 7611 6124 admit 9724 ja1 admit 9774 ja1 Declared attitudes: defend ad3 zz1 hostile ez0 neutral hv5 hx7 Unclaimed items: qty name weight --- ---- ------ 4,330 gold [1] 0 5 riding horses [52] 5,000 ride 750 100 stone [78] 10,000 ''' ret = {'ad': [to_int('ad3'), to_int('zz1')], 'ah': [to_int('ez0')], 'PL': {'am': [['4256', '52341', '50033'], ['7611', '6124'], ['9724', '52341'], ['9774', '52341']]}, 'an': [to_int('hv5'), to_int('hx7')], 'il': ['1', '4330', '52', '5', '78', '100']} data = {'1000': {}} turnparser.parse_faction(t, '1000', data) assert data['1000'] == ret
def test_oid(): for oid, oint in oid_to_int.items(): assert to_int(oid) == str(oint) assert to_oid(oint) == oid assert to_oid(int(oint)) == oid with pytest.raises(ValueError): for oid in invalid_oid: to_int(oid) for oint in range(1000, 100002): assert to_int(to_oid(oint)) == str(oint) data = {} intoid = allocate_oid(data, 'NNNN') oid = to_oid(intoid) assert len(oid) == 4 assert oid.isdigit() intoid = allocate_oid(data, 'CCNN') oid = to_oid(intoid) assert len(oid) == 4 assert oid[0:2].isalpha() assert oid[2:].isdigit()
from jinja2 import Environment, PackageLoader, select_autoescape from olymap.loc import build_complete_loc_dict from olymap.ship import build_complete_ship_dict from olymap.char import build_complete_char_dict from olymap.item import build_complete_item_dict from olymap.skill import build_complete_skill_dict from olymap.storm import build_complete_storm_dict from olymap.player import build_complete_player_dict import olymap.utilities as u import olymap.reports as reports from olymap.maps import write_index, write_map_leaves, write_top_map, write_bitmap from olymap.legacy import create_map_matrix, write_legacy_bitmap, write_legacy_top_map, write_legacy_map_leaves inlib = sys.argv[1] data = oio.read_lib(inlib) dbck.check_db(data, fix=True, checknames=True) rec_id = ' ' rec_id = input('Enter record id ("0" to exit): ') while rec_id != '0': try: rec_id_conv = to_int(rec_id) try: print(data[rec_id_conv]) except: print('Invalid key') except: print('Invalid key') rec_id = input('Enter record id ("0" to exit): ')
def test_parse_market_report(): t = ''' trade who price qty wt/ea item ----- --- ----- --- ----- ---- buy m19 7 17 5 clay pots [95] buy m19 65 3 1,000 riding horses [52] buy m19 83 38 43 tea [t526] sell m19 1,000 5 2,000 oxen [76] sell 2002 80 3 2,000 oxen [76] sell m19 130 3 1,000 riding horses [52] sell m19 82 41 80 fine cloaks [g950] sell m19 11 27 100 salt [r384] ''' r_all = ['1', '95', '17', '7', '0', '0', '0', '0', '4', '95', '17', '7', '0', '0', '0', '0', '1', '52', '3', '65', '0', '0', '0', '0', '4', '52', '3', '65', '0', '0', '0', '0', '1', to_int('t526'), '38', '83', '0', '0', '0', '0', '4', to_int('t526'), '38', '83', '0', '0', '0', '0', '2', '76', '5','1000', '0', '0', '0', '0', '3', '76', '5','1000', '0', '0', '0', '0', '2', '76', '3', '80', '0', '0', '0', '0', '3', '76', '3', '80', '0', '0', '0', '0', '2', '52', '3', '130', '0', '0', '0', '0', '3', '52', '3', '130', '0', '0', '0', '0', '2', to_int('g950'), '41', '82', '0', '0', '0', '0', '3', to_int('g950'), '41', '82', '0', '0', '0', '36', '2', to_int('r384'), '27', '11', '0', '0', '0', '0', '3', to_int('r384'), '27', '11', '0', '0', '0', '36', '1', '93', '80', '17', '0', '0', '0', '0', '4', '93', '80', '17', '0', '0', '0', '0'] r_cty = ['1', '95', '17', '7', '0', '0', '0', '0', '4', '95', '17', '7', '0', '0', '0', '0', '1', '52', '3', '65', '0', '0', '0', '0', '4', '52', '3', '65', '0', '0', '0', '0', '1', to_int('t526'), '38', '83', '0', '0', '0', '0', '4', to_int('t526'), '38', '83', '0', '0', '0', '0', '2', '76', '5','1000', '0', '0', '0', '0', '3', '76', '5','1000', '0', '0', '0', '0', '2', '52', '3', '130', '0', '0', '0', '0', '3', '52', '3', '130', '0', '0', '0', '0', '2', to_int('g950'), '41', '82', '0', '0', '0', '0', '3', to_int('g950'), '41', '82', '0', '0', '0', '36', '2', to_int('r384'), '27', '11', '0', '0', '0', '0', '3', to_int('r384'), '27', '11', '0', '0', '0', '36', '1', '93', '80', '17', '0', '0', '0', '0', '4', '93', '80', '17', '0', '0', '0', '0'] data = {} data_out = {'64950': {'IT': {'bp': ['82'], 'pl': ['fine cloaks'], 'wt': ['80']}, 'firstline': ['64950 item tradegood'], 'na': ['fine cloaks']}, '72384': {'IT': {'bp': ['11'], 'pl': ['salt'], 'wt': ['100']}, 'firstline': ['72384 item tradegood'], 'na': ['salt']}, '74526': {'IT': {'bp': ['83'], 'pl': ['tea'], 'wt': ['43']}, 'firstline': ['74526 item tradegood'], 'na': ['tea']}} assert turnparser.parse_market_report(t, data) == r_all assert data == data_out data = {} data_out = {'64950': {'IT': {'bp': ['82'], 'pl': ['fine cloaks'], 'wt': ['80']}, 'firstline': ['64950 item tradegood'], 'na': ['fine cloaks']}, '72384': {'IT': {'bp': ['11'], 'pl': ['salt'], 'wt': ['100']}, 'firstline': ['72384 item tradegood'], 'na': ['salt']}, '74526': {'IT': {'bp': ['83'], 'pl': ['tea'], 'wt': ['43']}, 'firstline': ['74526 item tradegood'], 'na': ['tea']}} assert turnparser.parse_market_report(t, data, include=to_int('m19')) == r_cty assert data == data_out
def test_parse_location_top(): t = 'Forest [ah08], forest, in Acaren, wilderness' ret = ['Forest', to_int('ah08'), 'forest', 0, 'Acaren', 0, 0, 0] assert turnparser.parse_location_top(t) == ret assert turnparser.regions_set == set(('Cloudlands', 'Great Sea', 'Hades', 'Undercity', 'Acaren', 'Nowhere', 'Subworld', 'Faery'))
def test_parse_attitudes(): t = ''' defend ad3 ez0 ig7 ja1 qm9 Hostile ad3 neutral ad3 ''' ret = {'defend': [to_int('ad3'), to_int('ez0'), to_int('ig7'), to_int('ja1'), to_int('qm9')], 'hostile': [to_int('ad3')], 'neutral': [to_int('ad3')]} assert turnparser.parse_attitudes(t) == ret t = ''' defend ad3 dk3 dq4 jq9 ''' ret = {'defend': [to_int('ad3'), to_int('dk3'), to_int('dq4'), to_int('jq9')]} assert turnparser.parse_attitudes(t) == ret
def test_parse_location(): t = '''Forest [bf23], forest, in Grinter, safe haven, civ-2 ------------------------------------------------------------------------ Routes leaving Forest: North, to Forest [bd23], 8 days East, to Ocean [bf24], Great Sea, impassable South, to Ocean [bg23], Great Sea, impassable West, to Forest [bf22], 8 days Inner locations: Wildefort [h63], port city, safe haven, 1 day A magical barrier surrounds Wildefort [h63]. Phra Ratchawang [9900], castle, defense 80, level 6, owner: Morathron [9901], earl, sorcerer, "Black raven on silver moon", with 727 crossbowmen, 565 elite archers, 13 riding horses, accompanied by: Jaturong [9902], sorcerer, wearing Phra Ram Amulet [x528], with 69 pikemen, four riding horses, one hound Anton [9903], wizard, with one riding horse, 38 workers, 143 swordsmen, 173 giant lizards Chulalongkorn [9904], tower, defense 40 It is raining. It is windy. Rain [109999], storm, strength 2 Wind [85687], storm, owner 8910, strength 33 Seen here: Gus McCrae [2554], with five peasants, accompanied by: New noble [6386], with one peasant, one worker ''' r = {'12323': {'LI': {'wh': ['Grinter']}, 'LO': {'pd': ['0', '0', '12423', '0']}, 'firstline': ['12323 loc forest'], 'il': ['77', '30', '10', '10', '96', '50', '101', '1', '276', '1', '274', '1'], 'na': ['Forest']}, '12422': {'LI': {'wh': ['Grinter']}, 'LO': {'pd': ['0', '12423', '0', '0']}, 'firstline': ['12422 loc forest'], 'il': ['77', '30', '10', '10', '96', '50', '101', '1', '276', '1', '274', '1'], 'na': ['Forest']}, '12423': {'LI': {'hl': ['57423', '9900'], 'wh': ['Grinter']}, 'LO': {'lc': ['2'], 'pd': ['12323', '12424', '12523', '12422']}, 'SL': {'sh': ['1']}, 'firstline': ['12423 loc forest'], # alas this one is sorted by the tax computation 'il': ['10', '10', '77', '30', '96', '150', '101', '1', '274', '1', '276', '1'], 'na': ['Forest']}, '12424': {'LI': {'wh': ['Great Sea']}, 'LO': {'pd': ['0', '0', '0', '12423']}, 'firstline': ['12424 loc ocean'], 'il': ['59', '30', '87', '50', '274', '1', '275', '1', '276', '1'], 'na': ['Ocean']}, '12523': {'LI': {'wh': ['Great Sea']}, 'LO': {'pd': ['12423', '0', '0', '0']}, 'firstline': ['12523 loc ocean'], 'il': ['59', '30', '87', '50', '274', '1', '275', '1', '276', '1'], 'na': ['Ocean']}, '57423': {'LI': {'wh': ['12423']}, 'SL': {'sh': ['1']}, 'firstline': ['57423 loc city'], 'il': ['10', '10', '294', '1', '277', '5', '96', '100', '101', '1'], 'na': ['Wildefort']}, '9900': {'LI': {'hl': ['9904'], 'wh': ['12423']}, 'SL': {'cl': ['6'], 'de': ['80']}, 'firstline': ['9900 loc castle'], 'na': ['Phra Ratchawang']}, '9904': {'LI': {'wh': ['9900']}, 'SL': {'de': ['40']}, 'firstline': ['9904 loc tower'], 'na': ['Chulalongkorn']}} data = {} turnparser.parse_location(t, to_int('ja1'), False, data) assert data == r r['12423']['LI']['hl'].extend(('2554', '109999', '85687')) r['9900']['LI']['hl'] = ['9901', '9904'] r['2554'] = {'CH': {'at': ['60'], 'df': ['60'], 'he': ['100']}, 'LI': {'hl': ['6386'], 'wh': ['12423']}, 'firstline': ['2554 char 0'], 'il': ['10', '5'], 'na': ['Gus McCrae']} r['6386'] = {'CH': {'at': ['60'], 'df': ['60'], 'he': ['100']}, 'LI': {'wh': ['2554']}, 'firstline': ['6386 char 0'], 'il': ['10', '1', '11', '1'], 'na': ['New noble']} r['9901'] = {'CH': {'at': ['60'], 'df': ['60'], 'he': ['100'], 'ra': ['50']}, 'LI': {'hl': ['9902', '9903'], 'wh': ['9900']}, 'firstline': ['9901 char 0'], 'il': ['21', '727', '22', '565', '52', '13'], 'na': ['Morathron']} r['9902'] = {'CH': {'at': ['60'], 'df': ['60'], 'he': ['100']}, 'LI': {'wh': ['9901']}, 'firstline': ['9902 char 0'], 'il': ['77528', '1', '16', '69', '52', '4', '295', '1'], 'na': ['Jaturong']} r['9903'] = {'CH': {'at': ['60'], 'df': ['60'], 'he': ['100']}, 'LI': {'wh': ['9901']}, 'firstline': ['9903 char 0'], 'il': ['52', '1', '11', '38', '20', '143', '282', '173'], 'na': ['Anton']} r['85687'] = {'LI': {'wh': ['12423']}, 'MI': {'sb': ['8910'], 'ss': ['33']}, 'firstline': ['85687 storm wind'], 'na': ['Wind']} r['109999'] = {'LI': {'wh': ['12423']}, 'MI': {'ss': ['2']}, 'firstline': ['109999 storm rain'], 'na': ['Rain']} turnparser.parse_location(t, to_int('ja1'), True, data) assert data == r
def test_parse_character(): t = ''' Osswid the Destroyer [7271] ------------------------------------------------------------------------ 0: > stop 0: Interrupt current order. 0: Trained nine soldiers. 1: > press 0 1: Press posted. 1: > train 12 11: Trained 11 soldiers. 12: > make 74 12: Don't have any iron [79]. 12: > train 20 12: Don't have any longswords [74]. 12: > wait item 10 1 14: Received ten peasants [10] from Osswid the Brave [2597]. 14: Wait finished: Osswid the Destroyer has ten peasants. 14: Received two iron [79] from Osswid the Brave [2597]. 14: > train 12 23: Trained ten soldiers. 29: Received ten peasants [10] from Osswid the Brave [2597]. 30: Collected 1,479 gold from owned provinces. 30: Collected 265 gold in taxes. 30: Paid maintenance of 944 gold. Location: Amber Keep [4256], in Inte [v25], in province Mountain [bc19], in Grinter Loyalty: Oath-2 Health: 100% Combat: attack 89, defense 168, missile 50 behind 0 (front line in combat) Break point: 0% (fight to the death) use 638 1 (concealing self) Receive Vision: 2 protection Pledged to: Yoyo 6 [6839] Pledged to us: Tom [1753] Gus McCrae [2554] Moriarity [4168] Yoyo [4797] Francisco Lopez [6710] Tom [8578] Current aura: 4 Maximum aura: 4 Declared attitudes: defend qm9 zb1 Skills known: Shipcraft [600] Sailing [601], apprentice Shipbuilding [602], apprentice Fishing [603], apprentice Combat [610] Survive fatal wound [611] Fight to the death [612] Construct catapult [613], apprentice Defense [614], adept Archery [615], apprentice Swordplay [616], adept Weaponsmithing [617], master Construction [680] Construct siege tower [681], apprentice Stone quarrying [682], apprentice Mining [720] Mine iron [721], apprentice Mine gold [722], apprentice Scrying [840] Scry location [841], apprentice Ciphered writing of Areth-Pirn [842], apprentice Create magical barrier [845], apprentice Partially known skills: Magic [800], 7/28 Gatecraft [860], 7/35 Inventory: qty name weight --- ---- ------ 26,834 gold [1] 0 10 peasants [10] 1,000 cap 1,000 (1,1,0) 380 soldiers [12] 38,000 cap 38,000 (5,5,0) 1 pikeman [16] 100 cap 100 (5,30,0) 29 blessed soldiers [17] 2,900 cap 2,900 (5,5,0) 28 swordsmen [20] 2,800 cap 2,800 (15,15,0) 303 stone [78] 30,300 2 iron [79] 20 11 woven baskets [94] 11 1 drum [98] 2 ====== 75,133 Capacity: 30,333/44,900 land (67%) Pending trades: trade price qty item ----- ----- --- ---- sell 7 100 clay pot [95] ''' ret = {'4256': {'LI': {'hl': ['7271']}}, '50033': {'PL': {'kn': ['600', '601', '602', '603', '610', '611', '612', '613', '614', '615', '616', '617', '680', '681', '682', '720', '721', '722', '840', '841', '842', '845', '800', '860'], 'un': ['7271']}}, '7271': {'firstline': ['7271 char 0'], 'na': ['Osswid the Destroyer'], 'il': ['1', '26834', '10', '10', '12', '380', '16', '1', '17', '29', '20', '28', '78', '303', '79', '2', '94', '11', '98', '1'], 'tl': ['2', '95', '100', '7', '0', '0', '0', '0'], 'ad': [to_int('qm9'), to_int('zb1')], 'CH': {'at': ['89'], 'df': ['168'], 'he': ['100'], 'lk': ['2'], 'lo': ['50033'], 'lr': ['2'], 'mi': ['50'], 'sl': ['600', '2', '21', '0', '0', '601', '2', '14', '0', '0', '602', '2', '14', '0', '0', '603', '2', '14', '0', '0', '610', '2', '21', '0', '0', '611', '2', '28', '0', '0', '612', '2', '28', '0', '0', '613', '2', '14', '0', '0', '614', '2', '14', '12', '0', '615', '2', '21', '0', '0', '616', '2', '14', '12', '0', '617', '2', '14', '21', '0', '680', '2', '21', '0', '0', '681', '2', '14', '0', '0', '682', '2', '14', '0', '0', '720', '2', '21', '0', '0', '721', '2', '14', '0', '0', '722', '2', '14', '0', '0', '840', '2', '35', '0', '0', '841', '2', '21', '0', '0', '842', '2', '21', '0', '0', '845', '2', '21', '0', '0', '800', '1', '7', '0', '0', '860', '1', '7', '0', '0']}, 'CM': {'ca': ['4'], 'hs': ['1'], 'im': ['1'], 'ma': ['4'], 'hs': ['1'], 'pl': ['6839'], 'vp': ['2']}, 'LI': {'wh': ['4256']}}} data = {} turnparser.parse_character('Osswid the Destroyer', '7271', '50033', t, data) assert data == ret
def test_generate_move_args(): tests = [[['29', '5', to_int('aa02'), to_int('aa01')], ['0', '0', '10002', '0', '0', '7', '10001', '0']]] for t in tests: print(len(t[0])) assert turnparser.generate_move_args(*t[0]) == t[1]