Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 18 #50

Closed
wants to merge 2 commits into from
Closed

Issue 18 #50

wants to merge 2 commits into from

Conversation

Cadesh
Copy link
Contributor

@Cadesh Cadesh commented Nov 24, 2019

[REFACTOR] returnHeightAndWeight()

Description of pull request

Util.js

  • Added a dice throw function that receives the quantity and sides of dice.

Core.js

  • Added function to calculate character height;
  • Added function to calculate character weight;
  • Deleted repeated function calls on each of character race (applySubraceBonuses) and replaced for a single call inside function NewCharacter;
  • Deleted old functions in core.js: returnCharacterHeight() and returnHeightAndWeight(height, weight);
  • Added test/core.test.js with methods to test character weight. This is to be used with JEST (check instructions bellow)

Resolves #18

Has it been tested?

  • Yes
  • No
  • Testing not needed

@Cadesh
Copy link
Contributor Author

Cadesh commented Nov 24, 2019

Hello @KingFruit85, here is a proposal for the refactoring of Weight and Height calculation.

I also added some JEST tests to validate Weight in the folder test. To run the tests you must add to your package.json the following fragments:

  "scripts": {
    "test": "jest"
  },
  "devDependencies": {
    "jest": "^24.9.0"
  }

Then run npm install. After the installation type npm test and the tests in folder will be executed with an output like this:

 PASS  test/core.test.js
  √ dragonborn weight in range (3ms)
  √ dwarf weight in range (1ms)
  √ elf weight in range
  √ gnome weight in range
  √ half-elf weight in range (1ms)
  √ half-orc weight in range
  √ human weight in range
  √ halfling weight in range (1ms)
  √ tiefling weight in range

Test Suites: 1 passed, 1 total
Tests:       9 passed, 9 total
Snapshots:   0 total
Time:        2.666s
Ran all test suites.

If you like we can add Travis to run this automatically and then add a nice badge to README like this one: Build Status

Copy link
Owner

@KingFruit85 KingFruit85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Cadesh I really appreciate you contributing to this project :)

I have reviewed and requested some changes. Please let me know if you need any more info.

* @param {Number} diceSides - integer for the number of sides 2, 4, 6, 8, 10, 12, 20, ...
* @returns {Number} integer with the result of dice throw.
*///------------------------------------------------------------------------------
function diceThrow (diceQuantity = 1, diceSides) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for diceQuantity = 1, does it provide any benefit over just diceQuantity?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a default value, actually it would be better if it was

function diceThrow (diceSides, diceQuantity = 1 )

this way you could call the function as diceThrow(8) and get a return of 1d8

test('tiefling weight in range', () => {
expect(calculateCharacterWeight('tiefling')).toBeGreaterThanOrEqual(114);
expect(calculateCharacterWeight('tiefling')).toBeLessThanOrEqual(238);
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are great, nice to see how the tests work :) however I think they are going to require a bit of tweaking.

Using a Dwarf as an example:

The max weight of 211 is never going to be reached, even if both d6's roll max: 115 + 12 = 127

The minimum weight can also fail if the result of the 2 x d6 rolls add up to less than 3 (1 - 1 / 2 - 1).

The issue is with the way you have calculated the characters weight, and to be fair the table you linked is quite misleading! I'll leave a comment on the calculateCharacterWeight() function that explains why these numbers don't match up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a doubt I had when checking the table here

It says the weight range, these are the numbers I used in the tests. I noticed that there were something wrong with the calculations but I did not want to change your original calculations. If you know the correct ones please send me a link and I will update the pull request.

* @param {String} race - the character race.
* @returns {Number} the calculated weight in lbs.
*///------------------------------------------------------------------------------
function calculateCharacterWeight(race) {
Copy link
Owner

@KingFruit85 KingFruit85 Nov 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the table you used as a source didn't explain how the weight figure is calculated, and my previous code was also incorrect so I wasn't helping you out there either!

While a player can just roll or pick a random number, the method described in the players hand book to calculate height and weight is as follows:

First step is to calculate the players height, using a hill dwarf as an example:

Base Height: 3'8"
Height Modifier: 2d4

Base Weight: 115lb
Weight Modifier: (result of Height Modifier) x 2d6

So if I rolled a height modifier of 6 I would calculate the players weight as 115 + (6 x 2d6)

This would also explain the weight ranges described in your source table, rolling minimum values on both height modifier and weight modifier would result in : 115 + (2x2) = 119

And max values would be 115 + (8x12) = 211

hopefully that makes sense 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, great I will fix it and then send a new commit to this PR.

break;
default: return "invalid race provided as function arguement [returnCharacterHeight()]";
}
return finalHeight;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have just tested this and in some instances the finalHeight isn't fixed to 1 decimal place

image

I assume the total result of the addition of the base height and the randomized amount needs to be set to .toFixed(1)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is correct, I will also add this change to the next PR

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REFACTOR] returnHeightAndWeight()
2 participants