Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

, you will update your main function to sort the player moves and check them using your new functions. Perform the following steps: 1. In

, you will update your main function to sort the player moves and check them using your new functions. Perform the following steps: 1. In main.cpp, after the end of the main loop, sort the array of player moves using your mySort function. 2. Change your program to use your new sortedFindSmallest, sortedFindLargest, and binarySearch functions in place of the corresponding Assignment 1 functions. Your program should act the same. Hint: Make sure you have a test that the player played at least one move before calling the search functions. If you call them when the player hasn't played any moves, the sortedFindSmallest and sortedFindLargest functions will fail with assert errors. This makes sense because an array of no elements doesn't have a smallest (or largest) element. 3. Test your program with the same tests as for Assignment 1. They should still work #include
#include
#include
#include

#include "PlaceString.h"
#include "BoardSize.h"
#include "Search.h"

using namespace std;

void printEnd (const string moves_in[],
int move_count_in);



int main ()
{
cout << "Welcome to my Go game!" << endl;
string name;
while(name == "")
{
cout << "Enter your name: ";
getline(cin, name);
}
cout << "Hello " << name << ". You will play black." << endl;
cout << endl;

const int MOVE_COUNT_MAX = 1000;
string moves[MOVE_COUNT_MAX];
int move_count = 0;

bool playing = true;
while(playing)
{
cout << "Enter your move: ";
string move_string;
getline(cin, move_string);

if(move_string == "quit")
playing = false;
else if(move_string == "pass")
{
cout << "Black passed" << endl;
cout << "White passed" << endl;
}
else if(isPlaceStringWellFormed(move_string))
{
int row = placeStringToRow (move_string);
int column = placeStringToColumn(move_string);

if(isOnBoard(row, column))
{
cout << "Black played a stone at row " << row << ", column " << column << endl;

moves[move_count] = move_string;
move_count++;

cout << "White passed" << endl;
}
else
cout << "Forbidden: Place row " << row << ", column " << column << " is outside board" << endl;
}
else
cout << "\"" << move_string << "\" is ill-formed." << endl;
cout << endl;
}

cout << endl;
printEnd(moves, move_count);

cout << "Goodbye, " << name << "!" << endl;

return 0;
}

void printEnd (const string moves_in[],
int move_count_in)
{
cout << "Black played " << move_count_in << " stones total" << endl;
if(move_count_in > 0)
{
int smallest = unsortedFindSmallest(moves_in, move_count_in);
int largest = unsortedFindLargest (moves_in, move_count_in);
int index_K9 = linearSearch(moves_in, move_count_in, "K9");

cout << "Smallest place was \"" << moves_in[smallest] << "\" (index " << smallest << ")" << endl;
cout << "Largest place was \"" << moves_in[largest] << "\" (index " << largest << ")" << endl;
if(index_K9 == VALUE_NOT_FOUND)
cout << "Did not play at \"K9\"" << endl;
else
cout << "Did play at \"K9\"" << endl;
}
}
C++

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

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions