Michael Bruce Allen wrote:I like your oneTwoThreeShoot and I feel this should have picked a random Gesture.
Michael Bruce Allen wrote:
Thinking about design, I like your oneTwoThreeShoot and I feel this should have picked a random Gesture. This makes me want to make another randomTest like before except call it through this method and new class. After making this pass, I would want to assert a test through another method which checks our gestures and produces a score. How does this sound?
Michael Bruce Allen wrote:
i mean the method doesnt return anything and I feel the next test I would be instantiating a class with a main method, creating a oneTwoThreeShoot() method, creating a instantiation named computer.. Normally, I would be fine with this, but isnt this too much?
Junilu Lacar wrote:Look it up on Wikipedia, there's a formula that you can use with specific rank values assigned to the different gestures.
I wrote:You either change your code or you change your tests but never both at the same time. Doing so complicates things because you have multiple moving parts that affect the balance of your software.
I wrote:
There's a lot of boolean logic going on in these few lines of code and it's subtle because it involves the meaning of "beats" and "losesTo". The "not equal to" doesn't help make the code easy to understand either. This small method is quite the mini brain twister actually.
Michael Bruce Allen wrote:What would you think of me restarting the project and using what I learned? Is that not a good idea to start over? I am open to either way.
Junilu Lacar wrote:
That's actually an excellent idea! I have solved this RPS problem many, many times and it seems like every time I try it with someone new, I discover something else I hadn't before.
Start over from scratch with only the lessons learned in the past in mind and as much as possible, forget about the implementation that you had before. Start over as though this were the very first time you've ever tried to solve the problem. There are a number of other "constraints" you can impose on your new start but I suggest for now you just start over and see what happens when you try it with a better understanding of the principles behind each action that you take throughout the process.
Those who know me in these forums might roll their eyes at what I'm about to tell you (that's Ok, I get it, but we're all good virtual friends here): I study Aikido and have done it long enough to have earned a black belt. It never ceases to amaze me when I work with new students to see the kind of things they can teach me or at least help me discover about the techniques we're practicing together. You see, Aikido practice is usually done in pairs, with the person of higher rank first performing the technique and the person with lower rank receiving it. Then we switch roles back and forth until sensei moves on to the next technique or variation. This gives both people the chance to experience the technique from the giving and the receiving end. And sometimes, maybe even often, I learn more from being on the receiving end of the technique.
That experience in Aikido is not unlike that which I have when pair or group programming, no matter what the other person's/people's level of experience. There's always a give and take, and I learn from the other person just as much as they learn from me.
So go ahead, by all means, start over and see what happens.
rock-paper-scissors-Spock-lizard (note the different order of the last two moves) may be modeled as a game in which each player picks a number from one to five. Subtract the number chosen by player two from the number chosen by player one, and then take the remainder modulo 5 of the result. Player one is the victor if the difference is one or three, and player two is the victor if the difference is two or four. If the difference is zero, the game is a tie.
Michael Bruce Allen wrote:
assertTrue(ROCK.beats(SCISSORS));
Would this be an ok first test?
Gesture is a good name and beats is a good name. I almost want to forcibly change them just to be different, but why would I? So I feel I am stuck in the old world that I learned from. What is there new to think? This might be the first thing I would want to do, test one of the gestures immediately with another gesture.
Michael Bruce Allen wrote:I have a few questions:
You mentioned that code readability is important to you. But is really a one line modulo logic really readable?
Wouldn't it be better to have a switch case for readability? Or anything else readable?
Campbell Ritchie wrote:Surely it's . . .You now have a redundant pair of () which I have left.
Junilu Lacar wrote:Michael's refactoring code diff (from github repo):
I like it. A little unorthodox for me but it still reads out loud nicely: "beats opponent's gesture" is proper grammar. The only niggle is that fraction of a second where the reader has to mentally insert the apostrophe to make it possessive instead of plural. See Campbell's and my previous comment about making this a one-liner though.
I'm guessing/hoping you were motivated to refactor because the parameter definition "Gesture opponentsGesture" looks redundant. Exactly the refactoring that I would have made.
Michael Bruce Allen wrote:I have a few questions:
..
I am not a fan of this - the test just passed - I would like to refactor
concidering that this is a static method, declaring Random rand = new Random() outside of the method would call for a static instantiation. I do not like that either.
I feel like this can be all cleaned up, I wrote this with the thought of extending the game later. I will try more tomorrow.
Michael Bruce Allen wrote:
How and why would you fail this code first? Make it return false? Is this an important step in the thought process?
Don't get me started about those stupid light bulbs. |