public Board(bool init = true) { // state history history = new HistoryStack <State>(24, i => new State()); state = history.Next(); data = new IPiece[64]; if (init) { white = new List <IPiece>(new IPiece[16]); black = new List <IPiece>(new IPiece[16]); pieces = new List <IPiece>(new IPiece[32]); //captured = new List<IPiece>(32); pieces[0] = black[0] = this[0, 0] = new Rook(this, new Square(0, 0), Player.Black); pieces[1] = black[1] = this[0, 1] = new Knight(this, new Square(1, 0), Player.Black); pieces[2] = black[2] = this[0, 2] = new Bishop(this, new Square(2, 0), Player.Black); pieces[3] = black[3] = this[0, 3] = new Queen(this, new Square(3, 0), Player.Black); pieces[4] = black[4] = this[0, 4] = blackKing = new King(this, new Square(4, 0), Player.Black); pieces[5] = black[5] = this[0, 5] = new Bishop(this, new Square(5, 0), Player.Black); pieces[6] = black[6] = this[0, 6] = new Knight(this, new Square(6, 0), Player.Black); pieces[7] = black[7] = this[0, 7] = new Rook(this, new Square(7, 0), Player.Black); pieces[8] = black[8] = this[1, 0] = new Pawn(this, new Square(0, 1), Player.Black); pieces[9] = black[9] = this[1, 1] = new Pawn(this, new Square(1, 1), Player.Black); pieces[10] = black[10] = this[1, 2] = new Pawn(this, new Square(2, 1), Player.Black); pieces[11] = black[11] = this[1, 3] = new Pawn(this, new Square(3, 1), Player.Black); pieces[12] = black[12] = this[1, 4] = new Pawn(this, new Square(4, 1), Player.Black); pieces[13] = black[13] = this[1, 5] = new Pawn(this, new Square(5, 1), Player.Black); pieces[14] = black[14] = this[1, 6] = new Pawn(this, new Square(6, 1), Player.Black); pieces[15] = black[15] = this[1, 7] = new Pawn(this, new Square(7, 1), Player.Black); pieces[16] = white[0] = this[6, 0] = new Pawn(this, new Square(0, 6), Player.White); pieces[17] = white[1] = this[6, 1] = new Pawn(this, new Square(1, 6), Player.White); pieces[18] = white[2] = this[6, 2] = new Pawn(this, new Square(2, 6), Player.White); pieces[19] = white[3] = this[6, 3] = new Pawn(this, new Square(3, 6), Player.White); pieces[20] = white[4] = this[6, 4] = new Pawn(this, new Square(4, 6), Player.White); pieces[21] = white[5] = this[6, 5] = new Pawn(this, new Square(5, 6), Player.White); pieces[22] = white[6] = this[6, 6] = new Pawn(this, new Square(6, 6), Player.White); pieces[23] = white[7] = this[6, 7] = new Pawn(this, new Square(7, 6), Player.White); pieces[24] = white[8] = this[7, 0] = new Rook(this, new Square(0, 7), Player.White); pieces[25] = white[9] = this[7, 1] = new Knight(this, new Square(1, 7), Player.White); pieces[26] = white[10] = this[7, 2] = new Bishop(this, new Square(2, 7), Player.White); pieces[27] = white[11] = this[7, 3] = new Queen(this, new Square(3, 7), Player.White); pieces[28] = white[12] = this[7, 4] = whiteKing = new King(this, new Square(4, 7), Player.White); pieces[29] = white[13] = this[7, 5] = new Bishop(this, new Square(5, 7), Player.White); pieces[30] = white[14] = this[7, 6] = new Knight(this, new Square(6, 7), Player.White); pieces[31] = white[15] = this[7, 7] = new Rook(this, new Square(7, 7), Player.White); Start(); } else { white = new List <IPiece>(); black = new List <IPiece>(); pieces = new List <IPiece>(); //captured = new List<IPiece>(); } }
public IPiece AddPiece(PieceType type, Player player, Square position) { IPiece piece = null; switch (type) { case PieceType.Pawn: piece = new Pawn(this, position, player); break; case PieceType.Queen: piece = new Queen(this, position, player); break; case PieceType.King: piece = new King(this, position, player); break; case PieceType.Rook: piece = new Rook(this, position, player); break; case PieceType.Bishop: piece = new Bishop(this, position, player); break; case PieceType.Knight: piece = new Knight(this, position, player); break; default: throw new InvalidOperationException("Unknown Piece Type"); } pieces.Add(piece); if (player == Player.White) { white.Add(piece); if (type == PieceType.King) { whiteKing = (King)piece; } } else { black.Add(piece); if (type == PieceType.King) { blackKing = (King)piece; } } data[position] = piece; return(piece); }