示例#1
0
        public List<string> validMoves(List<string> possibleMoves, Board board)
        {
            if (possibleMoves.Count() == 0) return possibleMoves;
            List<string> finalmoves = new List<string>();
            string origin=this.CurrentPos;

            foreach (var mv in possibleMoves)
            {
                board.MovePiece(this.CurrentPos, mv);
                if (White)
                {
                    if (!board.wCheck())
                    {
                        finalmoves.Add(mv);
                    }
                }
                else
                {
                    if (!board.bCheck())
                    {
                        finalmoves.Add(mv);
                    }

                }
                board.GetCell(origin).RestorePreviousPiece(board);
                board.GetCell(mv).RestorePreviousPiece(board);

            }

            return finalmoves;
        }
示例#2
0
        public void TestPieceGetMovesWithBlocker()
        {
            var target = new King(true, "Cc3");
            var board = new Board();
            board.GetCell("Cb4").AddPiece(new Pawn(true, "Cb4"));

            var blocky = new King(false, "Aa1");
            board.GetCell("Aa1").AddPiece(blocky);
            board._whitePieces.Add(board.GetCell("Cb4").GetPiece());
            board._blackPieces.Add(board.GetCell("Aa1").GetPiece());

            var tempList = new List<String> { "Cc4", "Bc4", "Dc4", "Cc2", "Bc2", "Dc2", "Cb3", "Bb3", "Db3", "Cd3", "Bd3", "Dd3", "Bc3", "Dc3", "Cd4", "Bd4", "Dd4", "Bb4", "Db4", "Cd2", "Bd2", "Dd2", "Cb2", "Db2" };
            Assert.AreEqual(tempList, target.GetMoves(board));
        }
示例#3
0
        public override List<string> GetBasicMoves(Board board)
        {
            var moves = new List<string>();

            foreach (var mainDirc in smallList)
            {

                for (var i = 0; i < (_directions.Length) / 2; i++)
                {
                    var currentCell = board.GetNeighborCell(board.GetCell(CurrentPos), mainDirc);
                    currentCell = board.GetNeighborCell(currentCell, _directions[i, 0]);
                    currentCell = board.GetNeighborCell(currentCell, _directions[i, 1]);

                    while (currentCell != null &&
                           (currentCell.GetPiece() == null || currentCell.GetPiece().White != White))
                    {
                        moves.Add(currentCell.GetName());
                        if (currentCell.HasPiece()) break;
                        currentCell = board.GetNeighborCell(currentCell, mainDirc);
                        currentCell = board.GetNeighborCell(currentCell, _directions[i, 0]);
                        currentCell = board.GetNeighborCell(currentCell, _directions[i, 1]);
                    }
                }
            }
            return moves;
        }
示例#4
0
        public override List<string> GetBasicMoves(Board board)
        {
            var boardNum = board.GetBoardNumber(CurrentPos);
            var rowNum = board.GetCellRow(CurrentPos);
            var colNum = board.GetCellCol(CurrentPos);
            var moves = new List<String>();

            var directions = White ? _WhiteDirections : _BlackDirections;
            for (var i = 0; i < (directions.Length) / 2; i++)
            {
                var currentCell = board.GetNeighborCell(board.GetCell(CurrentPos), directions[i, 0]);
                if (directions[i, 0] != directions[i, 1])
                {
                    currentCell = board.GetNeighborCell(currentCell, directions[i, 1]);
                    if (currentCell != null && currentCell.HasPiece() && currentCell.GetPiece().White != this.White)
                    {
                        moves.Add(currentCell.GetName());
                    }
                }
                else
                {
                    if (currentCell != null && !currentCell.HasPiece())
                    {
                        moves.Add(currentCell.GetName());
                    }
                }
            }
            return moves;
        }
