public void SetupPieces(BoardEngine <ChessPieceEntity> engine)
            {
                for (var rank = 7; rank >= 0; rank--)
                {
                    for (var file = 0; file < 8; file++)
                    {
                        var chr = _board[file, rank];

                        if (_chessPieceEntityFactory.ValidPieces.Contains(chr.ToString().ToUpper()))
                        {
                            var entity = _chessPieceEntityFactory.Create(
                                ChessPieceNameMapper.FromChar(chr),
                                char.IsUpper(chr) ? Colours.White : Colours.Black
                                );

                            var location = BoardLocation.At(file + 1, rank + 1);

                            engine.AddPiece(entity, location);
                            if (chr.ToString().ToUpper() == "E")
                            {
                                ((PawnEntity)entity).TwoStep = true;
                            }
                        }
                        else if (chr != ' ' && chr != '.' && chr != '\0')
                        {
                            Throw.InvalidPiece(chr);
                        }
                    }
                }
            }
示例#2
0
 private void AddPawns(BoardEngine <ChessPieceEntity> engine)
 {
     foreach (var colour in new[] { Colours.White, Colours.Black })
     {
         for (int x = 1; x <= engine.Width; x++)
         {
             engine.AddPiece(CreatePawn(colour),
                             BoardLocation.At(x, colour == Colours.White ? 2 : 7));
         }
     }
 }
示例#3
0
        private void AddMajorPieces(BoardEngine <ChessPieceEntity> engine)
        {
            foreach (var rank in new[] { 1, 8 })
            {
                var colour = rank == 1 ? Colours.White : Colours.Black;

                engine.AddPiece(CreateRook(colour), $"A{rank}".ToBoardLocation());
                engine.AddPiece(CreateKnight(colour), $"B{rank}".ToBoardLocation());
                engine.AddPiece(CreateBishop(colour), $"C{rank}".ToBoardLocation());
                engine.AddPiece(CreateQueen(colour), $"D{rank}".ToBoardLocation());
                engine.AddPiece(CreateKing(colour), $"E{rank}".ToBoardLocation());
                engine.AddPiece(CreateBishop(colour), $"F{rank}".ToBoardLocation());
                engine.AddPiece(CreateKnight(colour), $"G{rank}".ToBoardLocation());
                engine.AddPiece(CreateRook(colour), $"H{rank}".ToBoardLocation());
            }
        }