1 Morse Code. Function and subfunctions

Similar documents
Project 2: Bejeweled

Sample Table. Columns. Column 1 Column 2 Column 3 Row 1 Cell 1 Cell 2 Cell 3 Row 2 Cell 4 Cell 5 Cell 6 Row 3 Cell 7 Cell 8 Cell 9.

SYSTEMS OF EQUATIONS AND MATRICES WITH THE TI-89. by Joseph Collison

Math Games For Skills and Concepts

Python Lists and Loops

MATLAB Programming. Problem 1: Sequential

The Richard Pate School. Draft Year 4 Scheme of Work for Scratch

SECTION 5: Finalizing Your Workbook

Create a Poster Using Publisher

paragraph(s). The bottom mark is for all following lines in that paragraph. The rectangle below the marks moves both marks at the same time.

Week 2 Practical Objects and Turtles

If you know exactly how you want your business forms to look and don t mind

BrainMaster Macromedia Flash Player

Lab 4.4 Secret Messages: Indexing, Arrays, and Iteration

0 Introduction to Data Analysis Using an Excel Spreadsheet

Excel Database Management

Colored Hats and Logic Puzzles

Umbraco v4 Editors Manual

Beginner s Matlab Tutorial

An Introduction to the Moodle Online Learning Platform

Has difficulty with counting reliably in tens from a multiple of ten

Excel Level Two. Introduction. Contents. Exploring Formulas. Entering Formulas

Publisher 2010 Cheat Sheet

Using Format Manager For Creating Format Files

Curve Fitting, Loglog Plots, and Semilog Plots 1

To add a data form to excel - you need to have the insert form table active - to make it active and add it to excel do the following:

Instructions for the ACER Laptops

20 CODE CHALLENGES. GCSE (9 1) Computer Science GCSE REFORM. February 2015

Windows, Menus, and Universal Document Shortcuts

Math 2524: Activity 3 (Excel and Matrices, continued) Fall 2002

Web Forms for Marketers 2.3 for Sitecore CMS 6.5 and

Intro to the Art of Computer Science

DOING MORE WITH WORD: MICROSOFT OFFICE 2010

Sudoku puzzles and how to solve them

MATLAB Functions. function [Out_1,Out_2,,Out_N] = function_name(in_1,in_2,,in_m)

3. Add and delete a cover page...7 Add a cover page... 7 Delete a cover page... 7

Moving from CS 61A Scheme to CS 61B Java

Using Microsoft Word. Working With Objects

(Refer Slide Time: 2:03)

Years after US Student to Teacher Ratio

Chapter 19: XML. Working with XML. About XML

Xylophone. What You ll Build

Introduction to Microsoft Word 2008

MatLab Basics. Now, press return to see what Matlab has stored as your variable x. You should see:

SMART board 101. SMART board 101 Training

Intellect Platform - The Workflow Engine Basic HelpDesk Troubleticket System - A102

BEGINNER S BRIDGE NOTES. Leigh Harding

OA3-10 Patterns in Addition Tables

GDP11 Student User s Guide. V. 1.7 December 2011

EVENT REGISTRATION UPLOADER DOCUMENTATION

Decision Logic: if, if else, switch, Boolean conditions and variables

CS1112 Spring 2014 Project 4. Objectives. 3 Pixelation for Identity Protection. due Thursday, 3/27, at 11pm

Select the Crow s Foot entity relationship diagram (ERD) option. Create the entities and define their components.

Excel Intermediate. Table of Contents UPPER, LOWER, PROPER AND TRIM...28

Excel Using Pivot Tables

Enhanced Formatting and Document Management. Word Unit 3 Module 3. Diocese of St. Petersburg Office of Training Training@dosp.

Getting Started with Excel Table of Contents

Working with Tables: How to use tables in OpenOffice.org Writer

Creating Maze Games. Game Maker Tutorial. The Game Idea. A Simple Start. Written by Mark Overmars

Navigating the Online Application

1. Define: (a) Variable, (b) Constant, (c) Type, (d) Enumerated Type, (e) Identifier.

Media Console Using Atlas Import Wizard

Adobe Conversion Settings in Word. Section 508: Why comply?

Introduction to Microsoft Excel 2010

Basic Excel Handbook

