CSE1301 Computer Programming: Lecture 27 Game Programming: Bingo.

Slides:



Advertisements
Similar presentations
Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
Advertisements

Lecture # 21 Chapter 6 Uptill 6.4. Type System A type system is a collection of rules for assigning type expressions to the various parts of the program.
Building Java Programs
Mutual Exclusion By Shiran Mizrahi. Critical Section class Counter { private int value = 1; //counter starts at one public Counter(int c) { //constructor.
Announcements Assignment #4 is due tonight. Last lab program is going to be assigned this Wednesday. ◦ A backtracking problem.
ECE 103 Engineering Programming Chapter 11 One Minute Synopsis Herbert G. Mayer, PSU CS Status 7/1/2014.
Top-Down Design CSC 161: The Art of Programming Prof. Henry Kautz 9/16/2009.
1 CSE1301 Computer Programming: Lecture 23 Algorithm Design (Part 1)
Taylor Cummins Andrea Conley Connect Four. History Published by Milton Bradley in Ages 7 and up. Also known as Captain’s Mistress, Four up, Plot.
12 Pontoon1May Pontoon program CE : Fundamental Programming Techniques.
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.
1 CSE1301 Computer Programming Lecture 26: Case Study.
BINGO! Topic Create Your Game Card You will need a blank piece of paper.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts and Debugging.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 8 Multidimensional.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
CSE 115 Week 12 March 31 – April 4, Announcements March 31 – Exam 8 March 31 – Exam 8 April 6 – Last day to turn in Lab 7 for a max grade of 100%,
1 CSE1301 Computer Programming: Lecture 15 Flowcharts, Testing and Debugging.
Lecture 5 of Computer Science II Arrays Instructor: Mr.Ahmed Al Astal.
Chapter 1 Program Design
1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.
CSE1301 Computer Programming: Revision. Topics Type of questions What do you need to know? About the exam Exam technique Sample questions.
CSE1301 Computer Programming: Lecture 29 Group Project: “Quabble”
CHAPTER 7: SORTING & SEARCHING Introduction to Computer Science Using Ruby (c) Ophir Frieder at al 2012.
1 CSE1301 Computer Programming: Lecture 25 Group Project: "Hunt the Wumpus”
Quadratic BINGO Directions: 1. This will be turned in so show your work neatly! NO TALKING ALLOWED!!! 2. Work each problem on your own paper. 3. Circle.
Scratch Internet- Open Chrome hit “Create” 1.
CS161 Topic #15 1 Today in CS161 Lecture #15 Practicing! Writing Programs to Practice Write a game program (1 player) of Mad Math Reuse the functions to.
Announcements.
11 Finding Winners Using Arrays Session 8.2. Session Overview  Find out how the C# language makes it easy to create an array that contains multiple values.
Question 10 What do I write?. Spreadsheet Make sure that you have got a printout of your spreadsheet - no spreadsheet, no marks!
Computer Programming for Engineers. Outline Tic-Tac-Toe (O-X Game) Drawing 3x3 grid Receiving the inputs Checking for a winner Taking turns between.
CSE1301 Computer Programming: Lecture 26 List Processing (Search)
By the end of this session you should be able to...
Two Dimensional Arrays
1 CSE1301 Computer Programming: Lecture 24 - Supplement Teddy’s Modules.
By Melissa Dalis Professor Susan Rodger Duke University June 2011 Multiplication Table.
© Copyright 2013 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 8 Multidimensional Arrays.
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
CSE1222: Lecture 7The Ohio State University1. logExample.cpp // example of log(k) for k = 1,2,..,8... int main() { cout
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
Advanced Computer Science Lesson 4: Reviewing Loops and Arrays Reading User Input.
Loops Wrap Up 10/21/13. Topics *Sentinel Loops *Nested Loops *Random Numbers.
Two-Dimensional Arrays That’s 2-D Arrays Girls & Boys! One-Dimensional Arrays on Steroids!
Georgia Institute of Technology More on Creating Classes part 2 Barb Ericson Georgia Institute of Technology Oct 2005.
Dr. Soha S. Zaghloul2 Let arr be an array of 20 integers. Write a complete program that first fills the array with up to 20 input values. Then, the program.
CS1010E Programming Methodology Tutorial 9 Pointers in Arrays & Structures C14,A15,D11,C08,C11,A02.
CS 139-Programming Fundamentals Lecture 11B - Arrays Adapted from a presentation by Dr. Rahman Fall 2014.
Introducing Arrays We will often need to store collections of information –a list of names to sort –a list of values to compute averages, standard deviation,
CS Class 15 Today  More practice with arrays  Introduction to Multi-dimensional arrays Announcements  Programming project #4 due 10/23 by midnight.
Problem Decomposition and Abstraction. Problem Solving Which one is easier:  Solving one big problem, or  Solving a number of small problems?
Computer Programming for Engineers
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
Hossain Shahriar Announcement and reminder! Tentative date for final exam shown below, please choose a time slot! December 19.
When constructing a two-dimensional array, specify how many rows and columns are needed: final int ROWS = 3; final int COLUMNS = 3; String[][] board =
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.
1 CSE1301 Computer Programming: Lecture 16 Flow Diagrams and Debugging.
MR. CRONE Generating Random Numbers. Random Numbers Many programs require the computer to generate random numbers Random numbers are used in many applications.
CS 115 Lecture 17 2-D Lists Taken from notes by Dr. Neil Moore.
Lecture 5 of Computer Science II
Possible exam questions with Scenarios
Sit-In Lab 1 Ob-CHESS-ion
Multidimensional Arrays
Loops.
Tic Tac Toe application
Bingo Example: Analysis
Bingo Example: Analysis
Programming Fundamental
Data Structures & Programming
Presentation transcript:

CSE1301 Computer Programming: Lecture 27 Game Programming: Bingo

Topics Problem Specification Top-down Design Structure Chart Random number generation Reading: D&D: 5.9

Bingo: The Board Cards have random numbers assigned to cells in the ranges shown (each number can appear at most once only.) The central card is marked initially

The Game of Bingo The game master calls out numbers 1-75 randomly. The player places a marker on top of a number that is called if it is on the card. The winner is the first player whose card has a straight line (row, column or main diagonal) filled with markers.

Winning Positions

Example Game Use 5x5 grid in your lecture notes "Randomly" fill in your card, with numbers from the correct ranges. Swap cards with your neighbour.

Bingo Program Requirements To play Bingo with ?? –N players and a game master (the program). Each player has ?? –a bingo card whose entries have been chosen randomly. The game master (program) - does what??? –calls out a number in the range 1-75 at random

Bingo Program Requirements Each player - does what? –covers a cells with a marker if it contains the number called by the game master; –done by the program. The game ends when ?? –one player has markers covering all cells in a row, column, or main diagonal; –checked by the program. At the end of the game ?? –The winner is announced. –The prize is awarded

Main Task - Algorithm fill N game boards randomly print out N game boards while no player has won yet { call out a random number update game boards for all players printout N game boards } announce winner

Main Task - Structure Chart

Data Structures - the Board How do we organise the board? –Hint: how will we access the board? Organise the board around columns and rows. int board [5][5]; /*if cell value is 0, then it is marked*/

Printing a Board (algorithm) FUNCTION print Board (board) { print header for each row { for each column { printcell for that row and column } } }

Printing a cell (code) const int MARKED=0; printcell(int cellValue) { if (cellValue == MARKED) { printf (" **") } else { printf ("%4d", cellValue); } }

Creating the Board FUNCTION Create Board { for each column { generate 5 random numbers in range place them in that column } mark the cell at row 3 in column 3 } Q. Anyone see a problem with this algorithm? A. Random numbers must be unique.

FUNCTION Create Board { for each column { for each row from 1 to 5 { generate a random number in range for that column while random number is a duplicate { generate another number } } place random number in the row } mark the cell at row 3 in column 3 }

Checking for duplicates Use an integer array which server as flags: int numberFlags[75]; All elements are initialised to 0. If a number i is chosen, flag the number as “used” by setting value of numberFlags[i-1] to 1.

Checking for duplicates IsDuplicate (number, flags array) { if (content of flags array at position (number -1) is equal to 1) { return true /* duplicate found */ } return false }

Generating a random number Use C function rand (). rand() generates an integer between 0 and RAND_MAX.

Generating a random number int randomNumberInRange (int min, int max) { return (rand () % (max - min + 1) + min); }

Example column range (min 16, max 30) Suppose rand() returns 403 max - min + 1 = % 15 = = 29 int randomNumberInRange (int min, int max) { return (rand () % (max - min + 1) + min); }

Data structure for players N players: an array with N elements. What is each element to be? struct playerRec { char name[NAMELENGTH]; int board[5][5]; }; typedef struct playerRec Player; Player players[N];

Unique Called Numbers How to ensure that the number has been called out at most once? A boolean array is a good solution. int calledNumbers [75]; int i; /* initialise all to false */ for (i=0; i<75; i++) { calledNumbers[i] = 0; }

Playing one round (algorithm) playOneRound { generate a random number between 1 and MaxBingoInt while the random number has already been called { generate a random number } mark the number as called }

Updating board (algorithm) updateBoard (board, number) { for each row and column { if cell at row, column is equal to number { set cell to MARKED } } }

Summary First, analyse the problem - structure chart - data structures and actions on data Construct modules - main program loop : top-down - I/O: bottom up Bingo program available on the web: