Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objective: The main objective of this assignment is to assess students ability to apply the stepwise refinement process to develop a new algorithm and carry

Objective: The main objective of this assignment is to assess students ability to apply the stepwise refinement process to develop a new algorithm and carry that through to the implementation of the program. Implementation must follow the top-down design approach, where the solution starts by describing the general functionality of a game. Next, more details are provided in successive steps to refine the implementation.

Problem Description: Assume you are hired by a game developing company to write a new computer game for kids. This company has decided to create a version of tricky triangles with a few different rules hoping that this new game will be more entertaining. If you are unfamiliar with the original game of tricky triangle, please learn how to play. Here is a link that includes the instructions: http://www.memory-improvement-tips.com/pegs.html This modified version of tricky triangles that you required to create is very much like the original game. The differences between the games are as follows: The new board has 25 positions instead of the original 15 At the beginning of the game, you are to remove 4 chosen pegs instead of the usual 1 On each turn, you must jump twice with a chosen piece. In the original game, each turn consists of just jumping once.

There are several steps that you will need to implement: First request the user to remove 4 pieces from the board, make sure that the selections are valid. Next, the user should be given a prompt to choose a peg that they would like to move; again, make sure that the selection is valid. Now that you know which piece will be moved, ask the user to select a position that is the result of a valid jump. Be sure to remove the jumped piece! Now repeat the action of jumping with that original piece. Remember that in this version of tricky triangles, to complete your turn, a given peg must jump two pieces. Here is a demonstration of your final game: You need to write the stepwise refinement prior to implementing your game so you can show the project manager what you plan to do. You can use the lecture notes to read more about stepwise refinement.

General Instructions: You are given a code that compiles with no errors. Functions to update the board are already provided, you will need to update the data structures that correspond to places on the board. You only need to implement the playGame() function using the step-wise refinement approach. Your job is to ask the player for their input, then check that they have made a valid decision and update the board using the given data structures.

Task: Your task is to apply the technique of stepwise refinement to design an algorithm for the playGame()function and play the game of modified tricky triangles. Your playGame() function should not break the provided working code, and it should interact with and call other given functions.

Help: This assignment requires development of the program using step-wise refinements to write the C++ program which implements the tricky triangle game as described. The game will be played by one human players (no computer player). Step-wise refinement is a technique used for writing programs. The process starts with a simple statement describing the main functionality of the program. Thereafter, the programmer repeatedly and gradually expands this statement into two or more statements. Next, the new statement(s) is/are repeatedly expanded into more detailed statement(s) with the goal of moving towards the final implementation of your program.

