20 Questions Assignment Intro James Wei Professor Peck March 19, 2014 Slides by James Wei.

Slides:



Advertisements
Similar presentations
Microsoft ® Office 2007 Training Security II: Turn off the Message Bar and run code safely P J Human Resources Pte Ltd presents:
Advertisements

How can Microsoft PowerPoint 2007 help you share information?
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Lets Play Catch! Keeping Score in Alice By Francine Wolfe Duke University Professor Susan Rodger May 2010.
Let’s Play! Instructions Team Score.
Python Magic Select a Lesson: Why Learn to Code? Basic Python Syntax
Scavenger Hunt Scavenger Hunt Scavenger Hunt PowerPoint SCAVENGER HUNT.
CS 206 Introduction to Computer Science II 01 / 21 / 2009 Instructor: Michael Eckmann.
CA 121 Intro to Programming Tariq Aziz and Kevin Jones GUI Programming in Visual Studio.NET Chapter 2 Tariq Aziz and Kevin Jones.
CS 206 Introduction to Computer Science II 09 / 22 / 2008 Instructor: Michael Eckmann.
Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 4: 1 CMT1000: Introduction to Programming Ed Currie Lecture 5a: Input and.
CS 206 Introduction to Computer Science II 02 / 11 / 2009 Instructor: Michael Eckmann.
My Workspace Profile. Using the course menu, click on Profile.
CIS101 Introduction to Computing Week 12 Spring 2004.
SE320: Introduction to Computer Games Week 8: Game Programming Gazihan Alankus.
A Trainer Bubble Production © Trainer Bubble.
Adding Controls to User Forms. Adding Controls A user form isn’t much use without some controls We’re going to add controls and write code for them Note.
CS 206 Introduction to Computer Science II 09 / 30 / 2009 Instructor: Michael Eckmann.
Platforms for Learning in Computer Science July 28, 2005.
Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.
South Dakota Library Network ALEPH XSL Creator © South Dakota Library Network, 2008 Modified for SDLN Version 16 Last Update: June 2008 South Dakota Library.
Microsoft ® Office 2007 Training Security II: Turn off the Message Bar and run code safely presents:
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Iteration. Adding CDs to Vic Stack In many of the programs you write, you would like to have a CD on the stack before the program runs. To do this, you.
 We are going to learn about programming in general…How to think logically and problem solve. The programming language we will use is Python. This is.
©Robomatter – Distribution or copying without permission is prohibited. 3B STEM Computer Science 1 ©Robomatter – Distribution or copying without permission.
Nonvisual Arrays and Recursion by Chris Brown under Prof. Susan Rodger Duke University June 2012.
 Make sure you are subscribed to announcements on Moodle.  Activity 4 will be due 48hrs after your lab ends.
