Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please help complete this program. it is to make the \"game over\" come out... #

ID: 3534571 • Letter: P

Question

please help complete this program. it is to make the "game over" come out...


#include "StdAfx.h" // needed by VisualC++
#include <iostream>

using namespace std;

const int N=3;



bool game_over(char **ptr)
{
return 0;
}


void initialize(char **ptr)
{
for(int j=0; j<N; j++)
for(int i=0; i<N; i++)
*(ptr[j]+i) = '.';
}

void display(char **ptr)
{
for(int j=0; j<N; j++) {
for(int i=0; i<N; i++)
cout << *(ptr[j]+i);
cout << endl;
}
}

void play(char **ptr, int player)
{
int row, col;
bool movenotvalid = 1;

while( movenotvalid ) {
cout << "Enter move: ";
cin >> row >> col;
if( row<0 || row>2 || col<0 || col>2 ) {
cout << "Invalid move. Please enter new move." << endl;
continue;
}
if( *(ptr[row]+col) == '.' )
movenotvalid = 0;
else
cout << "Invalid move. Please enter new move." << endl;
}

if(player)
*(ptr[row]+col) = 'O';
else
*(ptr[row]+col) = 'X';
}

int main()
{
int player = 0;

// create board
char **ptr = new char*[N];
for(int i=0; i<N; i++)
ptr[i] = new char[N];

// setup
initialize(ptr);
display(ptr);

// play
while( ! game_over(ptr) ) {
play(ptr, player);
display(ptr);
player = !player;
}

// delete board
for(int i=0; i<N; i++)
delete[] ptr[i];
delete[] ptr;
}



Explanation / Answer

when do you need this by?