예제 #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);
        }
예제 #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);
     }
 }
예제 #3
0
파일: Piece.cs 프로젝트: hcesar/Chess
 protected virtual bool CanMove(PieceMove move)
 {
     var capturedPiece = move.CapturedPiece ?? this.Board[move.Target];
     return capturedPiece == null || (capturedPiece.Player != move.Piece.Player && move.CanCapture);
 }
예제 #4
0
파일: Player.cs 프로젝트: hcesar/Chess
 internal void OnMove(PieceMove move)
 {
     if (this.PieceMoved != null)
         this.PieceMoved(move);
 }
예제 #5
0
파일: Board.cs 프로젝트: hcesar/Chess
        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);
            }
        }
예제 #6
0
파일: Board.cs 프로젝트: hcesar/Chess
        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;
        }
예제 #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);
        }