Solving the Rubik's Revenge (4x4x4) Home Pre-Solution Stuff Step 1 Step 2 Step 3 Solution Moves Lists

Assignment 2: Matchismo 2

Live Text at Centenary College Quick Tips Guide

Microsoft Excel 2013 Tutorial

Basic Website Creation. General Information about Websites

STATGRAPHICS Online. Statistical Analysis and Data Visualization System. Revised 6/21/2012. Copyright 2012 by StatPoint Technologies, Inc.

Web Ambassador Training on the CMS

COMMONWEALTH OF PA OFFICE OF ADMINISTRATION. Human Resource Development Division. SAP LSO-AE Desk Guide 15 T H J A N U A R Y,

Employer Portal User Guide Last Updated: October 2015

One pile, two pile, three piles

How to Make the Most of Excel Spreadsheets

VERSION 3.0 MAC USER GUIDE

JAVASCRIPT AND COOKIES

Introduction to scripting with Unity

Special Notice. Rules. Weiss Schwarz Comprehensive Rules ver Last updated: October 15 th Outline of the Game

Most laptops allow you to plug in a second monitor, which can be a TV screen or Projector I will refer to a monitor in this document.

OBJECTIVES. The BIG Idea. How will taking notes improve my performance in school and on the job? Taking Notes

Version of Barcode Toolbox adds support for Adobe Illustrator CS

ADDING DOCUMENTS TO A PROJECT. Create a a new internal document for the transcript: DOCUMENTS / NEW / NEW TEXT DOCUMENT.

City of De Pere. Halogen How To Guide

Current California Math Standards Balanced Equations

SAP Business Intelligence ( BI ) Financial and Budget Reporting. 7.0 Edition. (Best Seller At Least 43 copies Sold)

Algebra I Notes Relations and Functions Unit 03a

COMP 112 Assignment 1: HTTP Servers

Barcode Labels Feature Focus Series. POSitive For Windows

Council of Ontario Universities. COFO Online Reporting System. User Manual

Computer Programming In QBasic

Selecting Features by Attributes in ArcGIS Using the Query Builder

Getting Started in Tinkercad

Creating Basic Excel Formulas

Excel 2007 Basic knowledge

IE Class Web Design Curriculum

User s Manual CAREpoint EMS Workstation D-Scribe Reporting System

How to test and debug an ASP.NET application

Microsoft Excel 2010 Part 3: Advanced Excel

Transcription:

CS1132 Fall 2014 Assignment 2 due 11/20 11:59pm Adhere to the Code of Academic Integrity. You may discuss background issues and general strategies with others and seek help from course staff, but the implementations that you submit must be your own. In particular, you may discuss general ideas with others but you may not work out the detailed solutions with others. It is never OK for you to see or hear another student s code and it is never OK to copy code from published/internet sources. If you feel that you cannot complete the assignment on you own, seek help from the course staff. There are two parts to Assignment 2. art 1 is given below; art 2 and the submission instructions will appear in a separate document. Do not use the break or continue statement in any homework or test in CS1132. 1 Morse Code erhaps the most famous of all coding schemes is the Morse code, developed by Samuel Morse in 1832 for use with the telegraph system. The Morse code assigns a series of dots and dashes to each letter of the alphabet, each digit, and a few special characters (such as period, comma, colon, and semicolon). In sound-oriented systems, the dot represents a short sound and the dash represents a long sound. Other representations of dots and dashes are used with light-oriented systems and signal-flag systems. The international version of the Morse code appears in the file mosecode.txt. We will refer to this set of characters (the letters of the alphabet, numbers, and punctuation marks) and their Morse-equivalents as the Morse Table. (i) Function and subfunctions Implement a function and two subfunctions, as specified below, that together will allow us to translate between English and Morse Code. In the description below, English refers to the upper and lower case letters of the English alphabet, the digits (0 to 9), and the punctuation marks in an English paragraph. Function (main function): function morsecell = MorseCodeConverter(morseCodeFilename, inputfilename,... convertedfilename, flag) % Translate a passage from the plain text file named by inputfilename. % If flag is 1, inputfilename contains English text, which should be % translated to Morse code. If flag is 2, inputfilename contains Morse text, % which should be translated to English. Use one blank (space) between % Morse-coded letters in a word; use three blanks between Morse-coded % words. The translated text is stored in the plain text file named by % convertedfilename. The translation of each line of the input file should % appear as one line of the output file. Return a cell array that stores % the data of the Morse Table. % % INUT: % morsecodefilename: a string that names the textfile that stores the Morse % Table. The first line contains title text. Each of the remaining line % has this format: an English character, followed by a comma, followed % by the Morse coding of that character. % inputfilename: a string that names the input file % convertedfilename: a string that names the file that contains the % translated text. % flag: Either 1 or 2. 1 means convert from English to Morse Code; % 2 means convert from Morse Code to English. 1

