Question

In: Computer Science

I have a project due and am having problems compiling a program: The only program I...

I have a project due and am having problems compiling a program: The only program I have written is check.c everything else is given and correct. Can you modify check.c to simply print out the chessboard, in other words, to get it to compile by any means thank you. The only thing you have to modify again is check.c nothing else. Just get it to print something thanks.

program chess.c

#include
#include
#include "chess.h"


void get_valid_move(int mover)
{
int x_from, y_from, x_to, y_to;
int move_valid;

move_valid = INVALID_MOVE;
while (move_valid == INVALID_MOVE) {
if (mover == WHITE) {
printf("\nWHITE: ");
} else {
printf("\nBLACK: ");
}

printf("Please enter a move: ");
scanf("%d %d %d %d", &x_from, &y_from, &x_to, &y_to);
printf("\n");

/* check for termination */
if ((x_from == -1) && (y_from == -1) && (x_to == -1) && (y_to == -1))
exit(0);

/* check for validity of move */
move_valid = check_move(mover, x_from, y_from, x_to, y_to);

if (move_valid == VALID_MOVE) {
/* o.k., move is valid; make move */
the_board_piece[y_to][x_to] = the_board_piece[y_from][x_from];
the_board_color[y_to][x_to] = the_board_color[y_from][x_from];
the_board_piece[y_from][x_from] = EMPTY;
the_board_color[y_from][x_from] = EMPTY;
} else {
printf("INVALID MOVE. TRY AGAIN!!\n");
}
}
}

void move_loop()
{
int mover;

mover = WHITE;

while (TRUE) {
print_board();

get_valid_move(mover);

if (mover == WHITE)
mover = BLACK;
else
mover = WHITE;
}
}

int main()
{
move_loop();
}

chess.h

/* definitions for pieces */
#define NUM_PIECES 7
#define EMPTY 0
#define PAWN 1
#define KNIGHT 2
#define BISHOP 3
#define ROOK 4
#define QUEEN 5
#define KING 6

#define WHITE 1
#define BLACK 2

#define VALID_MOVE 1
#define INVALID_MOVE 2

#define TRUE 1
#define FALSE 0


/* board definition */
#define BOARD_SIZE 8
extern int the_board_piece[BOARD_SIZE][BOARD_SIZE];
extern int the_board_color[BOARD_SIZE][BOARD_SIZE];

/* main move processing */
void get_valid_move(int mover);
void move_loop();

/* board print routines */
void print_row_box();
void print_row_end();
void print_side_box();
void print_side_box_piece(int type, int color);
void print_row(int j);
void print_board();

/* required functions for move validity checking */
int check_move(int color, int x_from, int y_from, int x_to, int y_to);
int check_pawn_move(int color, int x_from, int y_from, int x_to, int y_to);
int check_knight_move(int color, int x_from, int y_from, int x_to, int y_to);
int check_bishop_move(int color, int x_from, int y_from, int x_to, int y_to);
int check_rook_move(int color, int x_from, int y_from, int x_to, int y_to);
int check_queen_move(int color, int x_from, int y_from, int x_to, int y_to);
int check_king_move(int color, int x_from, int y_from, int x_to, int y_to);

check.c


#include "chess.h"
int check_move(int color, int x_from, int y_from, int x_to, int y_to) {

// color: color of the player making the move

// board_piece_color[x][y] represents the color of the piece at board[x][y]

if (x_from < 0 || x_from > 7) {

// x_from not in range 0-7

return INVALID_MOVE;

}

else if (x_to < 0 || x_to > 7) {

// x_to not in range 0-7

return INVALID_MOVE;

}

else if (y_from < 0 || y_from > 7) {

// y_from not in range 0-7

return INVALID_MOVE;

}

else if (y_to < 0 || y_to > 7) {

// y_to not in range 0-7

return INVALID_MOVE;

}

else if (x_from == x_to && y_from == y_to) {

// from and to are the same position

return INVALID_MOVE;

}

else if (the_board_color[x_from][y_from] != color) {

// piece at from position does not match player's color

return INVALID_MOVE;

}

else if(the_board_color[x_to][y_to] == color)
{

// to position by occupied by piece of same color as player

return INVALID_MOVE;

}

return VALID_MOVE;

}

