Commit a5821e84 authored by Colomban Wendling's avatar Colomban Wendling

LibOVCC: simplify a little scoring code for city, paths and fields

parent 6fca7e91
......@@ -324,11 +324,8 @@ namespace OVCC
uint n = 0; /* number of objects */
uint counts = 0; /* scoring ticks */
var table = new HashTable<Player, int>(null, null);
/* init table */
foreach (var p in this.players) {
table.insert (p, 0);
}
var list = new SList<Player>();
var table = new HashTable<Player, uint>(null, null);
/* loop on each TileObject */
foreach (var o in components) {
counts ++;
......@@ -339,59 +336,56 @@ namespace OVCC
}
/* handle occupied objects */
if (o.occupant != null) {
var cur = table.lookup (o.occupant.player);
uint power;
if (! table.lookup_extended (o.occupant.player, null, out power)) {
/* if the player wasn't in @table already, init its power and
* add it to the list */
power = 0;
list.prepend (o.occupant.player);
}
switch (o.occupant.kind) {
case PawnKind.NORMAL:
cur++;
power++;
break;
case PawnKind.DOUBLE:
cur+=2;
power += 2;
break;
}
table.insert (o.occupant.player, cur);
table.insert (o.occupant.player, power);
/* removing pawn now is efficient and not wrong */
if (components.nth_data(0).otype != TileObjectType.FIELD) {
remove_pawn (o.occupant);
}
}
}
var scorers = new SList<Player>();
uint current_power = 0;
/* compute list of players that score */
table.foreach ((k, v) => {
var power = v;
/* if that player is stronger, remember only him for now */
if (power > current_power) {
current_power = power;
scorers = new SList<Player>();
scorers.prepend (k);
}
/* if that player is equal in power to the current, store him too */
else if (power == current_power) {
scorers.prepend (k);
}
});
uint max_power = 0;
/* find out what power is needed to score */
foreach (var player in list) {
max_power = uint.max (max_power, table.lookup (player));
}
/* check that we actually found someone */
if (current_power > 0) {
/* make each player in the list actually score */
foreach (var player in scorers) {
/* handle small cities */
if (n == 2) {
player.score += 2;
} else {
/* score according to type */
switch (components.nth_data(0).otype) {
case TileObjectType.CITY:
/* TODO change when end */
player.score += counts * 2;
break;
case TileObjectType.PATH:
/* TODO change when end */
player.score += counts;
break;
case TileObjectType.FIELD:
player.score += 3;
break;
if (max_power > 0) {
/* make each player with enough power actually score */
foreach (var player in list) {
if (table.lookup (player) == max_power) {
/* handle small cities */
if (n == 2) {
player.score += 2;
} else {
/* score according to type */
switch (components.nth_data(0).otype) {
case TileObjectType.CITY:
/* TODO change when end */
player.score += counts * 2;
break;
case TileObjectType.PATH:
/* TODO change when end */
player.score += counts;
break;
case TileObjectType.FIELD:
player.score += 3;
break;
}
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment