Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hey, i am trying to add two 2D character matrices in a board game. in this order. when i start my game this is the

Hey, i am trying to add two 2D character matrices in a board game. in this order.

when i start my game this is the output i am getting:

Actual output: (user input is a one based index. I already have a function that handles this) the area around p (of 1s) is called a neighborhood. Like this: P is at (3,3) 0 0 0 0 0 0 0 1 1 1 0 0 0 1 P 1 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Then I am getting this: P is at (4,4) when i move char p 0 0 0 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 0 1 1 P 1 0 0 0 1 1 1 0 0 0 0 0 0 0 */

DESIRE OUTPUT: combine the last two matrices 0 0 0 0 0 0 0 1 1 1 0 0 0 1 2 2 1 0 0 1 2 P 1 0 0 0 1 1 1 0 0 0 0 0 0 0 */

message me of a c file if you have more questions

// this function deals with zero based indexes for testing purposes. User input is one based void test_find_neighborhood(char board[ROWS][COLS],int row, int col) { printf (" The neighbors of '%c' are: ", board[row][col]); for (int i = row ? row - 1 : row; i <= (row < ROWS - 1 ? row + 1 : row); i++) { for (int j = col ? col - 1 : col; j <= (col < COLS - 1 ? col + 1 : col); j++) { if (i == row && j == col) fputs (" ", stdout); else printf (" %c", board[i][j]); } putchar (' '); } } void place_mark_in_neighborhood_board(char board[ROWS][COLS], char marker , int row, int col)//User input is one based index { int player_building_level = 0; // increase building level around neighborhood for (int i = row ? row - 1 : row; i <= (row < ROWS - 1 ? row + 1 : row); i++)// rows { for (int j = col ? col - 1 : col; j <= (col < COLS - 1 ? col + 1 : col); j++) //column { // board[i][j] = '1'; for testing purpose board[row][col] = marker;

if (marker == 'P') { if (board[row][col] == 'A') { board[row][col] != marker; // dont place marker } else { /*If the player marker is placed at the beginning of the game*/ board[row][col] = marker; //place the marker } } } } }

i am thinking of making a function that would add two neighborhood matrices. it would search the board array and find the two neighboorhood 2d arrays and add two matrices. void add_two_matrices(int A[][COLS], int B[][COLS], int C[][COLS]) { int i, j; for (i = 0; i < ROWS; i++) for (j = 0; j < COLS; j++) C[i][j] = A[i][j] + B[i][j]; }

C is the result of adding matrix A and B. matrix A is player 1 and matrix two is AI or player two. if i convert the 2d array into and int char p is a ASCII value that is eventually going to be added together into a integer array. i wish i can use pointers but that isnt allowable on this one.

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

Step: 3

blur-text-image

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

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions

Question

=+free to pirate employees from competitors?

Answered: 1 week ago