int check_move_knight(int color, int x_from, int y_from, int x_to, int y_to)
{
/* not neceessary
if(y_from != 0 && x_from != 1 || x_from != 6 && y_from != 0)
{
return INVALID_MOVE;
}
*/
if(x_to == )
{
  
}
else if (x_from == x_to && y_from == y_to) {

// from and to are the same position

return INVALID_MOVE;

}
  
else if (the_board_color[x_from][y_from] != color) {

// piece at from position does not match player's color

return INVALID_MOVE;

}
  
else if(the_board_color[x_to][y_to] == color)
{

// to position by occupied by piece of same color as player

return INVALID_MOVE;


}
return VALID_MOVE;
}

int check_move_king(int color, int x_from, int y_from, int x_to, int y_to)
{

if((x_from==0) && ((x_to==1)||(x_to==0)))

{

//starting from 0th position of column

if ((y_from==0) && ((y_to==1) || (y_to==0)))

{

return VALID_MOVE;

}

else return INVALID_MOVE;

return VALID_MOVE;

}

else if((y_from==0) && ((y_to==1)||(y_to==0)))

{

//starting from 0th position of row

if ((x_from==0) && ((x_to==1) || (x_to==0)))

{

return VALID_MOVE;

}

else return INVALID_MOVE;

return VALID_MOVE;

}

else if ((x_from==7) && (x_to==x_from+1))

{

//check condition for last column

return INVALID_MOVE;

}

else if ((y_from==7) && (y_to==y_from+1))

{

//check condition for last row

return INVALID_MOVE;

}

else if (((x_to==x_from + 1)&&(y_to==y_from)) || ((x_to==x_from)&&(y_to==y_from+1))||((x_to==x_from - 1)&&(y_to==y_from)) || ((x_to==x_from)&&(y_to==y_from-1)) || ((x_to==x_from + 1)&&(y_to==y_from+1))||((x_to==x_from + 1)&&(y_to==y_from-1))||((x_to==x_from - 1)&&(y_to==y_from-1))||((x_to==x_from 1 1)&&(y_to==y_from-1)))

{

//checking the king move in any eight directions by +1

return VALID_MOVE;

}
else if (x_from == x_to && y_from == y_to) {

// from and to are the same position

return INVALID_MOVE;

}
  
else if (the_board_color[x_from][y_from] != color) {

// piece at from position does not match player's color

return INVALID_MOVE;

return VALID_MOVE;
}
int check_move_rook(int color, int x_from, int y_from, int x_to, int y_to)
{
/* not neceessary
if(y_from != 0 && x_from != 0 || x_from != 7 && y_from != 0)
{
return INVALID_MOVE;
}
*/
//Movement along columns and rows
if(y_to == 0 && x_to <= 0 || x_to == 0 && y_to <= 0 || y_to == 0 && x_to >= 7 || x_to == 7 && y_to <= 0)
{
return INVALID_MOVE;
}
  
else if (x_from == x_to && y_from == y_to)
{
// from and to are the same position

return INVALID_MOVE;
}
  
else if (the_board_color[x_from][y_from] != color)
{

// piece at from position does not match player's color

return INVALID_MOVE;

}
  
else if(the_board_color[x_to][y_to] == color)
{

// to position by occupied by piece of same color as player

return INVALID_MOVE;
}
return VALID_MOVE;

}

int check_move_bishop(int color, int x_from, int y_from, int x_to, int y_to)
{
//Movement
if(x_from != 2 && y_from != 0 || x_from != 5 && y_from != 0)
{
return INVALID_MOVE;
}
else if()
{
//Movement diagnoal
return INVALID_MOVE;
}
else if (x_from == x_to && y_from == y_to) {

// from and to are the same position

return INVALID_MOVE;

}
  
else if (the_board_color[x_from][y_from] != color) {

// piece at from position does not match player's color

return INVALID_MOVE;

}
  
else if(the_board_color[x_to][y_to] == color)
{

// to position by occupied by piece of same color as player

return INVALID_MOVE;

}
return VALID_MOVE;
}

int check_queen_move(int color, int x_from, int y_from, int x_to, int y_to)
{
if()
{
  
}
else if (x_from == x_to && y_from == y_to) {

// from and to are the same position

return INVALID_MOVE;

}
  
else if (the_board_color[x_from][y_from] != color) {

// piece at from position does not match player's color

return INVALID_MOVE;

}
  
else if(the_board_color[x_to][y_to] == color)
{

// to position by occupied by piece of same color as player

return INVALID_MOVE;

}
return VALID_MOVE;
}

int check_pawn_move(int color, int x_from, int y_from, int x_to, int y_to)

{

if(y_from > 6 || x_from > 7 || x_to > 7 || y_to > 7 || y_from < 1 || x_from < 0 || x_to < 0 || y_to < 2)

{

return INVALID_MOVE;

}

else if((x_from-x_to) > 1 || (x_from-x_to) < -1)

{

return INVALID_MOVE;

}

else if((y_to-y_from) < 0 ||(y_to-y_from) > 2)

{

return INVALID_MOVE;

}

else if((y_to-y_from) == 2 && y_from != 1)

{

return INVALID_MOVE;

}

else if ((x_from-x_to) != 0 && the_board_color(x_to, y_to) != color)

{

return INVALID_MOVE;

}

else if ((x_from-x_to) == 0 && the_board_color(x_to, y_to) == color)

{

return INVALID_MOVE;

}


return VALID_MOVE;

}

board.c

#include
#include "chess.h"

int the_board_piece[BOARD_SIZE][BOARD_SIZE] =
{{ROOK, KNIGHT, BISHOP, QUEEN, KING, BISHOP, KNIGHT, ROOK},
{PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN},
{EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY},
{EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY},
{EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY},
{EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY},
{PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN},
{ROOK, KNIGHT, BISHOP, QUEEN, KING, BISHOP, KNIGHT, ROOK}};

int the_board_color[BOARD_SIZE][BOARD_SIZE] =
{{WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE},
{WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE},
{EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY},
{EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY},
{EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY},
{EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY},
{BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK},
{BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK}};

char pieces[NUM_PIECES] = {' ', 'P', 'N', 'B', 'R', 'Q', 'K'};


/******************** board print routines ********************/
void print_row_box()
{
printf("|----");
}

void print_row_end()
{
printf("|\n");
}

void print_side_box()
{
printf("| ");
}

void print_side_box_piece(int type, int color)
{
if (type == EMPTY) {
print_side_box();
} else {
printf("| %c%c ", ((color == WHITE) ? 'W' : 'B'), pieces[type]);
}
}

void print_row(int j)
{
int i;

for (i = 0; i < BOARD_SIZE; i++) {
print_row_box();
}
print_row_end();

for (i = 0; i < BOARD_SIZE; i++) {
print_side_box();
}
print_row_end();

for (i = 0; i < BOARD_SIZE; i++) {
print_side_box_piece(the_board_piece[j][i], the_board_color[j][i]);
}
print_row_end();

for (i = 0; i < BOARD_SIZE; i++) {
print_side_box();
}
print_row_end();
}

void print_board()
{
int j, i;

for (j = 0; j < BOARD_SIZE; j++) {
/* print one row of boxes */
print_row(j);
}

for (i = 0; i < BOARD_SIZE; i++) {
print_row_box();
}
print_row_end();
}

Solutions

Expert Solution

The code is corrected and made to print the Chess Board.

Use the following files names and you won't get the error.

main.c

#include <stdio.h>
#include <stdlib.h>
#include "chess.h"

void get_valid_move(int mover)
{
   int x_from, y_from, x_to, y_to;
   int move_valid;

   move_valid = INVALID_MOVE;
   while (move_valid == INVALID_MOVE) {
       if (mover == WHITE) {
           printf("\nWHITE: ");
       } else {
           printf("\nBLACK: ");
       }

       printf("Please enter a move: ");
       scanf("%d %d %d %d", &x_from, &y_from, &x_to, &y_to);
       printf("\n");

/* check for termination */
       if ((x_from == -1) && (y_from == -1) && (x_to == -1) && (y_to == -1))
           exit(0);

/* check for validity of move */
       move_valid = check_move(mover, x_from, y_from, x_to, y_to);

       if (move_valid == VALID_MOVE) {
/* o.k., move is valid; make move */
           the_board_piece[y_to][x_to] = the_board_piece[y_from][x_from];
           the_board_color[y_to][x_to] = the_board_color[y_from][x_from];
           the_board_piece[y_from][x_from] = EMPTY;
           the_board_color[y_from][x_from] = EMPTY;
       } else {
           printf("INVALID MOVE. TRY AGAIN!!\n");
       }
   }
}

void move_loop()
{
   int mover;

   mover = WHITE;

   while (TRUE) {
       print_board();

       get_valid_move(mover);

       if (mover == WHITE)
           mover = BLACK;
       else
           mover = WHITE;
   }
}

int main()
{
   move_loop();
}

chess.h

#ifndef CHESS_H
#define CHESS_H

#define NUM_PIECES 7
#define EMPTY 0
#define PAWN 1
#define KNIGHT 2
#define BISHOP 3
#define ROOK 4
#define QUEEN 5
#define KING 6

#define WHITE 1
#define BLACK 2

#define VALID_MOVE 1
#define INVALID_MOVE 2

#define TRUE 1
#define FALSE 0


/* board definition */
#define BOARD_SIZE 8
extern int the_board_piece[BOARD_SIZE][BOARD_SIZE];
extern int the_board_color[BOARD_SIZE][BOARD_SIZE];

/* main move processing */
void get_valid_move(int mover);
void move_loop();

/* board print routines */
void print_row_box();
void print_row_end();
void print_side_box();
void print_side_box_piece(int type, int color);
void print_row(int j);
void print_board();

/* required functions for move validity checking */
int check_move(int color, int x_from, int y_from, int x_to, int y_to);
int check_pawn_move(int color, int x_from, int y_from, int x_to, int y_to);
int check_knight_move(int color, int x_from, int y_from, int x_to, int y_to);
int check_bishop_move(int color, int x_from, int y_from, int x_to, int y_to);
int check_rook_move(int color, int x_from, int y_from, int x_to, int y_to);
int check_queen_move(int color, int x_from, int y_from, int x_to, int y_to);
int check_king_move(int color, int x_from, int y_from, int x_to, int y_to);

#endif

chess.c

#include <stdio.h>
#include "chess.h"


int the_board_piece[BOARD_SIZE][BOARD_SIZE] =
{{ROOK, KNIGHT, BISHOP, QUEEN, KING, BISHOP, KNIGHT, ROOK},
{PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN},
{EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY},
{EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY},
{EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY},
{EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY},
{PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN},
{ROOK, KNIGHT, BISHOP, QUEEN, KING, BISHOP, KNIGHT, ROOK}};

int the_board_color[BOARD_SIZE][BOARD_SIZE] =
{{WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE},
{WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE},
{EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY},
{EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY},
{EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY},
{EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY},
{BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK},
{BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK}};

char pieces[NUM_PIECES] = {' ', 'P', 'N', 'B', 'R', 'Q', 'K'};


/******************** board print routines ********************/
void print_row_box()
{
   printf("|----");
}

void print_row_end()
{
   printf("|\n");
}

void print_side_box()
{
   printf("| ");
}

void print_side_box_piece(int type, int color)
{
   if (type == EMPTY) {
       print_side_box();
   } else {
       printf("| %c%c ", ((color == WHITE) ? 'W' : 'B'), pieces[type]);
   }
}

void print_row(int j)
{
   int i;

   for (i = 0; i < BOARD_SIZE; i++) {
       print_row_box();
   }
   print_row_end();

   for (i = 0; i < BOARD_SIZE; i++) {
       print_side_box();
   }
   print_row_end();

   for (i = 0; i < BOARD_SIZE; i++) {
       print_side_box_piece(the_board_piece[j][i], the_board_color[j][i]);
   }
   print_row_end();

   for (i = 0; i < BOARD_SIZE; i++) {
       print_side_box();
   }
   print_row_end();
}

void print_board()
{
   int j, i;

   for (j = 0; j < BOARD_SIZE; j++) {
/* print one row of boxes */
       print_row(j);
   }

   for (i = 0; i < BOARD_SIZE; i++) {
       print_row_box();
   }
   print_row_end();
}
int check_move(int color, int x_from, int y_from, int x_to, int y_to) {

// color: color of the player making the move

// board_piece_color[x][y] represents the color of the piece at board[x][y]

   if (x_from < 0 || x_from > 7) {

// x_from not in range 0-7

       return INVALID_MOVE;

   }

   else if (x_to < 0 || x_to > 7) {

// x_to not in range 0-7

       return INVALID_MOVE;

   }

   else if (y_from < 0 || y_from > 7) {

// y_from not in range 0-7

       return INVALID_MOVE;

   }

   else if (y_to < 0 || y_to > 7) {

// y_to not in range 0-7

       return INVALID_MOVE;

   }

   else if (x_from == x_to && y_from == y_to) {

// from and to are the same position

       return INVALID_MOVE;

   }

   else if (the_board_color[x_from][y_from] != color) {

// piece at from position does not match player's color

       return INVALID_MOVE;

   }

   else if(the_board_color[x_to][y_to] == color)
   {

// to position by occupied by piece of same color as player

       return INVALID_MOVE;

   }

   return VALID_MOVE;

}

int check_move_knight(int color, int x_from, int y_from, int x_to, int y_to)
{
/* not neceessary
if(y_from != 0 && x_from != 1 || x_from != 6 && y_from != 0)
{
return INVALID_MOVE;
}
*/
   if(x_to == 1)
   {

   }
   else if (x_from == x_to && y_from == y_to) {

// from and to are the same position

       return INVALID_MOVE;

   }

   else if (the_board_color[x_from][y_from] != color) {

// piece at from position does not match player's color

       return INVALID_MOVE;

   }

   else if(the_board_color[x_to][y_to] == color)
   {

// to position by occupied by piece of same color as player

       return INVALID_MOVE;


   }
   return VALID_MOVE;
}

int check_move_king(int color, int x_from, int y_from, int x_to, int y_to)
{

   if((x_from==0) && ((x_to==1)||(x_to==0)))

   {

//starting from 0th position of column

       if ((y_from==0) && ((y_to==1) || (y_to==0)))

       {

           return VALID_MOVE;

       }

       else return INVALID_MOVE;

       return VALID_MOVE;

   }

   else if((y_from==0) && ((y_to==1)||(y_to==0)))

   {

//starting from 0th position of row

       if ((x_from==0) && ((x_to==1) || (x_to==0)))

       {

           return VALID_MOVE;

       }

       else return INVALID_MOVE;

       return VALID_MOVE;

   }

   else if ((x_from==7) && (x_to==x_from+1))

   {

//check condition for last column

       return INVALID_MOVE;

   }

   else if ((y_from==7) && (y_to==y_from+1))

   {

//check condition for last row

       return INVALID_MOVE;

   }

   else if (((x_to==x_from + 1)&&(y_to==y_from)) || ((x_to==x_from)&&(y_to==y_from+1))||((x_to==x_from - 1)&&(y_to==y_from)) || ((x_to==x_from)&&(y_to==y_from-1)) || ((x_to==x_from + 1)&&(y_to==y_from+1))||((x_to==x_from + 1)&&(y_to==y_from-1))
       ||((x_to==x_from - 1)&&(y_to==y_from-1))||((x_to==x_from-1)&&(y_to==y_from-1)))

   {

//checking the king move in any eight directions by +1

       return VALID_MOVE;

   }
   else if (x_from == x_to && y_from == y_to) {

// from and to are the same position

       return INVALID_MOVE;

   }

   else if (the_board_color[x_from][y_from] != color) {

// piece at from position does not match player's color

       return INVALID_MOVE;
   }
   return VALID_MOVE;
}
int check_move_rook(int color, int x_from, int y_from, int x_to, int y_to)
{
/* not neceessary
if(y_from != 0 && x_from != 0 || x_from != 7 && y_from != 0)
{
return INVALID_MOVE;
}
*/
//Movement along columns and rows
   if(y_to == 0 && x_to <= 0 || x_to == 0 && y_to <= 0 || y_to == 0 && x_to >= 7 || x_to == 7 && y_to <= 0)
   {
       return INVALID_MOVE;
   }

   else if (x_from == x_to && y_from == y_to)
   {
// from and to are the same position

       return INVALID_MOVE;
   }

   else if (the_board_color[x_from][y_from] != color)
   {

// piece at from position does not match player's color

       return INVALID_MOVE;

   }

   else if(the_board_color[x_to][y_to] == color)
   {

// to position by occupied by piece of same color as player

       return INVALID_MOVE;
   }
   return VALID_MOVE;

}

int check_move_bishop(int color, int x_from, int y_from, int x_to, int y_to)
{
//Movement
   if(x_from != 2 && y_from != 0 || x_from != 5 && y_from != 0)
   {
       return INVALID_MOVE;
   }
   else if( 1 )
   {
//Movement diagnoal
       return INVALID_MOVE;
   }
   else if (x_from == x_to && y_from == y_to) {

// from and to are the same position

       return INVALID_MOVE;

   }

   else if (the_board_color[x_from][y_from] != color) {

// piece at from position does not match player's color

       return INVALID_MOVE;

   }

   else if(the_board_color[x_to][y_to] == color)
   {

// to position by occupied by piece of same color as player

       return INVALID_MOVE;

   }
   return VALID_MOVE;
}

int check_queen_move(int color, int x_from, int y_from, int x_to, int y_to)
{
   if( 1 )
   {

   }
   else if (x_from == x_to && y_from == y_to) {

// from and to are the same position

       return INVALID_MOVE;

   }

   else if (the_board_color[x_from][y_from] != color) {

// piece at from position does not match player's color

       return INVALID_MOVE;

   }

   else if(the_board_color[x_to][y_to] == color)
   {

// to position by occupied by piece of same color as player

       return INVALID_MOVE;

   }
   return VALID_MOVE;
}

int check_pawn_move(int color, int x_from, int y_from, int x_to, int y_to)

{

   if(y_from > 6 || x_from > 7 || x_to > 7 || y_to > 7 || y_from < 1 || x_from < 0 || x_to < 0 || y_to < 2)

   {

       return INVALID_MOVE;

   }

   else if((x_from-x_to) > 1 || (x_from-x_to) < -1)

   {

       return INVALID_MOVE;

   }

   else if((y_to-y_from) < 0 ||(y_to-y_from) > 2)

   {

       return INVALID_MOVE;

   }

   else if((y_to-y_from) == 2 && y_from != 1)

   {

       return INVALID_MOVE;

   }

   else if ((x_from-x_to) != 0 && the_board_color[x_to, y_to] != color)

   {

       return INVALID_MOVE;

   }

   else if ((x_from-x_to) == 0 && the_board_color[x_to, y_to] == color)

   {

       return INVALID_MOVE;

   }


   return VALID_MOVE;

}

Output:


Related Solutions

I am having a trouble with a python program. I am to create a program that...
I am having a trouble with a python program. I am to create a program that calculates the estimated hours and mintutes. Here is my code. #!/usr/bin/env python3 #Arrival Date/Time Estimator # # from datetime import datetime import locale mph = 0 miles = 0 def get_departure_time():     while True:         date_str = input("Estimated time of departure (HH:MM AM/PM): ")         try:             depart_time = datetime.strptime(date_str, "%H:%M %p")         except ValueError:             print("Invalid date format. Try again.")             continue        ...
Please fix this code I am having issues compiling it all together there is 3 codes...
Please fix this code I am having issues compiling it all together there is 3 codes here and it's giving me errors in my main method..... I feel like it might be something simple but I can't seem to find it. package assignement2; import java.util.ArrayList; import java.util.Scanner; public class reg1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the number of items: "); int number = input.nextInt(); input.nextLine(); for (int i = 0; i <...
I have a written report and powerpoint due tommorow night. (overain CAncer ) I am having...
I have a written report and powerpoint due tommorow night. (overain CAncer ) I am having trouble organizing, Every time i write and essay and or even a paragraph I end up with an unorganized in conclusize writting. how can I orgaize with out writting to much un necassry information. Project and power point (210 total points possible) (overain Cancer ) For this course, students are required to write a Report on a disease/condition and prepare a PowerPoint Presentation. Both...
I have the below program and I am having issues putting all the output in one...
I have the below program and I am having issues putting all the output in one line instead of two. how can I transform the program for the user enter format ( HH:MM) Like: Enter time using 24 format ( HH:MM) : " and the user enter format " 14:25 then the program convert. instead of doing two lines make all one line. Currently I have the user enter first the Hour and then the minutes but i'd like to...
I am working on an accounting assignment and am having problems. Firstly, 1.I need to journalize...
I am working on an accounting assignment and am having problems. Firstly, 1.I need to journalize these entries and post the closing entries 2. i need to prepare Dalhanis multi-step income statement and statement of owners equity for August 2010 3. i need to prepare the blance sheet at august 31,2010 4. i need to prepare a post-closing trial balance at august 31,2010 DALHANI makes all credit sales on terms 2/10 n/30 and uses the Perpetual Inventory System Aug 1...
I am working on an accounting assignment and am having problems. Firstly, 1.I need to journalize...
I am working on an accounting assignment and am having problems. Firstly, 1.I need to journalize these entries and post the closing entries 2. i need to prepare Dalhanis multi-step income statement and statement of owners equity for August 2010 3. i need to prepare the blance sheet at august 31,2010 4. i need to prepare a post-closing trial balance at august 31,2010 DALHANI makes all credit sales on terms 2/10 n/30 and uses the Perpetual Inventory System Aug 1...
I am having problems getting the second button part of this to work. this is for...
I am having problems getting the second button part of this to work. this is for visual basic using visual studio 2017. Please help. Create an application named You Do It 4 and save it in the VB2017\Chap07 folder. Add two labels and two buttons to the form. Create a class-level variable named strLetters and initialize it to the first 10 uppercase letters of the alphabet (the letters A through J). The first button’s Click event procedure should use the...
I am having an issue with the Java program with a tic tac toe. it isn't...
I am having an issue with the Java program with a tic tac toe. it isn't a game. user puts in the array and it prints out this. 1. Write a method print that will take a two dimensional character array as input, and print the content of the array. This two dimensional character array represents a Tic Tac Toe game. 2. Write a main method that creates several arrays and calls the print method. Below is an example of...
Hello! I am having trouble starting this program in Java. the objective is as follows: "...
Hello! I am having trouble starting this program in Java. the objective is as follows: " I will include a text file with this assignment. It is a text version of this assignment. Write a program that will read the file line by line, and break each line into an array of words using the tokenize method in the String class. Count how many words are in the file and print out that number. " my question is, how do...
I am not aware of GR, but due to curiosity i have a question in my...
I am not aware of GR, but due to curiosity i have a question in my mind. Please let me know if it is inappropriate to ask here. My question is about singularity. I am under the assumption that singularity means in mathematical terms equivalent to a discontinuity in a function. My question is what type of discontinuity are the ones corresponding to Penrose-Hawking singularity theorems and also to the the naked singularity ? by type i mean removable (left...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT