Fires of Heaven Guild Message Board  


Go Back   Fires of Heaven Guild Message Board > General forums > Development
User Name
Password
ForumSpy Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Share LinkBack Thread Tools Rate Thread Display Modes
Old 02-02-2012, 01:41 AM   #256 (permalink)
Fog
Registered User
 
Join Date: Feb 2006
Posts: 2,202
+3 Internets
By the way, what it turns out that you're trying to do is called "selection" (finding the Nth largest/smallest or the top N largest/smallest elements of a sequence.) There are various ways to go about it, but you picked one that works quite well on a list where you are finding a small number N of items. You're right to observe that it's faster than the strategy of "sort the whole list and pick items 1 through N."

One thing to consider: suppose you were picking a lot of dice, say, the top 100 out of 200? If you try that, I bet you will find that the sort beats you, because for each of the second hundred, your algorithm will need to look at each of the first hundred to figure out whether you should replace it.
Fog is offline   Reply With Quote
Old 02-02-2012, 01:57 AM   #257 (permalink)
grimsark
Registered User
 
Join Date: Jun 2005
Location: Houston, TX
Posts: 859
Quote:
Originally Posted by Fog View Post
By the way, what it turns out that you're trying to do is called "selection" (finding the Nth largest/smallest or the top N largest/smallest elements of a sequence.) There are various ways to go about it, but you picked one that works quite well on a list where you are finding a small number N of items. You're right to observe that it's faster than the strategy of "sort the whole list and pick items 1 through N."

One thing to consider: suppose you were picking a lot of dice, say, the top 100 out of 200? If you try that, I bet you will find that the sort beats you, because for each of the second hundred, your algorithm will need to look at each of the first hundred to figure out whether you should replace it.
You are up early!

Thanks for that info!

Yes, I suspected that the re-scan & replace method would slow down as it grew. But lucky me the mechanic I am designing shouldn't require that large a pool of dice (for any single result) pretty much EVER. But if it does, I may include a conditional that states, if X > Y, use alternate 'faster' version.
__________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." -- Albert Einstein
grimsark is offline   Reply With Quote
Old 02-02-2012, 07:03 AM   #258 (permalink)
grimsark
Registered User
 
Join Date: Jun 2005
Location: Houston, TX
Posts: 859
Looks like I am not doing much for the next several hours... Or days...

Just got invite to Diablo III Beta. (Installing now)
__________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." -- Albert Einstein
grimsark is offline   Reply With Quote
Old 02-02-2012, 07:34 PM   #259 (permalink)
grimsark
Registered User
 
Join Date: Jun 2005
Location: Houston, TX
Posts: 859
Quote:
Originally Posted by grimsark View Post
Looks like I am not doing much for the next several hours... Or days...

Just got invite to Diablo III Beta. (Installing now)
That was actually kind of underwhelming... :/

Dunno what I expected. But it was fun and a lot more easy on the wrist than the first two.

Now back to my projects!
__________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." -- Albert Einstein
grimsark is offline   Reply With Quote
Old 02-06-2012, 05:37 AM   #260 (permalink)
grimsark
Registered User
 
Join Date: Jun 2005
Location: Houston, TX
Posts: 859
Need some opinions...

Is this an effective way to store simple data in XML? (Using XDocument)

Code:
XElement subElement =                        //Create the new XML.
    new XElement(type,
        new XElement("Name", 
            new XAttribute("name", name),
            new XElement("Stats",
                new XAttribute("health", health),
                new XAttribute("strength", strength)
            ),
            new XElement("Weapon", 
                new XAttribute("weapon", weapon),
                new XAttribute("damage", weaponDamage)
            ),
            new XElement("Armor", 
                new XAttribute("armor", armor),
                new XAttribute("rating", armorRating)
            )
        )
    );
Or is there a simpler way??
Perhaps something you prefer over XDocument?

Code Output:
Attached Images
 
__________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." -- Albert Einstein
grimsark is offline   Reply With Quote
Old 02-06-2012, 09:43 AM   #261 (permalink)
Vinen
Open the eyes
 
Vinen's Avatar
 
Join Date: Oct 2002
Location: Not in fucking Acton, MA anymore!
Posts: 5,385
-89 Internets
Quote:
Originally Posted by grimsark View Post
Need some opinions...

Is this an effective way to store simple data in XML? (Using XDocument)

Code:
XElement subElement =                        //Create the new XML.
    new XElement(type,
        new XElement("Name", 
            new XAttribute("name", name),
            new XElement("Stats",
                new XAttribute("health", health),
                new XAttribute("strength", strength)
            ),
            new XElement("Weapon", 
                new XAttribute("weapon", weapon),
                new XAttribute("damage", weaponDamage)
            ),
            new XElement("Armor", 
                new XAttribute("armor", armor),
                new XAttribute("rating", armorRating)
            )
        )
    );
Or is there a simpler way??
Perhaps something you prefer over XDocument?

Code Output:
My god,
Make a schema.

Then you can easily serialize and deseralize the object without having to use terribleness to parse it.

XML Schema Tutorial
__________________
Vinen, Trolololol Druid
Vinen is offline   Reply With Quote
Old 02-06-2012, 10:58 AM   #262 (permalink)
grimsark
Registered User
 
Join Date: Jun 2005
Location: Houston, TX
Posts: 859
Quote:
Originally Posted by Vinen View Post
My god,
Make a schema.

Then you can easily serialize and deseralize the object without having to use terribleness to parse it.

XML Schema Tutorial
Thanks for the pointer. I am checking it out.

