- Commanding a Turtle
- Adding New Commands
- Iteration & Animation
- Hierarchical Structure
- Procedure Inputs
- Operators & Expressions
- Defining Operators
- Words & Sentences
- User Interface Events
- What If? (Predicates)
- Local Variables
- Global Variables
- Word/Sentence Iteration
- Mastermind Project
- Turtles As Actors
- File Input/Output
- A Java Program
- What's a Class?
- Extending Existing Classes
- Turtle Graphics
- Control Flow
- User Interface Events
- What Is TG?
- TG Directives
- jLogo Primitives
- TG Editor
- Java Tables
- Example Programs
- Installation Notes
- December 13, 2008
- January 6, 2012
- March 15, 2013
- January 20, 2014
- February 13, 2014
- July 29, 2014
- January 18, 2016
- January 29, 2016
You now have all of the basics for need to write very sophisticated Logo programs, including those with graphical user interfaces.
In the last lesson you learned how you can manipulate the characters in a word and the words in a sentence. In your Hangman game, you worked with words. In the program you wrote which generated stories, you played with sentences. You will use what you've learned to write a game named Mastermind. It's a game that is very addicting - you'll love playing it once you're done, with the added satisfaction that you wrote the program yourself.
This lesson is in a new format. The challenge for you is to stop reading the lesson as soon as you can. Try to write the program on your own. When you need help, return to explore the links to hints I provide. When you complete your version of Mastermind, come back and follow links to stuff you didn't read ahead of time. Compare and think about how your program evolved, versus the one I write in this lesson.
An Assignment - Write the Game: Mastermind
Congratulations, you've just been hired as a programmer for a company that provides cell phones. Your first assignment is to write a game which will run on phones. Your company is getting ready to release a new phone. The new phone has a jLogo interpreter in it. You've been hired because you have done so well on your jLogo lessons.
To see what you need to do, here is a Java applet that implements an advanced version of Mastermind.
The object of Mastermind is to guess a secret code that the program has chosen. The computer randomly picks four colors from a pallet of six. In this version of Mastermind, you get to choose whether all four colors are unique or if duplicate colors are allowed in the secret code. It has been decided that you do not have to provide this functionality; only the unique-color secret codes will be provided.
To play the game, you select colors from the column of six choices, filling in the row of empty frames to construct your current guess.
Clicking the left mouse button on a color choice box, fills the current empty guess box. If you want to change the choices in your guess, clicking on the [Clear Color] button, clears your previous choice (the guess box to the left of the current one). When your guess is complete, clicking on the [Guess] button provides feedback, guess hints.
If the guess is correct, "You Win" is displayed. Otherwise, two hints are given as feedback:
- the number of correct choices in the guess (in black), and
- the number of choices that are a correct color, but are not in the proper position in the sequence (in grey).
If you didn't win, and there is still room on the display, another set of empty boxes is drawn for you to fill with your next guess.
When you run out of room for another guess, "Sorry! Answer was:" is displayed along with the the secret code.
Try out the applet. See what it does when you interact with it. The program you write should perform as similarly as possible with this one.
How to Proceed
This lesson is a bit different from those that have come before it. You do not have to continue reading; you know all of the jLogo primitive procedures needed to complete the Mastermind program. You know all of the programming techniques necessary to write it. How you go about it is up to you.
You are now an apprentice programmer. In the real world, you would have a mentor assigned to you, that you could go to when you are stuck. The following section is an attempt at providing the advice you would get if you had someone to ask questions.
My suggestion to you at this point is for you to try to write the program on your own.
If you complete it without reading any further, congratulations! Now read (or at least scan) some of the questions below and their answers. Compare how you approached the problem versus what is suggested.
If you get stuck, explore the questions below and their answers. The Mastermind program has a few of tricky parts to it, but you can get through them it if you've come this far in these lessons.
In any case, as a programmer, you have joined the ranks of the learners for life. In the current world of computing, things are changing fast.
Most importantly, treat the assignment like a puzzle and HAVE FUN SOLVING IT!
Virtual Mentor - FAQs
- Where do I start?
- How about some help with the layout of things on the display?
- How does the program know which guess box to fill?
- Can I use the Grid Toolkit for the Guess Boxes?
- How are the secret code and current guess data represented?
- How do I choose a secret code?
- How about some help with the inexact match count?
- Help me find the bug in my program!
I've got some things for you to try.
- What happens in your program when all four guess boxes have been filled in and you keep clicking on choices?
- What happens in your program when all four guess boxes are empty (the current box is the first) and you click on [ClearChoice]?
By testing these situations, you are exercising edge conditions.
In previous lessons you have learned a lot about the Logo programming language and tricks of the trade of programming (e.g., iteration, conditional execution, use of global variables to hold the properties of things). This lesson was unique. I left the complete process of writing the Mastermind game up to you. In a way, this lesson itself was a game. I've tried to make it a, a puzzle for you, a mystery to solve, and adventure.
Much of my code is spread across the answers to the FAQs. You were hardly left alone. This is the way things are these days for programmers. The Net is full of answers and search engines like Google help find them. I hope you learned something from this approach.
Go to the Table of Contents
On to Turtles As Actors