Frogs and Toads 3: FrogGame and FrogGameTester

Slides:



Advertisements
Similar presentations
Overloading Having more than one method with the same name is known as overloading. Overloading is legal in Java as long as each version takes different.
Advertisements

1 Todays Objectives Announcements Homework #1 is due next week Return Quiz 1 – answers are posted on the Yahoo discussion page site Basic Java Programming.
1-10 Introduction to Complex Numbers What is a complex number?
EXAMPLES (Arrays). Example Many engineering and scientific applications represent data as a 2-dimensional grid of values; say brightness of pixels in.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of CHAPTER 7: Recursion Java Software Structures: Designing and Using.
Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. It is common to use two nested loops when filling or searching: for.
TOPIC 12 CREATING CLASSES PART 1 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson,
Representing a Game Board In a game, we represent the action taking place using an array – In a very simple game, we use individual variables to represent.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
CS 177 Recitation Week 8 – Methods. Questions? Announcements  Project 3 milestone due next Thursday 10/22 9pm  Turn in with: turnin –c cs177=xxxx –p.
Arrays  Writing a program that uses a large amount of information.  Such as a list of 100 elements.  It is not practical to declare.
State-Space Representation Read Chapter 3. Searches you use MapQuest –road maps Google –documents CiteSeer –research documents.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
COMPSCI 101 Principles of Programming Lecture 27 - Using the Canvas widget to draw rows and columns of shapes.
Complex objects How might you design a class called NestedRects of graphical objects that look like this? Requirements for the constructor: –Like many.
Announcements.
Set Theory Topic 1: Logical Reasoning. I can determine and explain a strategy to solve a puzzle. I can verify a strategy to win a game. I can analyze.
Module 1 Algebra Factoring Trinomial Expressions.
CSE 143 Lecture 17 More Recursive Backtracking reading: "Appendix R" on course web site slides created by Marty Stepp and Hélène Martin
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
CSE 143 Lecture 17 More Recursive Backtracking reading: "Appendix R" on course web site slides created by Marty Stepp and Hélène Martin
Problem Solving using the Java Programming Language May 2010 Mok Heng Ngee Day 5: Arrays.
Review Recursion Call Stack. Two-dimensional Arrays Visualized as a grid int[][] grays = {{0, 20, 40}, {60, 80, 100}, {120, 140, 160}, {180, 200, 220}};
CSC 205 Programming II Lecture 18 The Eight Queens Problem.
CSE 501N Fall ‘09 12: Recursion and Recursive Algorithms 8 October 2009 Nick Leidenfrost.
1 1-6 Solving Equations by Adding & Subtracting Aim: Aim: How can we write and solve equations using addition and subtraction? CCSS: 6.EE.7.
Whiteboardmaths.com © 2008 All rights reserved
Data Structures Using C++ 2E1 Recursion and Backtracking: DFS Depth first search (a way to traverse a tree or graph) Backtracking can be regarded as a.
Sudoku Jordi Cortadella Department of Computer Science.
State-Space Representation General Problem Solving via simplification Read Chapter 3.
Chapter 5 Recursion. Basically, a method is recursive if it includes a call to itself.
Two-Dimensional Arrays That’s 2-D Arrays Girls & Boys! One-Dimensional Arrays on Steroids!
NestedLoops-Mody7-part51 Two-Dimensional Arrays and Nested Loops – part 5 Rotations Barb Ericson Georgia Institute of Technology May 2007.
Defining Classes I Part A. Class definitions OOP is the dominant programming methodology in use today. OOP is the dominant programming methodology in.
TIC TAC TOE. import java.util.Scanner; import java.util.Random; public class PlayTTT{ public static void main(String[]args){ Scanner reader = new Scanner(System.in);
Chapter 2 Collections. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter Objectives Define the concept and terminology related.
CS 100Lecture 191 CS100J Lecture 19 n Previous Lecture –Two dimensional arrays. –Reasonable size problem (a past assignment). –Stepwise refinement. –Use.
Lec 21 More Fun with Arrays: For Loops. Agenda Some backfill for Lab 20: – Using an array in an applet or class – array instance variables – using Math.random()
1 Recursion Recursion is a powerful programming technique that provides elegant solutions to certain problems. Chapter 11 focuses on explaining the underlying.
CS305j Introduction to Computing Classes II 1 Topic 24 Classes Part II "Object-oriented programming as it emerged in Simula 67 allows software structure.
1 Arrays of Arrays An array can represent a collection of any type of object - including other arrays! The world is filled with examples Monthly magazine:
How Do I Solve This Thing?. You are familiar with Sudoku puzzles. For this variation, place the integers 1 – 9 into each row or column such that the.
An introduction to arrays, continued. Recall from last time… public static void main ( String args[] ) { //define number of rooms final int N = 100; //define.
CSE 143 Lecture 18 More Recursive Backtracking slides created by Marty Stepp
A: A: double “4” A: “34” 4.
1 Introduction 1. Why Data Structures? 2. What AreData Structure? 3. Phases of Software Development 4. Precondition and Postcondition 5. Examples.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
TOWERS OF HANOI. : If n = 1, move disk 1 from pole 'A' to pole 'B'. else: 1.First, move n-1 disks from pole 'A' to pole 'C', using pole 'B' as.
CompSci Problem Solving: Sudoku  Rules of the Game Sudoku is played with a 9 by 9 "board" consisting of nine 3 by 3 sub-boards. The symbols 1 -
When constructing a two-dimensional array, specify how many rows and columns are needed: final int ROWS = 3; final int COLUMNS = 3; String[][] board =
Two Dimensional Arrays. Students will be able to: code algorithms to solve two- dimensional array problems. use 2-D arrays in programs. pass two-use 2-D.
Arrays What is an array… –A data structure that holds a set of homogenous elements (of the same type) –Associate a set of numbers with a single variable.
COMP 110: Spring Announcements Lab 7 was due today Binary Expression Assignment due Friday.
Section 2.3 Array-Based StringLog ADT Implementation.
Section 2.2 The StringLog ADT Specification. 2.2 The StringLog ADT Specification The primary responsibility of the StringLog ADT is to remember all the.
CSE 143 read: 12.5 Lecture 18: recursive backtracking.
A 2-D Array is a structure that storage space both vertically and horizontally. Thus, the array has both rows and columns. 2-D Arrays are used to create.
Frogs and Toads 4 FrogApp and FrogApplet
Java Software Structures: John Lewis & Joseph Chase
Boolean logic Taken from notes by Dr. Neil Moore
Chapter 12 Recursion (methods calling themselves)
Review Operation Bingo
2D Arrays.
Jordi Cortadella Department of Computer Science
Boolean logic Taken from notes by Dr. Neil Moore
CSE 143 Lecture 18 More Recursive Backtracking
CSE 143 Lecture 18 More Recursive Backtracking
CSC 205 – Java Programming II
Presentation transcript:

Frogs and Toads 3: FrogGame and FrogGameTester

Summary Pad class Pond class FrogGame class FrogGameTester class

Dealing with complexity The full has much variability: a variable game board size means we are forced to generalize everything this could be challenging as we are just learning many new skills beginners often freeze in these situations A Winning Strategy? SIMPLIFICATION!

How can we simplify Frogs And Toads And still have an interesting experience? Reduce the board size? – only do 3x3 Change the rules? Any frog or toad can move any direction into vacant square Like one of those tile puzzles, very easy to solve Still needs Solving simpler version gives insights into harder version

Represents: A single lily pad in our game board Instance variables: int startState, currentState; Methods Pad(int startState) Creates a new lily pad with a given initial state int getStatus() Returns current state of the lily pad (FROG, etc) boolean isSolved() Returns true if this lily pad is in the solved state void reset() Restores the lily pad to the start state void setStatus(int status) Changes the current state of the lilypad String toString() Returns the string representation of the lily pad. Pad class

Pond Class Represents: A 2D array of lily pads (Game board) Instance variables: int size; Pad [][] grid; Methods: Pond(int size) Creates a grid of lily pads with height and width = size Pad getPad(int row, int column) Returns Pad object at the row,col int getSize() Returns the width of the pond boolean isSolved() Indicates whether or not all lily pads solved void reset() Resets the pond to the state it was in originally String toString() Returns the current state of the pond as a String

FrogGame Represents: An active Frog Game Instance variables: int size; Pond gameBoard; Methods FrogGame(int size) Creates a new game with the given size Pond getPond() Returns the pond object (Game Board) boolean isSolved() Indicates whether puzzle has been solved. void moveAmphibian(int row, int column) Moves Frog/Toad at given location to Vacant pad (if possible). Making row, column the new Vacant pad boolean moveStillPossible() Indicates if legal move is still possible void print() Prints the game board (using the Pond object). int statusOfPad(int row, int column) returns status of the pad at row, col boolean validMove(int row, int column) Returns true if the given coordinates represent a Pad that has an amphibian that can make a legal move (hint: you may want to use the statusOfPad method to make your job easier).

FrogGameTester A demo app that tries out the different features of Frog Game. Just has a main method Lets look at some example scenarios using "original" move rules

FrogGame fg = new FrogGame(3); size 3 gameBoard F T O

Result of fg.moveAmphibian(2,1) size 3 gameBoard F T O

Result of fg.moveAmphibian(2,0) size 3 gameBoard F T O

Result of fg.isValid(1,0) true Result of fg.isValid(2,1) false size 3 gameBoard F T O