Week 9 - Monday.  What did we talk about last time?  Method practice  Lab 8.

Slides:



Advertisements
Similar presentations
Apostles Chess Club Lesson #4. Algebraic Chess Notation System The board is set up from white’s position. Black must look at the board from the white.
Advertisements

Lesson Four: More of the Same
L.O. Today you will learn how to play chess. How to Play Chess.
Chapter 7 Multidimensional Arrays. Defining a two dimensional array elementType[][] arrayName; // Java pro elementType arrayName[][]; // C++ alternate.
Arrays CS177 (Week 06). Announcements ● Project 2 due today ● Project 3 will be posted tomorrow.
Week 9: Methods 1.  We have written lots of code so far  It has all been inside of the main() method  What about a big program?  The main() method.
Week 6: Arrays 1.  Loops are great  But, without a way to talk about a group of values, we can’t get the full potential out of a loop  Enter: the array.
Arrays  Writing a program that uses a large amount of information.  Such as a list of 100 elements.  It is not practical to declare.
Chapter 9 Introduction to Arrays
CS305j Introduction to Computing Two Dimensional Arrays 1 Topic 22 Two Dimensional Arrays "Computer Science is a science of abstraction -creating the right.
CS1061 C Programmuing Lecture 12 Arrays A. O’Riordan, 2004.
Arrays. A problem with simple variables One variable holds one value –The value may change over time, but at any given time, a variable holds a single.
Java Unit 9: Arrays Declaring and Processing Arrays.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Arrays After a while. Remember for loops? for(int i = 0; i < 10; i++){ System.out.println(i); } -But what if we are unsure of how many cycles we need?
Panther Chess Club Sponsors: –Mr. Sergio Treviño (English, Room 408) –Mr. Felix Esquivel (Criminal Justice, Room 50) Meetings every Monday and Wednesday.
Lists in Python.
Week 2 - Monday.  What did we talk about last time?  Software development  Lab 1.
Apostles Chess Club Session Three. Chess Piece Symbols The symbols shown above are the ones most used when showing chess pieces in print or on the internet.
Interpret area models to form rectangular arrays.
HISTORY The problem was originally proposed in 1848 by the chess player Max Bezzel, and over the years, many mathematicians, including Gauss have worked.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
How to Play Chess By: John. Dedication I dedicate this project to my family because we all love chess.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
The Game of Life A simulation of "life". From simple rules, complex behavior arises Rules –A cell that is alive and has fewer than two live neighbors dies.
Topic 26 Two Dimensional Arrays "Computer Science is a science of abstraction -creating the right model for a problem and devising the appropriate mechanizable.
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}};
Term 2, 2011 Week 1. CONTENTS Problem-solving methodology Programming and scripting languages – Programming languages Programming languages – Scripting.
11 Adding Tomato Targets Session Session Overview  We now have a game which lets a player bounce a piece of cheese on a bread bat  Now we have.
M180: Data Structures & Algorithms in Java Arrays in Java Arab Open University 1.
Lec 20 More Arrays--Algorithms. Agenda Array algorithms (section 7.5 in the book) – An algorithm is a well-defined specification for solving a problem.
Two-Dimensional Arrays That’s 2-D Arrays Girls & Boys! One-Dimensional Arrays on Steroids!
February ,  2/16: Exam 1 Makeup Papers Available  2/20: Exam 2 Review Sheet Available in Lecture  2/27: Lab 2 due by 11:59:59pm  3/2:
Lesson 1 History of Chess Why We Teach Chess Goal of Chess.
A game based off of the esteemed classic By: Tadziu Kosiara.
Every chess master was once a beginner. Irving Chernev
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:
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
Week 8 - Friday.  What did we talk about last time?  Static methods.
CHESS Basics for Beginners. BOARD SET-UP The letters go across the board in front of you. “White on right!” Each player has a white square in their right.
A Levoy PowerPoint Presentation
Week 9 - Wednesday.  What did we talk about last time?  2D arrays  Queen attacking pawn example  Started Game of Life.
Arrays.
Java – An Object Oriented Language CS 307 Lecture Notes Lecture Weeks 5-6 Khalid Siddiqui.
Week 10 - Wednesday.  What did we talk about last time?  Method example  Roulette simulation  Types in Java.
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.
Week 6 - Friday.  What did we talk about last time?  Loop examples.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Chapter 9 Introduction to Arrays Fundamentals of Java.
Loops. About the Midterm Exam.. Exam on March 12 Monday (tentatively) Review on March 5.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
Some counting questions with the Rules of Chess. Chessboard and Chess pieces The game of chess is played on an 8-by-8 grid of alternately colored squares.
A basic tutorial for fundamental concepts
Chapter 11 Chi-Square Tests.
2-D Lists Taken from notes by Dr. Neil Moore
Week 9 - Monday CS 121.
Two-Dimensional Arrays
Learning Objective LO: We’re learning to understand when it is appropriate to use particular data types.
Lesson 2: Building Blocks of Programming
Topic 26 Two Dimensional Arrays
Chapter 11 Chi-Square Tests.
Chapter 26 Comparing Counts.
Rules to play chess. Chess is a played with 16 pieces: 8 pawns, 2 towers, 2 knights, 2 bishops, 1 queen and 1 king. Movements: Pawns: They only can move.
Chapter 11 Chi-Square Tests.
2-D Lists Taken from notes by Dr. Neil Moore
Week 7 - Monday CS 121.
Presentation transcript:

