Page 1 of 1

accuracy vs. monster EV

PostPosted: Sunday, 6th September 2015, 12:12
by Utis
That debate about displaying exact numbers got me interested in exact numbers. So, I finally started code diving. I need a little help though with regard to melee attacks. I find the overall structure of melee_attack.cc hard to grasp.

What interests me right now is: after player accuracy is calculated, how is that number used vs. monster EV to determine whether a hit connects?

I have found
  Code:
attack::calc_to_hit
and
  Code:
melee_attack::calc_to_hit
. But even with grep I couldn't find where their results are actually used.

Any pointers?

Re: accuracy vs. monster EV

PostPosted: Sunday, 6th September 2015, 17:05
by greedo
Not sure, but personally I would not use grep, that guideline is pretty old and I would only use something like that for a script. Download sublime text editor, do open folder on the source code, and then you can cntrl(or command)-shift-f to get every case of the phrase, with about a paragraph of context. Might help, might not. Cntrl-p fuzzy searching files is also a godsend for wading through all the mon-X etc.

Re: accuracy vs. monster EV

PostPosted: Sunday, 6th September 2015, 17:41
by gammafunk
You can use grep just fine since our codebase is pretty flat, with most relevant files directly in the source directory, but it can be better to use a tool like git grep, which will search any file in the tree automatically and knows how to do things like search for a context function. Here's what git grep shows if you use -p to show the preceding function:

  Code:
$ git grep -p calc_to_hit
attack.cc=bool attack::handle_phase_end()
attack.cc:int attack::calc_to_hit(bool random)
attack.cc=void attack::init_attack(skill_type unarmed_skill, int attack_number)
attack.cc:    to_hit          = calc_to_hit(true);
attack.h=public:
attack.h:    virtual int calc_to_hit(bool random);
melee_attack.cc=void melee_attack::apply_staff_damage()
melee_attack.cc:int melee_attack::calc_to_hit(bool random)
melee_attack.cc:    int mhit = attack::calc_to_hit(random);
melee_attack.h=public:
melee_attack.h:    int calc_to_hit(bool random = true);
player.cc=static void _display_tohit()
player.cc:    const int to_hit = attk.calc_to_hit(false);
ranged_attack.cc=ranged_attack::ranged_attack(actor *attk, actor *defn, item_de*p
roj,                                                                           
ranged_attack.cc:int ranged_attack::calc_to_hit(bool random)
ranged_attack.cc:    orig_to_hit = attack::calc_to_hit(random);
ranged_attack.h=public:
ranged_attack.h:    int calc_to_hit(bool random);

The relevant function is attack::init_attack(), since you see:
  Code:
attack.cc=void attack::init_attack(skill_type unarmed_skill, int attack_number)
attack.cc:    to_hit          = calc_to_hit(true);


You should see the basic output you need if you did grep on *.cc and *.h files, and notice that second line in the output above. Once you have the file you need, it's often best to just open it and search for the relevant terms. You can use -n to print line numbers in grep or git grep output.

So attack::to_hit is where the resulting value is stored, and you'll want to look in attack.cc and melee_attack.cc for instances of to_hit to get further details on how to-hit is actually used. There are instances in both files, but melee_attack.cc will have most of the uses you're interested in.

Re: accuracy vs. monster EV

PostPosted: Sunday, 6th September 2015, 20:49
by neil
As far as how to_hit is used, you might in particular want to look for attack::test_hit; and for melee_attack::attack and ranged_attack::attack, which call it.

Re: accuracy vs. monster EV

PostPosted: Monday, 7th September 2015, 11:54
by Utis
Interesting. What I'm reading is that monster EV is doubled for EV rolls and that the average of two rolls is taken. So if the bot lists 10 EV for a monster, the roll is actually 2d9. Unfortunately, what with the way player to_hit is calculated, I forgot too much about stochastics to be able to calculate the average for a given player and monster, which is what actually interested me.

Anyways, thank you!

(Actually I didn't use grep directly, but M-x grep-find from within Emacs. I saw to_hit in init_attack, but I couldn't trace it, basically because I don't now how OO in C++ works. I try do make do with what I remember of plain C.)

Re: accuracy vs. monster EV

PostPosted: Friday, 20th May 2016, 00:32
by Rast
Utis wrote:I forgot too much about stochastics to be able to calculate the average for a given player and monster, which is what actually interested me.


http://anydice.com/