% % OUTUT: % morsecell: an n-by-2 cell array where n is the number of English-Morse % pairings in the Morse Table. morsecell{k,1} stores the kth English % character in the Morse Table; morsecell{k,2} stores the Morse Code (a % string) of the kth character in the Morse Table. The main function must read the data file storing the Morse Table in creating the cell array do not hard code the Morse Table into the function. See section (ii) for the list of built-in functions allowed for file and string handling. The main function must make effective use of the following two subfunctions, which you will implement as specified: function morseword = EnglishtoMorse(engWord,morseCell) % Translate one English word to Morse code. % INUT: % engword is a string. It is a "word" in English, which is simply a string % of non-space characters. E.g., the string CS1132 is considered a % word. Treat any symbol not represented in the Morse Table as a space. % morsecell is the cell array that stores the data of the Morse Table. % OUTUT: % morseword is a string. It is the Morse translation of engword. function engword = MorsetoEnglish(morseWord, morsecell) % Translate one Morse code string representing a word to the corresponding % English word. % INUT: % morseword is a string. It is a word coded in Morse. Assume morseword to % be a correct Morse string (no unspecified symbols). % morsecell is the cell array that stores the data of the Morse Table. % OUTUT: % engword is a string. It is the English translation of morseword. (ii) Built-in functions Below is a list of useful built-in functions for handling characters, strings, and files. Use only these builtin functions for handling characters, strings, and files. You may not need all of them. You can of course still use general built-in functions not related specifically to strings and files, such as length, zeros, rem, etc. You can use: fopen, feof, fgetl, fclose strcmp, upper, isspace, isletter You must NOT use Matlab built-in functions find, strfind, findstr. (iii) Hints The provided file encodedfile.txt contains correct Morse Code that you can use for testing. encodedfile.txt is the Morse translation of the English text file whychoosematlab.txt. Suggestions for program development: 1. Start with reading the Morse Table to create the cell array in the main function. 2

2. Next, develop each of the subfunctions one at a time, as an independent function instead of a subfunction! This way you can test each function independently without involving the rest of the code and functions. 3. Continue working on the main function. It is best to isolate the file handling tasks. So read the input text file and store the data in a cell array store one line of text into one cell. Then iterate through the cell array to do the translation, storing the translated text in another cell array. Finally open the output file and write the cell array of translated text into the file. You can implement additional subfunctions as appropriate. 4. Don t forget to close each file that you open. 5. After testing your entire program (all functions) to make sure that it works, copy to MorseCodeConverter.m the other functions that should be subfunctions. Submit only MorseCodeConverter.m. 2 Graphics Fun! eg Solitaire eg solitaire is a one-player board game with the goal of removing all pegs except one from the game board. If a single peg remains on the board and it is in the middle, then you have won! First, take a look at the Wikipedia entry on eg Solitaire (http://en.wikipedia.org/wiki/eg_solitaire) and pay attention to the second section (Board) and third section (lay) to learn how the player makes a move on the board. You will implement a Matlab function for playing the game on the English board (not European board). Our game board looks like this at the beginning of the game: all the holes in the board are filled with pegs (marked ) except for the hole in the middle of the board. An empty hole is marked in blue. A valid move is always a vertical or horizontal jump of one peg over another into a hole on the board. The jumped over peg is removed from the board. Below we show an example sequence of two moves starting from the initial board configuration. The first move is to select a peg (marked yellow) and jump it east, removing the jumped over peg that was adjacent to the selected peg. The second move in this example selects a peg and jumps it south. Observe that every move results in one more free space (blue) on the board. Select a space to put the yellow peg Select a space to put the yellow peg In this final exercise in the course, we give you the freedom to structure the code as you see fit. You should define helper functions as needed to make your solution modular do not submit one long giant function. The helper functions, i.e., subfunctions, must be saved in the same file containing the main function for the game: egsolitaire.m. The function takes no input argument and does not return any value. Below we give the specifications and some hints: Initialize the game board as the English game baord as shown in the left-most figure above. Valid move: A valid move comprises the selection of a valid peg and the selection of a valid empty space to which the selected peg can jump. Only the four directions north, east, south, and west are used. A peg can be selected for a move if, from that peg looking in any one of the four directions the adjacent position is a peg and is immediately followed by a space. Given a valid selected peg color that peg yellow a space selection is valid if there is exactly one peg between the selected space and the yellow peg. A valid move removes the jumped over peg from the board and turns that position to an empty space (blue). Throughout the game, appropriate messages should be displayed above the game board (the title area of the figure) to tell the user what to do, as shown in the figures above. 3

The player clicks on one of the squares of the game board in order to select a peg or a space. Use the Matlab built-in function ginput to get the coordinates of the user s click: [a,b]=ginput(1) stores the x and y coordinates of a user s mouse click in a and b, respectively. Any invalid click should not change the game board and the game proceeds only after the user makes a valid click. Throughout the game, an empty space is a blue square, a peg selected for a move is a yellow square with a inside, and the remaining pegs on the board are each a white square with a inside. The board should be updated according to each valid move. End of game: The game must stop when no valid move is possible. If a single peg remains on the board and it is in the middle, then the player wins; otherwise the player loses. An appropriate message indicating whether the player has won or lost should be displayed above the game board. The interaction happens only in one figure window. Below are some highly recommended subfunctions to design and implement in order to decompose the problem. We give only a descriptive name and the general idea for each recommended subfunction. It is up to you to design and implement the details or modify the purpose of a subfunction. function gameboard = creategameboard(): gameboard is a 7-by-7 matrix representing the English game board. Use 1, 0, and -1 to represent a peg, an open space, and an invalid location. function [isvalid, freespace] = checkroposedeg(peglocation, gameboard): Is a userclicked square a valid peg selection for a move? This subfunction is helpful for both determining whether a peg selection is valid and for checking for the end-of-game condition. This function returns also the locations of the valid free space for the proposed move to make the check for the next user-clicked square, the proposed space for the selected peg, simple. function [peglocation,freespace] = chooseeg(gameboard): Allow user clicks until a valid peg is selected. aint the valid peg yellow. function spacelocation = choosespace(freespace): Allow user clicks until a valid space associated with the selected (yellow) peg is chosen. function gameboard = updateboard(gameboard,peglocation,spacelocation): The function name and parameters say everything that needs to be said. But remember to update both the matrix and the graphic. function isendofgame = endofgame(gameboard): Check that no valid move is possible. 3 Self-check list The following is a list of the minimum necessary criteria that your assignment must meet in order to be considered satisfactory. Failure to satisfy any of these conditions will result in an immediate request to resubmit your assignment. Save yourself and the graders time and effort by going over it before submitting your assignment for the first time. Although all these criteria are necessary, meeting all of them might still not be sufficient to consider your submission satisfactory. We cannot list everything that could be possibly wrong with any particular assignment! Comment your code! Make sure your functions are properly commented, regarding function purpose and input/output parameters. Suppress all unnecessary output by placing semicolons (;) appropriately. At the same time, make sure that all output that your program intentionally produces is formatted in a user-friendly way. Make sure your functions names are exactly the ones we have specified, including case. Check that the number and order of input and output parameters for each of the functions match exactly the specifications we have given. Test each one of your functions independently, whenever possible, or write short scripts to test them. 4

Check that your scripts do not crash (i.e., end unexpectedly with an error message) or run into infinite loops. Check your script several times in a row. Before each test run, type the commands clear all; close all; to delete all variables in the workspace and close all figure windows. 4 Submission instructions 1. Upload files MorseCodeConverter.m and egsolitaire.m to CMS in the submission area corresponding to Assignment 1a in CMS before the deadline. Late submission is accepted up to 24 hours after the deadline with a 10% penalty. 2. After grading: If you resubmit the assignment, upload your corrected files and be sure to select the Regrade Request option. 5