示例#5
0
 public void TestBlackPawnTakeForwardRight()
 {
     var target = new Pawn(false, "Bd2");
     var board = new Board();
     board.GetCell("Be3").AddPiece(new Pawn(true, "Be3"));
     var tempList = new List<String> {"Cd2", "Bd3", "Be3"};
     Assert.AreEqual(tempList, target.GetMoves(board));
 }
示例#6
0
        public override List<string> GetBasicMoves(Board board)
        {
            var moves = new List<String>();
            foreach (var direction in Enum.GetValues(typeof(Board.CellNeighbor)))
            {
                var currentCell = board.GetNeighborCell(board.GetCell(CurrentPos), (Board.CellNeighbor)direction);
                if (currentCell != null && (!currentCell.HasPiece() || (currentCell.HasPiece() && currentCell.GetPiece().White != this.White)))
                {
                    moves.Add(currentCell.GetName());
                }

                if (!smallList.Contains((Board.CellNeighbor)direction))
                {
                    foreach (var dirc in smallList)
                    {
                        var tempCell = board.GetNeighborCell(currentCell, dirc);
                        if (tempCell != null && (!tempCell.HasPiece() || (tempCell.HasPiece() && tempCell.GetPiece().White != this.White)))
                        {
                            moves.Add(tempCell.GetName());
                        }
                    }
                }
            }

            for (var i = 0; i < (_directions.Length) / 2; i++)
            {
                var currentCell = board.GetNeighborCell(board.GetCell(CurrentPos), _directions[i, 0]);
                currentCell = board.GetNeighborCell(currentCell, _directions[i, 1]);
                if (currentCell != null && (!currentCell.HasPiece() || (currentCell.HasPiece() && currentCell.GetPiece().White != this.White)))
                {
                    moves.Add(currentCell.GetName());
                }

                foreach (var dirc in smallList)
                {
                    var tempCell = board.GetNeighborCell(currentCell, dirc);
                    if (tempCell != null && (!tempCell.HasPiece() || (tempCell.HasPiece() && tempCell.GetPiece().White != this.White)))
                    {
                        moves.Add(tempCell.GetName());
                    }
                }
            }
            return moves;
        }
示例#7
0
        public override List<string> GetBasicMoves(Board board)
        {
            var moves = new List<string>();

            foreach (var direction in Enum.GetValues(typeof(Board.CellNeighbor)))
            {
                var currentCell = board.GetNeighborCell(board.GetCell(CurrentPos), (Board.CellNeighbor)direction);

                while (currentCell != null && (currentCell.GetPiece() == null || currentCell.GetPiece().White != White))
                {
                    moves.Add(currentCell.GetName());
                    if (currentCell.HasPiece()) break;
                    currentCell = board.GetNeighborCell(currentCell, (Board.CellNeighbor)direction);
                }
            }
            return moves;
        }
示例#8
0
        public override List<string> GetBasicMoves(Board board)
        {
            var moves = new List<string>();

            foreach (var mainDirc in Enum.GetValues(typeof(Board.CellNeighbor)))
            {
                var mainCell = board.GetNeighborCell(board.GetCell(CurrentPos), (Board.CellNeighbor)mainDirc);
                if (mainCell == null) continue;
                mainCell = board.GetNeighborCell(mainCell, (Board.CellNeighbor)mainDirc);
                if (mainCell == null) continue;
                foreach(var secondaryDirc in Enum.GetValues(typeof(Board.CellNeighbor)))
                {
                    var checkCell = board.GetNeighborCell(mainCell, (Board.CellNeighbor)secondaryDirc);

                    if (board.IsSameOrOpposite((Board.CellNeighbor)mainDirc, (Board.CellNeighbor)secondaryDirc) ||
                        checkCell == null || (checkCell.GetPiece() != null && checkCell.GetPiece().White == this.White)) continue;
                    moves.Add(checkCell.GetName());

                }
            }

            return moves;
        }
