Register for your free account! | Forgot your password?

You last visited: Today at 05:19

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



GuildWars Question

Discussion on GuildWars Question within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
GuildWars Question

I'm selecting the top 5 for the score like below:
Code:
        private static Dictionary<byte, string> SelectTopFive()
        {
            Dictionary<byte, string> Select = new Dictionary<byte, string>();
            int count = (Damage.Count > 0) ? (Damage.Count > 5) ? 5 : Damage.Count : 0;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    KeyValuePair<uint, GuildWarsGuild> sel =
                        Damage.Aggregate((l, r) => l.Value.Score > r.Value.Score ? l : r);
                    Select.Add((byte)i, sel.Value.Guild.Name + ": " + sel.Value.Score);
                }
            }
            return Select;
        }
This is the Damage Dictionary.
Code:
//guildid, gwguild
public static Dictionary<uint, GuildWarsGuild> Damage = new Dictionary<uint, GuildWarsGuild>();
GuildWarsGuild is just containing 2 variables. uint as damage and guild as guild.

It does work, but my question is would there be any better ways to get the top five?

Thanks.
I don't have a username is offline  
Old 02/15/2012, 16:13   #2
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,379
..... and what happens when two guilds have the same score? Do you throw an exception, throw away one record... what?


I'd swap it around so that you have a dictionary holding all Guilds which have competed in the current round... then have their value be damage. Sort by value and display up to top 5 in scoreboard. When pole dies just take top entry from that dict as winner.
pro4never is offline  
Thanks
1 User
Old 02/15/2012, 17:47   #3
 
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
Quote:
Originally Posted by pro4never View Post
..... and what happens when two guilds have the same score? Do you throw an exception, throw away one record... what?


I'd swap it around so that you have a dictionary holding all Guilds which have competed in the current round... then have their value be damage. Sort by value and display up to top 5 in scoreboard. When pole dies just take top entry from that dict as winner.
It can never throw an exception. It returns the last added.

if you eg. adds 3 values with 1000000.
a 1000000
b 1000000
c 1000000

Output will be:
Code:
c
b
a
If a and c is 1000000 and b 500000, then output would be.
Code:
c
a
b


--
Changed the method a bit, because it could be slightly better xD
I don't have a username is offline  
Old 02/15/2012, 18:20   #4
 
elite*gold: 0
Join Date: Oct 2009
Posts: 768
Received Thanks: 550
Interesting method. (Though not working, at least not the way you use it.)
I got a couple of questions:
1. Why do you do:
Code:
int count = (Damage.Count > 0) ? (Damage.Count > 5) ? 5 : Damage.Count : 0;
You don't need at least 5 competitors to be able to chose the top 5(at least one is needed to be able to win the GW war).
2. Why use Linq.Aggregate?
I mean it just gives one value, one at a time using the given compare function, but, the way you do it, it will give you the same result all the time (as in one value only...).
I, myself, use the SortedDictionary but you can use directly Damage.OrderBy(p => p.Value.Score);
PHP Code:
private static List<stringSelectTopFive()
{
    List<
string> List = new List<string>();
    var array = 
Damage.OrderBy(=> p.Value.Score);
    for (
int i 0Math.Min(array.Length5); i++)
        List.
Add(array[i].Value.Guild.Name);
    return List;

-impulse- is offline  
Thanks
1 User
Old 02/15/2012, 18:25   #5
 
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
Quote:
Originally Posted by -impulse- View Post
...
I love you Impulse *****.
I don't have a username is offline  
Old 02/15/2012, 18:39   #6
 
.Kinshi's Avatar
 
elite*gold: 0
Join Date: Dec 2010
Posts: 341
Received Thanks: 255
Top 5:
Code:
var sorted = (from g in GuildDamages.Values
    orderby g.Points descending
    select g).Take(5);
.Kinshi is offline  
Thanks
1 User
Old 02/15/2012, 18:57   #7
 
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
Quote:
Originally Posted by .Kinshi View Post
Top 5:
Code:
var sorted = (from g in GuildDamages.Values
    orderby g.Points descending
    select g).Take(5);
Even better ;o I should do some better research.
I don't have a username is offline  
Reply


Similar Threads Similar Threads
[Biete] 1x Guildwars Prophecies 1x Guildwars Nightfall (Key)[Suche] Psc/Egold
12/08/2011 - Guild Wars Trading - 5 Replies
Hallo verkaufe hier mein spielpacket mit 2 spielen Guildwars Prophecies und Guildwars Nightfall. ich habe die spiele nie ausgepackt aus der follie,heisst sind noch komplett eingepackt--> ungeöffnet ,keys noch nicht freigerubbelt. Hinweis: Verkaufe sie entweder als key oder verschicke sie per post.Lieber wäre mir sie als key zu verkaufen spare ich mir den versand. Bezhalmöglichkeiten: Psc/Egold
VK Guildwars acc
12/15/2010 - Guild Wars Trading - 0 Replies
Hey ho ich vk mien guildwars acc, denn ich habe kaum zeit bzw die lust es je wieda zu spieln... zu den acc es gibt 2 chars nen monk und nen ritu alle kamp sind durch gezockt worden,wertsachen auf den acc gibs keine mehr dennn die hab ich alle meiner gilde geschenkt^^ für weitere infos einfach Pm an mich Liebe grüße das Odu
[WTS]Various GuildWars MiniPets/Verschiedene GuildWars Minipets
01/10/2009 - Trading - 0 Replies
Da ich nicht die Zeit habe, ingame zuschreien und alle zu verkaufen, biete ich euch meine Restbestände an Minipets zu echten Schleuderpreisen an. Since I don't have enough time to sell them ingame, I'm offering you my pets for real low prices. Miniatur-Tempelwächter / Temple Guardian Miniatur-Hydra Miniatur-Jade-Rüstung / Jade Armor Miniatur-Peitschenschwanz-Verschlinger / Whiptail Devourer Miniatur-Belagerungs-Schildkröte / Siege Turtle Miniatur-Dschungeltroll / Jungle Troll
Need Bot! For GuildWars!
02/16/2008 - Guild Wars - 2 Replies
I realy realy realy need a bot for guildwars plz...
Guildwars
11/02/2004 - Guild Wars - 14 Replies
Wer von euch wird bei Guildwars einsteigen/wartet sehnsüchtig auf das game wie ich?



All times are GMT +1. The time now is 05:19.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.