Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// h9 todo items - this function should make the given move in the game. void do_move (chess_game_t *game, board_location_t from_pos, board_location_t to_pos) { int

// h9 todo items - this function should make the given move in the game.

void do_move(chess_game_t *game, board_location_t from_pos, board_location_t to_pos) {

int from_row, from_col, to_row, to_col;

chess_notation_to_indexes(from_pos, &from_row, &from_col);

chess_notation_to_indexes(to_pos, &to_row, &to_col);

char from_piece = piece_at_pos(game, from_pos);

// h9 todo - if it was an en passant move, then also remove the captured pawn

game->board[to_row][to_col] =

game->board[from_row][from_col];

game->board[from_row][from_col] = ' ';

// h9 todo - check if we need to do pawn promotion and if so do it

// h9 todo - record the move into the move history, and update move_number

// make sure to only put in a new move into game->move_history if there is

// room (if game->move_number < MAX_MOVES)

//

// for the move, you should store a string that first has a character for what

// piece was moved, then a space, then the position moved from, then a -, then

// the position moved to. For example,

// "p d2-d4" is for the pawn on d2 moving to d4

// note that some of the code assumes this exact formatting, so you need to

// use this formatting.

}

// h9 todo - should return the proper character to use for an empty space on the given

// position (alternates between ' ' and '-' to show white versus black spaces

// make sure that the bottom right space is ' ' ("white on the right").

char empty_char(board_location_t pos) {

// hint - add up the rank and file and look at the remainder % 2.

return ' '; // standing in, for now

}

// h9 todo - should return 1 if the position is empty, 0 otherwise, so 1 if the character

// in that position is ' '

int is_empty(const chess_game_t *game, board_location_t pos) {

return 0;

}

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_2

Step: 3

blur-text-image_3

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 Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions

Question

Evaluate the following integrals. x 2 sin 2x dx

Answered: 1 week ago

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago