Please help in guiding me in the necessary steps i should take when tackling this assignment, there is a main.cpp given 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. 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. 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. 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. Please help in guiding me in the necessary steps i should take when tackling this assignment
Please help in guiding me in the necessary steps i should take when tackling this assignment, there is a main.cpp given
Objective: The main objective of this assignment is to assess students’ ability to apply the stepwise refinement process to develop a new
#include <iostream>
#include <cmath>
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
Solved in 3 steps with 1 images