Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Pokemon RPG in Ruby

Name: Anonymous 2010-12-07 21:26

Is there a more efficient way to do this? In terms of lines of code that is; I really don't want to have to do a fuck ton of case when case when shits again....

http://pastebin.com/gdTevCRJ

Name: Anonymous 2010-12-07 21:27

Hashes and tables.

Name: Anonymous 2010-12-07 21:49

Make a DSL.

Name: Anonymous 2010-12-07 22:04

Write the logic in PROLOG

Name: Anonymous 2010-12-07 22:28

>>3
???
>>4
Don't know the language, not going to bother with it.

Name: Anonymous 2010-12-07 23:06

Not really; the data has to be written somewhere. You can also do something like this to make the expression of the data more concise:

enum type { NORMAL, FLYING, ROCK, /* ... */ NTYPES };
float damage_mod(enum type a, enum type b) {
  float m[NTYPES][NTYPES] = {
    [NORMAL][NORMAL] = 1,
    [NORMAL][FLYING] = 1,
    [NORMAL][ROCK] = 0.5,
    /* ... */
  };
  return m[a][b];
}

Name: Anonymous 2010-12-08 0:21

>>6

I see...

Well, if I'm going to have a giant ass function either way, I might as well do it the ruby way...

Name: Anonymous 2010-12-08 0:41

giant ass-function

Name: Anonymous 2010-12-08 0:53

>>8

def ass
giant
end

Name: Anonymous 2010-12-08 3:48

This thread has been closed and replaced with the following thread:

Subject:
Learning Python
Name:
Email:


What book do you recommend? I have already read SICP, HTDP, K&R.

Name: Anonymous 2010-12-08 4:49

>>6
That would be even longer, since you'd have to do every type for every other type, whereas there are only modifiers for a few combinations in the pastebin.

Name: Anonymous 2010-12-08 5:19

enum TYPE { NORMAL, FLYING, ROCK, ... };
#define BIT(n) (1<<(n))
struct damagemod {
    int normal, int strong_or_weak, int useless;
}
#define NO_HIT(atk,rec) (atk.useless & BIT(rec))
#define STRONG_AGAINST(atk,rec) (atk.strong_or_weak & BIT(rec))
#define WEAK_AGAINST ~STRONG_AGAINST

etc.

Name: Anonymous 2010-12-08 7:19

>>11
Yes, it'd be longer if you wrote one entry per line like that, but this problem is begging to be solved with a simple data table. You can really cram it into few lines with something like:

enum type {NOR, FIR, WAT, ELE, /* ... */ NTYPES};
float dmgmod[NTYPES][NTYPES] = {
  /*         NOR  FIR  WAT  ELE     ... */
  /* NOR */ {1.0, 1.0, 1.0, 1.0, /* ... */ },
  /* FIR */ {1.0, 0.5, 0.5, 1.0, /* ... */ },
  /* WAT */ {1.0, 2.0, 0.5, 1.0, /* ... */ },
  /* ELE */ {1.0, 1.0, 2.0, 0.5, /* ... */ },
  /* ... */
};

Name: Anonymous 2011-02-04 11:47

Don't change these.
Name: Email:
Entire Thread Thread List