last day (15 days later) » 

04:14
3
A: Console-based Rock-Paper-Scissors game

Mat's MugI'd start with your enum: enum R_P_S { invalid, rock, paper, scissor } I'm not going to mention R_P_S is a really bad name for it and that types and their members should be PascalCase (or did I just... yeah I did), but the biggest problem here is this invalid value. If you ha...

Sorry I could not help laughing throughout your post. The only thing I have to disagree with is changing Choice to a nullable type too much nullable type casting. Explain why Game_Info should be a class and why rock,paper,scissor variables should be taken out. As for how I will read my code in a few months from now... I am sure it's simple enough for me to figure out what it does.
The variables are just redundant, they add an unneeded layer of indirection vs. using the plain enum values. Game_Info being a mutable struct defies all best practices about value types, and ignoring that will inevitably come and bite you somewhere, some day. As for the nullable, it's semantically what's right to do (absence of a meaningful value is a null value, not some "special" valid value), and the worries about too much casting are injustified, since Nullable<T> has implicit conversion to T, so there's no need to explicitly cast anything. Welcome to CR, glad you enjoyed!
@Mat'sMug can you please show me your casting? cause i seriously had to cast about 9 things right now i am firm believer of your words Mat.
@funTertain say you have a Selection? selection, instead of casting, you use selection.Value, and instead of comparing to null, you use selection.HasValue. And you can compare selection == Selection.Rock without casting, and assign selection = Selection.Scissors without casting either.
I don't get it and should i use pascal case or camel case for methods?
04:14
Those are really just stylistic guidelines, what matters most is consistency, but most C# devs will expect camelCase to be only used for locals/parameters and instance fields. Notice the PascalCase casing for methods throughout the .NET framework?
hi!
hi
I can't change things to nullable without a massive overhaul
how so?
string playerChoice = Console.ReadLine().Trim();
you know, if your input is "invalid", you have a valid "invalid" input...
bool validEntry = Enum.TryParse(playerChoice, out element);
i changed everything to nullable and then it expected me to change the inherited field "wins" to nullable and i was like wuuuuuuuut!?
i should say derived field "wins"
public fields are sloppy
fields should be private... always
why?
i never understood this
aren't public properties with just {get;set;} the same thing as a public field?
brewing some tea
04:22
no. they're the same thing as a getter+setter methods, backed by a private field
also:
25
A: Should I use public properties and private fields or public fields for data?

John NolanSee this article http://www.codinghorror.com/blog/archives/000654.html Specifically Reflection works differently on variables vs. properties, so if you rely on reflection, it's easier to use all properties. You can't databind against a variable. Changing a variable to a property is a breaking...

i will try
lol the C# terminologies are too advanced for me so i almost always end up just skimming through posts without getting any type of info whatsoever.
I often find myself googling big words i never hear in society today.
anyways....
back to the nullable thing
let me link the code with all the nullables in it
i am telling you its too much
already up to 3
I'm not following. I didn't say make everything nullable ...just that Choice method should return a nullable type
yes doing so everything becomes super PARANOID
    public override R_P_S? Choice()
    {

        R_P_S element;
        string playerChoice = Console.ReadLine().Trim();
        bool validEntry = Enum.TryParse(playerChoice, out element);

            if (!validEntry)
            {
                return null;
            }
          return element;
       }
^^ that's all
i swear it's like Ebola up in this code
yes that's what i'm saying
since i don't know anyway to set a enum type to nullable
i have to go into the code
and set playerChoice and computerChoice to null
after that
i had to set the local parameter of player inside DetermineWinner
04:28
public override R_P_S? Choice()  //Override the abstract method Choice inside the Participant class
{
    R_P_S element;
    element = (R_P_S)rand.Next(1,Enum.GetNames(typeof(R_P_S)).Length);
    return element;
}
to null
and then...
i don't even know what is wrong with wins
i am telling you these guys are paranoid man
    R_P_S? computerChoice;
    R_P_S? playerChoice;
yes
i have to do that
and then i have to set the parameter player to null too
04:30
why?
why did you set computer to nullable?
idk
because hmmm
because that's your return type... the base class says Choice() returns a R_P_S?, won't compile otherwise
        Console.WriteLine("Player: " + playerChoice.Value);
        Console.WriteLine("\n" + "Computer: " + computerChoice.Value);
