Let’s talk about strategies to win a game like noughts-and-crosses (tic-tac-toe), or to solve a puzzle like Sudoku. What is your strategy?
In 1996, a supercomputer named Deep Blue won a chess game against Garry Kasparov, the reigning chess champion at the time.
As a class, discuss the question: Was Deep Blue smarter than Kasparov?
Some prompts to help in the discussion:
Deep Blue used a brute force method to win chess. It used its powerful processor to test out millions of possible futures in the game, over and over, then to select the move most likely to result in a win. Many times, computer programs seem ‘smart’, but they just have access to more data than a human and can repeat a behaviour more quickly.
Long Zheng/flickr, CC BY-SA 2.0
Could a powerful enough computer predict every single possible outcome of a chess game, guaranteeing that it would know how to win at every stage? This video on ‘Shannon’s number’ reveals there are more games of chess than you might ever imagine.
What other approaches are computer scientists taking to make computers smarter at chess?
In this lesson, students will:
Begin by watching the following video introducing loops:
BEGIN For n from 1 to 5 Display ‘DEFCON ’, n End For END PROGRAM OUTPUT: DEFCON 1 DEFCON 2 DEFCON 3 DEFCON 4 DEFCON 5
BEGIN Repeat 4 times Display ‘May it rain,’ End Repeat Display ‘Whisper words of water, may it rain.’ END PROGRAM OUTPUT: May it rain, May it rain, May it rain, May it rain, Whisper words of water, may it rain.
For more on setting up and choosing a language, see Setting Up.
Modify your times table program to go all the way up to 20.
Next, add a second prompt to ask the user how high the times table should go. For example, if they enter 25, the times tables goes all the way up to 25.
Lastly, add a second table that shows the powers for the number. Here’s an example of the output:
5 to the power of 0 = 1
5 to the power of 1 = 5
5 to the power of 2 = 25
5 to the power of 3 = 125
These challenges use the skills covered so far. By writing or modifying their own programs, students have an opportunity to demonstrate Application and Creation.
1. Carefully examine the password check system in the flow chart below.
a. Convert the algorithm to pseudocode (structured English) first. You will need to use a while loop to handle the repetition, so it won’t be the exact same sequence as the flowchart.
BEGIN password ← “x1yG2k4!” Display “Enter the password” guess ← input from user While guess is not equal to password repeat Display “Try again” guess ← input from user End While Display “Access Granted!” END
2. Improve the password check program in Challenge 1 so that there is a limited number of guesses before the program ends. HINT: You’ll need to add a variable to keep track of the number of tries.
3. (Optional) Create a countdown, rather than counting up. The output of the program should be:
Beginning countdown 10 9 8 7 6 5 4 3 2 1 Blast off!
There are at least two ways you can do this, as shown in these solution codes. One way does not require any new knowledge about loops.
4. (Optional) Choose from the links below to find pre-made code with some arrays declared. The code also includes a simple program to display all the items in the colours array using a loop.
Add some code to display all the items in the months array using a loop.
Finally, add some code to find the sum of all the items in the numbers array.