Project 2: Bejeweled



Similar documents
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.

CISC 181 Project 3 Designing Classes for Bank Accounts

The resulting tile cannot merge with another tile again in the same move. When a 2048 tile is created, the player wins.

State of Michigan Data Exchange Gateway. Web-Interface Users Guide

FTP client Selection and Programming

CmpSci 187: Programming with Data Structures Spring 2015

PA2: Word Cloud (100 Points)

Computer Literacy Syllabus Class time: Mondays 5:00 7:00 p.m. Class location: 955 W. Main Street, Mt. Vernon, KY 40456

Review of Hashing: Integer Keys

Simple File Input & Output

CS 103 Lab Linux and Virtual Machines

ASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters

5 Arrays and Pointers

Visual Basic Programming. An Introduction

Member Functions of the istream Class

Unit 11 Fractions and decimals

Basic Excel Handbook

Lexical Analysis and Scanning. Honors Compilers Feb 5 th 2001 Robert Dewar

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0

Ready, Set, Go! Math Games for Serious Minds

The Crescent Primary School Calculation Policy

Hypercosm. Studio.

Lab 1: Introduction to C, ASCII ART and the Linux Command Line Environment

Introduction to Programming System Design. CSCI 455x (4 Units)

An Incomplete C++ Primer. University of Wyoming MA 5310

Pizza. Pizza with Everything Identifying & Estimating Fractions up to 1. Serves 2-4 players / Grades 3+ (Includes a variation for Grades 1+)

CS170 Lab 11 Abstract Data Types & Objects

A Brief Introduction to MySQL

csce4313 Programming Languages Scanner (pass/fail)

1 Description of The Simpletron

HOW TO CREATE AN HTML5 JEOPARDY- STYLE GAME IN CAPTIVATE

Arrays. number: Motivation. Prof. Stewart Weiss. Software Design Lecture Notes Arrays

How to Configure and Use the Moodle Grade Book

Iteration CHAPTER 6. Topic Summary

arrays C Programming Language - Arrays

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science

State of Illinois Web Content Management (WCM) Guide For SharePoint 2010 Content Editors. 11/6/2014 State of Illinois Bill Seagle

Getting Started with Excel Table of Contents

Software Requirement Specification (SRS) for Personal Investment Management System (PIMS)

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

J a v a Quiz (Unit 3, Test 0 Practice)

SQLITE C/C++ TUTORIAL

7-1. This chapter explains how to set and use Event Log Overview Event Log Management Creating a New Event Log...

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c

Sample CSE8A midterm Multiple Choice (circle one)

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, Introduction 1. 2 Invoking Shell Scripts 2

Tutorial on C Language Programming

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

Comp151. Definitions & Declarations

Study Skills. Multiple Choice Tests & Exams. Mount Allison University

Before you can use the Duke Ambient environment to start working on your projects or

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

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

User s Guide for the Texas Assessment Management System

C++FA 5.1 PRACTICE MID-TERM EXAM

Notes on Excel Forecasting Tools. Data Table, Scenario Manager, Goal Seek, & Solver

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

Excel 2007 Basic knowledge

INTRODUCTION TO EXCEL

ECDL / ICDL Spreadsheets Syllabus Version 5.0

CPSC 2800 Linux Hands-on Lab #7 on Linux Utilities. Project 7-1

Arrays in Java. Working with Arrays

Lecture 4: Writing shell scripts

Trading Integration for ViTrade

The Pointless Machine and Escape of the Clones

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

LEARNING MANAGEMENT SYSTEM USER GUIDE: TURNITIN GRADEMARK RUBRICS

Time Sheet Instructions

Boolean Expressions 1. In C++, the number 0 (zero) is considered to be false, all other numbers are true.

CSCI110: Examination information.

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

