Let's get programmy!

If you have some randomness to share that you can't post elsewhere, this is the place to do it.
Post Reply

Is Assembly the best programming language?

Yes
3
9%
Oh God my eyes
3
9%
Oh God my brain
12
38%
I perform unholy incantations to keep Assembly at bay
4
13%
Real men write binaries by hand
10
31%
 
Total votes: 32
ranger
Community Villain

Posts:
3588

Re: Let's get programmy!

Post by ranger »

also using notepad++

:/
Image
Image
Akonyl
Community Hero

Posts:
4200

Re: Let's get programmy!

Post by Akonyl »

hey, at least it looks better than Dev-C++, which is what I used for C++ code.

Stupid IDE didn't even have code-folding.
User avatar
Callid
Ratio vincit omnia.

Posts:
1433

Re: Let's get programmy!

Post by Callid »

Somehow, programming a Condition (yes, for checking whether a certain variable is larger/smaller/equal to a certain value) feels so redundant...
Also, I'm sure there's some kind of bug in there :x

Code: Select all

public class Condition extends ConditionHolder {

    Object loc;
    Field attribute;
    short comp;
    /* 0: ==
     * 1: !=
     * 2: >
     * 3: >=
     * 4:  value;
            case 3:
                return val >= value;
            case 4:
                return val < value;
            case 5:
                return val <= value;
            case 7:
                return val == Double.NaN;
            default:
                return false;
        }
    }
If  ;), :D, ;D, ::), :P, :-X, :o or >:D are attached, that paragraph may not be 100% serious. Seriously.
This link provides further information.
Callid Conia Pact - Petitions - Archive
c-square
Shounen Tantei Dan, Dai Seikou!

Posts:
1040

Re: Let's get programmy!

Post by c-square »

Callid wrote: Somehow, programming a Condition (yes, for checking whether a certain variable is larger/smaller/equal to a certain value) feels so redundant...
Also, I'm sure there's some kind of bug in there :x
Huh?  Why would anyone need something like this?  ???
Image - Get your Detective Conan bobbleheads today! - Image
Akonyl
Community Hero

Posts:
4200

Re: Let's get programmy!

Post by Akonyl »

Though I can't say what Callid's using it for, making classes/objects from conditionals could probably be useful for evaluating equations from a file / user input / what-have-you, depending on your implementation. In the past I've just had a master function which parses the input into tokens and then evaluates them, just a question of if the code lies inside or outside the tokens.

Though, if he is just trying to write an equation parser, it's probably been done before so I would say to google it before writing the whole thing :-X
ranger
Community Villain

Posts:
3588

Re: Let's get programmy!

Post by ranger »

Callid - you might have better luck going to like StackOverflow or something...I'm just far too lazy to do any more debugging during my free time, or reading someone else's code that isn't mine.
Image
Image
User avatar
Callid
Ratio vincit omnia.

Posts:
1433

Re: Let's get programmy!

Post by Callid »

Akonyl wrote: Though I can't say what Callid's using it for, making classes/objects from conditionals could probably be useful for evaluating equations from a file / user input / what-have-you, depending on your implementation.
That's exactly the purpose. Basically, the idea was to store most of the initial world generation parameters in a .txt file so the user can easily change (or, heaven forbid, mod) it. However, I've come to believe that that'd be too much of a hassle in Java, especially as modding .jars is possible on its own. And in case I really need it later on for some reason, I can just create it at that time ::)

To be precise, it was originally intended for magical items, i.e. an amulet or whatever that, for example, increases the wearer's skill in magical destruction if he has more than ten ranks in any heavy weapon related skill. However, the description for that amulet would be stored in the .txt, and therefore would the condition (skill.twohander>10||...||skill.waraxe>10) would need to be created while the program was running (there is another class (ConditionBranch extends ConditionHolder) that allows multiple conditions).
If  ;), :D, ;D, ::), :P, :-X, :o or >:D are attached, that paragraph may not be 100% serious. Seriously.
This link provides further information.
Callid Conia Pact - Petitions - Archive
c-square
Shounen Tantei Dan, Dai Seikou!

Posts:
1040

Re: Let's get programmy!

Post by c-square »

Callid wrote: To be precise, it was originally intended for magical items, i.e. an amulet or whatever that, for example, increases the wearer's skill in magical destruction if he has more than ten ranks in any heavy weapon related skill. However, the description for that amulet would be stored in the .txt, and therefore would the condition (skill.twohander>10||...||skill.waraxe>10) would need to be created while the program was running (there is another class (ConditionBranch extends ConditionHolder) that allows multiple conditions).
Have you considered xml?  It's easily readable, editable and there are lots of parser libraries out there for it.  Maybe you could do something like this:

Code: Select all

<item>
     <name>Amulet of Whatever</name>
     <effect>
          <skill_effect>
               <name>Magical Destruction</name>
               <abs_value_change>10<abs_value_change>
          </skill_effect>
     </effect>
     <conditions>
          <or>
               <skill_condition>
                    <name>TwoHander</name>
                    <comparator>GreaterThan</comparator>
                    <value>10</value>
               </skill_condition>
               <skill_condition>
                    <name>WarAxe</name>
                    <comparator>GreaterThan</comparator>
                    <value>10</value>
               </skill_condition>
          </or>
     </conditions>
</item>
You can then get a parser to parse it into a set of objects so that you can then access the information.
Image - Get your Detective Conan bobbleheads today! - Image
User avatar
Callid
Ratio vincit omnia.

Posts:
1433

Re: Let's get programmy!

Post by Callid »

c-square wrote:
Callid wrote: To be precise, it was originally intended for magical items, i.e. an amulet or whatever that, for example, increases the wearer's skill in magical destruction if he has more than ten ranks in any heavy weapon related skill. However, the description for that amulet would be stored in the .txt, and therefore would the condition (skill.twohander>10||...||skill.waraxe>10) would need to be created while the program was running (there is another class (ConditionBranch extends ConditionHolder) that allows multiple conditions).
Have you considered xml?  It's easily readable, editable and there are lots of parser libraries out there for it.  Maybe you could do something like this:

Code: Select all

<item>
     <name>Amulet of Whatever</name>
     <effect>
          <skill_effect>
               <name>Magical Destruction</name>
               <abs_value_change>10<abs_value_change>
          </skill_effect>
     </effect>
     <conditions>
          <or>
               <skill_condition>
                    <name>TwoHander</name>
                    <comparator>GreaterThan</comparator>
                    <value>10</value>
               </skill_condition>
               <skill_condition>
                    <name>WarAxe</name>
                    <comparator>GreaterThan</comparator>
                    <value>10</value>
               </skill_condition>
          </or>
     </conditions>
</item>
You can then get a parser to parse it into a set of objects so that you can then access the information.
Really? That works? :o
Wait, how does the parser recognize skill_condition and WarAxe? I mean, the actual way to get the war axe skill is not simply skill.waraxe, but rather "skillDb.getTrueSkill(2,5)" (or ".getSkill(2,5)", depending on whether you want the modified or unmodified value), so it's not that obvious...
(Also, setting the magic skill would be "skillDb.modSkill(5,19,10)")
Last edited by Callid on February 28th, 2012, 10:41 pm, edited 1 time in total.
If  ;), :D, ;D, ::), :P, :-X, :o or >:D are attached, that paragraph may not be 100% serious. Seriously.
This link provides further information.
Callid Conia Pact - Petitions - Archive
Akonyl
Community Hero

Posts:
4200

Re: Let's get programmy!

Post by Akonyl »

depends on how the xml parser you use does things, but when I was using a JSON library (just another markup language like XML) in C++, to access it you would do something like

item.name["Amulet of Whatever"].conditions[0][0].name.asString()
would get you the value "TwoHander" and then you could shove that into your code however. Something like that at least, haven't used it for a while. :V

Either way, just google for java XML parsing examples :P
c-square
Shounen Tantei Dan, Dai Seikou!

Posts:
1040

Re: Let's get programmy!

Post by c-square »

Callid wrote: Really? That works? :o
Wait, how does the parser recognize skill_condition and WarAxe? I mean, the actual way to get the war axe skill is not simply skill.waraxe, but rather "skillDb.getTrueSkill(2,5)" (or ".getSkill(2,5)", depending on whether you want the modified or unmodified value), so it's not that obvious...
(Also, setting the magic skill would be "skillDb.modSkill(5,19,10)")
It'll recognize skill_condition because it's an xml element.  Like Akonyl said, the parser will pickup and organize all the xml elements for you.  It'll create an item object with a list or set of condition objects, each containing a list or set of skill_conditions (or whatever other conditions you set up).  You'll be able to loop through the conditions to read them and get the information.  

As for WarAxe, because it's an xml value and not an element, all the parser knows is that it's found a chunk of text, and will create a string object with "WarAxe" as its contents.  It'll be up to you to figure out how to use that.  Personally, I can see two ways of doing it.  First, you could have a set of predefined strings for skill names.  You then can use a map to internally translate those skill names to your numbering system.  An alternative (and IMHO a better way to do it) would be to store the skill names in a reference table in the DB, and use joins to get and set the appropriate data.  After all, skillDb.GetSkill("WarAxe") is much easier code to read and understand than skillDb.GetSkill(2,5).

EDIT: I was looking over my xml and I realized it was pretty sloppy.  Here's an updated version:

Code: Select all

<items>
     <item>
          <name>Amulet of Whatever</name>
          <effects>
               <effect>
                    <name>MagicalDestruction</name>
                    <type>Skill</type>
                    <change>10<change>
                    <changeType>Absolute</changeType> <!--As compared to Percent -->
              </effect>
          </effects>
          <conditions>
               <operator>
                    <type>or</type>
                    <condition>
                         <name>TwoHander</name>
                         <type>Skill</type>
                         <comparator>GreaterThan</comparator>
                         <value>10</value>
                    </condition>
                    <condition>
                         <name>WarAxe</name>
                         <type>Skill</type>
                         <comparator>GreaterThan</comparator>
                         <value>10</value>
                    </condition>
               </operator>
          </conditions>
     </item>
</items>
This probably could be improved further, especially the operators, but it's a start.
Last edited by c-square on February 29th, 2012, 12:38 am, edited 1 time in total.
Image - Get your Detective Conan bobbleheads today! - Image
Akonyl
Community Hero

Posts:
4200

Re: Let's get programmy!

Post by Akonyl »

c-square wrote: After all, skillDb.GetSkill("WarAxe") is much easier code to read and understand than skillDb.GetSkill(2,5).
or at the very least, stop using magic numbers and use enums instead like skillDb.GetSkill(Skills.WarAxe) :P

edit: The talk about parsing input expressions actually got me looking at a more elegant (but probly slower) solution to solving equations without having to parse them yourself (dynamic code compilation), buuut then I realized in my utility classes I apparently already wrote a string-expression evaluator :x

gogo almost-solving-the-same-problem-twice!
Last edited by Akonyl on March 2nd, 2012, 7:17 pm, edited 1 time in total.
Cheesus
Community Revolutionary

Posts:
102

Re: Let's get programmy!

Post by Cheesus »

c-square wrote: WarAxe
Image
'Che Guevara is an inspiration for every human being who loves freedom.'
-Nelson Mandela-
ranger
Community Villain

Posts:
3588

Re: Let's get programmy!

Post by ranger »

Cheesus wrote:
c-square wrote: WarAxe
Image
Cheesus! Sup dude.


Man, one of my friends is workin at TripAdvisor - SO MUCH MONEY.  I might wanna gear my classes toward software in the future..semiconductor companies don't pay nearly enough
Image
Image
ranger
Community Villain

Posts:
3588

Re: Let's get programmy!

Post by ranger »

To all the college grads and current undergrads.  We've all done this.

Sign says " No food or drink allowed in Soda Hall"
Image
Image
Image
Post Reply