In the mean time, could you give me your opinion regarding the use of LINQ XDocument and reading writing XML with C#?

edit:
Hmmm, I can definitely see the strength of using the XML Schema when you are sharing data... But for my purposes it seems overkill... And I can always learn to use them if it becomes necessary.

Also, I would need to decide how I am structuring it in order to use a schema anyway...
__________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." -- Albert Einstein
grimsark is offline   Reply With Quote
Old 02-06-2012, 12:22 PM   #263 (permalink)
Kallian
Registered User
 
Join Date: Jul 2004
Location: Texas
Posts: 848
As another option, look into binary serialization.
Kallian is offline   Reply With Quote
Old 02-06-2012, 12:28 PM   #264 (permalink)
grimsark
Registered User
 
Join Date: Jun 2005
Location: Houston, TX
Posts: 859
Quote:
Originally Posted by Kallian View Post
As another option, look into binary serialization.
Thanks. I already have. That is what I will be using for saved games.

What I am doing now is deciding how I am going to store defaults (and support modding). I can go with basic .txt files (like 2da's). But I figure I might as well learn to mess with XML a bit more.

I can see why my original question isn't getting me the answers I expected...
I posted it using the writing XML code, rather then reading it.

I apologize.

I suppose it doesn't matter in the end, as long as I accomplish what I want.
__________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." -- Albert Einstein
grimsark is offline   Reply With Quote
Old 02-06-2012, 01:18 PM   #265 (permalink)
Froofy-D
upper management material
 
Froofy-D's Avatar
 
Join Date: Nov 2002
Location: Orlando, FL
Posts: 2,657
+27 Internets
- You can serialize to plain text XML files and no binary, so the output will be human readable and basically self-documenting. Good for debugging and for any data you want other people to change, like config files.

- You don't need to make a schema. The C# serialization parser ignores any fields in XML files that don't match the XML tags in your classes.

This tutorial is pretty good: C# Tutorial - XML Serialization | Switch on the Code
Froofy-D is offline   Reply With Quote
Old 02-06-2012, 01:45 PM   #266 (permalink)
Fog
Registered User
 
Join Date: Feb 2006
Posts: 2,202
+3 Internets
I strongly agree that worrying about specifying a schema separately is an absurd amount of overkill for the task at hand. If you even get tempted to do such a thing, then stop serializing your thing in XML and just put it in a flat text file or JSON or something so that the temptation disappears

Your serialization code is fine. Match it with similar deserialization code and hooray it works. As I recall, you already jumped through the hoops to figure out how to do XML object serialization with magic attributes and stuff in C#, so you should be aware of whether that is more convenient for this purpose or not.
Fog is offline   Reply With Quote
Old 02-06-2012, 02:34 PM   #267 (permalink)
grimsark
Registered User
 
Join Date: Jun 2005
Location: Houston, TX
Posts: 859
Quote:
Originally Posted by Froofy-D View Post
- You can serialize to plain text XML files and no binary, so the output will be human readable and basically self-documenting. Good for debugging and for any data you want other people to change, like config files.

- You don't need to make a schema. The C# serialization parser ignores any fields in XML files that don't match the XML tags in your classes.

This tutorial is pretty good: C# Tutorial - XML Serialization | Switch on the Code
Thanks for pointing that out. I had actually started doing that, but for some reason I found myself playing with LINQ to XML and the XDocument class, and started thinking in reverse...


Quote:
Originally Posted by Fog View Post
...

Your serialization code is fine. Match it with similar deserialization code and hooray it works. As I recall, you already jumped through the hoops to figure out how to do XML object serialization with magic attributes and stuff in C#, so you should be aware of whether that is more convenient for this purpose or not.
You are correct. I do not have trouble with the actual serialization. Just how to structure the XML for default game details. I suppose I may be over thinking this... As usual.
__________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." -- Albert Einstein
grimsark is offline   Reply With Quote
Old 02-07-2012, 05:17 AM   #268 (permalink)
grimsark
Registered User
 
Join Date: Jun 2005
Location: Houston, TX
Posts: 859
Download: XML Notepad 2007 - Microsoft Download Center - Download Details

I used this quite a bit yesterday to get a better idea how to structure the XML... I like its simplicity. But I would like to see the output while I work in the XML tree view. (Without switching between views)

Is there a free XML editor that is as simple and has that functionality?

I tried Googling XML editor, and the tidal wave of IDE's hit me... So I walked away. Not enough time to sift through them all, and all their trial offers.

Thanks.

Edit:
Well I managed it... And apparently XML Notepad is about as good as the free ones get. Everything else is clunky or IDE level with 30 day trials.
__________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." -- Albert Einstein

Last edited by grimsark; 02-08-2012 at 05:06 AM..
grimsark is offline   Reply With Quote
Old 02-08-2012, 05:04 AM   #269 (permalink)
grimsark
Registered User
 
Join Date: Jun 2005
Location: Houston, TX
Posts: 859
Sometimes I wish coding was less tedious and more like content creation... That is actually kinda fun.
__________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." -- Albert Einstein
grimsark is offline   Reply With Quote
Old 02-08-2012, 05:14 AM   #270 (permalink)
lendarios
PedoAid
 
lendarios's Avatar
 
Join Date: Jun 2005
Location: Miami, FL
Posts: 3,143
? coding is super fun.
__________________
Sky Rocket Super Punch!!!
Alphonse Elric: "Brother... Win"
lendarios is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On

uberguilds network



All times are GMT -7. The time now is 07:46 PM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.0 RC6