Vous êtes sur la page 1sur 8

[MUSIC].

All right, it's time for our first mini


project rock paper scissors lizard Spock.
Lets see if we can do it.
Okay, scissors cuts paper, paper covers
rock, rock crushes lizard, lizard poisons
Spock.
Wait a second, uh-oh.
I've got the wrong class just a second
here.
[MUSIC].
Sorry, I get a little confused sometime.
It's great to be here working on
Principles of Computing.
I think we're going to have a blast in
this class.
In this video, I kind of want to talk
about what
you need to know to survive and thrive in
this class.
We'll talk about three things.
We'll review, kind of, the elements of
Python
that you need to know from previous
experience.
And we'll quickly walk through a practice
mini project, that
will help assess whether you have the
sufficient Python knowledge.
And finally, we'll talk a little bit about
the role of math in this class.
Okay, let's get to it.
Okay, let's get started.
I first want to talk a little bit about
how I'm going to provide the material
that you're going to see in the video
here, for you to look at during class.
The reality is that my ability to kind of
type dynamically,
or write dynamically on the video is just
not very good.
I make tons of errors.
My handwriting's poor.
So instead what I'm going to do is I'm
going to either
prepare class pages that we can kind of
look at together.
Or I'm going to provide examples and code
sculpture that we can work over together.
So what I have here is a page that I
provided, which kind of walks
you through, kind o,f the Python that you
need to know to succeed in this class.
So I want to start off by noting that
we're going to be using Python
2 in this class, but if you know Python 3
you should be fine.
The only differences you're going to see
is in Python
3 when you print, you put parentheses
around things.
In Python 2, you don't.
Let's see.
In Python 3, when you divide two integers,
you get a float.
In Python 2, you don't.
You should be familiar with the basic
elements of Python.
We covered all these in Introduction to
Interactive Programming in Python.
So you should probably be good if you took
that class.
If you haven't, you should know things
like integers, floating point numbers,
streams, Booleans.
You should also be familiar with composite
data
types, things like list, tuples,
dictionaries, or sets.
You should also have at least a little bit
of knowledge
about how to work with user-defined data
types built using classes.
You should be able to take those kind of
data types and kind of
munge them together to make expressions,
using
constants and variables to make more
complicated things.
You can take those expressions and then
actually use them in statements statements
you should be aware of are things
like assignments, prints, returns, a few
others.
You should also understand how a kind of
compound statement work.
Things like conditionals function
definitions, for
loops, while loops and again, class
definitions.
One thing that you don't need to know is,
kind of, how to build a
GUI in IIPP, we actually taught you how to
build a GUI using simple GUI.
You don't need to understand how simple
GUI works to take this class.
In fact, you don't need to understand how
something like TK enter pi gang works.
We're going to provide you with a GUI
occasionally, that you can
run and code sculptor to kind of visualize
how your programs are running.
But you don't need to understand that.
Okay.
Let's go on.
[BLANK_AUDIO].
Okay.
In the last segment, we talked about, kind
of what
you needed to know about, kind of, the
structure of Python.
Of course, the real question is, can you
do something with what you know with
Python?
So, I prepared a practice mini project
here, that should kind of be a
fair test of whether you know enough
Python to survive in this class.
More generally, I've prepared a collection
of
practice activities, that you can kind of
try out each week to bridge the
gap from video lecture to homework and
mini-project.
And you can access those over here
on the left navigation bar under Practice
Activities.
It kind of bounced out here for week zero
and the
particular project that we're going to
work on is called Solitaire Mancala.
So, it's actually built on a game called
Cala,
which will kind of pop out here to the
Wikipedia entry.
It's essentially kind of what people in
the United States think of as Mancala.
The idea is, it's a game in which you have
a board.
It consists of six houses, kind of two
rows of six houses facing players that sit
across each other from the board and two
stores, one on each end of the table.
And the idea of the game is that you pick
up stones out of the houses.
And kind of place them one at a time,
counter clock wise around the board.
And, I'll kind of let you read the
description and think about the rules, but
the,
essentially the idea is that your goal was
to kind of capture as many stones as
possible.
We're not quite up to actually building
kind of a two player version of Mancala.
So instead, what we're going to do is
build
kind of what I'm going to call Solitaire
Mancala.
This is really essentially a mathematical
game.
It's a game that you don't really play too
much.
But it's kind of simple enough that it'll
get you
a chance to, kind of test out your
programming skills.
The basic idea is, that you have six
houses sitting on your
side of the board, and a store that sits
to your right.
And your goal is to get all the seeds,
'Kay, those are the
things that you're actually picking up out
of the houses, into the store.
The restriction on what you can do with
your seeds is that when you
pick up a set of seeds, you have to place
them one at a time.
Progressively to the right and the last
seat always
has to go in the store here highlighted in
red.
You win this game by getting all the seeds
in your houses into the store.
So let me do, I'm going to actually pop
over and take a quick look at
the code that I've built and had a demo of
my interface to Solitaire Mancala.
[BLANK_AUDIO].
Okay, let's take a quick look at my
implementation of Solitaire
Mancala and kind of play around with it
for a few seconds.
here, I've got my solutions sitting inside
code sculpture.
You notice that I've used the docstring at
the top here.
Look at the docstring for this class.
The implementation consist of one class
called Solitaire Mancala
and you need to build nine methods
associated with it.
Here I've used code folding to hide the
implementations of those methods.
When you're trying this as a
self-assessment,
don't copy my code from the video.
Okay, the solution is out there.
You can even look at the solution
directly.
But the goal is to do without doing this.
So after you've built your first cut, you
should test it.
We have some testing templates that we've
provided to help you with testing it.
But I want to show you something that I
built and provided to you, which
is a GUI that actually plays Solitaire
Mancala based on the code that you've
written.
So I've added two statements here at the
bottom of the program.
The first one imports a GUI that I've
built
in simple GUI, so this runs inside code
sculpture.
And then fires up that GUI.
So if I hit run, what we see here is a
frame.
It has the six houses and a store.
The store is in pink.
So, remember our goal was to pick up the
seeds.
And place them one at a time to the right
with the last seed always ending up in the
store.
So, in my description of how to
build Solitaire Mancala, I suggest a
numbering scheme.
We number this zero, this one, two, three,
four, five and six.
So with the rule the way I describe it, a
legal move would be
one in which the number sees the house
equals the index of the house.
So in this configuration, if I look at it,
there's only really one legal move and
that's to
move, click on six here and it plays one
seed at a time and all the various stores.
Now what I'm going to do is I, in this
particular choice, let's see, I
can actually pick up something in house
one, I can pick up something in house two.
Or I can pick up something in house five.
What the heck, lets do start off and move
to house two here.
Okay that's good it placed one here and
one here.
And lets see, then I guess I can grab one
in house five, then I could do house
four, I could do house two and hm, there's
no legal moves left now.
If I picked up six seeds, I'd have to have
some
kind of spillover at the end, so that's
not going to work.
So, when I play that board, I didn't win
because
all the boards I'm going to give you are
actually winnable boards.
So let's restart again.
And I'll tell you the trick to playing
Solitaire Mancala.
When you're given the choice of two legal
moves, you always
choose the legal move whose house is
closest to the store.
The smaller of index.
So here, we have a legal move where we
could grab
something in house three, or we could grab
something in house six.
So we're going to grab three.
Then one is the closest legal move, then
two, then one, then
six, then one, then five, then one, then
two, then one, then
four, then one, then three, then one, then
two, then one.
So eventually, if I follow that strategy
of always
moving, choosing the legal move that's
closest to the store.
I will always be able to win the game
here.
So your, your job is to kind of,
essentially build some Python code that
implements that logic.
It's not that complicated.
Eight of the nine methods require at most
like three or four lines of Python.
The last method requires a little bit more
Python.
All right, let's go on and just talk a
little bit about math.
[BLANK_AUDIO].
So the point of this video was to kind of
give you an idea about what
you need to know to survive in this class,
and you clearly need to know some python.
But there's a kind of a common theme that
comes up
in Introduction to Interactive Programing
in Python, which is math phobia.
Everybody's like, oh my God, I'm here to
program I don't want to have to learn
math.
But the reality is we're going to train
you to be more than programmers.
We're going to train you to be computer
scientists.
And the scientific part of computer
science is mathematics.
Now you don't have to know a lot of math
to come in and succeed in this class.
But you have to be willing to learn math.
We'll try to teach you the math you need
to know.
But the critical aspect of here is to
understand that it's not easy.
There was a great post on one of the
sessions of IIPP in which a student
talked about a panel debate that was held
that included Bill Nye and Neil deGrasse
Tyson.
And they really had some great comments in
there, so
I've kind of got it here up on the screen.
And the student said, I want to be
an astronautical engineer, but I'm
horrible at math.
I really want to do this, but it's, it's
hard and Bill Nye actually had a great,
great comment.
He said, when it comes to math there's no
substitute for practice.
That means, if you don't understand it,
get your hands on it, work with it, try it
out, do examples, read lots of sources,
read
what's in the class, read what's outside
the class.
But practice with it.
Tyson actually had an interesting quote
also, which
he's talking about, people expect things
to be easy.
He makes the point here in this quote that
he says, imagine you are trying to learn
Chinese.
At first it looks just terribly complex
and
you have no chance, but you might realize
that
it might take you five, five years to
actually learn to be even partially fluent
in Chinese.
Well, math is the same way it takes time,
you have to practice you have to work.
So you've got to give yourself a chance to
become good at math because again, math is
going
to be the key that's going to help you go
from being a programmer to be a computer
scientist.
It's going to allow you to tell a story
with your programs, the way
a great writer might tell a story using
English or French or Russian.
I think the other thing down here at the
bottom is quite interesting.
They talk about kind of, what are the kind
of, two
things that you could do that would help
you succeed?
Bill Nye's response was, learn algebra.
That's why we have high school math as a
prereq for this.
If you kind of understood how to think
abstractly
using algebra, you're on the right path to
succeeding.
I think the other one that Tyson said was,
ambition, you got to want it.
You got to work hard, you got to try hard.
If it turns out you only make it halfway
through the class, then
go out, take more classes, prepare more,
come back, take our class again.
Or heck, take somebody else's class.
But be ambitious, be persistent, be
tenacious.
That's the key that's going to get you to
your goals.

Vous aimerez peut-être aussi