Execute Workflow. Home page To execute a workflow navigate to My Workflows Page.
Salt Suite User Guide (Copyright Salt ).
Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.
CS 206 Introduction to Computer Science II 09 / 10 / 2009 Instructor: Michael Eckmann.
Quiz Me Tutorial. Introduction QuizMe is a trivia game (the example uses baseball) you can use as a template to build quizzes on any topic. The user steps.
Diagnostic Pathfinder for Instructors. Diagnostic Pathfinder Local File vs. Database Normal operations Expert operations Admin operations.
1 Advanced Issues on Classes Part 3 Reference variables (Tapestry pp.581, Horton 176 – 178) Const-reference variables (Horton 176 – 178) object sharing:
Chapter Two Creating a First Project in Visual Basic.
Code reading skills LEVEL GAME.  Skeleton has error messages.  Notice the red lines on right slider. Click… you’ll go to an error.  pieces = levels.getPieces();
Compsci 201 Midterm 2 Review Jimmy Wei Make sure you sign in on the paper being passed around!
Discussion 4. Labs public MyPoint(double xInit, double yInit ) { MyPoint p = new MyPoint(0, 0); } ClassProblem.java recursive java.lang.StackOverflowError.
PROGRAMMING In Lesson 2. STARTER ACTIVITY Complete the starter activity in your python folder – lesson 2 Now we will see how you got on and update your.
Making Python Pretty!. How to Use This Presentation… Download a copy of this presentation to your ‘Computing’ folder. Follow the code examples, and put.
Optimizing Your Computer To Run Faster Using Msconfig Technical Demonstration by: Chris Kilkenny.
11/25/2015Slide 1 Scripts are short programs that repeat sequences of SPSS commands. SPSS includes a computer language called Sax Basic for the creation.
XP Tutorial 8 Adding Interactivity with ActionScript.
Introduction Chapter 1 8/31 & 9/1 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
1 Quiz Template: Using the ‘ask user’ functions By Deborah Nelson Duke University Under the direction of Professor Susan Rodger July 2009.
Balancing the scales: Inequalities By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Nonvisual Arrays by Chris Brown under Prof. Susan Rodger Duke University June 2012.
Use Flowchart modeling to design and create an interactive quiz to be run on Powerpoint. Start Question Click to start the quiz Correct Incorrect, try.
You will need Dev C++ to help you with this project. If you do not already have this programming tool on your device you can visit
CS 206 Introduction to Computer Science II 10 / 02 / 2009 Instructor: Michael Eckmann.
HTML Overview Part 5 – JavaScript 1. Scripts 2  Scripts are used to add dynamic content to a web page.  Scripts consist of a list of commands that execute.
CHAPTER 14 Classes, Objects, and Games XNA Game Studio 4.0.
1 CS 106 Computing Fundamentals II Chapter 210 “Adding Controls to User Forms” Herbert G. Mayer, PSU CS Status 7/4/2013 Initial content copied verbatim.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Creating a GUI Class An example of class design using inheritance and interfaces.
Debugging tools in Flash CIS 126. Debugging Flash provides several tools for testing ActionScript in your SWF files. –The Debugger, lets you find errors.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
GCSE Computing: Programming GCSE Programming Remembering Python.
Perfecto Mobile Automation
Introduction to TouchDevelop Lesson 3 – Comments & Lists Created by S. Johnson
Using Forms and Form Elements In Visual Basic.NET.
By Melissa Dalis Professor Susan Rodger Duke University June 2011
CLICK HERE TO BEGIN THE GAME!!
File IO and Strings CIS 40 – Introduction to Programming in Python
Assignment 4 For this assignment refer to the notes on MATLAB from an MIT course that you can find here (or at the original website, lectures 14, 15, 16).
Introduction to TouchDevelop
Presentation transcript:

20 Questions Assignment Intro James Wei Professor Peck March 19, 2014 Slides by James Wei

Outline A look at the game of 20Q Classes of 20Q/Model-View design Implementation Reading a file Building a tree Playing the game Adding to the tree Saving a file

A look at 20Q We want to create a simplified version of 20Q Here are the features we implement: Can play 20Q Can create game trees from files Can improve tree when computer loses Can save improved game trees to files Sample playthrough

Classes of 20Q The classes of 20Q: GameMain – runs 20Q IAnimalModel – defines the methods and behaviors available to the model AnimalGameModel – implements IAnimalModel AnimalGameViewer – handles display logic AnimalNode – represents a node on the tree WebGameInfo – don’t worry about this one

Model-View Design Code is split between model and view You write the model Know how to interact with the view Nothing new here…

Model-View Design

Implementation -- Overview A few parts to this assignment: Reading a file: initialize() Building a tree: initialize() Playing the game: newGame(), processYesNo() Adding to the tree: addNewQuestion(), addNewKnowledge() Saving a file: write() Also consider while you’re coding—what instance variables do we need in the model?

Implementation -- Overview View methods you will need to use: void update(String) – displays text in main pane void showMessage(String) – displays text in message pane void showDialog(String) – displays a popup with the given text void getNewInfoLeaf() – tells view to ask for a new tree leaf void getDifferentiator() – tells view to ask for a new question node

Implementation -- Overview

Implementation – File I/O Reading a file Need to start by building the 20Q tree from a file Implement this method: void initialize(Scanner) initialize must do the following: Use the scanner to read the file line by line Use each line to build one node of the tree (in preorder) Strip the “#Q:” from each question before creating its internal node Call myView.setEnabled(true) Call newGame() at the very end to start a game

Implementation – File I/O

Your life will be much easier if you write a recursive helper method Some pseudo-code to get you started: private AnimalNode readHelper(Scanner s) { String line = s.nextLine(); if (line is leaf) { // create new leaf } // recursively create left (yes) subtree // recursively create right (no) subtree // create internal node from subtrees }

Implementation – File I/O Writing a file Need to be able to save trees to file Implement this method: void write(FileWriter) write must do the following: Write one line in the file for each node using the FileWriter write() method Write a preorder traversal Prepend “#Q:” for each question (internal node) Append “\n” to the end of each line to signify new line

Implementation -- Overview A few parts to this assignment: Reading a file: initialize() Building a tree: initialize() Playing the game: newGame(), processYesNo() Adding to the tree: processYesNo(), addNewQuestion(), addNewKnowledge() Saving a file: write()

Implementation – Playing 20Q Playing the game Begins when the player clicks “New Game”, or when the player loads a file, both of which call the model method newGame() First implement this method: void newGame() newGame must do the following: Set all instance variables to their initial state Ask the first question

Implementation – Playing 20Q Playing the game As you ask questions, the user responds with YES or NO by clicking a button in the view—those buttons call processYesNo(boolean) Next implement this method: void processYesNo(boolean) processYesNo must do the following: Update the current position on the game tree according to the user’s response Ask the next question – remember this varies depending on if we are at an internal or a leaf! Display a WIN or LOSE message if game has ended Few more things which we’ll discuss in the next part…

Implementation -- Overview A few parts to this assignment: Reading a file: initialize() Building a tree: initialize() Playing the game: newGame(), processYesNo() Adding to the tree: processYesNo(), addNewQuestion(), addNewKnowledge() Saving a file: write()

Implementation – Improving Improving the tree If the computer loses, it’s time to add to our tree! Go back and add to this method: void processYesNo(boolean) processYesNo must also do the following: Ask for the answer (what were you thinking of?) Call getNewInfoLeaf() – this will tell the view to popup a dialog box where the user can type a response

Implementation – Improving Improving the tree getNewInfoLeaf will call another model method Implement this method: void addNewQuestion(String) addNewQuestion must do the following: Display a list of all of the user’s answers up to that point, e.g. “You answered YES to, You answered NO to, etc.” Create a new leaf node for the correct answer Ask for a differentiator question Call getDifferentiator()

Implementation – Improving Improving the tree addNewQuestion will call the final method Implement this method: void addNewKnowledge(String) addNewKnowledge must do the following: Create a new internal node for the differentiator Set the differentiator’s YES answer to the existing, incorrect answer that the computer guessed, and the differentiator’s NO answer to the new, correct answer Add the internal node to the game tree Start a new game

Implementation – Improving Example – here’s the tree before playing: For reference ->

Implementation – Improving Example – here’s the tree after playing: For reference ->

Wrapping Up So you slept through this whole thing and now you just want to know what to do, eh? My recommended course of action: Implement file I/O, aka initialize() and write() Test by opening a file and saving it Implement newGame() and processYesNo(), leaving out improving the tree for now Play the game – try winning and losing Implement addNewQuestion() and addNewKnowledge() Test it – open a file, play several times (win/lose), improve the tree, play with new tree, save file

Good luck! I didn’t have time to find a witty tree or 20Q related cartoon… 