#C# Dnd Character

157 messages ยท Page 1 of 1 (latest)

little wasp
#

What am I supposed to do in the Ability method?

#

I am having this problem: DndCharacter.cs(16,9): error CS0200: Property or indexer 'DndCharacter.Strength' cannot be assigned to -- it is read only

#

I don't know what means a modifier to be 3

#

I don't know this game

#

Am i supposed to generate a random number in the ability method?

#

What I have done so far: ``` public static int Modifier(int score)
{
Console.WriteLine(score);
DndCharacter character = new DndCharacter();
Console.WriteLine(character.Strength);
Console.WriteLine(character.Dexterity);
Console.WriteLine(character.Constitution);
Console.WriteLine(character.Intelligence);
Console.WriteLine(character.Wisdom);
Console.WriteLine(character.Charisma);
return character.Strength + character.Dexterity + character.Constitution + character.Intelligence + character.Wisdom + character.Charisma;
}

public static int Ability() 
{
    Random rnd = new Random();
    int[] roll = new int[4];

for (int i = 0; i < 4; i++)
{
roll[rnd.Next(roll.Length)]++;
}
Console.WriteLine(Minimum(roll));
return 2;
}

public static int Minimum(int[] roll) {
     int Min = roll[0];
    for (var i = 1; i < roll.Length; i++)

{
Console.WriteLine(roll[i]);
if (roll[i + 1] < Min)
{
Min = roll[i + 1];
}
}
return Min;
}

public static DndCharacter Generate()
{
    DndCharacter dndCharacter = new DndCharacter();

    return dndCharacter;
}```
tardy socket
#

You don't need to know the game. The instructions and tests should be plenty.

#

Yes, this requires random numbers

#

Are there tests that aren't passing?

little wasp
#

only 1 passes

#

this is my current code: ``` public static int Modifier(int score)
{
DndCharacter character = new DndCharacter();
character.Strength = Ability();
/character.Dexterity = Ability();
character.Constitution = Ability();
character.Intelligence = Ability();
character.Wisdom = Ability();
character.Charisma = Ability();
/
return character.Strength + character.Dexterity + character.Constitution + character.Intelligence + character.Wisdom + character.Charisma;
}

public static int Ability() 
{
    Random rnd = new Random();
    int[] roll = new int[4];

for (int i = 0; i < 4; i++)
{
roll[i] = rnd.Next(1,6);
Console.WriteLine(roll[i]);
}
int min = Minimum(roll);
int ability = 0;
for (int i = 0; i < 4; i++) {
if (roll[i] != min)
ability += roll[i];
}

    return ability;
}

public static int Minimum(int[] roll) {
     int Min = roll[0];
    for (var i = 1; i < roll.Length-1; i++)

{
if (roll[i + 1] < Min)
{
Min = roll[i + 1];
}
}
return Min;
}

public static DndCharacter Generate()
{
    DndCharacter dndCharacter = new DndCharacter();

    return dndCharacter;
}```
#

what do you think about it? ๐Ÿ™‚

#

I updated it now ๐Ÿ™‚

tardy socket
#

I think I'd need to see test output to understand what isn't working

little wasp
#

what isn't working is my comprehension of the whole task

#
Assert.Equal(-4, DndCharacter.Modifier(3));
TEST FAILURE
Assert.Equal() Failure
Expected: -4
Actual:   10```
tardy socket
#

What does the instructions say the modifier function is supposed to return?

little wasp
#

well, at the momment that is a bit complex to me

#

but has to do to 6 abilities

#

generated randomly

#

with a sum of three max numbers out of four

tardy socket
#

Try taking another look at the instructions

#

The modifier function returns one int

little wasp
#

Yes, indeed

#

that is the sum of various abilities

tardy socket
#

No. It's not.

little wasp
#

I suppose

tardy socket
#

Take another look at the instructions. You're confusing parts.

little wasp
#

ok

#

This I do "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."

tardy socket
#

That has nothing to do with the modifier function

tardy socket
#

Figured it out?

little wasp
#

Yes

#

I put it on the Generate function

#

Modifier is now empty

tardy socket
#

Passes more tests now?

little wasp
#

one more

#

random ability is within range

#

17 left

tardy socket
#

That's progress

little wasp
#
    {
        DndCharacter character = new DndCharacter();
 character.Strength = Ability(); 
        character.Dexterity = Ability();
        character.Constitution = Ability();
        character.Intelligence = Ability();
        character.Wisdom = Ability();
        character.Charisma = Ability();
        character.Hitpoints = (int) Math.Floor((10 + (character.Constitution - 10))/2m);
        return character;
    }```