Week 9 - Monday

 What did we talk about last time?  Method practice  Lab 8

 Just as it is possible to make a one dimensional list out of a single data type, it is also possible to make a table out of one data type  We can extend the arrays you know to have two dimensions with very similar syntax

 To declare a two dimensional array, we just use two sets of square brackets ( [][] ):  Doing so creates a variable that can hold a 2D array of int s  As before, we still need to instantiate the array to have a specific size: int [][] table; table = new int[5][10];

 Like matrices, we usually visualize the first dimension as the rows and the second dimension as the columns Second Dimension First Dimension

 Let’s write a little code to put data into the table int [][] table = new int[5][10]; int label = 1; for( int i = 0; i < 5; i++ ) for( int j = 0; j < 10; j++ ) { table[i][j] = label; label++; } int [][] table = new int[5][10]; int label = 1; for( int i = 0; i < 5; i++ ) for( int j = 0; j < 10; j++ ) { table[i][j] = label; label++; }

 The result of that code is: Second Dimension First Dimension

 We could represent a chessboard as an 8 x 8 array of char s  Use the following encoding:  'P' = pawn  'N' = knight  'B' = bishop  'R' = rook  'Q' = queen  'K' = king  Use upper case characters for black pieces and lower case characters for white ones

 Imagine there is a pawn randomly set on the board and a queen of the opposite color on the board  Write a program to see if the queen can capture the pawn in the next move

 Find the row and column location of both the queen and the pawn  The pawn is in danger if: 1. The queen and the pawn have the same row 2. The queen and the pawn have the same column 3. If the absolute value of the differences between their rows and the absolute value of the differences between their columns are the same

 A cell is represented by a block in a grid  Each cell has 8 neighbors  Simple rules for a cell “coming to life” or “dying”: 1. A live cell with fewer than 2 live neighbors dies from loneliness 2. A live cell with more than 3 live neighbors dies from overcrowding 3. A live cell with exactly 2 or 3 neighbors keeps living 4. A dead cell with exactly 3 neighbors comes to life

 We can represent the grid of cells with a 2D array of boolean values  true means alive  false means dead  Each iteration, we draw the grid onto the screen with StdDraw  Black means alive  White means dead  Then, we update the grid to contain the new values  The grid stores the state of the game  We still have to use StdDraw to draw that state

 It doesn’t have to stop at 2 dimensions!  You can have 3 or more  Here’s an example with 3 dimensions: int[][][] rubiksCube = new int[3][3][3]; int count = 1; for( int i = 0; i < 3; i++ ) for( int j = 0; j < 3; j++ ) for( int k = 0; k < 3; k++ ) { rubiksCube[i][j][k] = count; count++; } int[][][] rubiksCube = new int[3][3][3]; int count = 1; for( int i = 0; i < 3; i++ ) for( int j = 0; j < 3; j++ ) for( int k = 0; k < 3; k++ ) { rubiksCube[i][j][k] = count; count++; }

 It looks like whatever you want it to  You can visualize it in 3D if you want  There are other techniques  It’s just a way to store data  It doesn’t actually look like anything inside the computer

 Sometimes you have data categorized in several different ways  For example, E-town might keep some statistics according to Year, Gender, and Race  0 – Freshman  1 – Sophomore  2 – Junior  3 – Senior  Perfect candidate for a 3D array  0 – Male  1 – Female  0 – African American  1 – Asian  2 – Caucasian  3 – Other

 Too many brackets  Too much stuff  Total size used is the product of the length of all the dimensions  100 x 100 x 100 = 1,000,000  Hard to visualize, hard to imagine  Up as high as 4 is sometimes useful  Don’t go beyond 2 on a regular basis

 Finish Game of Life  Overloading methods  More method practice

 Keep reading Chapter 8 of the textbook  Keep working on Project 3  Due this Friday