EGR 115 Introduction to Computing for Engineers Designing The Battleship Game in MATLAB Monday 22 Sept 2014 EGR 115 Introduction to Computing for Engineers.

Slides:



Advertisements
Similar presentations
Introduction to Programming using Matlab Session 2 P DuffourJan 2008.
Advertisements

COMP 116: Introduction to Scientific Programming Lecture 37: Final Review.
M AT L AB Programming: scripts & functions. Scripts It is possible to achieve a lot simply by executing one command at a time on the command line (even.
Input and Output ENGR 1181 MATLAB 5. Input and Output In The Real World Script files (which provide outputs given inputs) are important tools in MATLAB.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 20P. 1Winter Quarter Propulsion Lab with MATLAB Lecture 20.
Chapter 1 - An Introduction to Computers and Problem Solving
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 19P. 1Winter Quarter MATLAB: Script and.
Computer Science in Practice This course is an introduction to problems (and solutions) that arise in applied fields of computer science such as machine.
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
Excel Battleship.
ME457 Mechatronic System Modeling MICHIGAN STATE UNIVERSITY Matlab® refresher Your objective: to dominate! My objective: to help you dominate!
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Java Programming, 3e Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
Lecture 1: Introduction Lecture series based on the text: Essential MATLAB for Engineers and Scientists By Hahn & Valentine
MATLAB and SimulinkLecture 11 To days Outline  Introduction  MATLAB Desktop  Basic Features  Branching Statements  Loops  Script file / Commando.
Lecture 4 MATLAB Windows Arithmetic Operators Maintenance Functions
Introduction to MATLAB. Windows in MATLAB Command Window – where you enter data, run MATLAB code, and display results Command History - displays a log.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
1 Agenda – 9/25/2013/ Wednesday Howard J Rattliff, Jr. – Principles of Technology - Course #
A Brief Introduction to Matlab Laila Guessous Dept. of Mechanical Engineering Oakland University.
1 Agenda – 9/23/2013/ Monday Howard J Rattliff, Jr. – Principles of Technology - Course #
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Advanced Topics- Functions Introduction to MATLAB 7 Engineering 161.
Structured Programming: Debugging and Practice by the end of this class you should be able to: debug a program using echo printing debug a program using.
Introduction to Engineering MATLAB – 7 Script Files - 2 Agenda Script files continued.
Introduction to Engineering MATLAB - 13 Agenda Conditional statements  If – end  If – else – end  if – elseif – else - end.
EGR 115 Introduction to Computing for Engineers Introduction to MATLAB Friday 29 August 2014 EGR 115 Introduction to Computing for Engineers.
EGR 115 Introduction to Computing for Engineers User-Defined Functions1 – Part 1 Wednesday 22 Oct 2014 EGR 115 Introduction to Computing for Engineers.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 2: Sub-Arrays Friday 05 Sept 2014 EGR 115 Introduction to Computing for Engineers.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 1 Monday 29 Sept 2014 EGR 115 Introduction to Computing for Engineers.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 3: Array Operations Monday 08 Sept 2014 EGR 115 Introduction to Computing for Engineers.
ENG 1181 College of Engineering Engineering Education Innovation Center 1 Script File Input – Output : Chapter 4 PLEASE HAVE STUDENTS START MATLAB NOW.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 6: Debugging in MATLAB Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers.
Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal.
Structured Programming II: If Statements By the end of this class you should be able to: implement branching in a program describe and use an “if” statement.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 5: Applications – Vector Math Friday 12 Sept 2014 EGR 115 Introduction to Computing for Engineers.
Introduction to Engineering MATLAB – 4 Arrays Agenda Creating arrays of numbers  Vectors: 1-D Arrays  Arrays: 2-D Arrays Array Addressing Strings & String.
1 Lecture 4 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 1: Variables & Arrays Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers.
The Hashemite University Computer Engineering Department
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
Warship C++: An entity of Battleship
EGR 115 Introduction to Computing for Engineers Graphical User Interface Design in MATLAB - Part 2 Monday 24 Nov 2014 EGR 115 Introduction to Computing.
The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development Lecture 2 Debugging,
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 20P. 1Winter Quarter Propulsion Lab with.
EGR 115 Introduction to Computing for Engineers Loops and Vectorization – Part 1 Monday 13 Oct 2014 EGR 115 Introduction to Computing for Engineers.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 4 Monday 06 Oct 2014 EGR 115 Introduction to Computing for Engineers.
PHP Form Processing * referenced from
EGR 115 Introduction to Computing for Engineers Loops and Vectorization – Part 3 Friday 17 Oct 2014 EGR 115 Introduction to Computing for Engineers.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
Outline of Script Import Modules Setup Workspace Environment and Assign Data Path Variables Summary of Script Title and Author Info.
EGR 115 Introduction to Computing for Engineers
MATLAB – More Script Files
Introduction to Matlab
Lecture: MATLAB Chapter 1 Introduction
Introduction to MATLAB
EGR 115 Introduction to Computing for Engineers
EGR 115 Introduction to Computing for Engineers
MATLAB Introduction Dr. Theodore Cleveland University of Houston
Scripts & Functions Scripts and functions are contained in .m-files
Introduction To Matlab Class 1
Lecture 1: Introduction
Advanced Data Import & Export Jeff Henrikson
Battleship
funCTIONs and Data Import/Export
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Introduction to MATLAB
‘If’ statements, relational operators, and logical operators
Using Script Files and Managing Data
Your objective: to dominate! My objective: to help you dominate!
Presentation transcript:

EGR 115 Introduction to Computing for Engineers Designing The Battleship Game in MATLAB Monday 22 Sept 2014 EGR 115 Introduction to Computing for Engineers

Lecture Outline Monday 22 Sept 2014 EGR 115 Introduction to Computing for Engineers Designing The Battleship Game in MATLAB Grid Occupancy Legend: 0 = unoccupied 1 = occupied 9 = unknown Slide 2 of 14

Designing The Battleship Game in MATLAB Monday 22 Sept 2014 EGR 115 Introduction to Computing for Engineers Design the game of battleships using MATLAB  Two players on separate computers o Each player will display two 10  10 “grids”  One grid corresponding to your own ship locations (completely known = 0 or 1)  The other corresponding to your view of your opponents grid (initially all unknown = 9)  Own Grid: Each player will first deploy 5 ships (each a row or col vector) o One length five, o One length four, o Two length three, and o One length two Slide 3 of 14

Designing The Battleship Game in MATLAB Flowchart - Initialization Phase Monday 22 Sept 2014 EGR 115 Introduction to Computing for Engineers Start Initialize My grid My view of my opponents grid Save grids Player Opponent Initialization Phase Start Initialize My grid My view of my opponents grid Save grids Slide 4 of 14

Designing The Battleship Game in MATLAB Flowchart – Playing Phase Monday 22 Sept 2014 EGR 115 Introduction to Computing for Engineers Fire a salvo (request coordinates) Update actual opponents grid with a ‘0’ Update your copy of opponents grid with a ‘1’ Your Turn! Load your opponents grid Hit? yes Update your copy of opponents grid with a ‘0’ no Load your own gridSave your opponents grid Opponent’s Turn! Save Your Grids Slide 5 of 14

Designing The Battleship Game in MATLAB Monday 22 Sept 2014 EGR 115 Introduction to Computing for Engineers Task 0: Create an empty script file named “YourLastName_initialize_game.m”  Document the header of the file,  Add code to clear any variables in the workspace, and  Clear text from the command window % COURSE: EGR 115 Introduction to Computing for Engineers % DESCRIPTION: Initialize Battleship Game % AUTHOR: LastName, FirstName % DATE: 9/??/2014 % COMMENTS: Any comments which you may have. clear all; % Clear all of the variables in the workspace clc; % Clear text from the Command Window Slide 6 of 14

Designing The Battleship Game in MATLAB Initialization Phase Monday 22 Sept 2014 EGR 115 Introduction to Computing for Engineers TASK #1: Build the initial grids 1.Your grid: o Build a 10x10 matrix containing either a ‘1’ (occupied by a ship) or ‘0’ (unoccupied) in each cell. (5 ships)  Assign this matrix to the variable “my_grid” 2.Your opponents grid: o Build a 10x10 matrix containing a ‘9’ in every cell. The 9 corresponds to ‘unknown’  Assign this matrix to the variable “opponents_grid” 3.Assign your Name o my_name = 'YourLastName'; Slide 7 of 14

Designing The Battleship Game in MATLAB Initialization Phase Monday 22 Sept 2014 EGR 115 Introduction to Computing for Engineers An example of starting grids: What is the sum of the elements in my_grid? Slide 8 of 14

Designing The Battleship Game in MATLAB Initialization Phase Monday 22 Sept 2014 EGR 115 Introduction to Computing for Engineers TASK #2: Save the grids & name to a file  Save your three variables to a *.mat file named 'YourLastName'.mat o Note: Save this file to the course drive => T:\EGR115\Bruder o E.g., if your last name is “TBD” >> save T:\EGR115\Bruder\TBD.mat my_grid opponents_grid my_name o Saves all three variables from your workspace!! Check to see if you have created a YourLastName.mat file on the “T” drive. Slide 9 of 14

Designing The Battleship Game in MATLAB Monday 22 Sept 2014 EGR 115 Introduction to Computing for Engineers Task 3: Create the logic & Play the Game  Create a second script file named “YourLastName_battleship_game.m”  Look on the T-drive to select an opponent o Preferably the person sitting next to you o He or she should select you as their opponent  “Hard code” the name of your opponent >> my_opponent = 'TBD';  Load your opponents *.mat file >> opponents_filename = ['T:\EGR115\Bru… >>load(opponents_filename) Slide 10 of 14

Designing The Battleship Game in MATLAB Monday 22 Sept 2014 EGR 115 Introduction to Computing for Engineers  Store the sum of your opponent’s grid >> prior_sum = ????;  Select the row, col coordinates for firing a salvo >> row= input('Enter your Row Target Coordinate: '); >> col= input('Enter your Col Target Coordinate: ');  Write a zero to those coordinates in your opponents grid. >> my_grid(row, col) = 0;  Record the new sum. Did you hit a ship? >> new_sum = ???  Resave your opponents mat file. >> save(opponents_filename, ' my_grid ', ' opponents_grid ' ); Slide 11 of 14

Designing The Battleship Game in MATLAB Monday 22 Sept 2014 EGR 115 Introduction to Computing for Engineers  Load your own grid file >> load T:\EGR115\Bruder\???.mat  Update your view of your opponents grid with a ‘0’ at location (row, col): >> if (new_sum < prior_sum) % Hit!!! >> opponents_grid(row, col) = 1; >> disp('You hit a ship - Go again!!!'); >> else % Missed >> opponents_grid(row, col) = 0; >> disp('You missed – Opponent goes next!'); >> end Slide 12 of 14

Designing The Battleship Game in MATLAB Monday 22 Sept 2014 EGR 115 Introduction to Computing for Engineers  Save your grids >> save T:\EGR115\Bruder\???.mat my_grid opponents_grid  View your own grids >> my_grid >> opponents_grid Task 4:  Next move!! Slide 13 of 14

Next Lecture Monday 22 Sept 2014 EGR 115 Introduction to Computing for Engineers Debugging and Playing The Battleship Game in MATLAB Slide 14 of 14