Skip to content

Implement D&D Character exercise#20

Merged
BNAndras merged 3 commits intoexercism:mainfrom
BNAndras:add-dnd-character-exercise
Jul 2, 2023
Merged

Implement D&D Character exercise#20
BNAndras merged 3 commits intoexercism:mainfrom
BNAndras:add-dnd-character-exercise

Conversation

@BNAndras
Copy link
Copy Markdown
Member

This will need an instruction append to explain some of the basics of a data declaration.

@BNAndras
Copy link
Copy Markdown
Member Author

I also forgot my name in the config.json. Whoops

@BNAndras BNAndras self-assigned this Jun 30, 2023
@BNAndras BNAndras added x:rep/small Small amount of reputation x:module/practice-exercise Work on Practice Exercises x:size/small Small amount of work x:type/content Work on content (e.g. exercises, concepts) x:knowledge/none No existing Exercism knowledge required x:type/docs Work on Documentation labels Jun 30, 2023
@BNAndras
Copy link
Copy Markdown
Member Author

BNAndras commented Jun 30, 2023

Right, I'm reconsidering this one already because we're requiring them to create an empty Character and then initialize it. They could solve this by defining a character function that returns an object expression with the field values already populated. We're not playing to the strengths of having a named type here like using the type detectors so I think it'd be easier to forgo it. Clock could be my data declaration exercise instead. :)

modifier = lam(value): num-floor((value - 10) / 2) end
ability = lam():
    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

fun character():
  cached_constitution = ability()
  {
    strength: ability(),
    dexterity: ability(),
    constitution: cached_constitution,
    intelligence: ability(),
    wisdom: ability(),
    charisma: ability(),
    hitpoints: modifier(cached_constitution)
  }
end

character() #  {strength: 11, dexterity: 9, constitution: 9,  intelligence: 7,  wisdom: 14,  charisma: 15,  hitpoints: -1}

@BNAndras BNAndras marked this pull request as ready for review July 2, 2023 05:48
@BNAndras BNAndras merged commit 86fd015 into exercism:main Jul 2, 2023
@BNAndras BNAndras deleted the add-dnd-character-exercise branch July 2, 2023 05:48
BNAndras added a commit that referenced this pull request Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

x:knowledge/none No existing Exercism knowledge required x:module/practice-exercise Work on Practice Exercises x:rep/small Small amount of reputation x:size/small Small amount of work x:type/content Work on content (e.g. exercises, concepts) x:type/docs Work on Documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant