2 games

There are 2 games that I want you to look at today

The first one you have to play with a friend.  Whoever gets the last flag wins.

21 flags

Is it better to go first or second?  What is the winning strategy?

here’s another game.  It’s called stick or switch.  Pick the correct door and win a new car (not really)

stick or switch

Is there any strategy here or is it all just luck?

Try this simulation which will run the game over an over and see what happens

search engines

card catalouge

First of all, the internet is big.  How big? Click here to find out the number of web pages.

Considering the size of the wold wide web, search engines do a pretty good job figuring out what you’re looking for, based on a couple of words you type into a search bar.

They do such a good job, that most people don’t even look past the first five or ten results.

How do they accomplish this?

Let’s start by imagining a search for the “best toothbrush.”

Step one: indexing

A search engine doesn’t look through actual web pages.  Rather it looks through a massive index, stored on a server, that has been assembled, and is constantly being updated by “webcrawlers” which request webpages and store every word found in them.

Once you have the the index that tells you what words are on every page, the computer can search to find which pages have both the words “best” and “toothbrush” and show you the results

they might end up looking something like this

best toothbrush

all of these pages contain the words “best” and “toothbrush” but which is the one that I really want, and how could a computer tell the difference?

The location trick

Not only does a computer index every word on a webpage, but it also indexes the location of every word on every page.

This allows you to look for an exact phrase

Let’s say I hear a song and I can only remember this snippet of the lyrics “got such dark eyes”

If I put those words in quotes, a search engine can search its index for any page that has the word “got” at location n, “such” at location n+1, “dark” at location n+2, and “eyes” at location n+3, and show me only those results

But search engines also use the location trick to determine relevance.

In my toothbrush example, the closer the word “best” is to the word “toothbrush”, the more relevant the computer decides web page is

This test helps to weed out results like

extra toothbrush

But it probably would not weed out the  page claiming a “toothbrush works best to get gum out of carpet” The word “best” is only one word away from “toothbrush”

But there’s another trick search engines use.  It’s called:

The metaword trick

To understand the metaword trick you have to know that a webpage can be broken down into various parts: Head, title, body, etc, and these parts are established using html tags

The title of a web page might be constructed like this:

<title>Title of the document</title>

The meta word trick rests on assumptions such as, if the word “best” and “toothbrush” are in the title of a web page, it’s probably more relevant to a search for best toothbrush, than results where those words are merely found in the body.

To accomplish this aspect of search, a search engine must index the location of each of the tags

The metaword trick catapulted AltaVista to the top of the internet search game in 1995.

And then came Google and their page rank

The Hyperlink Trick

Page rank is based on the popularity of a website, and popularity is mainly determined by the incoming hyperlinks a web page has.  That is, how many people who have websites linked to your page.  The more links you have, the higher your page rank.

But shouldn’t an incoming link from a popular website be worth more than a link from a website nobody has ever heard of? Yes

The Authority Trick

All websites start out with an authority score of 1, but if a page has incoming links its authority is calculated by adding up the authority scores of the pages that point to it. (Actually a webpage gives a page it links to its authority score divided by the number of outgoing links it contains)

Here’s a diagram from John MacCormick s book 9 Algorithms that Changed the Future.

authority trick

Because 100 people with a page rank of 1 had linked to Alice Water’s home page, she passed on a page rank of 100 to Bert’s scrambled eggs recipe, while John MacCormick’s homepage only had two incoming links and passed on a page rank of 2 to Ernie’s Recipe.  Therefore, Bert’s recipe will appear first in the results of searches for scrambled eggs.

But there is a potential problem here.  What if we have a cycle of hyperlinks, like this:

cycle

If C, D, and E all start with a page rank of 1, page A, which all three link to, will have a  rank of 3, which it will pass along to page B, and B will pass it to page E.  But now A is out of date.  But if we adjust A, we’ll have to adjust B, and then E, and around and around it goes.

The Random Surfer Trick

The solution to this problem is an algorithm that simulates a random surfer, who randomly visits a page, and randomly follows a chain of hyperlinks, picking a new page to start on 15% of the time.

The more hyperlinks a page has to it, and the more popular the pages that link to it (also the fewer links those pages have) the more often the random surfer will visit, and the higher it’s page rank will be.

Though there are many other factors that influence Google Searches, it is this idea that catapulted Google to the top of the internet search game

But to run a successful search you need more than a good algorithm.  Click here to look inside one of Google’s data centers

And here are 9 questions you need to answer

inventor prezi project

Pick an inventor or an invention that you would like to research.  Here are some links to resources you might want to take a look at to help make up your mind.

  1. Invention at Play
  2. Important inventors of today
  3. 50 Greatest Breakthroughs Since the Wheel
  4. List of Inventors

Make sure to pick something or someone you find interesting, and are able to find enough information about.

The handout I’m passing out provides a list of questions you will want to consider when you are working on your project.  You don’t have to answer all of them, some of them will not apply.

Your project should provide at least 10 screens of information, and include several images

I would like you to use Prezi, the online presentation creator, to put your project together.  (The presentations I made on Communication technology, and GPS were made on Prezi)

Here’s a link to prezi.com you have to sign up using your email (I recommend using your student email)

Random numbers and algorithms

A week or two ago we were talking about technological systems and I showed this diagramsystem loopThis is a diagram of a closed loop because it has feedback.

Like the dish washer that could sense if the dishes were clean enough before it would turn off.

Our experiments with Scratch have involved both open (no feedback) and closed loops.

here is a simple script from Scratch

open loop

It tells the program that when you press the space bar the sprite will move 10 steps, and turn 15 degrees, and it will repeat this 10 times before stopping.

Is this an open or closed loop?

Is there any feedback?

Since there is no feedback it is an open loop.

here is what that script does to the cat if you’re interested

spinning cat

not really that interesting

A closed loop responds to feedback, and open loop does not

Here’s another example of a system.

closed loop

After a player loses a life, it asks a question (does the player have more than 0 lives left)   If the answer to that question is yes, the sprite appears, if the answer is no it broadcasts game over

It has an input, process, and output.  Is there any feedback?

Here is a word we talked about last week:  algorithm

An algorithm is a set of step by step procedures that can be followed explicitly.  An algorithm tells you what to do at every turn.

Even when a computer is exhibiting random behavior, it is relying on specific instructions to do so.

Remember this game

spaceman

I used a random number generator to make these red enemy ovals that appear at random y coordinates

One method a computer might use to generate a seemingly random sequence of numbers is called middle squares algorithm

Here is a video about it

Here is a program I made that uses the center squares algorithm to generate random walks

the space bar, and keys a, s, d, f start the programs

The longer the seed, the longer it will take before a pattern starts to repeat.

Some of them will get stuck when they output 000, or 001, and some of them will.

random walk

And here’s a simple script I used that uses a random number generator

sierpinski pic 

here’s the most critical parts of the script

sierpinski script

The algorithm tells the sprite to  randomly pick one of the triangle’s three vertices, point in that direction, go half way to it, and make a dot or stamp, and repeat this process forever.

Is this an open or a closed loop?

Is there any feed back?

And here’s another algorithm that might be used by your calculator

square root script

It might be a little hard to read in the scratch language, but it is an algorithm for finding square roots

It works like like this: you enter a number you want to find the square root of.  Let’s say 361

Then you take a guess

the computer checks your guess by squaring it to see if it gets you back to your original number.  If it does, you guessed the square root, and we are done

If squaring your guess doesn’t get you back to the number, it takes the average of your guess and the original number divided by your guess

then uses that answer as its next guess and repeats the process, until it guesses right.

It knows it’s right when the number its guessing times itself gets you back to the number you were looking for the square root of.

That was a mouthful, but  here it is in action

When you play with it use both the rounding and the exact buttons.  You have to select one before it it it tells you to input a number

square roots

If you’re try to find the the exact square root of 19, what happens?  Why?

Do you think the blocks I show above from the “rounding” or the “exact” script?

Look inside the program and see if you can figure out what I needed to use to round my answer

And Finally:  Is this an open or closed loop?  Is there feedback?

Answer this, and other questions right here 

Just one week left

It’s the last week of class, and our post assessment will be on Thursday

I’m giving you today to get caught up on all the work I have assigned so far in the class. Everyone should finish up the scratch projects they are working on and show them to me by the end of class today.  The major assignment is the target practice game, which most everyone should have working to some degree (I’m aware that allowed a few of you to work on your own games)

Notice that I have added two tabs to the banner of the class blog.  These tabs take you to pages that have lists with links to every assignment we have done in this class.  If you have anything to make up, you can find it there.

 

Here’s what we are doing for the rest of the week

Tuesday: lesson on algorithms and random number generators

Wednesday: review for post assessment

Thursday: post assessment

Friday: Make up day for post assessment, paper tower challenge

Adding to an existing game

Remember this game

bouncing ball  (2)

for today’s assignment, I would like you to figure out how to add one of the red enemy sprites to a platform on level one.

To think accomplish this, think about everything it needs to do:

  1. It needs to show when level 1 is broadcast
  2. It needs to go to a specific location (on to one of the platforms)
  3. It needs to move back and forth
  4. It needs to hide if you aren’t on level 1 (hint: when level 2 is broadcast)
  5. The sprite you control has to hide, and lose a life when it touches your new sprite.

To accomplish number 5. you are going to have to edit the script that controls the # of lives remaining  by adding the sensing block “if touching your new spite” to this script

enemy sprite script

which controls the black bouncing ball

I’m not going to help anyone for the first 15 minutes of class.

If you finish try to figure out how to make another level.

This requires broadcasting level 4, instead of you win, and assigning each platform and sprite to some location when it receives the broadcast

 

Maze

Today’s game

new maze picture

For today’s assignment I would either like you to continue working on the target practice game you were working on last week.  I would like to see a completed game with a timer, the ability to keep score, multiple sprites controlled by a random number generator, rapid fire where each projectile is able to eliminate target sprites (this requires the use of an “or statement” and directions can be seen below)

You also have the choice of making a color gate like those seen in today’s maze.   It requires making two backgrounds that you can move a sprite back and forth between using Scratch’s coloring sensing capabilities.  Here are detailed instructions for completing the color gate.

1) Step one.

Make a simple sprite that can move around the screen.  In my case it’s just a dot.

The sprite is going to need control to move back and forth up and down.  (the up arrow changes the y by positive 10, down arrow changes y by negative 10, right arrow changes x by positive 10, left arrow changes x by negative 10.

direction controls

Step 2

create the stage

maze stage

A simple white path through darkness will work just fine.  It is important to have a different colored rectangle at the end of each path because that is what signal the change to the next screen.

To get to the stage editor click stage

pick stage

and then click the edit button

edit background

You are going to need to draw at least two stages that you can switch between

To make a new background click the paint button next to the words “new background”

Now that you have two backgrounds we want to move back and forth between them

red gate

blue gate

In this simple example we are going to start in the screen with the blue gate at the top, and move to the screen with the red gate at the bottom, and be able to move back and forth between the two screens

So here is the most important step

When our moving sprite, the green dot touches the blue gate, we switch to the background with the red gate.  This is done by using an “if” block,and a color sensor

the “if” block is in the control category

if block

and the color sensor is in the sensing category

touching color

our block is going to look like this

begining of needed script

This tells us that when the green flag is clicked and we’re playing the game, we begin at the beginning position    x=0    y=-165

and, anytime during the game (that’s what the forever loop says)

if we touch the color blue, we broad cast stage 2

we haven’t used the broadcast block yet

you find it in the control category

finding broadcast

you are going to have to use the broadcast block, select new, and type stage 2 to create the signal

new broadcast

So anytime the dot touches royal blue, broadcasts stage 2

Now, when stage 2 is broadcast, we need to create a script in the stage that receives the broadcast and switches to stage 2

So you write this script for the stage, not for the sprite

recieving stage 2

(The receive block is in the control category, the switch background block is in the looks category)

Now you have to make a switch that takes you from stage two back to stage 1

once you’ve done that your sprite script should look a little like this

back and forth

and you should have two scripts for the stage that look like this stage scripts

You’re almost there.  At this point the game should work like this

beginnig maze

What’s wrong with it?

When we switch screens we want the spite to be close to the door

So we have to tell the program to move the sprite to that location using a “go to” command in the motion category, at each screen change

You can move your cursor over the screen to find the x and y coordinate for any point, and enter the desired coordinates into the go to block

it should end up looking like this

ading go to comand

and your game should work like this

beginnig maze 

Now you can add a command that sends you back to the beginning when you wandered of  the path

If touching black, broadcast stage 1, go to (initial position)  When you do this you are going to need to put some wait time into you switches between stages or it will take you to the beginning every time you try to go through a gate.

finished block

and here’s how the completed color gate should work

beginnig maze

Now you know everything you need to to make a maze, assuming you can figure out how to import pictures for dead ends and a winner screen

Enemy sprites that disappear when you hit them with any of your projectile sprites

After you have made multiple projectile sprites, and used a variable to control the order in which they shoot, allowing for a rapid fire action, you may discover another problem.

When you play this game, you’ll see that only every third ball counts as a hit.

simple shooting game

This is because the target sprites are only programmed to hide when touching ball 1

hide if touching ball

you need to us an “or statement” or more specifically two nested “or statements” which you find under operators

put two or statements together so they look like this

nested or statements

Then you need to insert every projectile sprite into the blanks

Here’s an example from the turret game you saw on Friday

The red enemy sprites need to be able to be eliminated by projectile sprites “sprite68” or “sprite69” or “sprite70″ or sprite71”

bullet sprites

 

so each enemy sprite requires a script that looks something like this

 

disjunction