示例#9
0
        public object Clone()
        {
            var board = new Board();
            try
            {
                foreach (var p in this._blackPieces)
                {
                    if (p.GetType() == typeof(Pawn)) board._blackPieces.Add(new Pawn(p.White, p.CurrentPos));
                    if (p.GetType() == typeof(King)) board._blackPieces.Add(new King(p.White, p.CurrentPos));
                    if (p.GetType() == typeof(Queen)) board._blackPieces.Add(new Queen(p.White, p.CurrentPos));
                    if (p.GetType() == typeof(Unicorn)) board._blackPieces.Add(new Unicorn(p.White, p.CurrentPos));
                    if (p.GetType() == typeof(Bishop)) board._blackPieces.Add(new Bishop(p.White, p.CurrentPos));
                    if (p.GetType() == typeof(Knight)) board._blackPieces.Add(new Knight(p.White, p.CurrentPos));
                    if (p.GetType() == typeof(Rook)) board._blackPieces.Add(new Rook(p.White, p.CurrentPos));

                }
                foreach (var q in this._whitePieces)
                {
                    if (q.GetType() == typeof(Pawn)) board._whitePieces.Add(new Pawn(q.White, q.CurrentPos));
                    if (q.GetType() == typeof(King)) board._whitePieces.Add(new King(q.White, q.CurrentPos));
                    if (q.GetType() == typeof(Queen)) board._whitePieces.Add(new Queen(q.White, q.CurrentPos));
                    if (q.GetType() == typeof(Unicorn)) board._whitePieces.Add(new Unicorn(q.White, q.CurrentPos));
                    if (q.GetType() == typeof(Bishop)) board._whitePieces.Add(new Bishop(q.White, q.CurrentPos));
                    if (q.GetType() == typeof(Knight)) board._whitePieces.Add(new Knight(q.White, q.CurrentPos));
                    if (q.GetType() == typeof(Rook)) board._whitePieces.Add(new Rook(q.White, q.CurrentPos));
                }
            }
            catch {
                return null;
            }

                board._board = (new Board())._board;

                board._whitePieces.ForEach(e => board.GetCell(e.CurrentPos).AddPiece(e));
                board._blackPieces.ForEach(e => board.GetCell(e.CurrentPos).AddPiece(e));

            board.state = this.state;
            return board;
        }
示例#10
0
 public void TestwhitePawnTakeForwardLeft()
 {
     var target = new Pawn(true, "Dc4");
     var board = new Board();
     board.GetCell("Dd3").AddPiece(new Pawn(false, "Dd3"));
     var tempList = new List<String> {"Cc4", "Dc3", "Dd3"};
     Assert.AreEqual(tempList, target.GetMoves(board));
 }
示例#11
0
        public List<string> IsCheck(List<string> moves, Board board)
        {
            //var pieces = White ? board._blackPieces : board._whitePieces;
            var pieces = new List<Piece>();
            pieces.AddRange(White ? board._blackPieces : board._whitePieces);
            List<Piece> origPieces = new List<Piece>();
            List<Cell> origCells = new List<Cell>();
            foreach (var piece in pieces)
            {
                List<string> piecemoves;
                 piecemoves = piece.GetBasicMoves(board);
                if (piece.GetType() == typeof(Pawn))
                {                    
                    foreach (var mv in moves)
                    {
                        origPieces.Add(board.GetCell(mv).GetPiece());
                        origCells.Add(board.GetCell(mv));
                        board.GetCell(mv).AddPiece(new Pawn(White, mv));
                    }
                    piecemoves.AddRange(piece.GetMoves(board));
                }
               
                foreach (var move in piecemoves)
                {
                    moves.Remove(move);
                }

                for(var i = 0; i< origCells.Count; i++){
                    board.GetCell((origCells[i]).GetName()).AddPiece(origPieces[i]);
                }

            }
            return moves;
        }
示例#12
0
 public void addInitialPiece()
 {
     target = new Board();
     target.GetCell("Aa1").AddPiece(new Pawn(true,"Aa1"));
     target._whitePieces.Add(target.GetCell("Aa1").GetPiece());
 }