Fix a regression failure between the Perl and Python versions of map_convert
that was due to the two languages having different dictionary hash functions.
This commit is contained in:
parent
9730b4d28e
commit
d9dcde6f33
2 changed files with 24 additions and 4 deletions
|
@ -143,6 +143,10 @@ while($line=<TERRAIN>){
|
|||
}
|
||||
close(TERRAIN);
|
||||
|
||||
#while (($k, $v) = each(%conversion)) {
|
||||
# print "$k -> $v\n";
|
||||
#}
|
||||
|
||||
$width=$max_len+2;
|
||||
open(MAP, "<$map_file");
|
||||
@mfile=();
|
||||
|
@ -221,7 +225,7 @@ while($#mfile){
|
|||
if($hex=~/_K/){
|
||||
#convert keeps according to adjacent hexes
|
||||
$adj=get_adjacent($x,$y,@map);
|
||||
# print "adjacent: $adj\n";
|
||||
# print "adjacent: $adj\n";
|
||||
%hexcount=();
|
||||
for($i=1;$i<length($adj);$i++){
|
||||
#intentionally skipping 0 as it is original hex
|
||||
|
@ -238,13 +242,20 @@ while($#mfile){
|
|||
}
|
||||
$maxc=0;
|
||||
$maxk="Ch";
|
||||
foreach(keys(%hexcount)){
|
||||
# Next line is a hack to make this code pass regression
|
||||
# testing against the Python port. Without the sort, when
|
||||
# there are two terrain types that occur in equal numbers
|
||||
# greater than any others, which one gets picked will be
|
||||
# randomly dependent on Perl's dictionary hash function.
|
||||
@sorted = sort keys(%hexcount);
|
||||
foreach(@sorted){
|
||||
if($hexcount{$_}>$maxc){
|
||||
$maxc=$hexcount{$_};
|
||||
$maxk=$_;
|
||||
}
|
||||
# print "$_ $hexcount{$_}\n";
|
||||
}
|
||||
# print "Dominated by $maxk\n";
|
||||
$maxk=~s/^C/K/;
|
||||
$hex=~s/_K/$maxk/;
|
||||
}
|
||||
|
|
|
@ -116,6 +116,7 @@ while True:
|
|||
conversion[char] = string;
|
||||
tfp.close()
|
||||
width = max_len+2
|
||||
|
||||
#keys = conversion.keys()
|
||||
#keys.sort()
|
||||
#for k in keys:
|
||||
|
@ -188,7 +189,7 @@ while mfile:
|
|||
if "_K" in ohex:
|
||||
# Convert keeps according to adjacent hexes
|
||||
adj = get_adjacent(x,y, outmap)
|
||||
# print "adjacent: adj\n";
|
||||
# print "adjacent: %s" % adj
|
||||
hexcount = {}
|
||||
for i in range(1, len(adj)):
|
||||
# Intentionally skipping 0 as it is original hex
|
||||
|
@ -202,10 +203,18 @@ while mfile:
|
|||
hexcount[ca] = hexcount.get(ca, 0) + 1
|
||||
maxc = 0;
|
||||
maxk = "Ch";
|
||||
for k in hexcount:
|
||||
# Next line is a hack to make this code pass regression
|
||||
# testing against the Perl original. Without the sort, when
|
||||
# there are two terrain types that occur in equal numbers
|
||||
# greater than any others, which one gets picked will be
|
||||
# randomly dependent on Python's dictionary hash function.
|
||||
sorted = hexcount.keys()
|
||||
sorted.sort()
|
||||
for k in sorted:
|
||||
if hexcount[k] > maxc:
|
||||
maxc = hexcount[k]
|
||||
maxk = k
|
||||
#print "Dominated by %s" % maxk
|
||||
maxk = re.sub("^C", "K", maxk)
|
||||
ohex = ohex.replace("_K", maxk)
|
||||
line += ohex
|
||||
|
|
Loading…
Add table
Reference in a new issue