#include  #include  using namespace std; //check data structures to see if position is occupied by peg or not string checkRow(int row, int pos, bool row0[], bool row1[], bool row2[], bool row3[], bool row4[], bool row5[], bool row6[]) { if(row == 0) if(row0[pos]) return "o"; else return " "; if(row == 1) if(row1[pos]) return "o"; else return " "; if(row == 2) if(row2[pos]) return "o"; else return " "; if(row == 3) if(row3[pos]) return "o"; else return " "; if(row == 4) if(row4[pos]) return "o"; else return " "; if(row == 5) if(row5[pos]) return "o"; else return " "; if(row == 6) if(row6[pos]) return "o"; else return " "; } //print board void printBoard(bool row0[], bool row1[], bool row2[], bool row3[], bool row4[], bool row5[], bool row6[]) { cout << " /\\" << endl; cout << "6 / \\" << endl; cout << " / " << checkRow(6, 0, row0, row1, row2, row3, row4, row5, row6) << " \\" << endl; cout << " /______\\" << endl; cout << " /\\\\\\\\////\\" << endl; cout << "5 / \\\\\\/// \\" << endl; cout << " / " << checkRow(5, 0, row0, row1, row2, row3, row4, row5, row6) << " \\\\// " << checkRow(5, 1, row0, row1, row2, row3, row4, row5, row6) << " \\" << endl; cout << " /______\\/______\\" << endl; cout << " /\\\\\\\\////\\\\\\\\////\\" << endl; cout << "4 / \\\\\\/// \\\\\\/// \\" << endl; cout << " / " << checkRow(4, 0, row0, row1, row2, row3, row4, row5, row6) << " \\\\// " << checkRow(4, 1, row0, row1, row2, row3, row4, row5, row6) << " \\\\// " << checkRow(4, 2, row0, row1, row2, row3, row4, row5, row6) << " \\" << endl; cout << " /______\\/______\\/______\\" << endl; cout << " /\\\\\\\\////\\\\\\\\////\\\\\\\\////\\" << endl; cout << "3 / \\\\\\/// \\\\\\/// \\\\\\/// \\" << endl; cout << " / " << checkRow(3, 0, row0, row1, row2, row3, row4, row5, row6) << " \\\\// " << checkRow(3, 1, row0, row1, row2, row3, row4, row5, row6) << " \\\\// " << checkRow(3, 2, row0, row1, row2, row3, row4, row5, row6) << " \\\\// " << checkRow(3, 3, row0, row1, row2, row3, row4, row5, row6) << " \\" << endl; cout << " /______\\/______\\/______\\/______\\" << endl; cout << " /\\\\\\\\////\\\\\\\\////\\\\\\\\////\\\\\\\\////\\" << endl; cout << "2 / \\\\\\/// \\\\\\/// \\\\\\/// \\\\\\/// \\" << endl; cout << " / " << checkRow(2, 0, row0, row1, row2, row3, row4, row5, row6) << " \\\\// " << checkRow(2, 1, row0, row1, row2, row3, row4, row5, row6) << " \\\\// " << checkRow(2, 2, row0, row1, row2, row3, row4, row5, row6) << " \\\\// " << checkRow(2, 3, row0, row1, row2, row3, row4, row5, row6) << " \\\\// " << checkRow(2, 4, row0, row1, row2, row3, row4, row5, row6) << " \\" << endl; cout << " /______\\/______\\/______\\/______\\/______\\" << endl; cout << " /\\\\\\\\////\\\\\\\\////\\\\\\\\////\\\\\\\\////\\\\\\\\////\\" << endl; cout << "1 / \\\\\\/// \\\\\\/// \\\\\\/// \\\\\\/// \\\\\\/// \\" << endl; cout << " / " << checkRow(1, 0, row0, row1, row2, row3, row4, row5, row6) << " \\\\// " << checkRow(1, 1, row0, row1, row2, row3, row4, row5, row6) << " \\\\// " << checkRow(1, 2, row0, row1, row2, row3, row4, row5, row6) << " \\\\// " << checkRow(1, 3, row0, row1, row2, row3, row4, row5, row6) << " \\\\// " << checkRow(1, 4, row0, row1, row2, row3, row4, row5, row6) << " \\\\// " << checkRow(1, 5, row0, row1, row2, row3, row4, row5, row6) << " \\" << endl; cout << " /______\\/______\\/______\\/______\\/______\\/______\\" << endl; cout << " /\\\\\\\\////\\\\\\\\////\\\\\\\\////\\\\\\\\////\\\\\\\\////\\\\\\\\////\\" << endl; cout << "0 / \\\\\\/// \\\\\\/// \\\\\\/// \\\\\\/// \\\\\\/// \\\\\\/// \\" << endl; cout << " / " << checkRow(0, 0, row0, row1, row2, row3, row4, row5, row6) << " \\\\// " << checkRow(0, 1, row0, row1, row2, row3, row4, row5, row6) << " \\\\// " << checkRow(0, 2, row0, row1, row2, row3, row4, row5, row6) << " \\\\// " << checkRow(0, 3, row0, row1, row2, row3, row4, row5, row6) << " \\\\// " << checkRow(0, 4, row0, row1, row2, row3, row4, row5, row6) << " \\\\// " << checkRow(0, 5, row0, row1, row2, row3, row4, row5, row6) << " \\\\// " << checkRow(0, 6, row0, row1, row2, row3, row4, row5, row6) << " \\" << endl; cout << " /______\\/______\\/______\\/______\\/______\\/______\\/______\\" << endl; } //checks that selection is on the board (DOES NOT LOOK AT DATA STRUCTURE POSTIONS) bool validPegSelection(int row, int column) { if(row >= 0 && row <= 6) { //check valid column if(row == 0 && column >= 0 && column <= 6) return true; if(row == 1 && column >= 0 && column <= 5) return true; if(row == 2 && column >= 0 && column <= 4) return true; if(row == 3 && column >= 0 && column <= 3) return true; if(row == 4 && column >= 0 && column <= 2) return true; if(row == 5 && column >= 0 && column <= 1) return true; if(row == 6 && column == 0) return true; } return false; } //removes peg based on row and column passed to function void removePeg(int tempRow, int tempColumn, bool row0[], bool row1[], bool row2[], bool row3[], bool row4[], bool row5[], bool row6[]) { if(tempRow == 0 && row0[tempColumn]) row0[tempColumn] = false; if(tempRow == 1 && row1[tempColumn]) row1[tempColumn] = false; if(tempRow == 2 && row2[tempColumn]) row2[tempColumn] = false; if(tempRow == 3 && row3[tempColumn]) row3[tempColumn] = false; if(tempRow == 4 && row4[tempColumn]) row4[tempColumn] = false; if(tempRow == 5 && row5[tempColumn]) row5[tempColumn] = false; if(tempRow == 6 && row6[tempColumn]) row6[tempColumn] = false; } //move peg from row1,column1 to row2,column2 void movePeg(int tempRow1, int tempColumn1, int tempRow2, int tempColumn2, bool row0[], bool row1[], bool row2[], bool row3[], bool row4[], bool row5[], bool row6[]) { //delete first peg removePeg(tempRow1, tempColumn1, row0, row1, row2, row3, row4, row5, row6); //move peg if(tempRow2 == 0 && !row0[tempColumn2]) row0[tempColumn2] = true; if(tempRow2 == 1 && !row1[tempColumn2]) row1[tempColumn2] = true; if(tempRow2 == 2 && !row2[tempColumn2]) row2[tempColumn2] = true; if(tempRow2 == 3 && !row3[tempColumn2]) row3[tempColumn2] = true; if(tempRow2 == 4 && !row4[tempColumn2]) row4[tempColumn2] = true; if(tempRow2 == 5 && !row5[tempColumn2]) row5[tempColumn2] = true; if(tempRow2 == 6 && !row6[tempColumn2]) row6[tempColumn2] = true; } void playGame(bool row0[], bool row1[], bool row2[], bool row3[], bool row4[], bool row5[], bool row6[]) { } int main() { //initialize data structures bool row0[7] = {true,true,true,true,true,true,true}; bool row1[6] = {true,true,true,true,true,true}; bool row2[5] = {true,true,true,true,true}; bool row3[4] = {true,true,true,true}; bool row4[3] = {true,true,true}; bool row5[2] = {true,true}; bool row6[1] = {true}; printBoard(row0, row1, row2, row3, row4, row5, row6); playGame(row0, row1, row2, row3, row4, row5, row6); return 0; } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

More Books

Students also viewed these Databases questions