|
| | #256 (permalink) |
| 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. |
| | |
| | #257 (permalink) | |
| Registered User Join Date: Jun 2005 Location: Houston, TX
Posts: 859
| Quote:
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 | |
| | |
| | #258 (permalink) |
| 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 |
| | |
| | #259 (permalink) | |
| Registered User Join Date: Jun 2005 Location: Houston, TX
Posts: 859
| Quote:
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 | |
| | |
| | #260 (permalink) |
| 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)
)
)
); Perhaps something you prefer over XDocument? Code Output:
__________________ "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 |
| | |
| | #261 (permalink) | |
| Open the eyes Join Date: Oct 2002 Location: Not in fucking Acton, MA anymore!
Posts: 5,385
| Quote:
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 | |
| | |
| | #262 (permalink) | |
| Registered User Join Date: Jun 2005 Location: Houston, TX
Posts: 859
| Quote:
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 | |
| | |
| | #264 (permalink) |
| Registered User Join Date: Jun 2005 Location: Houston, TX
Posts: 859
| 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 |
| | |
| | #265 (permalink) |
| upper management material 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 |
| | |
| | #266 (permalink) |
| 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. |
| | |
| | #267 (permalink) | ||
| Registered User Join Date: Jun 2005 Location: Houston, TX
Posts: 859
| Quote:
Quote:
__________________ "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 | ||
| | |
| | #268 (permalink) |
| 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.. |
| | |
| | #269 (permalink) |
| 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 |
| | |
![]() |
|
| Thread Tools | |
| Display Modes | Rate This Thread |
| |