0:00
[MUSIC]
Well, I had planned to use a fabulous clip from The Big Bang Theory and
have Sheldon Cooper explain the rules to Rock, Paper, Scissors, Lizard, Spock.
But unfortunately the copyright police told me that was a very bad idea.
So since my wife thinks that I'm already a lot like Sheldon,
I'm going to take my crack at explaining the rules to rock paper scissors
lizard Spock a la Sheldon Cooper.
0:33
Let's do this.
It's very simple.
Scissors cuts paper, paper covers rock, rock crushes lizard.
Lizard poisons Spock.
Spock smashes scissors, scissors decapitates lizard.
Lizard eats paper, paper disproves Spock.
Spock vaporizes rock and has always been, rock crushes scissors.
Yeah.
0:57
Well I hope you enjoyed that.
Our mini project that ended week one and the first one that you'll turn in for
a grade is rock paper scissor lizard Spock.
Now, when we were brainstorming on kind of what mini projects we should use for
this class, our first inclination was to do something on income taxes.
So I kind of balance this idea off of my focus group at home consisting of my three
kids and their reaction was income taxes, yuck!
Who wants to do income taxes?
So we watch a lot of Big Bang Theory at home, and so they came up with the idea,
hey yeah lets do something on rock, paper, scissors, lizard, Spock, so
that's where the idea came from.
In this video I'm going to do you two things.
I'm going to start off by walking you through the rules for rock, paper,
scissors and then later rock, paper, scissors, lizard, Spock.
I'll show you a clever idea for
how to determine who wins the game of Rock Paper Scissor Lizard Spock.
And in the second part of the video I'll walk you through the mini project and,
in particular, I'll show you how you can get help if
you're having trouble actually completing the mini project.
We've got kind of some nice support structures in place in the class and
I'll show you how to use those in If you get stuck, you should come back and
look at this video.
Because they give you some nice hints about how to proceed.
Okay, let's go on and get started.
2:14
All right, let's go to the rules of rock, paper, scissors, lizard,
Spock a little slower.
So this is just a variant of rock, paper, scissors We have rock, paper and scissors.
So rock smashes scissors, scissors cuts paper, paper covers rock.
The problem with playing Rock, Paper, Scissors is that you tie a lot.
And if you play friends where they know your patterns,
you may tie more than half the time.
So one way to avoid having lots of ties is to add more items.
So this variant you add in lizard and you add in Spock.
2:47
And this little poem over here is
actually what Sheldon recites on The Big Bang Theory to describe it.
My kids love it when I do that.
But I don't expect you to actually program those rules in your first project.
I'm going to tell you a simpler way using, surprise surprise, modular arithmetic.
So over here I have the rock-paper-scissor-lizard-Spock wheel.
And in fact it's really the rock-Spock-paper-lizard-scissors wheel.
And the way to remember this is you put Spock next to rock, And
lizard next to scissors.
Now why is this wheel useful?
It's because I can figure out who I win and
lose to based on where I sit on the wheel.
So, let's consider Spock.
Spock always beats his counterclockwise opponents, Spock vaporizes rock,
Spock smashes scissors.
But he always loses to his clockwise opponents.
Paper disproves Spock, lizard poisons Spock.
3:40
In fact, this holds for every item on the wheel.
So if we want to go through and figure out who wins at Rock, Paper, Scissors we can
take the numbers for each of the items, and then we look at their difference.
So we can take paper minus Spock.
3:55
Okay, paper appears in the clockwise.
So 2 minus 1 is positive.
It's 1, therefore paper beats Spock, okay?
Lizard, 3 minus 1 is 2.
It's actually clockwise.
What about, let's see, we have scissors minus Spocks.
So we have 4 minus 1, that's 3.
Well see 3 has gone far enough around that we're actually kind of counter clockwise.
4:19
In fact we have less rock, rock is 4.
So we have 0 minus 1, it's negative 1.
Gosh, what do we do there?
We could use modular remainders.
We could go through and take minus 1 remainder 5.
Remember what I talked about?
Whenever you have a negative number and you're taking a remainder
just think about adding in the number you're taking the remainder with.
As many times as it takes to get it in the range between 0 and 5.
So here if we take negative one, we add have to it, we get four.
So rule is really that if you take the first item minus the second.
If the difference is one or two the first item wins.
If the difference is three or four the second item wins.
4:59
So we'll go and see that in a program in a second but
this is a simpler way to actually program this stuff.
All you're going to need to do is build an else, else if, if, else if,
else clause and use a little modular arithmetic.
So, let's move on the program to input and I'll kind of be more tangible.
5:28
And then it has very detailed step by step walk through of implementing rock,
paper, scissor, lizard, Spock, please read this, this give you important hints
on how to implement the project for example, I mentioned when you are doing
generating random numbers, you use random.randrange().
So read that I will give you lots of nice insights on there.
Notice also to include what the output of the program should look like, okay?
So, if you are curious kind of what it produces,
should produce something on this format.
It includes a grading rubric that discuss kind of how to handle deviations and
then gives you items for how to evaluate if your implementation is correct or not.
So it's important that you familiarize yourself with this.
One important point here, the first rubric item says you need to use code sculptor.
Though don't try to cut and paste your code into the submission box.
I know it's tempting because you want to use a tool like Idle,
well you could kind of get by with it for this project but
in the future you're going to need to be using code sculptor because a lot of
the interactivity is going to take place inside the web browser.
It's not going to be able to be implemented inside Idle.
So just get used to it now.
Use CodeSkulptor.
It's going to make peer assessment much more reliable and much more easy.
When you're ready to start writing code, you can scroll up here.
We have a template, every mini-project has a template.
We can click on this and this pops up basically a CodeSkulptor
url which contains the starting point for your project.
Really, if you look at the project,
there's really three things you need to do.
You need to implement a function number_to_name,
a function name_to_number, and a function rpsls.
So you kind of have to fill in this comments with Python code.
At the bottom, there are five calls to rpsls.
That will essentially test if you're implementation is correct or not.
So, when you run your code, you should expect to see some text up here,
over here.
We've actually echoed that text right here for you.
7:31
I'm also show it to you in the video so you can actually see that in action.
This is my implementation of rock paper, scissors lizard spock.
You can see, you might ask, well where are my definitions of these functions?
I've used the function,
basically kind of feature of Code Sculptor called code folding.
If you right click in this little column here, you can actually either fold up and
hide code or expose code.
I've actually hid Definitions of number to name, name to number and RPSLS.
If I run this what you can see here is the textual output.
So I noticed a couple of things about this that using random numbers I made kind of
a different response with the computer on each particular individual game here.
So I didn't always choose the same value for the computer.
And then if I run this again, I see different choices for the computer.
Notice the players choices are always the same for every single run, and
that is because we have these five values here.
8:52
Well, the first thing you can do is If you're confused about some particular
Python concept, go back and take a look at the appropriate class video.
For example, if you don't understand how conditionals work,
take a look at Scott's video on conditionals.
9:38
The next thing I suggest you do is,
inside CodeSkulptor, there's a button up here that says tips.
This links to a particular thread inside the current week's mini-project forum.
So here we're in the forum for Rock Paper Scissors Lizard Spock, and
I've created a thread called Code Clinic tips for RPSLS.
9:57
So in this thread, I've essentially posted some information about students'
errors and things that help with solving this particular week's mini-project.
For this session, what we're going to do is we're going to always
start off with some essentially testing functions that help you make sure
that the helper functions you're building for your mini-project are correct.
So remember you have to implement name to number and number to name.
We've put out here two CodeSkulptor URLs that you can use
to test to see if your implementations of those functions are correct.
So for example, if I click on this, it pops up a CodeSkulptor URL
which has a place for you to paste in your definition of name to number.
And then it has some test calls to name to number with the appropriate data and
it tells you what should come out of that, what the output format should look like.
So if your implementation of name to number is correct and
you paste it in here, you should see something like this coming out.
This basically gives you a way to check and
see if your helper function is written correctly.
That passes this test, there's a good chance the implementation is correct.