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

Write a function that takes as input the same input parameters as isValidMove()

ID: 3667840 • Letter: W

Question

Write a function that takes as input the same input parameters as isValidMove() and returns a "1* if it is a valid jump move (30pts). The function prototype is as follows: int isValidJump (int *board, int rl, int cl, int r2, int c2) f Again, notice that isValidJump() requires 5 parameters so you will need to use the stack pointer to pass parameters. Also, it should call isLegalPosition( for (r1,c1) and (r2,c2). If isLegalPosition() returns 0 for either row/column pair, then isValidJump() should return 0. Consider the board positon of figure 3: 01 2 3 4 5 6 7 Figure 3 for this board position, stlegoalump) should return the followingvalues gving the sample inputs: isValidiump(board,5,3,7,5) returns 1 isvalid/ump(board,5,3,3,1) returns 1 (kings can move backward) isvaidiump(board,5,3,6,3) returns 0 (because islega!Move() returns 0) isvalidJump(board,5,3,6,2) returns 0 (notice that only jumps are valid, not regular moves) isvalidiump(board,2,6,0,4) isvalidiump(board,1,5,3,7) returns 1 returns 0 (regular game pieces cannot move backward) ·

Explanation / Answer

/* Header files */
#define N 8

int isLegalPosition(int r1, int c1)
{
if(r1>=0 && r1 <=7 && c1>=0 && c1<=7) return 1;
else return 0;
}

int isValidMove(int *board, int r1, int c1, int r2, int c2)
{
if(isLegalPosition(r1,c1)==0 || isLegalPosition(r2,c2)==0)
return 0;
else{
/* Logic to check a valid move */
}
}

int isValidJump(int *board, int r1, int c1, int r2, int c2)
{
if(isLegalPosition(r1,c1)==0 || isLegalPosition(r2,c2)==0)
return 0;
else return 1;
}

int main()
{
/* Create a 8x8 board space and initialize all state to zero */
vector< vector<int> > board(8, vector<int>(8, 0));

/* Begin loop */
while(1)
{
/* Print the Board */
for(int i=0; i<N; i++)
{
for(int j=0; j<N; j++) cout << board[i][j] << " ";
   cout << endl;
}
  
/* Ask for row */
int rowNum=0, colNum=0;
cout << "Enter the row number(If you are done with all the cells on board, enter -1 to go out of loop)"; cin >> rowNum;
if(rowNum==-1)
{
cout << "Row number cannot be -1" << endl;
   break; // Get out of the while loop
}
cout << "Enter the column number "; cin >> colNum;
if(isLegalPosition(rowNum, colNum)==0)
{
cout << "Illegal Position found" << endl;
   continue; // Next iteration of while loop
}
else
{
cout << "Enter the value to be set at row-col"; cin >> value;
   board[rowNum][colNum]=value;
   continue;
}
} // while ends

/* Begin loop */
int r1=0, c1=0, r2=0, c2=0;
while(1)
{
cout << " Enter r1, c1, r2, c2 "; cin >> r1 >> c1 >> r2 >> c2;
cout << isValidMove(board,r1,c1,r2,c2);
cout << isValidJump(board,r1,c1,r2,c2);

cout << "Do you want to come out of the loop(y/Y)"; cin>>ch;
if(ch=='y' || ch=='Y') break;
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote