Skip to content

Implement D&D Character Exercise #676

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

Merged
merged 9 commits into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,17 @@
"math"
]
},
{
"slug": "dnd-character",
"uuid": "b373e13c-f179-4b36-b6e8-2a0f41540344",
"core": false,
"unlocked_by": null,
"difficulty": 2,
"topics": [
"classes",
"randomness"
]
},
{
"slug": "trinary",
"uuid": "1acf1d2d-a25e-4576-94de-0470abc872d9",
Expand Down
2 changes: 1 addition & 1 deletion exercises/accumulate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/acronym/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/all-your-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/allergies/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/alphametics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/anagram/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/armstrong-numbers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/atbash-cipher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/beer-song/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/binary-search-tree/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/binary-search/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/binary/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/bob/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/bowling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/change/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/circular-buffer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/clock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/collatz-conjecture/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/complex-numbers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/connect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/crypto-square/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/custom-set/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/darts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/diamond/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/difference-of-squares/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion exercises/diffie-hellman/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
26 changes: 26 additions & 0 deletions exercises/dnd-character/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"root": true,
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module"
},
"env": {
"es6": true,
"node": true,
"jest": true
},
"extends": [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings"
],
"rules": {
"linebreak-style": "off",

"import/extensions": "off",
"import/no-default-export": "off",
"import/no-unresolved": "off",
"import/prefer-default-export": "off"
}
}
62 changes: 62 additions & 0 deletions exercises/dnd-character/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# D&D Character

For a game of [Dungeons & Dragons][DND], each player starts by generating a character they can play with. This character has, among other things, six abilities; strength, dexterity, constitution, intelligence, wisdom and charisma. These six abilities have scores that are determined randomly. You do this by rolling four 6-sided dice and record the sum of the largest three dice. You do this six times, once for each ability.

Your character's initial hitpoints are 10 + your character's constitution modifier. You find your character's constitution modifier by subtracting 10 from your character's constitution, divide by 2 and round down.

Write a random character generator that follows the rules above.

For example, the six throws of four dice may look like:

* 5, 3, 1, 6: You discard the 1 and sum 5 + 3 + 6 = 14, which you assign to strength.
* 3, 2, 5, 3: You discard the 2 and sum 3 + 5 + 3 = 11, which you assign to dexterity.
* 1, 1, 1, 1: You discard the 1 and sum 1 + 1 + 1 = 3, which you assign to constitution.
* 2, 1, 6, 6: You discard the 1 and sum 2 + 6 + 6 = 14, which you assign to intelligence.
* 3, 5, 3, 4: You discard the 3 and sum 5 + 3 + 4 = 12, which you assign to wisdom.
* 6, 6, 6, 6: You discard the 6 and sum 6 + 6 + 6 = 18, which you assign to charisma.

Because constitution is 3, the constitution modifier is -4 and the hitpoints are 6.

## Notes

Most programming languages feature (pseudo-)random generators, but few programming languages are designed to roll dice. One such language is [Troll].

[DND]: https://en.wikipedia.org/wiki/Dungeons_%26_Dragons
[Troll]: http://hjemmesider.diku.dk/~torbenm/Troll/

## Setup

Go through the setup instructions for Javascript to install the necessary
dependencies:

[https://exercism.io/tracks/javascript/installation](https://exercism.io/tracks/javascript/installation)

## Requirements

Install assignment dependencies:

```bash
$ npm install
```

## Making the test suite pass

Execute the tests with:

```bash
$ npm test
```

In the test suites all tests but the first have been skipped.

Once you get a test passing, you can enable the next one by changing `xtest` to
`test`.

## Source

Inspired by an exercise created by a professor Della Paolera in Argentina

## Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have
completed the exercise.
14 changes: 14 additions & 0 deletions exercises/dnd-character/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
presets: [
[
'@babel/env',
{
targets: {
node: 'current',
},
useBuiltIns: false,
},

],
],
};
Loading