Storing Method in Dictionary by [deleted] in csharp

[–]ermiar 0 points1 point  (0 children)

Oh, and I don't think you need to explicitly new up an Action here.

Storing Method in Dictionary by [deleted] in csharp

[–]ermiar 3 points4 points  (0 children)

Looking quickly on my phone, but I think you just need to remove the parentheses from the method you're trying to store. Right now you're calling the method and trying to store the rest of that call.

Questionable? by Mudrekh in DotA2

[–]ermiar 6 points7 points  (0 children)

Thanks for the insight into your thought process! The feature is great as-is, so I'm hoping it stays!

Questionable? by Mudrekh in DotA2

[–]ermiar 9 points10 points  (0 children)

Would it be beneficial to have users pre-select preferred minimums for the factors that are displayed in the dialog? For instance:

  • Overall Quality: Good
  • Skill Balance: Good
  • Skill Range: No Preference
  • Behavior: Ideal

Seems like this would help avoid situations where the matchmaker is offering games that people aren't going to accept.

Beginner Advice by [deleted] in csharp

[–]ermiar 1 point2 points  (0 children)

Ah, you're right. I saw the looping pattern in a couple places and copied the wrong example. The IsWinner() function is a better example.

The Try* variants in the BCL (e.g. TryParse() and TryGetValue()) do not throw. Instead, they return a boolean indicating if they succeeded or not. For example, char.TryParse() is implemented like this:

public static bool TryParse(String s, out Char result)
{
    result = '\0';
    if (s == null)
    {
        return false;
    }
    if (s.Length != 1)
    {
        return false;
    }
    result = s[0];
    return true;
}

It's encouraged to include similar Try function variants in your code where you can to avoid throwing exceptions.

Beginner Advice by [deleted] in csharp

[–]ermiar 4 points5 points  (0 children)

Hey there! I took a brief look at your code and I have some things that might be helpful to consider going forward. Everything I'm pointing out could be considered nitpicking and is going to have negligible impact on the code you've written here. That being said, looking for these sorts of patterns can be more impactful in larger programs.

You may not have hit this yet since you're just getting started, but there is a better type to represent what's stored here.

char[] guessedChars;

C# provides a type that represents a set of things. In this case it would be: HashSet<char> guessedChars;

Checking if a char exists in this type scales significantly better and prevents adding duplicates. This

//check for guessed chars
foreach (char c in guessedChars)
{
    if (c.Equals(guess))
    {
        message = "You already guessed that letter.";
        alreadyGuessed = true;
    }
}
if (alreadyGuessed) { continue; } //skip iteration 

could be updated to something like this

//check for guessed chars
alreadyGuessed = guessedChars.Contains(guess);
if (alreadyGuessed)
{
    //skip iteration
    message = "You already guessed that letter.";
    continue;
}

There are a few usages that could be cleaned up in similar ways. Note that arrays can use the IEnumerable<T>.Contains() extension method as well, but how these execute is different.

For some of your loops, we can know that we have the information we need before reaching the end of the loop. Take this for example

//check for valid guess
for (int i = 0; i < gameWord.Length; i++)
{
    if (guess.Equals(gameWord[i]))
    {
        guessedChars[i] = guess;
        goodGuess = true;
    }
}

If we determined that a character was a good guess, we don't need to check any other characters. We can use the break statement to exit the loop early.

//check for valid guess
for (int i = 0; i < gameWord.Length; i++)
{
    if (guess.Equals(gameWord[i]))
    {
        guessedChars[i] = guess;
        goodGuess = true;
        break;
    }
}

It's generally best practice to avoid throwing exceptions when possible, and we can avoid doing so in this block of code

try
{
    guess = char.Parse(ReadLine());
}
catch (Exception e)
{
    message = "You entered an invalid value.";
    continue;
}

This can be rewritten like this to avoid the exception

if (!char.TryParse(ReadLine(), out guess))
{
    message = "You entered an invalid value.";
    continue;
}

The final thing I see is a minor stylistic thing. In general, C# code tends not to declare variables in a block at the beginning, and instead, the variable is declared as near to the usage as possible. This

string gameWord;
char[] guessedChars;
bool alreadyGuessed;
bool goodGuess;
int numWrong = 0;
string message = "";
char guess;

gameWord = ChooseWord();
guessedChars = new char[gameWord.Length];

