From c87ecd0eb3513eb0dc286756ff3b1c38c7a21d09 Mon Sep 17 00:00:00 2001 From: mdb Date: Wed, 7 Nov 2001 10:39:00 +0000 Subject: [PATCH] When scoring a feature, we can't simply count up the elements in the claim group list because that may contain the same tile multiple times when tiles that contain multiple features are included in a single claim group with both of their features. So we have to do some extra jockeying to ensure that we count a tile only once. git-svn-id: https://samskivert.googlecode.com/svn/trunk@436 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../com/samskivert/atlanti/util/TileUtil.java | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/projects/atlanti/src/java/com/samskivert/atlanti/util/TileUtil.java b/projects/atlanti/src/java/com/samskivert/atlanti/util/TileUtil.java index 1fb1f053..54a4d483 100644 --- a/projects/atlanti/src/java/com/samskivert/atlanti/util/TileUtil.java +++ b/projects/atlanti/src/java/com/samskivert/atlanti/util/TileUtil.java @@ -1,5 +1,5 @@ // -// $Id: TileUtil.java,v 1.13 2001/10/24 03:24:36 mdb Exp $ +// $Id: TileUtil.java,v 1.14 2001/11/07 10:39:00 mdb Exp $ package com.threerings.venison; @@ -307,10 +307,26 @@ public class TileUtil implements TileCodes } // if we're here, it's a road or city feature, which we score by - // loading up the group and counting its size + // loading up the group and counting the number of tiles in it List flist = new ArrayList(); boolean complete = enumerateGroup(tiles, tile, featureIndex, flist); - int score = flist.size(); + + // we sort the group which will order the tile feature objects by + // their tiles, ensuring that features on the same tile are next + // to one another, so that we can only count them once + Collections.sort(flist); + + // now iterate over the list, counting only unique tiles + int score = 0; + VenisonTile lastTile = null; + int fsize = flist.size(); + for (int i = 0; i < fsize; i++) { + TileFeature feat = (TileFeature)flist.get(i); + if (feat.tile != lastTile) { + score++; + lastTile = feat.tile; + } + } // for city groups, we need to add a bonus of one for every tile // that contains a shield and mutiply by two if the city is @@ -598,7 +614,7 @@ public class TileUtil implements TileCodes } /** Used to keep track of actual features on tiles. */ - protected static final class TileFeature + protected static final class TileFeature implements Comparable { /** The tile that contains the feature. */ public VenisonTile tile; @@ -627,6 +643,12 @@ public class TileUtil implements TileCodes } } + /** We sort based on our tiles. */ + public int compareTo (Object other) + { + return tile.compareTo(((TileFeature)other).tile); + } + /** Generate a string representation. */ public String toString () {