^^ when you know you have non-null values, just get them here
let me post you the new script
lol
i have new variable and function names
so it gets crazy
determineWinner doesn't need to take nullables if you've validated the user input before
oh, but determineWinner is validating the user input....
you see, your code does need a major overhaul.
that method is making the Single Responsibility Principle take a serious beating
If i got your point maybe i will be able to see that but i can't see it
did you actually run this in VS?
04:35
nope
wow
real nice of you
T_T
you're probably thinking "man 14 yr olds are weird"
not all of 'em ;-)
I know a few regulars on this site that are your age
I am the exception hue hue hue
You watch anime?
like one piece
no time for that :/
Do you like the new names i chose for the methods and variables?
04:39
it's much better, yes
I cloned it, hold on..
pfft i don't know where "much" better stands on your chart
but it could be like like a 0.1111% increase in quality
lol
abstract class Participant   //Abstract - no need for instances, Many common functionality
    {
        public int wins;
        float winRate;

        public void DisplayWinRate()
        {
            winRate = ((float)wins / Game_Info.gamesPlayed) * 100;  //Win rate percentage

            string _winRate = String.Format("win rate: {0}%", winRate.ToString());
            Console.WriteLine(_winRate.PadLeft(0));
        }

        public abstract Selection? ChooseSelection();   //Every participant needs to have a choice. No choice about that TROLLOLOLOL
there
shouldn't need any more nullables than that
hold on my inexperienced eyes are still trying to figure out the differences
Let me put my coding glasses on
nah i think i need coding binoculars
Selection? is shorthand notation for Nullable<Selection>
I removed the Invalid enum member, and made ChooseSelection return a Selection?
the computer participant will never return a null, but an invalid input from the Player will.
then, I didn't want to change your logic, so where you print the selections after the tie-breaking loop...
Console.WriteLine("Player: " + playerSelect ?? "(invalid selection)");
I null-coalesced the player's selection into a valid string
Is there really... a need for computerChoice to be a nullable dude?
04:47
the compiler requires it
wow
this compiler is on acid
as far as the compiler is concerned, the signature for ChooseSelection - the "contract" if you will, stipulates that the return type is a Nullable<Selection>... for all derived types, regardless of the implementation details.
lol
i just removed it and it worked
the fact that the computer player isn't ever returning a null, is an implementation detail
what's a "implementation detail" my inexperienced ears can't understand
sheesh... the nuances of sentences are overwhelming
04:50
@funTertain oh you meant the parameter in the DetermineWinner method... I thought you meant the ChooseSelection
i changed everything that had to do with computer giving a null value
even ChooseSelection
I hope my bad coding practices don't override how your brain functions ....
@funTertain I'm not following that part - so now the computer is returning null all the time?
nvm
shouldve tested
the run failed for me
wait
oh i see
because ChooseSelection is abstract i am forced to implement
null
04:56
that's how abstract members work
ik that
it just slipped out of my mind for a sec
i have not focused on that part of the code for awhile that's all
now, the DetermineWinner logic needs a major cleanup
i almost feel like
is it the structure????
04:57
determining the winner should be a function that returns one of the two players involved, no?
it almost feels like the other option of having a invalid option inside my enum was wise
it does not return
hence it's void
it's about to hit 12:00 am
anyway, sleep on it - imagine what the logic would look like (pursuing that way) if you implemented Rock-Paper-Scissors-Lizard-Spock-Spiderman-Batman-Wizard-Glock ;-)
so don't
take out the nulls
it's not the nulls, it's the structure of the method.
well
no
because it's the implementation
that forces me to have to make computer a nullable also
05:01
and that shouldn't be a problem at all
ChosenSelection to be exact
goin to bed
'night
anything to say?
i want you opinion on this
or tormorrow we have breakfast over it
bye
take a look at this when you have a chance:
10
Q: Rock-Paper-Scissors-Lizard-Spock Challenge, take 2

Mat's MugThis post is following-up on Rock-Paper-Scissors-Lizard-Spock Challenge I had a gut feeling that I was somehow abusing IComparable<T>, @svick's answer confirmed that. As @dreza was posting his answer I was in the process of proceeding with exactly that refactoring: stuffing the SelectionBase c...

05:06
(and the answers, too)
 
11 hours later…
16:26
Ok so i casted the Selection? to Selection is this a good solution?
 
4 hours later…
20:23
hello

last day (15 days later) »