#

character.Hitpoints doesn't always passes

#

so sometimes I still get 1 test passed

tardy socket
#

You know the drill ๐Ÿ˜‰ If you want help with a test, share test output!

little wasp
#
for (var i = 0; i < 10; i++)
        {
            Assert.InRange(DndCharacter.Ability(), 3, 18);
        }
TEST FAILURE
Assert.InRange() Failure
Range:  (3 - 18)
Actual: 2```
tardy socket
#
  1. Do you understand what the test is doing?
  2. Do you understand what the test is expecting and why?
  3. Do you understand what your code returns and how it differs?
  4. Do you understand why your code is returning what it returns?
tardy socket
#

@little wasp got it working?

little wasp
#

not yet

tardy socket
#

Do you want help?

little wasp
#

Let me see the instructions better

#

According to my expression character.Hitpoints = (int) (10 + (character.Constitution - 10)/2);

tardy socket
#

That doesn't seem related to the test you shared

#

If you need help with something, please share the test output and code you want help with. Then answer the four questions.

little wasp
#
Assert.Equal(-4, DndCharacter.Modifier(3));
TEST FAILURE
Assert.Equal() Failure
Expected: -4
Actual:   -1```
#

Actually I passed 4 and failed 16

#

My Actual value is always different

tardy socket
#
  1. Do you understand what the test is doing?
  2. Do you understand what the test is expecting and why?
  3. Do you understand what your code returns and how it differs?
  4. Do you understand why your code is returning what it returns?
little wasp
#

sometimes is -1, other times is -2, etc.

#
  1. isn't the test calling this function? public static int Modifier(int score) { DndCharacter character = Generate(); int constitutionModifier = (int) Math.Round((character.Constitution - 10)/2m); Console.WriteLine(constitutionModifier); return constitutionModifier; }
#

"You find your character's constitution modifier by subtracting 10 from your character's constitution, divide by 2 and round down."

#

this is what I did and returned

tardy socket
#

Does your function use all the parameters passed in?

little wasp
#

what do you mean the agility parameters?

#

don't know yet the purpose of the score input

tardy socket
#

The modifier is supposed to be based on the score

#

Not based on a new character

#

I'm pretty sure all functions across all of Exercism needs you to use all inputs every time.

little wasp
#

So the score is related to this "These six abilities have scores"

#

Don't know yet what do with the score

#

subtract each ability score

#

?

tardy socket
#

The modifier is based only on the score

little wasp
#

yes

#

the modifier of what? abilities?

tardy socket
#

The character isn't needed for the modifier. Only the score.

#

The modifier function takes a score number, does math on the score and returns a modifier value

little wasp
#

I need to use Ability and Generate functions in some way ๐Ÿ™‚

tardy socket
#

Not for the modifier function

little wasp
tardy socket
#

The x modifier is modifier(character.x)

little wasp
#

if yes, where'

tardy socket
#

"You find your character's constitution modifier by subtracting 10 from your character's constitution, divide by 2 and round down."

#

Replace constitution with x

#

Or score

little wasp
#

so it's this: public static int Modifier(int score) { int constitutionModifier = (int) Math.Round((score - 10)/2m); return constitutionModifier; }

#

15 passed 5 failed

tardy socket
little wasp
#

better

tardy socket
#

๐Ÿ‘

little wasp
#

10 more passed than before

tardy socket
#

Good job

#

Progress!

little wasp
#

Now more challenges: CODE RUN Assert.Equal(-3, DndCharacter.Modifier(5)); TEST FAILURE Assert.Equal() Failure Expected: -3 Actual: -2

#

But before that, I become a bit lost because I don't know how to use the Generate and Ability that I've implemented ๐Ÿ™‚

#

All code is implemented I suppose

tardy socket
#
  1. Do you understand what the test is doing?
  2. Do you understand what the test is expecting and why?
  3. Do you understand what your code returns and how it differs?
  4. Do you understand why your code is returning what it returns?
little wasp
#
  1. the test is calling only Modifier method, not Generate nor Ability
