;ò Nýy>c@sìdkZdkZdkZdkZdZdZd„Zd„Zd„Zdfd„ƒYZ dfd „ƒYZ d fd „ƒYZ d fd „ƒYZ d„Z e ƒd„Zdfd„ƒYZdfd„ƒYZdfd„ƒYZdS(NsujnbgysbgyujncCsN|\}}|\}}||d||d||d||dfSdS(s. normalize coordinates according to world sizeiN(scoordssxsys world_sizessize_xssize_y(scoordss world_sizessize_xssize_ysysx((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pys norm_coordss  c Cs¹tidd}|\}}t|d|df|ƒt|d|f|ƒt|d|df|ƒt|d|df|ƒt|d|f|ƒt|d|df|ƒgSdS(s" neighbours ordered as directions sversions worldsizeiiN(sempDbsmegaDBsworldscoordssxsys norm_coords(scoordssxsysworld((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pys neighbours"s cCs|\}}| d| SdS(Ns,(scoordssxsy(scoordssysx((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pys coords_to_str0s sMobCostcBs tZdZd„Zd„ZRS(s" Mobility cost using the move cmd cCsdS(N((sself((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pys__init__;scCsadti}tidi|hƒ}|o|idƒtijoti |ƒ}n|SdS(s cost for moving into sector f2.0sSECTORsownerN( s empSectorsinfinite_mob_costsresultsempDbsmegaDBsgetscoordsssectsCN_OWNEDsmob_cost(sselfscoordssresultssect((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pyscost>s   (s__name__s __module__s__doc__s__init__scost(((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pysMobCost9s  s ExplMobCostcBs tZdZd„Zd„ZRS(s" Mobility cost using the expl cmd cCsdS(N((sself((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pys__init__IscCsqdti}tidi|hƒ}|o&|idƒtijp ti |ƒoti |ƒ}n|SdS(s cost for moving into sector f2.0sSECTORsownerN( s empSectorsinfinite_mob_costsresultsempDbsmegaDBsgetscoordsssectsCN_OWNEDsis_explorable_intosmob_cost(sselfscoordssresultssect((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pyscostLs  0(s__name__s __module__s__doc__s__init__scost(((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pys ExplMobCostGs  sPathcBs2tZdZd„Zd„Zd„Zd„ZRS(s* Empire path between sectors in a hex map cCs(||_||_d|_||_dS(Ns(ssectsselfsstartsends directionssmob_costscost(sselfssectsmob_cost((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pys__init___s   cCsGt|i|i|iƒ}|i||i|_|i|_|SdS(s concatinate two paths N( sPathsselfsstartscoststailsresults directionssdirsend(sselfstailsdirsresult((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pysappendes  cCs:t|i|i|ƒ}|i||_||_ |SdS(s# add a step at the end of the path N( sPathsselfsstartscostsmob_costsresults directionssdirssectsend(sselfssectsmob_costsdirsresult((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pys post_extendls  cCs:t||i|ƒ}||i|_|i|_|SdS(s) add a step at the beginning of the path N( sPathssectsselfscostsmob_costsresultsdirs directionssend(sselfssectsmob_costsdirsresult((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pys pre_extendss  (s__name__s __module__s__doc__s__init__sappends post_extends pre_extend(((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pysPath]s    sPathscBsŒtZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „Zd „Zd„ZRS(s# Paths between two sets of sectors cCs||_h|_h|_h|_g|_g|_g|_xY|D]Q}t |dƒ}|df|i|i <|g|i|i <|i|i|ƒqFWxe|D]]}t ||ii|ƒƒ}|df|i|i<|g|i|i<|i|i|ƒq¢W|iƒdS(Nf0.0ii(smcostsselfs _Paths__mobs_Paths__visiteds_Paths__starting_ats_Paths__ending_ats _Paths__headss _Paths__tailss_Paths__completes from_sectssectsPathspathsstarts_Paths__insert_pathsto_sectscostsends_Paths__make_paths(sselfs from_sectsto_sectsmcostssectspath((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pys__init__œs(       cCs1t|iƒdjp|iditijSdS(s no path exits iN(slensselfs_Paths__completescosts empSectorsinfinite_mob_cost(sself((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pysempty´scCs|idSdS(s7 the best path ( lowest cost ) between any two sectors iN(sselfs_Paths__complete(sself((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pysbest¹scCsz|i p|i }| oUti}|io|idi}n|idi|idi}||j}n|SdS(s have we found the best path iN( sselfs _Paths__headss _Paths__tailss done_searchs empSectorsinfinite_mob_costs best_so_fars_Paths__completescosts best_possible(sselfs done_searchs best_so_fars best_possible((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pys__found_best_path½s  cCsMd}x0|D](}|i|ijoPq |d}q W|i||ƒdS(s insert path in a sorted list iiN(sindexs path_listselemspathscostsinsert(sselfs path_listspathsindexselem((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pys __insert_pathÊscCsGd }x9|iƒ o*|o|iƒn |iƒ| }q WdS(s expand tail and head paths iN(s expand_headssselfs_Paths__found_best_paths_Paths__expand_headss_Paths__expand_tails(sselfs expand_heads((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pys __make_pathsÕs cCs|id}|id=d}xßt|iƒD]Î}t|}|i i |ƒ ob|i ||i i |ƒ|ƒ}|i|i|ƒ|df|i |<|i|ii|ƒn?|i |\}}| o#|i|i|i||ƒƒn|d}q-WdS(s expand best head path iiN(sselfs _Paths__headsspathsis neighbourssendssectsmove_directionssdirs_Paths__visitedshas_keys post_extends _Paths__mobscostsnew_paths_Paths__insert_paths_Paths__starting_atsstartsappendstails is_head_paths_Paths__complete(sselfsnew_pathsistailssectspaths is_head_pathsdir((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pys__expand_headsßs&      cCs|id}|id=d}xÞt|iƒD]Í}t|}|i i |ƒ ob|i ||i i |ƒ|ƒ}|i|i|ƒ|df|i |<|i|ii|ƒn>|i |\}}|o#|i|i|i||ƒƒn|d}q-WdS(s expand best tail path iiN(sselfs _Paths__tailsspathsis neighbourssstartssectsmove_reverse_directionssdirs_Paths__visitedshas_keys pre_extends _Paths__mobscostsnew_paths_Paths__insert_paths_Paths__ending_atsendsappendsheads is_head_paths_Paths__complete(sselfsheadsnew_pathsissectspaths is_head_pathsdir((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pys__expand_tailsös&      cCsg}x2|i|D]#}|i|i=|i|iƒqW|i|=|i|i |ƒ|_ |i|i |ƒ|_ |i |ƒ|i ƒdS(s0 remove a sector from the set of source sectors N( sremovedsselfs_Paths__starting_atscoordsspaths_Paths__visitedsendsappends_Paths__not_starting_ats _Paths__headss_Paths__completes_Paths__activate_neighbours_ofs_Paths__make_paths(sselfscoordsspathsremoved((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pys remove_froms       cCsg}x2|i|D]#}|i|i=|i|iƒqW|i|=|i|i |ƒ|_ |i|i |ƒ|_ |i |ƒ|i ƒdS(s5 remove a sector from the set of destination sectors N( sremovedsselfs_Paths__ending_atscoordsspaths_Paths__visitedsstartsappends_Paths__not_ending_ats _Paths__tailss_Paths__completes_Paths__activate_neighbours_ofs_Paths__make_paths(sselfscoordsspathsremoved((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pys remove_to#s       cCs@g}x/|D]'}|i|jo|i|ƒq q W|SdS(s( filter out path not starting at coords N(sresults path_listspathsstartscoordssappend(sselfs path_listscoordssresultspath((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pys__not_starting_at2scCs@g}x/|D]'}|i|jo|i|ƒq q W|SdS(s( filter out path not starting at coords N(sresults path_listspathsendscoordssappend(sselfs path_listscoordssresultspath((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pys__not_ending_at<scCsPxI|D]A}x8t|ƒD]*}|ii|ƒo|i|ƒqqWqWdS(s< enable neighbouring paths to expand into unvisited sectors N(s removed_listsremoveds neighboursssectsselfs_Paths__visitedshas_keys_Paths__activate_path_end(sselfs removed_listsremovedssect((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pys__activate_neighbours_ofGs cCsp|i|\}}|o+||ijo|i|i|ƒqln(||ijo|i|i|ƒndS(s) insert path to head_paths or tail_paths N(sselfs_Paths__visitedssectspaths is_head_paths _Paths__headss_Paths__insert_paths _Paths__tails(sselfssectspaths is_head_path((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pys__activate_path_endOs(s__name__s __module__s__doc__s__init__semptysbests_Paths__found_best_paths_Paths__insert_paths_Paths__make_pathss_Paths__expand_headss_Paths__expand_tailss remove_froms remove_tos_Paths__not_starting_ats_Paths__not_ending_ats_Paths__activate_neighbours_ofs_Paths__activate_path_end(((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pysPathsšs         cCs=t|iƒd|idt|iƒd|i dSdS(s make a string out of a path s s (s)N(s coords_to_strspathsstarts directionssendscost(spath((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pyspath_str^scCsDt}t|g|g|ƒ}|iƒ o|iƒ}n|SdS(N( sNonesresultsPathsssrcsdstsmob_costspathssemptysbest(ssrcsdstsmob_costspathssresult((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pys best_pathos s MoveGeneratorcBs8tZdZeƒd„Zd„Zd„Zd„ZRS(s generator of moves cCsY||_||_t|_||_t |ii ƒ|ii ƒ|ƒ|_ |i ƒdS(N(ssrc_secssselfs_MoveGenerator__from_mapsdst_secss_MoveGenerator__to_mapsNones_MoveGenerator__moves commoditys_MoveGenerator__commoditysPathsskeyssmcosts_MoveGenerator__pathssnext(sselfs commodityssrc_secssdst_secssmcost((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pys__init__zs      cCs |i SdS(s no more move commands N(sselfs_MoveGenerator__move(sself((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empPath.pysempty‘scCs t|_x|iiƒp|i ot|iiƒ}|i|i\}}}||i |jo!t i|||i ƒ}||jo |}n|i|i}||jo |}n||}||}t i|||i |ƒ}|i||f|_|djo||i|i