Question

C language code plz !!! Generate an 10-by-10 character map, where each cell is initially filled...

C language code plz !!!

Generate an 10-by-10 character map, where each cell is initially filled with character ’ . ’(dot). Now suppose a player is located at the top left-most corner of this map. Start from this position, and random walk the player. And mark the tranversing location with the alphabetic characters sequentially started with ’A’. When the predicted location of the next step is located outside the map, or has been occupied with the previous alphabetic characters, a new direction has to be selected again. The random walk stops when all four directions (left, right, up, down) has been tranversed, or the alphabetic character reaches ’Z’. Requirement: Your program should at least have two functions: void generate random walk(char walk[10][10]), and void print map(char walk[10][10]), where the first function takes in the array and initialize all its entries with character ’.’, and conduct random walk, the second function prints out the resulting map after the random walk.

0 0
Add a comment Improve this question Transcribed image text
Answer #1


As per the problem statement I have solve the problem. Please let me know if you have any doubts or you want me to modify the answer. And if you find this answer useful then don't forget to rate my answer as thumps up. Thank you! :)

//main.c

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

//function to generate random walk
void generate_random_walk(char walk[10][10]);

//function to print map
void printMap(char walk[10][10]);

int main()
{
    char random_walk[10][10] = {{'.', '.', '.', '.', '.', '.', '.', '.', '.', '.'},
                                {'.', '.', '.', '.', '.', '.', '.', '.', '.', '.'},
                                {'.', '.', '.', '.', '.', '.', '.', '.', '.', '.'},
                                {'.', '.', '.', '.', '.', '.', '.', '.', '.', '.'},
                                {'.', '.', '.', '.', '.', '.', '.', '.', '.', '.'},
                                {'.', '.', '.', '.', '.', '.', '.', '.', '.', '.'},
                                {'.', '.', '.', '.', '.', '.', '.', '.', '.', '.'},
                                {'.', '.', '.', '.', '.', '.', '.', '.', '.', '.'},
                                {'.', '.', '.', '.', '.', '.', '.', '.', '.', '.'},
                                {'.', '.', '.', '.', '.', '.', '.', '.', '.', '.'}};

    generate_random_walk(random_walk);
    printMap(random_walk);

    return 0;
}


//function to generate random walk
void generate_random_walk(char walk[10][10])
{
    int row = 0, column = 0, blocked = 0;

    srand((unsigned) time(NULL));

    for (char character = 'A'; character <= 'Z'; character++)
    {
        walk[row][column] = character;

        for(;;)
        {
            if (rand() % 4 == 0 && row > 0 && walk[row - 1][column] == '.')
            {
                row--;
                break;
            }
            if (rand() % 4 == 1 && column > 0 && walk[row][column - 1] == '.')
            {
                column--;
                break;
            }
            if (rand() % 4 == 2 && row < 9 && walk[row + 1][column] == '.')
            {
                row++;
                break;
            }
            if (rand() % 4 == 3 && column < 9 && walk[row][column + 1] == '.')
            {
                column++;
                break;
            }
            if (walk[row - 1][column] != '.' && walk[row][column - 1] != '.' &&
                walk[row + 1][column] != '.' && walk[row][column + 1] != '.')
            {
                blocked = 1;
                break;
            }
        }

        if (blocked)
            break;
    }
}

//function to print map after andom walk
void printMap(char walk[10][10])
{
    for (int i = 0; i < 10; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            printf("%c ", walk[i][j]);
        }
        printf("\n");
    }
}


------------------------------------------------------------------------------------------------------------------------------------------------------------------

Program Output :

RandomWalkProgram - main.c RandomWalkProgram a main.c RandomWalkProgram Debug Project > RandomWalkProgram --/CLion Projects/R

Add a comment
Know the answer?
Add Answer to:
C language code plz !!! Generate an 10-by-10 character map, where each cell is initially filled...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ for this exercise, you will make a simple Dungeon Crawl game. For an enhanced version,...

    C++ for this exercise, you will make a simple Dungeon Crawl game. For an enhanced version, you can add monsters that randomly move around. Program Requirements While the program is an introduction to two-dimensional arrays, it is also a review of functions and input validation. check: Does the program compile and properly run? does all functions have prototypes? Are all functions commented? Is the program itself commented? Are constants used where appropriate? Are the required functions implemented? Is the dungeon...

  • In C++ write a complete and correct x++ program that generates student email addresses and prints...

    In C++ write a complete and correct x++ program that generates student email addresses and prints them to the screen based upon the data found in an input file, called students . txt. Each line of the space, followed by the student’s last name. Every email address is to be of the form [email protected]. In general, each username has four parts in this order: (i) the student; last name in lowercase letters; (ii) a number between 10- 99 generated at...

  • programming language: C++ *Include Line Documenatations* Overview For this assignment, write a program that will simulate...

    programming language: C++ *Include Line Documenatations* Overview For this assignment, write a program that will simulate a game of Roulette. Roulette is a casino game of chance where a player may choose to place bets on either a single number, the colors red or black, or whether a number is even or odd. (Note: bets may also be placed on a range of numbers, but we will not cover that situation in this program.) A winning number and color is...

  • Implement a tic-tac-toe game. At the bottom of these specifications you will see a template you...

    Implement a tic-tac-toe game. At the bottom of these specifications you will see a template you must copy and paste to cloud9. Do not change the provided complete functions, or the function stub headers / return values. Currently, if the variables provided in main are commented out, the program will compile. Complete the specifications for each function. As you develop the program, implement one function at a time, and test that function. The provided comments provide hints as to what...

  • This is for C programming: You will be given files in the following format: n word1...

    This is for C programming: You will be given files in the following format: n word1 word2 word3 word4 The first line of the file will be a single integer value n. The integer n will denote the number of words contained within the file. Use this number to initialize an array. Each word will then appear on the next n lines. You can assume that no word is longer than 30 characters. The game will use these words as...

  • Please develop the following code using C programming and using the specific functions, instructi...

    Please develop the following code using C programming and using the specific functions, instructions and format given below. Again please use the functions given especially. Also don't copy any existing solution please write your own code. This is the first part of a series of two labs (Lab 7 and Lab 8) that will complete an implementation for a board-type game called Reversi (also called Othello). The goal of this lab is to write code that sets up the input...

  • Assignment Overview In Part 1 of this assignment, you will write a main program and several...

    Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...

  • In C++. Write a class named FBoard for playing a game, where player x is trying to get her piece to row 7 and player o i...

    In C++. Write a class named FBoard for playing a game, where player x is trying to get her piece to row 7 and player o is trying to make it so player x doesn't have any legal moves. It should have: An 8x8 array of char for tracking the positions of the pieces. A data member called gameState that holds one of the following values: X_WON, O_WON, or UNFINISHED - use an enum type for this, not string (the...

  • I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I...

    I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I just have to explain a lot so you understand how the program should work. In C programming, write a simple program to take a text file as input and encrypt/decrypt it by reading the text bit by bit, and swap the bits if it is specified by the first line of the text file to do so (will explain below, and please let me...

  • #include<stdio.h> #include<stdlib.h> #include <time.h> int main() { /* first you have to let the computer generate...

    #include<stdio.h> #include<stdlib.h> #include <time.h> int main() { /* first you have to let the computer generate a random number. Then it has to declare how many tries the user has for the game loop. we then need the player to enter their guess. After every guess we have to give an output of how many numbers they have in the right location and how many they have the right number. The player will keep guessing until their 10 tries are...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT