IrmaMoves.h : #include \"IrmaMoves.h\" typedef struct Move { Irma irma; // an in
ID: 3752356 • Letter: I
Question
IrmaMoves.h :
#include "IrmaMoves.h"
typedef struct Move {
Irma irma; // an instance of Irma
L Location from_loc; // location where Irma is moving from
Location current_loc; // location where Irma is passing over
Location to_loc; // location where Irma is moving to
} Move;
typedef struct Location {
char col; // the square's column ('a' through 'h')
int row; // the square's row (0 through 7)
} Location;
typedef struct Irma {
int ws; // wind speed (MPH)
int wg; // wind gusts (MPH)
} Irma;
IrmaMoves.c:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "IrmaMoves.h"
char **createMapBoard(void){
char **board = malloc(8*sizeof(char *)); //dynamically allocate memory for rows
for(int i = 0 ; i < 8 ; i++) //dynamically allocate memory for indiviual elements
board[i] = malloc( 8*sizeof(char) );
board[0][0] = 'F'; //initialize the array with the map layout
board[0][1] = 'F';
board[0][2] = ' ';
board[0][3] = ' ';
board[0][4] = ' ';
board[0][5] = ' ';
board[0][6] = ' ';
board[0][7] = ' ';
board[1][0] = ' ';
board[1][1] = 'F';
board[1][2] = ' ';
board[1][3] = ' ';
board[1][4] = ' ';
board[1][5] = ' ';
board[1][6] = ' ';
board[1][7] = ' ';
board[2][0] = ' ';
board[2][1] = 'F';
board[2][2] = 'F';
board[2][3] = ' ';
board[2][4] = ' ';
board[2][5] = ' ';
board[2][6] = ' ';
board[2][7] = ' ';
board[3][0] = ' ';
board[3][1] = ' ';
board[3][2] = 'F';
board[3][3] = ' ';
board[3][4] = ' ';
board[3][5] = ' ';
board[3][6] = ' ';
board[3][7] = ' ';
board[4][0] = ' ';
board[4][1] = ' ';
board[4][2] = 'K';
board[4][3] = ' ';
board[4][4] = ' ';
board[4][5] = ' ';
board[4][6] = ' ';
board[4][7] = ' ';
board[5][0] = 'C';
board[5][1] = ' ';
board[5][2] = ' ';
board[5][3] = 'B';
board[5][4] = ' ';
board[5][5] = ' ';
board[5][6] = ' ';
board[5][7] = ' ';
board[6][0] = ' ';
board[6][1] = 'C';
board[6][2] = 'C';
board[6][3] = ' ';
board[6][4] = 'D';
board[6][5] = ' ';
board[6][6] = ' ';
board[6][7] = ' ';
board[7][0] = ' ';
board[7][1] = ' ';
board[7][2] = 'C';
board[7][3] = ' ';
board[7][4] = ' ';
board[7][5] = 'D';
board[7][6] = 'D';
board[7][7] = ' ';
return board;
};
char **destroyMapBoard(char **board){
//frees up the memory allocated to the board
free(board);
return NULL;
};
void printMapBoard(char **board){
//printing the map in the specified format
printf("======== ");
for (int i = 0; i < 8; i++){
for (int j = 0; j < 8; j++){
printf("%c",board[i][j]);}
printf(" ");}
printf("========");
printf(" ");
printf(" ");
};
Problems:
char **predictIrmaChange (char* str, Move *irmaMove);
Description: This function should start by printing the map board with Irma in its starting position, using the arrangement described in “Appendix A: Irma Movement” and the specific format shown in the test case output files included with this assignment. (You will want to call createMapBoard() from within this function to create a 2D char array to represent the map board, and then call the printMapBoard() function to print it to the screen. See above for the descriptions of both of those functions.)
After printing the initial map board, this function should parse all of the algebraic notation strings passed in through making calls to the parseNotationString() function (described below). The printMapBoard() function is called once after the Irma’s location has been identified, and another time after the board’s final configuration has been processed. Note that this function should print the resulting board (again, with a line of eight equal signs above and below the board each time, always followed by a blank line).
In addition, updating Irma’s wind speed/gusts and checking Irma directions should be
======== FF F FF F K C B CC D C DD ========
Note: This is a completely blank line. (No spaces.)
implemented in this function as described in “Appendix A: Irma Movement”.
Output: This should print out the map board in the manner described above, with precisely the same format shown in the test case output files included with this assignment.
Return Value: A pointer to the dynamically allocated 2D array (i.e., the base address of the 2D array), or NULL if any calls to malloc() fail.
void parseNotationString(char* str, Move* irmaMove);
Description: This function receives an algebraic notation string, str, and one Move struct pointer. The function must parse str and extract information about Irma moves encoded there, and populate all corresponding fields in the struct pointed to by irmaMove.
At the very least, it will always be possible to set the from_loc, current_loc, to_loc, and irma.ws, irma.wg fields in Irma struct. It is necessary to denote which column and/or row the Irma’s move is coming from, and also the column and/or row in a move’s to_loc field which determine where Irma ends. To initialize from_loc, current_loc, to_loc fields, you must initialize that move’s from/current/to_loc.col fields to ‘x’ to indicate that the column is currently unknown. Similarly, the move’s from/current/to_loc.row coordinate must be initialized to -1.
After initialization, update from_loc, current_loc, to_loc, and irma.ws, irma.wg fields through extracting information from given algebraic notation string.
Output: This function should not print anything to the screen.
Return Value: There is no return value. This is a void function.
double difficultyRating(void);
Output: This function should not print anything to the screen.
Return Value: A double indicating how difficult you found this assignment on a scale of 1.0 (ridiculously easy) through 5.0 (insanely difficult).
double hoursSpent(void);
Output: This function should not print anything to the screen.
Return Value: An estimate (greater than zero) of the number of hours you spent on this assignment.
Above is the Header file for IrmaMoves and the beginning of IrmaMoves.c. I bolded the functions that I am unsure of how to do.
Explanation / Answer
void printMapBoard(char **board){
//printing the map in the specified format
printf("======== ");
for (int i = 0; i < 8; i++){
for (int j = 0; j < 8; j++){
printf("%c",board[i][j]);}
printf(" ");}
printf("========");
printf(" ");
printf(" ");
};
} Move;
typedef struct Location {
char col; // the square's column ('a' through 'h')
int row; // the square's row (0 through 7)
} Location;
typedef struct Irma {
int ws; // wind speed (MPH)
int wg; // wind gusts (MPH)
} Irma;
IrmaMoves.c:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "IrmaMoves.h"
char **board = malloc(8*sizeof(char *)); //dynamically allocate memory for rows
for(int i = 0 ; i < 8 ; i++) //dynamically allocate memory for indiviual elements
board[i] = malloc( 8*sizeof(char) );
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.