Author: esr
Date: Tue Apr 24 14:41:57 2007
New Revision: 17030

URL: http://svn.gna.org/viewcvs/wesnoth?rev=17030&view=rev
Log:
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.

Modified:
    trunk/data/tools/map_convert.pl
    trunk/data/tools/map_convert.py

Modified: trunk/data/tools/map_convert.pl
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/map_convert.pl?rev=17030&r1=17029&r2=17030&view=diff
==============================================================================
--- trunk/data/tools/map_convert.pl (original)
+++ trunk/data/tools/map_convert.pl Tue Apr 24 14:41:57 2007
@@ -143,6 +143,10 @@
 }
 close(TERRAIN);
 
+#while (($k, $v) = each(%conversion)) {
+#    print "$k -> $v\n";
+#}
+
 $width=$max_len+2;
 open(MAP, "<$map_file");
 @mfile=();
@@ -221,7 +225,7 @@
                 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 @@
                     }
                     $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/;
                 }

Modified: trunk/data/tools/map_convert.py
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/map_convert.py?rev=17030&r1=17029&r2=17030&view=diff
==============================================================================
--- trunk/data/tools/map_convert.py (original)
+++ trunk/data/tools/map_convert.py Tue Apr 24 14:41:57 2007
@@ -116,6 +116,7 @@
                        conversion[char] = string;
 tfp.close()
 width = max_len+2
+
 #keys = conversion.keys()
 #keys.sort()
 #for k in keys:
@@ -188,7 +189,7 @@
                 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 @@
                             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


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to