Jump to content
  • Advertisement
Sign in to follow this  
lookyboop

borland

This topic is 3757 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

for all the users of borland, i need some help. im making a chess game the code is like this : ________________________________________________________________________________ #include <iostream> using namespace std; int main() { char c[8][8] = {}; c[0][3] = 'Q'; c[7][3] = 'q'; c[0][4] = 'K'; c[7][4] = 'k'; c[0][2] = 'N'; c[0][5] = 'N'; c[7][5] = 'n'; c[7][2] = 'n'; c[7][1] = 'b'; c[7][6] = 'b'; c[0][6] = 'B'; c[0][1] = 'B'; c[0][7] = 'R'; c[7][7] = 'r'; c[7][0] = 'r'; c[0][0] = 'R'; c[1][1] = 'P'; c[1][2] = 'P'; c[1][3] = 'P'; c[1][4] = 'P'; c[1][5] = 'P'; c[1][6] = 'P'; c[1][7] = 'P'; c[1][0] = 'P'; c[6][1] = 'p'; c[6][2] = 'p'; c[6][3] = 'p'; c[6][4] = 'p'; c[6][5] = 'p'; c[6][6] = 'p'; c[6][7] = 'p'; c[6][0] = 'p'; for(int i = 0; i<8; i++){ for(int j = 0; j<8; j++){ cout << c[j] << " "; } cout << endl; ________________________________________________________________________________ when i ompile that using borland it says somehting is wrong with the line that says: char c[8][8] = {}; it says there is an expected expression in function main(). can someone tell me how to fix this?

Share this post


Link to post
Share on other sites
Advertisement
Here's what you wrote:

int main() {
for(int i = 0; i<8; i++){
for(int j = 0; j<8; j++){
cout << c[j] << " ";
}

Number of opening brackets: 3
Number of closing brackets: 1

Also:
char c[8][8] = {};
is not a proper way to declare an array.
char c[8][8];
will do fine.

Do you know what an enum is? They're much less cryptic than using chars and will make your code more self-explanatory. Otherwise, good documentation would note your code: 'Q' = Queen, 'K' = King, 'N' = knight, etc. I'd expect 'k' to be knight, you see, but it's good that you didn't do that because it's a little easy to confuse K and k.

Share this post


Link to post
Share on other sites
Quote:
Original post by Splinter of Chaos
Do you know what an enum is?

Possible use of enum for chess:
#include <iostream>

enum player { black, white };
enum piece { empty, pawn, bishop, knight, rook, queen, king };

const char display[2][7] = {{'.', 'p', 'b', 'n', 'r', 'q', 'k'},
{'.', 'P', 'B', 'N', 'R', 'Q', 'K'}};
struct field
{
player pl : 1;
piece pi : 3;

bool is(player pla, piece pie)
{
return pl == pla && pi == pie;
}

friend std::ostream& operator<<(std::ostream& os, field f)
{
os << display[f.pl][f.pi];
return os;
}
};

#define EMPTY {black, empty}
#define EMPTYLINE {EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY},

#define PAWNS(player) {{player, pawn}, {player, pawn}, {player, pawn}, {player, pawn}, {player, pawn}, {player, pawn}, {player, pawn}, {player, pawn}},

#define LINE(player) {{player, rook}, {player, knight}, {player, bishop}, {player, queen}, {player, king}, {player, bishop}, {player, knight}, {player, rook}},

int main()
{
field board[8][8] = {
LINE(black)
PAWNS(black)
EMPTYLINE
EMPTYLINE
EMPTYLINE
EMPTYLINE
PAWNS(white)
LINE(white)
};

for (int i = 0; i < 8; ++i)
{
for (int k = 0; k < 8; ++k)
{
std::cout << board[k] << ' ';
}
std::cout << std::endl;
}


if (board[0][0].pl == black)
std::cout << "that's how you test for color\n";

if (board[0][0].pi == rook)
std::cout << "that's how you test for piece\n";

if (board[0][0].is(black, rook))
std::cout << "that's how you test for colored piece\n";
}

You should possible make the board a class, too (if you know classes already).

Hm, the gamedev board doesn't seem to like the trailing backslash in macro definitions, it expands them itself :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!