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

IrmaMoves.h : #include \"IrmaMoves.h\" typedef struct Move { Irma irma; // an in

ID: 3751525 • 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;


How would I write the function for createMapBoard?

1. Overview The algebraic notation has been used in a few different notation systems to denote the moves made in a game. In our game, we are going to predict the wind speed and wind gusts of hurricane Irma when it starts from a point and moves toward its destination. The Irma's moves with its initial wind speed and wind gusts, and its destination is recorded as a series of strings that look something like this: h6 150 100f4 h6" and "f4" are the coordination of start and destination points in a board of 8x8 grid of squares, respectively, while the first integer number denotes the wind speed and the second integer number denotes the wind gusts of Irma when it starts its movement. For this assignment, you will write a program that parses through a series of algebraic notation strings and prints out what the map board looks like at the end. To do this, you will first have to leam (or brush up on) how Ima moves (see Appendix A in this document) A complete list of the functions you must implement, including their functional prototypes, is given below in Section 4, "Function Requirements". You will submit a single source file, named IrmalMoves.a, that contains all required function definitions, as well as any auxiliary functions you deem necessary. In i functions to work, including the custom IrmaMoves.h file we have distributed with this assignment (see Section 3, "IrmaMoves.h"). rmaMoves., you will have to #include an y header files necessary for your Note: You will not write a main0 function in the source file you submit! Rather, we will compile your source file with our own main function(s) in order to test your code. We have attached example source files that have main) functions, which you can use to test your code. You can write your own main functions for testing purposes, realize this is completely new territory for most of you, so don't panic. We've included instructions for compiling multiple source files into a single executable (g, mixing your Irmallove.e with our IrmaMoves.h and escaseX.c files) in Sections 5 and 6 of this PDF but the code you submit must not have a main function. We Although we have included test cases with sample main functions to get you started with testing the functionality of your code, we encourage you to develop your own test cases, as well. Ours are by no means comprehensive. We will use much more elaborate test cases when grading your submission.

Explanation / Answer

testcase01.c

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


void failwhale(void)
{
   printf("fail whale :( ");
   exit(0);
}

int main(void)
{
   // Create a map board.
   char **board = createMapBoard();

   // Check that some of lands and ocean squares are in the correct positions.
   if (board[0][1] != 'F')
       failwhale();
   if (board[4][2] != 'K')
       failwhale();
   if (board[5][3] != 'B')
       failwhale();
   if (board[2][0] != ' ')
       failwhale();

   printMapBoard(board);

   printf("Hooray! ");

   return 0;
}


IrmaMoves.h

#ifndef __IRMAMOVES_H
#define __IRMAMOVES_H


typedef struct Location
{
   // the square's column ('a' through 'h')
   char col;

   // the square's row (1 through 8)
   int row;
} Location;

typedef struct Irma
{
   // wind speed (MPH)
   int ws;

   // wind gusts (MPH)
   int wg;

}Irma;

typedef struct Move
{
   // an instance of Irma
   Irma irma;

   // location where this piece is moving from
   Location from_loc;

   // location where this piece is currently exist
   Location current_loc;

   // location where Irma is moving to
   Location to_loc;

} Move;


// Functional Prototypes

char **createMapBoard(void);

char **destroyMapBoard(char **board);

void printMapBoard(char **board);

void parseNotationString(char *str, Move *Irma);

char **predictIrmaChange (char* str, Move *irmaMove);

double difficultyRating(void);

double hoursSpent(void);


#endif


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(" ");
};


int colToInt(char col){
    //this is a helper function to convert the char col index to a usable int index
    if (col == 'a')
        return 0;
    if (col == 'b')
        return 1;
    if (col == 'c')
        return 2;
    if (col == 'd')
        return 3;
    if (col == 'e')
        return 4;
    if (col == 'f')
        return 5;
    if (col == 'g')
        return 6;
    if (col == 'h')
        return 7;
    else{
        puts("Column Error!");
        return 0;
      
    }
};

void vertMove(char **board, Move *Irma){
    //this is a helper function to handle N->S and S->N movements
    int direction = 0;
  
    //Determing the direction
    if (Irma->from_loc.row > Irma->to_loc.row)
        direction = -1; //North
    if (Irma->from_loc.row < Irma->to_loc.row)
        direction = 1; //South
    if (Irma->from_loc.row == Irma->to_loc.row)
        direction = 0; //No movement
  
    //Handles wind speeds and wind gusts for each space moved
    for(int i = Irma->from_loc.row; i != Irma->to_loc.row; i+= direction){
        if(board[i+direction][colToInt(Irma->to_loc.col)] == ' '){
            Irma->irma.ws+=6;
            Irma->irma.wg+=3;
        }
        else if(board[i+direction][colToInt(Irma->to_loc.col)] != ' '){ //else if implemented due to bugs with else
            Irma->irma.ws-=2;
            Irma->irma.wg-=1;
        }
    }
};

void horizMove(char **board, Move *Irma){
    //this is a helper function to handle E->W and W->E movements
    int direction = 0;
  
    //Determining the direction
    if (colToInt(Irma->from_loc.col) > colToInt(Irma->to_loc.col))
        direction = -1; //West
    if (colToInt(Irma->from_loc.col) < colToInt(Irma->to_loc.col))
        direction = 1; //East
    if (colToInt(Irma->from_loc.col) == colToInt(Irma->to_loc.col)){
        direction = 0; // No movement
    }

    //Handles wind speeds and wind gusts for each space moved
    for(int i = colToInt(Irma->from_loc.col); i != colToInt(Irma->to_loc.col); i += direction){

        if(board[Irma->from_loc.row][i+direction] == ' '){
            Irma->irma.ws+=10;
            Irma->irma.wg+=5;
        }
        else if(board[Irma->from_loc.row][i+direction] != ' '){ //else if implemented due to bugs with else
            Irma->irma.ws-=15;
            Irma->irma.wg-=10;
        }
    }
};

char **predictIrmaChange (char* str, Move *irmaMove){
    //initialize empty board
    char **board = createMapBoard();
  
    //parse the input string
    parseNotationString(str, irmaMove);
  
    //get initial coordinates
    int row = irmaMove->from_loc.row;
    int col = colToInt(irmaMove->from_loc.col);
  
    //print Initial Location
    board[row][col] = 'I';
    printMapBoard(board);
    destroyMapBoard(board);
  
    //calculate moves effect on ws and wg
    horizMove(board, irmaMove);
    vertMove(board, irmaMove);
  
    //get final coordinates
    row = irmaMove->to_loc.row;
    col = colToInt(irmaMove->to_loc.col);
  
    //print final Location
    board = createMapBoard();
    board[row][col] = 'I';
    printMapBoard(board);
  
    return board;
};

void parseNotationString(char *str, Move *Irma){
    //parse start location
    Irma->from_loc.col = str[0];
    Irma->from_loc.row = atoi(&str[1]);

    char temp[3];
  
    //parse wind speeds
    for (int i = 0; i < 3; i ++)
        temp[i] = str[i+3];
    Irma->irma.ws = atoi(temp);
  
    //parse wind gusts
    for (int i = 0; i < 3; i ++)
        temp[i] = str[i+7];
    Irma->irma.wg = atoi(temp);
  
    //parse final location
    Irma->to_loc.col = str[11];
    Irma->to_loc.row = atoi(&str[12]);
  
};


double difficultyRating(void){
    return 3;
};


double hoursSpent(void){
    return 5;
};

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