Skip to content

Commit

Permalink
Update D&D character (#169)
Browse files Browse the repository at this point in the history
* roll a 6-sided die, not 5

* return type for get-hitpoints method

* "TODO-izing" the stub. Do we want to remove more?

* sync tests

* Add comment for students. Reformat indentation for "with" methods.
  • Loading branch information
glennj authored Dec 27, 2023
1 parent 23cd1bc commit 60d80bf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
4 changes: 2 additions & 2 deletions exercises/practice/dnd-character/.meta/example.arr
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ data Character:
character(strength, dexterity, constitution, intelligence, wisdom, charisma)
end
| character(strength, dexterity, constitution, intelligence, wisdom, charisma) with:
method get-hitpoints(self):
method get-hitpoints(self) -> NumInteger:
10 + self.modifier(self.constitution)
end
sharing:
method ability(self) -> NumInteger:
roll-dice = lam(_): num-random(5) + 1 end
roll-dice = lam(_): num-random(6) + 1 end
rolls = map(roll-dice, repeat(4, 0))
rolls.sort().drop(1).foldl(lam(elt, acc): elt + acc end, 0)
end,
Expand Down
7 changes: 6 additions & 1 deletion exercises/practice/dnd-character/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@ description = "random character is valid"

[2ca77b9b-c099-46c3-a02c-0d0f68ffa0fe]
description = "each ability is only calculated once"
include = "false"
include = false

[dca2b2ec-f729-4551-84b9-078876bb4808]
description = "each ability is only calculated once"
reimplements = "2ca77b9b-c099-46c3-a02c-0d0f68ffa0fe"
include = false
38 changes: 17 additions & 21 deletions exercises/practice/dnd-character/dnd-character.arr
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,26 @@ use context essentials2020 # Don't delete this line when using Pyret on Exercism

provide-types *

#|
Replace the ... with your code to pass the tests. Good luck!
|#

data Character:
| blank-character() with:
method randomize-stats(self) -> Character:
abilities = self.ability()
strength = self.ability()
dexterity = self.ability()
constitution = self.ability()
intelligence = self.ability()
wisdom = self.ability()
charisma = self.ability()
character(strength, dexterity, constitution, intelligence, wisdom, charisma)
end
| character(strength, dexterity, constitution, intelligence, wisdom, charisma) with:
method get-hitpoints(self):
10 + self.modifier(self.constitution)
end
| blank-character()
with:
method randomize-stats(self) -> Character:
...
end
| character(strength, dexterity, constitution, intelligence, wisdom, charisma)
with:
method get-hitpoints(self) -> NumInteger:
...
end
sharing:
method ability(self) -> NumInteger:
roll-dice = lam(_): num-random(5) + 1 end
rolls = map(roll-dice, repeat(4, 0))
rolls.sort().drop(1).foldl(lam(elt, acc): elt + acc end, 0)
...
end,
method modifier(self, value :: NumInteger) -> NumInteger:
modified = (value - 10) / 2
num-floor(modified)
...
end
end
end

0 comments on commit 60d80bf

Please sign in to comment.