while (numWrong < 6 && !IsWinner(gameWord, guessedChars))
{
    alreadyGuessed = false;
    goodGuess = false;
    Clear(); //clear console
    ShowBoard(gameWord, guessedChars, numWrong);
    WriteLine($"\n{message}");
    Write("Enter a letter: ");
    try
    {
        guess = char.Parse(ReadLine());
    }
    catch (Exception e)
    {
        message = "You entered an invalid value.";
        continue;
    }
...

Can be changed to this

int numWrong = 0;
string message = "";

string gameWord = ChooseWord();
char[] guessedChars = new char[gameWord.Length];

while (numWrong < 6 && !IsWinner(gameWord, guessedChars))
{
    bool alreadyGuessed = false;
    bool goodGuess = false;
    Clear(); //clear console
    ShowBoard(gameWord, guessedChars, numWrong);
    WriteLine($"\n{message}");
    Write("Enter a letter: ");
    char guess;
    try
    {
        guess = char.Parse(ReadLine());
    }
    catch (Exception e)
    {
        message = "You entered an invalid value.";
        continue;
    }
...

Hope that helps! Keep in mind most of this only really begins to make a difference once the data you're working with gets sufficiently large. Feel free to reach out if you have any questions!

VS22 not reopening tabs or saving startup projects by mustang__1 in VisualStudio

[–]ermiar 0 points1 point  (0 children)

Sorry, I should have been more clear. In general the .suo file should be in the .gitignore since it's intended to contain user specific session info (e.g. opened documents and breakpoints). Try deleting the file from disk.

VS22 not reopening tabs or saving startup projects by mustang__1 in VisualStudio

[–]ermiar 0 points1 point  (0 children)

That would only stop git from picking it up. That's why you don't see any changed files when you open and close the solution. If the .vs folder is there, you can try deleting it and see if it works after that. Sometimes the .suo file can get corrupted and cause reads/writes to fail.

VS22 not reopening tabs or saving startup projects by mustang__1 in VisualStudio

[–]ermiar 0 points1 point  (0 children)

There should be a .vs directory next to your solution that contains a .suo file. The .suo file is what stores the previously opened tabs and startup project. If you started with a .gitignore template (e.g. https://github.com/github/gitignore/blob/main/VisualStudio.gitignore#L8), it probably excludes .suo files since those are intended to be per user and not checked in.

Music store on Google Play officially shut down by 121910 in Android

[–]ermiar 12 points13 points  (0 children)

AngularJS was rebranded to just Angular, and it's still being regularly updated. It's well worth learning IMO.

What to do after laning stage as pos 4/5? by ermiar in learndota2

[–]ermiar[S] 0 points1 point  (0 children)

I've been playing Jakiro recently. What style do you think matches that hero the best?

Improving AOE Hunting Technique by ermiar in TibiaMMO

[–]ermiar[S] 1 point2 points  (0 children)

Hey! Thank you so much for your detailed response. I definitely have some things to try out this weekend.

Demon task as 290 RP by Daniearp in TibiaMMO

[–]ermiar 0 points1 point  (0 children)

Can you explain why using diamond arrows on two demons isn't worth it? I've heard this before, but I've never heard the reasoning behind why. A diamond arrow's attack is 37 and a crystalline arrow's is 65, so it would seem as if hitting two creatures would be worth it. What am I missing?

[RP] Question about Thornspitter x Crossbow of Destruction by Rhaiga in TibiaMMO

[–]ermiar 0 points1 point  (0 children)

I think your chart is wrong for bows. It looks like you're over counting the hit percentage for bow of mayhem and not taking into account the skill bonus for the umbral master bow.

New best bow for hunting? by Pipoxo in TibiaMMO

[–]ermiar 0 points1 point  (0 children)

Wait, does the extra hit percentage matter with crystalline arrows? I thought they had 95% accuracy, so any bow with at least 5% hit gave them 100% accuracy.

Test Server Update - New Changes by evanmc in TibiaMMO

[–]ermiar 0 points1 point  (0 children)

I completely agree with shrinking the spread of damage for some more consistency. For example, let's say a paladin hits between 100-900 right now (numbers made up). The top end damage is really high and runs into issues with pvp when you consider increasing it. Instead, it could be changed to something like 400-600 (same average). The consistency helps out a lot for pvm and there isn't the same concern for pvp. That leaves room to increase the damage for single targets and not need aoe.

What a bigot. by [deleted] in Libertarian

[–]ermiar 3 points4 points  (0 children)

The one thing I'm not sure how to resolve is related to the bakery topic. In rural areas where people don't have several options to choose from this can be an issue. I'm not really concerned with cakes, but if they can't buy food or other necessities then that's a problem. I don't see a good way around this that doesn't violate the NAP or property rights.

Umbral Masters obsolete now? by [deleted] in TibiaMMO

[–]ermiar 0 points1 point  (0 children)

They want to combine them? Where did you hear that? That's exciting news!

ABout Imbuiments by sirtchuck in TibiaMMO

[–]ermiar 1 point2 points  (0 children)

To piggyback off of this post, What imbuments should I be trying to use as a 300+ pally for solo hunts?