[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  Changing who; race sections
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Changing who; race sections

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Zeno   USA  (2,871 posts)  [Biography] 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
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] 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
[Go to top] top

Posted by Nick Cash   USA  (626 posts)  [Biography] 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
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] 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
[Go to top] top

Posted by Zeno   USA  (2,871 posts)  [Biography] 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
[Go to top] 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.


4,291 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]