Exemple #1
0
        private bool WouldCheck(PieceMove moveVector)
        {
            Board testBoard = Clone() as Board;

            testBoard.Move(moveVector);
            return(testBoard.FindChecks(this[moveVector.vector.p1].GetColour()).Count() > 0);
        }
Exemple #2
0
 public void Move(PieceMove vector)
 {
     cash = null;
     history.Add(vector.vector);
     ExecuteVector(vector.vector);
     foreach (Vector vec in vector.additionalMoves ?? new Vector[] { })
     {
         ExecuteVector(vec);
     }
 }
Exemple #3
0
 protected virtual bool CanMove(PieceMove move)
 {
     var capturedPiece = move.CapturedPiece ?? this.Board[move.Target];
     return capturedPiece == null || (capturedPiece.Player != move.Piece.Player && move.CanCapture);
 }
Exemple #4
0
 internal void OnMove(PieceMove move)
 {
     if (this.PieceMoved != null)
         this.PieceMoved(move);
 }
Exemple #5
0
        private void MoveCore(PieceMove move, bool raiseEvent)
        {
            this[move.Target] = this[move.Source];

            if (raiseEvent)
            {
                this.OnSquareChanged(move.Source);
                this.OnSquareChanged(move.Target);
            }
            if (move.HasEnPassantCapture())
            {
                this[move.CapturedPiece.Square] = null;
                if (raiseEvent)
                    this.OnSquareChanged(move.CapturedPiece.Square);
            }
        }
Exemple #6
0
        private bool IsValid(PieceMove move)
        {
            MoveCore(move, false);
            bool ret = !this.IsInCheck();

            //Undo move
            this[move.Source] = this[move.Target];
            if (move.CapturedPiece != null)
                this[move.CapturedPiece.Square] = move.CapturedPiece;

            return ret;
        }
Exemple #7
0
        public override PieceMove Move(Board board)
        {
            BitBoard highlighted = new BitBoard();

            PieceMove[] moves       = board.GetMoves(GetColour());
            Vector      buildVector = new Vector();

            new StateMachine(
                new State[]
            {
                new State(
                    new TransitionExpressioin[]
                {
                    new TransitionExpressioin
                    {
                        function = () => { },
                        ptr      = 0
                    },

                    new TransitionExpressioin
                    {
                        function = () =>
                        {
                            buildVector.p1 = mouse.GetLastClicked();
                            renderer.SetHighlight(renderHandle, Highlight.CellSelected, buildVector.p1);
                            foreach (PieceMove selectedMove in moves.Where(move => move.vector.p1 == mouse.GetLastClicked()))
                            {
                                highlighted[selectedMove.vector.p2] = true;
                                renderer.SetHighlight(renderHandle, selectedMove.type == MoveType.Move ? Highlight.MovePossible : Highlight.AttackMovePossible, selectedMove.vector.p2);
                            }
                        },
                        ptr = 1
                    }
                },

                    () =>
                {
                    mouse.WaitForInput();
                    return(board[mouse.GetLastClicked()]?.GetColour() == GetColour() ? 1 : 0);
                }),

                new State(
                    new TransitionExpressioin[]
                {
                    new TransitionExpressioin
                    {
                        function = () =>
                        {
                            highlighted = new BitBoard();
                            renderer.ResetHighlights(renderHandle);
                        },
                        ptr = 0
                    },

                    new TransitionExpressioin
                    {
                        function = () =>
                        {
                            highlighted = new BitBoard();
                            renderer.ResetHighlights(renderHandle);
                            buildVector.p1 = mouse.GetLastClicked();
                            renderer.SetHighlight(renderHandle, Highlight.CellSelected, buildVector.p1);
                            foreach (PieceMove selectedMove in moves.Where(move => move.vector.p1 == mouse.GetLastClicked()))
                            {
                                highlighted[selectedMove.vector.p2] = true;
                                renderer.SetHighlight(renderHandle, selectedMove.type == MoveType.Move ? Highlight.MovePossible : Highlight.AttackMovePossible, selectedMove.vector.p2);
                            }
                        },
                        ptr = 1
                    },

                    new TransitionExpressioin
                    {
                        function = () => buildVector.p2 = mouse.GetLastClicked(),
                        ptr      = -1
                    }
                },

                    () =>
                {
                    mouse.WaitForInput();
                    return(highlighted[mouse.GetLastClicked()] ? 2 : (board[mouse.GetLastClicked()]?.GetColour() == GetColour() ? 1 : 0));
                })
            }).Run();

            renderer.ResetHighlights(renderHandle);

            PieceMove ret = moves.First(x => x.vector == buildVector);

            if (board[buildVector.p1]?.GetType() == Type.Pawn && (buildVector.p2.y == 0 || buildVector.p2.y == 7))
            {
                ret.additionalMoves = new Vector[] { new Vector(new Point((int)RequestPawnPromo().Value, GetColour() ? -1 : -2), buildVector.p2) }
            }
            ;

            return(ret);
        }