#
  1. I understand more or less
#
  1. I understand all my code, and don't know how to apply Ability and Generate
#
  1. I understand code is returning only the Modifier function result
#

what is missing in my answers? ๐Ÿ™‚

little wasp
#

score 5 is the score of what ability?

tardy socket
#

modifier function: by subtracting 10 from your score, divide by 2 and round down.

little wasp
#

ok

#

18 passed

#

I failed on ability and generate functions

#

tests'

tardy socket
#

Code, test output, 4 questions.

little wasp
#

The only test I'm failing, related to Ability: CODE RUN var expectedDistribution = new Dictionary<int, int> { [3] = 1, [4] = 4, [5] = 10, [6] = 21, [7] = 38, [8] = 62, [9] = 91, [10] = 122, [11] = 148, [12] = 167, [13] = 172, [14] = 160, [15] = 131, [16] = 94, [17] = 54, [18] = 21 }; var actualDistribution = new Dictionary<int, int>(expectedDistribution); foreach (var key in actualDistribution.Keys) actualDistribution[key] = 0; const int times = 250; const int possibleCombinationsCount = 6 * 6 * 6 * 6; // 4d6 for (var i = 0; i < times * possibleCombinationsCount; i++) actualDistribution[DndCharacter.Ability()]++; const double minTimes = times * 0.8; const double maxTimes = times * 1.2; foreach (var k in expectedDistribution.Keys) Assert.InRange(actualDistribution[k], expectedDistribution[k] * minTimes, expectedDistribution[k] * maxTimes); TEST FAILURE Assert.InRange() Failure Range: (200 - 300) Actual: 510

#

a bit complex this output ๐Ÿ™‚

tardy socket
#

Interesting test...
What's your code?

little wasp
#
    {
        Random rnd = new Random();
        int[] roll = new int[4];
        for (int i = 0; i < 4; i++)
        {
                roll[i] = rnd.Next(1,6);
        }
        int min = Minimum(roll);
        int ability = 0;
        for (int i = 0; i < 4; i++) {
            ability += roll[i];
        }
        
        return ability - min;
    }

    public static int Minimum(int[] roll) {
        int Min = roll[0];
        for (var i = 1; i < roll.Length-1; i++)
          {
            if (roll[i + 1] < Min)
            {
              Min = roll[i + 1];
            }
          }
        return Min;
    }```
tardy socket
#

Try not creating a new Random object every time the function is called

#

I think your minimum function is broken

#

What does Minimum (2,1,4,3) return?

little wasp
#

4,3,2? let me check

tardy socket
#

I thought it returned one int?

little wasp
#

and returns

tardy socket
#

What does Minimum(2,1,4,3) return?

little wasp
#

4,3,2

#

with this new code ``` public static int Minimum(int[] roll) {
int min = roll.Min();
return min;

}```
#

using System.Linq

tardy socket
#

Minimum (2,1,4,3) returns 3 numbers?

little wasp
#

yes

#

no

#

returns 1

tardy socket
#

Does your new code pass?

little wasp
#

no

tardy socket
#
  1. Try not creating a new Random object every time the function is called
  2. Paste new code and error.
little wasp
#

I can't take Random rnd = new Random(); out of the function

#

I tried to put it near abilities properties but I can't

tardy socket
#

What about the class initializer?

little wasp
#
Assert.InRange() Failure
Range:  (200 - 300)
Actual: 507```
#

maybe ability is badly calculated

#

don't know what's wrong: ```public static int Ability()
{
int[] roll = new int[4];
for (int i = 0; i < 4; i++)
roll[i] = rnd.Next(1,6);

    int min = roll.Min();
    int ability = 0;
    for (int i = 0; i < 4; i++) {
        ability += roll[i];
    }
    return ability - min;
}```
#

I deleted Minimum function

#

I don't understand the code run

#

it's very complex

#

I only know it uses Ability here: actualDistribution[DndCharacter.Ability()]++;

tardy socket
#

Read very closely how the two arguments are used

#

Does that help?

little wasp
#

I'm reading it

#

doesn't seem too much

tardy socket
#

Keep reading ๐Ÿ˜‰

little wasp
#

got it

#

"the exclusive upper bound"

#

I thought it was inclusive

#

done ๐Ÿ™‚

#

Now, I have to go

#

thanks!

#

see you soon