1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
#ifndef BOARD_H
#define BOARD_H
#include "piece.h"
#include "bishop.h"
#include "king.h"
#include "knight.h"
#include "pawn.h"
#include "queen.h"
#include "rook.h"
class Board
{
public:
Board();
~Board();
void setPieceColor();
void display();
int getPieceAtPosition(int row, int col);
void setPieceAtPosition(int index, Piece &piece);
bool isEmptySquare();
private:
Piece * pieces[32];
};
#endif
#include "board.h"
#include<iostream>
Board::Board()
{
pieces[0] = new Rook(0, 0);
pieces[1] = new Knight(0, 1);
pieces[2] = new Bishop(0, 2);
pieces[3] = new Queen(0, 3);
pieces[4] = new King(0, 4);
pieces[5] = new Bishop(0, 5);
pieces[6] = new Knight(0, 6);
pieces[7] = new Rook(0, 7);
int col = 0;
for (int i = 8; i < 16; i++)
{
pieces[i] = new Pawn(1, col);
col++;
}
col = 0;
for (int i = 48; i < 56; i++)
{
pieces[i] = new Pawn(6, col);
col++;
}
pieces[56] = new Rook(7, 0);
pieces[57] = new Knight(7, 1);
pieces[58] = new Bishop(7, 2);
pieces[59] = new Queen(7, 3);
pieces[60] = new King(7, 4);
pieces[61] = new Bishop(7, 5);
pieces[62] = new Knight(7, 6);
pieces[63] = new Rook(7, 7);
}
Board::~Board()
{
for (int i = 0; i < 64; i++)
{
pieces[i] = NULL;
}
delete[] &pieces;
}
void Board::setPieceColor()
{
for (int i = 0; i < 64; i++)
{
if (i < 16)
{
pieces[i]->setColor(true);
}
else if (i > 46)
{
pieces[i]->setColor(false);
}
}
}
int Board::getPieceAtPosition(int row, int col)
{
int index = row * 8 + col;
return index;
}
void Board::setPieceAtPosition(int index, Piece &piece)
{
piece.setRow(index / 8);
piece.setCol(index % 8);
}
bool Board::isEmptySquare()
{
{
}
}
void Board::display()
{
for (int i = 0; i < 64; i++)
{
pieces[i]->display();
}
}
|