|
| 1 | +# Dnd Character |
| 2 | + |
| 3 | +For a game of [Dungeons & Dragons][DND], each player starts by generating a |
| 4 | +character they can play with. This character has, among other things, six |
| 5 | +abilities; strength, dexterity, constitution, intelligence, wisdom and |
| 6 | +charisma. These six abilities have scores that are determined randomly. You |
| 7 | +do this by rolling four 6-sided dice and record the sum of the largest three |
| 8 | +dice. You do this six times, once for each ability. |
| 9 | + |
| 10 | +Your character's initial hitpoints are 10 + your character's constitution |
| 11 | +modifier. You find your character's constitution modifier by subtracting 10 |
| 12 | +from your character's constitution, divide by 2 and round down. |
| 13 | + |
| 14 | +Write a random character generator that follows the rules above. |
| 15 | + |
| 16 | +For example, the six throws of four dice may look like: |
| 17 | + |
| 18 | +* 5, 3, 1, 6: You discard the 1 and sum 5 + 3 + 6 = 14, which you assign to strength. |
| 19 | +* 3, 2, 5, 3: You discard the 2 and sum 3 + 5 + 3 = 11, which you assign to dexterity. |
| 20 | +* 1, 1, 1, 1: You discard the 1 and sum 1 + 1 + 1 = 3, which you assign to constitution. |
| 21 | +* 2, 1, 6, 6: You discard the 1 and sum 2 + 6 + 6 = 14, which you assign to intelligence. |
| 22 | +* 3, 5, 3, 4: You discard the 3 and sum 5 + 3 + 4 = 12, which you assign to wisdom. |
| 23 | +* 6, 6, 6, 6: You discard the 6 and sum 6 + 6 + 6 = 18, which you assign to charisma. |
| 24 | + |
| 25 | +Because constitution is 3, the constitution modifier is -4 and the hitpoints are 6. |
| 26 | + |
| 27 | +## Notes |
| 28 | + |
| 29 | +Most programming languages feature (pseudo-)random generators, but few |
| 30 | +programming languages are designed to roll dice. One such language is [Troll]. |
| 31 | + |
| 32 | +[DND]: https://en.wikipedia.org/wiki/Dungeons_%26_Dragons |
| 33 | +[Troll]: http://hjemmesider.diku.dk/~torbenm/Troll/ |
| 34 | + |
| 35 | +## Exception messages |
| 36 | + |
| 37 | +Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to |
| 38 | +indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not |
| 39 | +every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include |
| 40 | +a message. |
| 41 | + |
| 42 | +To raise a message with an exception, just write it as an argument to the exception type. For example, instead of |
| 43 | +`raise Exception`, you should write: |
| 44 | + |
| 45 | +```python |
| 46 | +raise Exception("Meaningful message indicating the source of the error") |
| 47 | +``` |
| 48 | + |
| 49 | +## Running the tests |
| 50 | + |
| 51 | +To run the tests, run the appropriate command below ([why they are different](https://github.com/pytest-dev/pytest/issues/1629#issue-161422224)): |
| 52 | + |
| 53 | +- Python 2.7: `py.test dnd_character_test.py` |
| 54 | +- Python 3.4+: `pytest dnd_character_test.py` |
| 55 | + |
| 56 | +Alternatively, you can tell Python to run the pytest module (allowing the same command to be used regardless of Python version): |
| 57 | +`python -m pytest dnd_character_test.py` |
| 58 | + |
| 59 | +### Common `pytest` options |
| 60 | + |
| 61 | +- `-v` : enable verbose output |
| 62 | +- `-x` : stop running tests on first failure |
| 63 | +- `--ff` : run failures from previous test before running other test cases |
| 64 | + |
| 65 | +For other options, see `python -m pytest -h` |
| 66 | + |
| 67 | +## Submitting Exercises |
| 68 | + |
| 69 | +Note that, when trying to submit an exercise, make sure the solution is in the `$EXERCISM_WORKSPACE/python/dnd-character` directory. |
| 70 | + |
| 71 | +You can find your Exercism workspace by running `exercism debug` and looking for the line that starts with `Workspace`. |
| 72 | + |
| 73 | +For more detailed information about running tests, code style and linting, |
| 74 | +please see [Running the Tests](http://exercism.io/tracks/python/tests). |
| 75 | + |
| 76 | +## Source |
| 77 | + |
| 78 | +Simon Shine, Erik Schierboom [https://github.com/exercism/problem-specifications/issues/616#issuecomment-437358945](https://github.com/exercism/problem-specifications/issues/616#issuecomment-437358945) |
| 79 | + |
| 80 | +## Submitting Incomplete Solutions |
| 81 | + |
| 82 | +It's possible to submit an incomplete solution so you can see how others have completed the exercise. |
0 commit comments