Example #1
0
        AttackMap _map; // = new AttackMap(new List<Move>(), board);

        #endregion Fields

        #region Constructors

        public ClassForTest(Figure figure, string cell)
        {
            Board = new Board();
            ValidCells = new List<string>();
            Figure = figure;
            Board[cell] = Figure;
            _map = new AttackMap(new List<Move>(), Board);
        }
Example #2
0
 private void West(Board board, char i, int currentCell, Figure currentFigure)
 {
     for (var k = (char)(i - 1); k >= 'a'; k--)
     {
         Figure f1 = board[k.ToString(CultureInfo.InvariantCulture) + currentCell];
         if (f1.GetType() == typeof(FigureNone))
         {
             Attackers[k - 'a', currentCell - 1].Add(currentFigure);
         }
         else if (f1.Side != currentFigure.Side)
         {
             Attackers[k - 'a', currentCell - 1].Add(currentFigure);
             break;
         }
         else
         {
             break;
         }
     }
 }
Example #3
0
        private void SouthWest(Board board, char i, int currentCell, Figure currentFigure)
        {
            int l = currentCell - 1;
            var k = (char)(i - 1);
            for (; k >= 'a' && l >= 1; )
            {
                Figure f1 = board[k.ToString(CultureInfo.InvariantCulture) + l];

                if (f1.GetType() == typeof(FigureNone))
                {
                    Attackers[k - 'a', l - 1].Add(currentFigure);
                    k--;
                    l--;
                }
                else
                {
                    if (f1.Side != currentFigure.Side)
                    {
                        Attackers[k - 'a', l - 1].Add(currentFigure);
                    }
                    break;
                }
            }
        }
Example #4
0
 private void South(Board board, char i, int currentCell, Figure currentFigure)
 {
     for (int k = currentCell - 1; k >= 1; k--)
     {
         Figure f1 = board[i.ToString(CultureInfo.InvariantCulture) + k];
         if (f1.GetType() == typeof(FigureNone))
         {
             Attackers[i - 'a', k - 1].Add(currentFigure);
         }
         else if (f1.Side != currentFigure.Side)
         {
             Attackers[i - 'a', k - 1].Add(currentFigure);
             break;
         }
         else
         {
             break;
         }
     }
 }
Example #5
0
        private void PassedPawn(IReadOnlyList<Move> moves, Board board, Figure pawn)
        {
            int rowFrom;
            int rowTo;
            int rows;
            var pawnX = board.ReturnPosition(pawn).Item1;
            var pawnY = board.ReturnPosition(pawn).Item2;
            switch (pawn.Side)
            {
                case Side.BLACK:
                    rows = 4;
                    rowFrom = rows - 2;
                    rowTo = rows - 1;
                    break;
                case Side.WHITE:
                    rows = 5;
                    rowFrom = rows + 2;
                    rowTo = rows + 1;
                    break;
                default:
                    return;
            }

            var cell = new List<string>();
            if (pawnX != 'a')
                cell.Add(((char)(pawnX - 1)).ToString(CultureInfo.InvariantCulture) + rows);
            if (pawnX != 'h')
                cell.Add(((char)(pawnX + 1)).ToString(CultureInfo.InvariantCulture) + rows);

            foreach (var c in cell)
            {
                if (board[c].GetType() == typeof(FigurePawn) && board[c].Side != pawn.Side &&
                    moves[moves.Count - 1].To == c && moves[moves.Count - 1].From ==
                    c[0].ToString(CultureInfo.InvariantCulture) + rowFrom && pawnY == rows)
                    Attackers[c[0] - 'a', rowTo - 1].Add(pawn);

            }
        }
Example #6
0
        private void NorthEast(Board board, char i, int currentCell, Figure currentFigure)
        {
            int l = currentCell + 1;
            var k = (char)(i + 1);
            for (; k <= 'h' && l <= Board.BoardSize; )
            {
                Figure f1 = board[k.ToString(CultureInfo.InvariantCulture) + l];

                if (f1.GetType() == typeof(FigureNone))
                {
                    Attackers[k - 'a', l - 1].Add(currentFigure);
                    k++;
                    l++;
                }
                else if (f1.Side != currentFigure.Side)
                {
                    Attackers[k - 'a', l - 1].Add(currentFigure);
                    break;
                }
                else
                {
                    break;
                }
            }
        }
Example #7
0
 private void KingKnightStep(Board board, Figure currentFigure, char x, int y)
 {
     Figure f1 = board[x.ToString(CultureInfo.InvariantCulture) + y];
     if (f1.GetType() == typeof(FigureNone))
         Attackers[x - 'a', y - 1].Add(currentFigure);
     else if (f1.Side != currentFigure.Side)
         Attackers[x - 'a', y - 1].Add(currentFigure);
 }
Example #8
0
 private void CastlingFunc(Board board, Figure king, Figure rook, int rows, char rookX)
 {
     if (rookX == 'a')
     {
         if (board["b" + rows].GetType() == typeof(FigureNone) &&
             board["c" + rows].GetType() == typeof(FigureNone) &&
             board["d" + rows].GetType() == typeof(FigureNone) &&
             IsColorFigureAttack(this["c" + rows], king.Side) &&
             IsColorFigureAttack(this["d" + rows], king.Side))
         {
             Attackers['c' - 'a', rows - 1].Add(king);
             //Attackers['d' - 'a', rows - 1].Add(rook);
         }
     }
     else if (rookX == 'h')
     {
         if (board["f" + rows].GetType() == typeof(FigureNone) &&
             board["g" + rows].GetType() == typeof(FigureNone) &&
             IsColorFigureAttack(this["f" + rows], king.Side) &&
             IsColorFigureAttack(this["g" + rows], king.Side))
         {
             Attackers['g' - 'a', rows - 1].Add(king);
             //Attackers['f' - 'a', rows - 1].Add(rook);
         }
     }
 }
Example #9
0
        private void Castling(List<Move> moves, Board board, Figure king, Figure rook)
        {
            int rows = 0;
            if (king.Side == Side.WHITE)
                rows = 1;
            else if (king.Side == Side.BLACK)
                rows = 8;

            char rookX = board.ReturnPosition(rook).Item1;
            int rookY = board.ReturnPosition(rook).Item2;
            char kingX = board.ReturnPosition(king).Item1;
            int kingY = board.ReturnPosition(king).Item2;

            if (moves.Count != 0)
                foreach (Move move in moves)
                {
                    if (!move.From.Contains(rookX + rookY.ToString(CultureInfo.InvariantCulture)))
                    {
                        foreach (Move move2 in moves)
                            if (!move2.From.Contains(kingX + kingY.ToString(CultureInfo.InvariantCulture)))
                            {
                                CastlingFunc(board, king, rook, rows, rookX);
                            }
                            else
                                return;
                    }
                    else
                        return;
                }
            else
            {
                CastlingFunc(board, king, rook, rows, rookX);
            }
        }
Example #10
0
 public bool IsContains(Figure figure)
 {
     for (int i = 0; i < 8; i++)
     {
         for (int j = 0; j < 8; j++)
         {
             if (Attackers[i, j].Contains(figure))
                 return true;
         }
     }
     return false;
 }
Example #11
0
 public Tuple<char, int> ReturnPosition(Figure figure)
 {
     for (char i = 'a'; i <= 'h'; i++)
     {
         for (int j = 1; j <= BoardSize; j++)
         {
             if (this[i + j.ToString(CultureInfo.InvariantCulture)] == figure)
                 return  new Tuple<char, int>(i, j);
         }
     }
     throw new Exception("Figure not found");
 }