CHECKERS

can't determine the error here: 6 errors and 1 warning

#include <algorithm>
#include <cassert>
#include <iostream>

const int EMPTY = 0;

const int BLACK = 2;
const int BLACK_CROWNED = 3;
const int WHITE = 4;
const int WHITE_CROWNED = 5;

const int BOARD_SIZE = 8;

class Board
{
int board[BOARD_SIZE][BOARD_SIZE];

void check_position(int x, int y) const
{
assert(x >= 0);
assert(x < BOARD_SIZE);
assert(y >= 0);
assert(y < BOARD_SIZE);

assert((x+y)&1); // only black positions are legal
}

public:
Board()
{
std::fill(board[0], board[BOARD_SIZE], EMPTY);
}

int get_checker(int x, int y) const
{
check_position(x, y);
return board[y][x];
}

bool is_empty(int x, int y) const
{
return get_checker(x, y) == EMPTY;
}

bool is_crowned(int x, int y) const
{
return get_checker(x, y) & 1;
}

void crown(int x, int y)
{
assert(!is_crowned(x, y));
board[y][x] |= 1;
}

void uncrown(int x, int y)
{
assert(is_crowned(x, y));
board[y][x] &= ~1;
}

void put_checker(int x, int y, int checker)
{
assert(is_empty(x, y));
assert(checker != EMPTY);
board[y][x] = checker;
}

void remove_checker(int x, int y)
{
assert(!is_empty(x, y));
board[y][x] = EMPTY;
}

friend std::ostream& operator<<(std::ostream& os, const Board& b)
{
static char display[] = {' ', '@', 'b', 'B', 'w', 'W'};
for (int y = 0; y < BOARD_SIZE; ++y)
{
std::cout << '|';
for (int x = 0; x < BOARD_SIZE; ++x)
{
os << display[b.board[y][x]] << '|';
}
std::endl(os);
}
return os;
}
};

int main()
{
for(int i=0;i<36;i++)
cin >> Board b;
b.put_checker(0, 1, WHITE);
b.put_checker(1, 2, BLACK_CROWNED);
std::cout << b << std::endl;
}
cin >> Board b;
What are you expecting this line to do?
Topic archived. No new replies allowed.