Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Entire forum
➜ SMAUG
➜ SMAUG coding
➜ Changing who; race sections
Changing who; race sections
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Zeno
USA (2,871 posts) Bio
|
Date
| Wed 06 Sep 2006 12:16 AM (UTC) |
Message
| What would be a good way to change the who code so that it splits up each race into a section? I can think of a way to do this, but it involves looping through all players and checking their race, thus making it 3 loops (for each race). I'm sure there's a better way to do this.
Example who output (not exact):
=====Race1=====
Bob
Joe
=====Race2=====
James
=====Race3=====
Gin
Rob
=====Immortals=====
Zeno
|
Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #1 on Wed 06 Sep 2006 12:53 AM (UTC) |
Message
| I think that looping through the players 3 times isn't such a bad solution; you won't ever have enough players for it to really make things inefficient. (You'd need several thousand before it would start mattering.)
To be fast, you'd need to do complex things like keep your player list sorted into three buckets, one per race. That's way too complicated for what you're doing, though, I think. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Nick Cash
USA (626 posts) Bio
|
Date
| Reply #2 on Wed 06 Sep 2006 03:09 PM (UTC) |
Message
| A relatively simple way to accomplish the "sorting into three buckets" would be to use linked lists.
You could make three local linked lists (one for each race) and loop through everyone once, adding them to their respective local linked list. You could also then sort by level, class, or whatever else you wanted.
Then, for output, you just print out your "=====Race=====" header and print out each person in your presorted order.
Thus you eliminate the need for a third iteration of each person (each person would get processed twice) and you get the added bennefit of sorting. |
~Nick Cash
http://www.nick-cash.com | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #3 on Wed 06 Sep 2006 05:35 PM (UTC) |
Message
| That would be a good way of doing it. It would also make it very easy to sort as you inserted, even though the easy sort (insertion sort) is a fair bit slower than quicksort. Insertion sort is O(n^2), I believe, whereas Quicksort is O(n log n), which is a quite a lot better.
Again, though, for these efficiency concerns to be relevant, you need at least 4-digit numbers of players. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Zeno
USA (2,871 posts) Bio
|
Date
| Reply #4 on Tue 12 Sep 2006 04:32 AM (UTC) |
Message
| Well, who was sort of complicated but not really. Turns out I just had to add a WT_RACE, a new who->type and bam. |
Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
14,401 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top