protected IEnumerable<NormalMove> CalculateMoveInDirection(Int32 fileAddition, Int32 rankAddition, int ply)
 {
     var stoppedSearching = false;
     int fileAdder = fileAddition, rankAdder = rankAddition;
     while (!stoppedSearching)
     {
         var squareToCheck = new BareSquare(Square.File + fileAdder, Square.Rank + rankAdder);
         var squareStatus = Board.GetSquareStatus(squareToCheck);
         switch (squareStatus)
         {
             case SquareStatus.Illegal:
                 stoppedSearching = true;
                 break;
             case SquareStatus.Empty:
                 yield return new NormalMove(this,Square,squareToCheck,null,ply);
                 break;
             case SquareStatus.Occupied:
                 var piece = Board.GetPieceOn(squareToCheck);
                 if (piece.Color!=Color)
                     yield return new NormalMove(this,Square,squareToCheck,piece,ply);
                 stoppedSearching = true;
                 break;
         }
         fileAdder += fileAddition;
         rankAdder += rankAddition;
     }
 }
 protected IEnumerable<ISquare> FindCoveredSquaresInDirection(int fileAddition, int rankAddition)
 {
     var stoppedSearching = false;
     int fileAdder = fileAddition, rankAdder = rankAddition;
     while (!stoppedSearching)
     {
         var squareToCheck = new BareSquare(Square.File + fileAdder, Square.Rank + rankAdder);
         var squareStatus = Board.GetSquareStatus(squareToCheck);
         switch (squareStatus)
         {
             case SquareStatus.Illegal:
                 stoppedSearching = true;
                 break;
             case SquareStatus.Empty:
                 yield return squareToCheck;
                 break;
             case SquareStatus.Occupied:
                 yield return squareToCheck;
                 stoppedSearching = true;
                 break;
         }
         fileAdder += fileAddition;
         rankAdder += rankAddition;
     }
 }
Beispiel #3
0
        //What a mess
        public override IEnumerable<NormalMove> CalculateAllMoves(int ply)
        {
            var firstSquare = new BareSquare(Square.File,Square.Rank+MoveForward);
            var doubleSquare = new BareSquare(Square.File,Square.Rank+(MoveForward*2));
            var captureSquare1 = new BareSquare(Square.File - 1, Square.Rank + MoveForward);
            var captureSquare2 = new BareSquare(Square.File + 1, Square.Rank + MoveForward);
            var enpassantPieceSquare1 = new BareSquare(Square.File - 1,Square.Rank);
            var enpassantPieceSquare2 = new BareSquare(Square.File + 1, Square.Rank);
            if (Board.GetSquareStatus(firstSquare) == SquareStatus.Empty)
            {
                yield return new NormalMove(this,Square,firstSquare,null,ply);
                if (Board.GetSquareStatus(doubleSquare)==SquareStatus.Empty && Square.Rank==_startRank)
                {
                    yield return new PawnDoubleMove(this,Square,doubleSquare,ply);
                }
            }
            var captureMove1 = GetCaptureMove(captureSquare1, ply);
            if (captureMove1 != null)
                yield return captureMove1;
            var captureMove2 = GetCaptureMove(captureSquare2, ply);
            if (captureMove2 != null)
                yield return captureMove2;

            var enPassantMove1 = GetEnPassantMove(enpassantPieceSquare1, captureSquare1, ply);
            if (enPassantMove1 != null)
                yield return enPassantMove1;

            var enPassantMove2 = GetEnPassantMove(enpassantPieceSquare2, captureSquare2, ply);
            if (enPassantMove2 != null)
                yield return enPassantMove2;
        }
Beispiel #4
0
 private IEnumerable<ISquare> CheckIfSquareIsCovered(int fileAdder, int rankAdder)
 {
     var squareToCheck = new BareSquare(Square.File + fileAdder, Square.Rank + rankAdder);
     if (Board.GetSquareStatus(squareToCheck) == SquareStatus.Illegal)
         yield break;
     else yield return squareToCheck;
 }
Beispiel #5
0
 private IEnumerable<NormalMove> CheckMove(int fileAdder, int rankAdder, int ply)
 {
     var squareToCheck = new BareSquare(Square.File + fileAdder, Square.Rank + rankAdder);
     var squareStatus = Board.GetSquareStatus(squareToCheck);
     if (squareStatus == SquareStatus.Illegal)
         yield break;
     if (squareStatus == SquareStatus.Empty)
     {
         yield return new NormalMove(this, Square, squareToCheck, null, ply);
     }
     else if (squareStatus == SquareStatus.Occupied)
     {
         var piece = Board.GetPieceOn(squareToCheck);
         if (piece.Color != Color)
             yield return new NormalMove(this, Square, squareToCheck, piece, ply);
     }
 }
Beispiel #6
0
 private ISquare CheckIfSquareIsCovered(int file, int rank)
 {
     var square = new BareSquare(file, rank);
     var squareStatus = Board.GetSquareStatus(square);
     if (squareStatus == SquareStatus.Empty)
         return square;
     else
         return null;
 }
Beispiel #7
0
 private static void GetPositions(IBoard board, string posData)
 {
     var ranks = posData.Split('/');
     for (var r=7;r>=0;r--)
     {
         var f = 0;
         var cPos = 0;
         while (f<8)
         {
             var num =0;
             if (int.TryParse(ranks[r][cPos].ToString(),out num))
             {
                 f+=num;
                 cPos++;
             }
             else
             {
                 var currentSquare = new BareSquare(f, 7 - r);
                 switch (ranks[r][cPos])
                 {
                     case 'p':
                         board.SetPiece(currentSquare, new Pawn(Color.Black,board));
                         break;
                     case 'P':
                         board.SetPiece(currentSquare, new Pawn(Color.White, board));
                         break;
                     case 'q':
                         board.SetPiece(currentSquare, new Queen(Color.Black, board));
                         break;
                     case 'Q':
                         board.SetPiece(currentSquare, new Queen(Color.White, board));
                         break;
                     case 'k':
                         board.SetPiece(currentSquare, new King(Color.Black, board));
                         break;
                     case 'K':
                         board.SetPiece(currentSquare, new King(Color.White, board));
                         break;
                     case 'n':
                         board.SetPiece(currentSquare, new Knight(Color.Black, board));
                         break;
                     case 'N':
                         board.SetPiece(currentSquare, new Knight(Color.White, board));
                         break;
                     case 'r':
                         board.SetPiece(currentSquare, new Rook(Color.Black, board));
                         break;
                     case 'R':
                         board.SetPiece(currentSquare, new Rook(Color.White, board));
                         break;
                     case 'b':
                         board.SetPiece(currentSquare, new Bishop(Color.Black, board));
                         break;
                     case 'B':
                         board.SetPiece(currentSquare, new Bishop(Color.White, board));
                         break;
                 }
                 f++;
                 cPos++;
             }
         }
     }
 }