answersLogoWhite

0

One way to represent the state of a Chess board as a string matrix containing names of pieces, is to have an array of pointers. Each pointer would either point to a piece name, or it would be NULL, indicating no piece is there...

char *board[8][8];

int i, j;

for (i=0; i<8; i++) for (j=0; j<8; j++) board[i][j] = NULL; // clear board

board[0][0] = "White Rook";

board[0][1] = "White Bishop";

board[1][0] = "White Pawn"; // etc...

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Engineering

What does the java new operator do?

The new keyword tells Java that you want to create a new instance of a class by invoking one of the constructors for that class.// Create a new, empty String objectString s1 = new String();// Create a new String object with a different constructorString s2 = new String("howdy");


What are the two ways strings can be combined to create a new string?

Concat()


C program to perform addition of matrices using functions?

#include&lt;iostream&gt; #include&lt;iomanip&gt; #include&lt;vector&gt; #include&lt;string&gt; #include&lt;sstream&gt; using namespace std; const unsigned width = 4; const unsigned height = 3; class matrix { private: vector&lt; vector&lt;unsigned&gt; &gt; m_data; string m_title; public: matrix(string title=""): m_data(height, vector&lt;unsigned&gt;(width)), m_title(title) {} matrix(const matrix&amp; copy): m_data(copy.m_data), m_title(copy.m_title) {} matrix&amp; operator=(matrix rhs) { // Note: assignment does not overwrite the matrix title. for(unsigned row=0; row&lt;height; ++row) for(unsigned col=0; col&lt;width; ++col) operator[](row)[col]=rhs[row][col]; return(*this); } vector&lt;unsigned&gt;&amp; operator[](const unsigned index){return(m_data[index]);} void set_title(const string title){ m_title = title; } string&amp; get_title(){return(m_title);} void show() { cout&lt;&lt;m_title&lt;&lt;'\n'&lt;&lt;endl; for(unsigned row=0; row&lt;height; ++row) { for(unsigned col=0; col&lt;width; ++col) cout&lt;&lt;setw(7)&lt;&lt;(*this)[row][col]; cout&lt;&lt;endl; } cout&lt;&lt;endl; } matrix&amp; operator+=(matrix rhs) { for(unsigned row=0; row&lt;height; ++row) for(unsigned col=0; col&lt;width; ++col) (*this)[row][col]+=rhs[row][col]; return(*this); } matrix operator+(matrix rhs) { matrix result(m_title+" + "+rhs.m_title); for(unsigned row=0; row&lt;height; ++row) for(unsigned col=0; col&lt;width; ++col) result[row][col]=(*this)[row][col]+rhs[row][col]; return(result); } matrix&amp; operator-=(matrix rhs) { for(unsigned row=0; row&lt;height; ++row) for(unsigned col=0; col&lt;width; ++col) (*this)[row][col]-=rhs[row][col]; return(*this); } matrix operator-(matrix rhs) { matrix result(m_title+" - "+rhs.m_title); for(unsigned row=0; row&lt;height; ++row) for(unsigned col=0; col&lt;width; ++col) result[row][col]=operator[](row)[col]-rhs[row][col]; return(result); } }; unsigned input_num (std::string prompt) { unsigned id = 0; while (1) { cout&lt;&lt;prompt&lt;&lt;": "; string input=""; getline (cin, input); stringstream ss (input); if (ss&gt;&gt;id) break; cout&lt;&lt;"Invalid input.\n"; } return (id); } void initialise(matrix&amp; m) { for(unsigned row=0; row&lt;height; ++row) { for(unsigned col=0; col&lt;width; ++col) { stringstream ss; ss&lt;&lt;"Enter a value for "&lt;&lt;m.get_title()&lt;&lt;'['&lt;&lt;row&lt;&lt;"]["&lt;&lt;col&lt;&lt;']'; m[row][col]=input_num(ss.str()); } } cout&lt;&lt;endl; } int main() { matrix matrix_1("matrix_1"); initialise(matrix_1); matrix_1.show(); matrix matrix_2("matrix_2"); initialise(matrix_2); matrix_2.show(); matrix matrix_3 = matrix_1 + matrix_2; matrix_3.show(); matrix matrix_4 = matrix_3 - matrix_2; matrix_4.show(); }


What is string class constructors?

Hello friends...The String class supports several constructors. To create an empty String, you call the default constructor.For example,String s = new String(); Thank youIf you want CA CPT coaching in Tamil nadu kindly visit our website ksacademy


String reverse program with single string and without using library functions in java?

You can create a separate string initially empty. Then using a loop, start at the end of the string and add it to the end of the other string. At the end of the loop, the other string would contain the reverse.

Related Questions

How can I create string and nail art?

To create string and nail art, you will need a wooden board, nails, hammer, and colored string. Start by hammering nails into the board in a pattern or design. Then, wrap the string around the nails to create different shapes and patterns. Experiment with different nail placements and string colors to create unique art pieces.


String to matrix converting matlab code?

Here is an example code snippet in MATLAB that converts a string into a matrix: str = '123456789'; % input string numChars = length(str); % number of characters in the string matrixSize = ceil(sqrt(numChars)); % calculate the size of the resulting matrix % pad the string with zeros to make it divisible by the matrix size str = [str, num2str(zeros(1, matrixSize^2 - numChars))]; % reshape the string into a matrix matrix = reshape(str, matrixSize, matrixSize); This code takes an input string and calculates the size of the matrix needed to store all the characters. It then pads the string with zeros to make it divisible by the matrix size. Finally, it uses the reshape function to convert the string into a matrix.


How do you cut a rectangle into 16 pieces with only 5 pieces of string?

You can cut the string into 15 total pieces.


How do you create a folder on a nook?

get 2 pieces of paper puch 2 hole in them on the side atch with string a wala there it is when you want open the string n put your work in hope this helped


What are the instructions for creating string art patterns?

To create string art patterns, you will need a wooden board, nails, a hammer, and colored string. First, hammer nails into the board in a pattern or design of your choice. Then, wrap the string around the nails to create the desired pattern, making sure to secure the string tightly. Experiment with different nail placements and string colors to create unique and intricate designs.


What are the fewest pieces of string need to string a tennIs racket?

100,0000


Can you separate the two pieces without breaking the string or removing the end?

Yes, it is possible to separate the two pieces without breaking the string or removing the end by tying a temporary knot on one of the pieces and sliding it off the end of the string. Then you can separate the two pieces.


How do you create a string reference?

String strReference = new String();


Jim has 5 pieces of string?

yes


How many pieces of string does it take to get to the moon?

One. But it's a mighty loooooong string.


How do you create a string and reverse a string in vb?

gov


Java variable for favorite movie?

If you only want to store the title, make it of type String. If you want to store several pieces of information, create a class and call it (For example) Movie, assign it fields for the different things you want to store about the movie, then create an object based on that class.If you only want to store the title, make it of type String. If you want to store several pieces of information, create a class and call it (For example) Movie, assign it fields for the different things you want to store about the movie, then create an object based on that class.If you only want to store the title, make it of type String. If you want to store several pieces of information, create a class and call it (For example) Movie, assign it fields for the different things you want to store about the movie, then create an object based on that class.If you only want to store the title, make it of type String. If you want to store several pieces of information, create a class and call it (For example) Movie, assign it fields for the different things you want to store about the movie, then create an object based on that class.