/* File: blkcopy.c. size_t n

A TOOL FOR DATA STRUCTURE VISUALIZATION AND USER-DEFINED ALGORITHM ANIMATION

This is great when speed is important and relatively few words are necessary, but Max would be a terrible language for writing a text editor.

CP Lab 2: Writing programs for simple arithmetic problems

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

The Technology Behind a Graphical User Interface for an Equational Reasoning Assistant

SPSS INSTRUCTION CHAPTER 1

IBM Operational Decision Manager Version 8 Release 5. Getting Started with Business Rules

Basic Firewall Lab. Lab Objectives. Configuration

CSC230 Getting Starting in C. Tyler Bletsch

UM Online Practice Programming Contest September 20, 2011

UTILITY INSTRUCTION MANUAL BNP-B2196 (ENG)

Easy Casino Profits. Congratulations!!

Calculator Practice: Computation with Fractions

The 2010 British Informatics Olympiad

Lecture 2 Mathcad Basics

Andreas Burghart 6 October 2014 v1.0

VB.NET Programming Fundamentals

Chapter 6. Linear Programming: The Simplex Method. Introduction to the Big M Method. Section 4 Maximization and Minimization with Problem Constraints

How to Write a Simple Makefile

Lab 4.4 Secret Messages: Indexing, Arrays, and Iteration

2 ASCII TABLE (DOS) 3 ASCII TABLE (Window)

IBM Emulation Mode Printer Commands

Mass . General Use

LaGuardia Community College Thomson Ave, Long Island City, New York Created by ISMD s Dept. Training Team. Overview

Transcription:

Project 2: Bejeweled Project Objective: Post: Tuesday March 26, 2013. Due: 11:59PM, Monday April 15, 2013 1. master the process of completing a programming project in UNIX. 2. get familiar with command line argument and file I/O. 3. practice with array and two dimensional array operations. 4. learn techniques on problem solving and efficient programming Project Description: In this project, you will design and implement the game Bejeweled (read more on its wiki page at http://en.wikipedia.org/wiki/bejeweled). You will have a 8x8 board full of different kind of gems. The goal of the game is to swap one gem with an adjacent gem to form a horizontal of vertical chain of three or more gems. Gems disappear when chains are formed and gems fall from the top to fill in gaps. Sometimes chain reactions, called cascades, are triggered, where chains are formed by the falling gems. Points are given when a chain of three or more gems is formed; bonus points are given when more than three identical gems are formed, when two chains are formed at the same time; or when cascades occur. Your goal in this project is to score as many points as you can within a given number of swaps. General Requirements: 1) Your program will run by typing the following command (assuming that the executable of your program is named a.out): a.out board swaps moves points board is the input file that contains all the gems that will appear on the game board during playtime, swaps is a non-negative integer indicating the number of swaps you are allowed to make, moves and points are the file names where you keep your gameplay and score. Your program should check the number of command argument, verify the value of swaps, and make sure the input and output files can be opened. If there is any error, print out an error message and terminate the execution. No need to write anything to the output file. You can run the sample executable (which will be posted in the GLUE public directory) for proper error messages. 2) The output file moves will record all the swaps you have made. The output file points records the details of the gameplay for each move/swap: the swap you have made, the points you have earned, and the game board after the move, as well as the total points. It is very important to produce output files with the required format. Your program will be tested and graded based on these files.

Game Rules 1) The game board The size of the game board will be 8x8. There will be 8 different kinds of gems, represented by A B C D E F G H. Following is an example of the game board 8 A B C D E F G H 7 A B C D E F G H 6 D A B A D E F G 5 A B F D F D G H 4 H A B C D E F G 3 B C D E F D H C 2 A B C D E F G H 1 A B C D E F G H where the numbers 1-8 in the first column and on the last row show the coordinates of the positions in the game board. For example, the E is positioned at (6,4). You will need to print out the numbers 1-8. Bold font and underlines are just to make it clear to see, you should not print them out. 2) How to make a swap You enter four (4) integers between 1 and 8 to indicate the two gems you want to swap. For example, if you want to swap the E and the D, you enter 6 4 5 4 You can only swap two gems that are horizontally or vertically adjacent to each other. When you enter invalid coordinates (numbers outside of the range of 1-8) or coordinates for gems that are not next to each other, your program should print out an error message and ask you to re-enter all the four (4) integers. 3) How to update the board on a swap i. Initially the game board from the input file does not contain any row or column with three consecutive identical gems (called chain). ii. If a swap results in one or more chains of three or more identical gems a. the chains will be moved away from the game board; b. you will earn points (see item 4) below for more details); c. gems on top of the empty positions will fall to fill those empty positions d. empty positions on top of the board will be filled by gems from the input file iii. When there are chains in the new game board, repeat the steps a-d above until there is no chains on the board. (And then wait for user s next move). 4) How points are awarded for chains of three or more i. 10 points a chain of 3 ii. 10 bonus points per extra gem in a chain iii. 10 bonus points per each gem shared in two chains iv. 10 bonus points per chain per round when cascade happens

Input and Game Board The input file gives the game board information. It has 2000 lines, each line has exactly eight (8) characters. The characters are chosen from A, B, C, D, E, F, G, and H, each letter represents a different type of gem. The first line are the gems on the bottom row of the board, the second line are the gems on the second row from bottom, and so on. On each line, the gems are from left to right. For example, the first 12 lines of the input file that gives the sample game board is (letters in bold font and underlined are examples on how to fill the game board, ignore them for now). Game board Input file 8 A B C D E F G H ABCDEFGH 7 A B C D E F G H ABCDEFGH 6 D A B A D E F G BCDEFDHC 5 A H F H F D G H HABCDEFG 4 H A B C D E F G AHFHFDGH 3 B C D E F D H C DABADEFG 2 A B C D E F G H ABCDEFGH 1 A B C D E F G H ABCDEFGH BDABCDEF DABCDEFG DABCDEFG ABCDEFGH When the chains are removed from the game board, we will fill the empty positions by gems from the input file. For example, when the second and third gems on the third row (C and D) are swapped, there will be a chain of 3 C s in the third column and should be removed (see the left game board below). The gems on top of this column (BFBCC) will fall to fill the empty slots and create three empty positions on the top of this column, which we will fill by getting gems from the third letters on lines 9-11 in the input file, which are ABB. This gives us the middle game board below. On this new game board we have another chain, 3 A s on the sixth row. This is what we called cascade. Similarly, we need to remove this chain; let BBD and BBD on row 7 and row 8 to fall into row 6 and row 7, respectively; then fill the three empty positions on the top row by DCB from the input file (as underlined in the input file above). Notice that D and B are from line 9 of the input file, but C is from line 12 (because the 3 letters ABB in this position on lines 9-11 were already taken). The right game board below is the final game board after this swap. 8 A B C D E F G H 7 A B C D E F G H 6 D A B A D E F G 5 A H F H F D G H 4 H A B C D E F G 3 B D E F D H C 2 A B D E F G H 1 A B D E F G H 8 A B B D E F G H 6 D A A A D E F G 5 A H C H F D G H 4 H A C C D E F G 8 A D C B E F G H 6 D B B D D E F G 5 A H C H F D G H 4 H A C C D E F G

Points and End of the Game Basic points: 10 points for a chain of exactly 3 identical gems, either horizontally or vertically. Bonus points: o 10 bonus points for extra gem in a chain. That is, 20 points for a chain of 4; 30 for a chain of 5; 40 points for a chain of 6; 50 points for a chain of 7; and 60 points for a chain of 8. o 10 bonus points for each gem shared in two chains. On the fraction of a game board shown on the right, swapping the underlined A with the C on its left will give a chain of 3 C s in one row and a chain of 4 C s in one column. This will be rewarded by 10 points for the row, 20 points for the column, and A H C H F D G H H C A C C E F G B D C E F D H C A B C D E F G H 10 more points for the fact that the two chains share one C in common. So a total of 40 points. o 10 bonus points for each chain in each round when cascade happens. In the middle game board above, the chain of 3 A s on the sixth row is formed when the first cascade occurs, so it will worth 20 points (10 for a chain of 3 and 10 for cascade bonus). If cascade happens for the second time, each chain formed in that round will have 20 bonus points. Chains formed in the third round of a cascade will get 30 bonus points, and so on. Points evaluation: when there are multiple chains formed by a swap or in the case of cascade, points (including bonus when applicable) will be given for each of the chains. Then you will need to remove all the gems that are involved in any of the chains, fill in the empty positions by new gems from the input file, and check whether another round of cascade occurs. The game ends when (i) the user has entered swaps number of valid swaps (recall that swaps is the maximal number of times the user can swap two gems), or (ii) all the gems from the input file have been filled in the game board and there are less than 3 gems left on the game board (no chance to form any chain of 3 or more). Output 1) Output file moves: this file records all the valid swaps that the user has made. There will be four (4) integers between 1 and 8 on each line, and a total number of swaps lines (recall that swaps is the number of swaps that the user can choose). For example, 6 4 5 4 2 3 3 3 4 4 4 5 2) Output file points: this file records the details of the gameplay for each move/swap and the total points when the game is over. For each valid swap, you need to print out the positions of the two gems that will be swapped, the total points that you earn as a result of this swap (including all the basic points and bonus points), the game board when there is no chain of three or more. It has the following format (check the same output files for spacing between the words):

swap: (2,3) and (3,3) points: 30 8 A D C B E F G H 6 D B B D D E F G 5 A H C H F D G H 4 H A C C D E F G swap: (8,4) and (8,5) points: 0 8 A D C B E F G H 6 D B B D D E F G 5 A H C H F D G G 4 H A C C D E F H swap: (8,3) and (7,3) points: Total points: Special Note 1) A sample executable file will be posted on the GLUE public directory together with an input file and some output files. a. Your program will be graded by comparing the output files generated by your program and the output files generated by the sample executable. So pay attention to the output format. b. The input file posted in the GLUE public directory will be used for grading. c. Other input files will also be used for grading and they will be posted one day before the project due date. d. Input error-free assumption: you can assume that the input file is error-free. i. the input files will follow exactly the format listed above ii. 2000 lines, 8 letters on each line, no other characters other than A-H iii. there is no chains of three or more in the initial board (first 8 lines of the input)

2) You will need to store all the input information in your program. The following two dimensional array might be the most convenient data structure for this purpose (but not necessarily the only one) char gems[8][2001]; where gems[0], for example, will store the first letters of each line in the input file and they will be used to fill the first column of the game board. Recall that you need a \0 at the end of each string so we declare the size of each gems[i] to be 2001, instead of 2000. You may also find it convenient to remove the gems in a chain by deleting them from the two dimensional array gems. Therefore, when gems[0], for example, becomes empty, you know that there are no gems in the first column of the game board. 3) Although it is not required, you may find it helpful to print out the positions of the gems that are in a chain of three or more. This will help you to test your program. 4) You should play with the same executable and your code for testing and debugging purpose. To encourage this, we will give up to 10 points as bonus. For the first input file posted in the GLUE public directory, use swaps =20 and enter moves the way you want in order to score more points. Send us the output file moves when you find a high score. Name this file moves.20. The moves that result in the top 10 high scores with get up to 10 bonus points. 5) A Question and Answer file will be posted under the GLUE public directory and updated frequently. Email notice will be sent to you only when important update is added. Project Requirements: 1. You must program using C under GLUE UNIX system and name your program p2.c. 2. Your program must be properly documented. 3. One day before the project due time, the input files that will be used to grade your project will be posted. IMPORTANT: Input files are critical for this project, use cp command to copy the input files from GLUE class public directory to your own directory for testing. 4. submit the project (p2.c and moves.20) by the following commend (remember to replace the???? by your own section number): submit 2013 spring enee 140???? 3 p2.c submit 2013 spring enee 140???? 3 moves.20 Grading Criteria: Correctness of the program 90% Good coding style and documentation 10% moves.20 bonus +10% Late submission penalty: within the first 24 hours -40% after the first 24 hours -100% program that does not compile under GLUE UNIX -100% wrong file name (other than p2.c) -100%

-------------------------------------------------------------------- - A programming template/outline just for your reference. It is by no means a complete program or defines all the necessary variables. You do not have to follow it. int main(int argc, char * argv[]) { declare variables that include at least the followings: FILE *IN, *OUT1, *OUT2; char gems[8][2001]; // information from the input file int moves, // number of moves a user can make count = 0, // counts the number of moves made cascade = 0, // number of rounds cascade happens points = 0, // total points for one swap total = 0; // total points for the game check argc == 5 or not; open files with safety check; read data from input file and store them in gems; while (count <= moves && number of gems left >= 3) { print out game board on screen; do{ prompt user for two gems to swap; read in user input; } while (input is invalid); points = 0; cascade = 0; moves ++; do{ update gems[][] based on user input or cascade; evaluate the game board to find all the chains; update points, cascade, gems[][], etc. } while (there is cascade); print out information about this swap to the output files; total += points; } print out total points to the output file; close all files; } return 0;