these 2 functions are linked with each other. #define MAX_BOARD_SIZE 12 // Players #define PLAYER_EMPTY 0 #define PLAYER_BLACK 1 #define PLAYER_WHITE 2 int board_size; int current_player = PLAYER_BLACK; char board[MAX_BOARD_SIZE][MAX_BOARD_SIZE]; int main(void); void announce_winner(void); unsigned int count_discs(int player); void announce_winner(void) { int black_count = count_discs(PLAYER_BLACK); int white_count = count_discs(PLAYER_WHITE); if (white_count > black_count) { printf("The game is a win for WHITE!\n"); white_count += count_discs(PLAYER_EMP
convert c code to mips
these 2 functions are linked with each other.
#define MAX_BOARD_SIZE 12
// Players
#define PLAYER_EMPTY 0
#define PLAYER_BLACK 1
#define PLAYER_WHITE 2
int board_size;
int current_player = PLAYER_BLACK;
char board[MAX_BOARD_SIZE][MAX_BOARD_SIZE];
int main(void);
void announce_winner(void);
unsigned int count_discs(int player);
void announce_winner(void) {
int black_count = count_discs(PLAYER_BLACK);
int white_count = count_discs(PLAYER_WHITE);
if (white_count > black_count) {
printf("The game is a win for WHITE!\n");
white_count += count_discs(PLAYER_EMPTY);
} else if (black_count > white_count) {
printf("The game is a win for BLACK!\n");
black_count += count_discs(PLAYER_EMPTY);
} else {
printf("The game is a tie! Wow!\n");
}
printf("Score for black: %d, for white: %d.\n", black_count, white_count);
}
unsigned int count_discs(int player) {
int count = 0;
for (int row = 0; row < board_size; ++row) {
for (int col = 0; col < board_size; ++col) {
if (board[row][col] == player) {
count++;
}
}
}
return count;
}
Step by step
Solved in 2 steps