private void UpdateSelection()
        {
            switch (SelectState)
            {
                case SelectionState.SelectPiece:
                    if (CurrentSquare != null)
                    {
                        PieceToMove = GetPiece(CurrentSquare.World.Translation + new Vector3(0, 2, 0));

                        if (PieceToMove != null && ((int)PieceToMove.ColorType) == (int)Turn)
                        {
                            FromSquare = CurrentSquare;
                            SelectState = SelectionState.PieceSelected;
                        }

                        CurrentSquare = null;
                    }
                    break;

                case SelectionState.PieceSelected:
                    MovesAvailable = GenerateMoves(PieceToMove, FromSquare);
                    if (MovesAvailable != null)
                    {
                        foreach (Square s in MovesAvailable)
                            s.IsMoveOption = true;
                        SelectState = SelectionState.SelectMove;
                    }
                    else
                    {
                        ResetMovesAvailable();
                        SelectState = SelectionState.SelectPiece;
                    }
                    break;

                case SelectionState.SelectMove:
                    if (CurrentSquare != null && MovesAvailable.Contains(CurrentSquare))
                    {
                        PieceToCapture = GetPiece(CurrentSquare.World.Translation + new Vector3(0, 2, 0));

                        if (PieceToCapture != null)
                            IsFight = true;

                        ToSquare = CurrentSquare;

                        SelectState = SelectionState.MoveSelected;
                    }
                    else if (CurrentSquare != null)
                    {
                        Piece p = GetPiece(CurrentSquare.World.Translation + new Vector3(0, 2, 0));

                        if (p != null && ((int)PieceToMove.ColorType) == (int)Turn) //Replace selection with this piece
                        {
                            PieceToMove = p;
                            FromSquare = CurrentSquare;
                            SelectState = SelectionState.PieceSelected;
                        }
                        else
                            SelectState = SelectionState.SelectPiece;
                        ResetMovesAvailable();
                    }

                    CurrentSquare = null;
                    break;

                case SelectionState.MoveSelected:
                    ResetMovesAvailable();

                    //check for pawn queening

                    var m = new Move(Engine, GameBoard, FromSquare, ToSquare, PieceToMove, IsFight, PieceToCapture, false); //add new Move to list AllMoves
                     if (m.IsValidMove)
                     {

                         if(Turn == TurnState.Black)
                            BlackMoves.Add(m.ToAlgebraic());
                         else if(Turn == TurnState.White)
                             WhiteMoves.Add(m.ToAlgebraic());
                         Engine.Audio.PlayEffect("MovePiece");
                         SelectState = SelectionState.SelectPiece;
                         IsFight = false;
                         SwitchTurn(false);
                     }
                     else
                         NotificationEngine.AddNotification(new Notification("Sorry that would leave you in check!!", 4000));
                    break;

            } // end switch
        }
        private void MoveOtherPiece(Vector3 pos, UInt64 bbFrom, UInt64 bbTo)
        {
            bool isCapture = false;
            Square s = GetSquareFromBB(bbTo);
            Piece capturedPiece = GetPiece(s.World.Translation + new Vector3(0, 2, 0));
            if (capturedPiece != null)
                isCapture = true;
            Move m = new Move(Engine, GameBoard, GetSquareFromBB(bbFrom), s, GetPiece(pos), isCapture, capturedPiece, false);
            if (m.IsValidMove)
            {

            }
        }
Пример #3
0
        private void MoveOtherPiece(UInt64 bbFrom, UInt64 bbTo)
        {
            Square s = GameBoard.GetSquareFromBB(bbTo);
            Square sqFrom = GameBoard.GetSquareFromBB(bbFrom);

            Piece capturedPiece = GameBoard.GetPiece(s);
            Piece movedPiece = GameBoard.GetPiece(sqFrom);

            Move m = new Move(Engine, GameBoard, GameBoard.GetSquareFromBB(bbFrom), s, movedPiece, capturedPiece,true, PromoteTo);

            GameBoard.AllMoves.Add(m);
        }
Пример #4
0
        private void UpdateSelection()
        {
            switch (SelectState)
             {
                 case SelectionState.SelectPiece:
                     if (CurrentSquare != null)
                     {
                         PieceToMove = GameBoard.GetPiece(CurrentSquare.World.Translation + new Vector3(0, 2, 0));

                         if (PieceToMove != null && ((int)PieceToMove.ColorType) == (int)Turn)
                         {
                             FromSquare = CurrentSquare;
                             SelectState = SelectionState.PieceSelected;
                         }

                         CurrentSquare = null;
                     }
                     break;

                 case SelectionState.PieceSelected:
                     MovesAvailable = MoveGen.GenerateMoves(PieceToMove, FromSquare);
                     if (MovesAvailable != null)
                     {
                         foreach (Square s in MovesAvailable)
                             s.IsMoveOption = true;
                         SelectState = SelectionState.SelectMove;
                     }
                     else
                     {
                         ResetMovesAvailable();
                         SelectState = SelectionState.SelectPiece;
                     }
                     break;

                 case SelectionState.SelectMove:
                     if (CurrentSquare != null && MovesAvailable.Contains(CurrentSquare))
                     {
                         PieceToCapture = GameBoard.GetPiece(CurrentSquare.World.Translation + new Vector3(0, 2, 0));

                         ToSquare = CurrentSquare;

                         SelectState = SelectionState.MoveSelected;
                     }
                     else if (CurrentSquare != null)
                     {
                         Piece p = GameBoard.GetPiece(CurrentSquare.World.Translation + new Vector3(0, 2, 0));

                         if (p != null && ((int)p.ColorType) == (int)Turn) //Replace selection with this piece
                         {
                             PieceToMove = p;
                             FromSquare = CurrentSquare;
                             SelectState = SelectionState.PieceSelected;
                         }
                         else
                             SelectState = SelectionState.SelectPiece;
                         ResetMovesAvailable();
                     }

                     CurrentSquare = null;
                     break;

                 case SelectionState.MoveSelected:
                     ResetMovesAvailable();

                     //check for pawn promotion
                     if (GameBoard.TestForPromotion(PieceToMove.ColorType, ToSquare.Rank) &
                         PromoteTo == Piece.PieceType.None)
                     {
                         SelectState = SelectionState.Promote;
                         break;
                     }

                     Move m = new Move(Engine, GameBoard, FromSquare, ToSquare, PieceToMove, PieceToCapture, false, PromoteTo); //add new Move to list AllMoves
                     if (m.IsValidMove)
                     {
                         GameBoard.AllMoves.Add(m);
                         Engine.Audio.PlayEffect("MovePiece");
                         SelectState = SelectionState.SelectPiece;
                         SwitchTurn();
                     }
                     else
                     {
                         NotificationEngine.AddNotification(new Notification("Sorry that would leave you in check!!", 4000));
                         SelectState = SelectionState.SelectPiece;
                     }
                         PromoteTo = Piece.PieceType.None;

                     break;

             } // end switch
        }
Пример #5
0
        public static List<Square> GenerateMoves(Piece pieceToMove, Square fromSq)
        {
            //Call method based on Type of Piece passed in
            List<Square> list = new List<Square>();
            List<Square> result;

            switch (pieceToMove.Piece_Type)
            {
                case Piece.PieceType.King:
                   result = new List<Square>();
                   list = _board.GetSquareListFromBB(GenerateKingMoves(fromSq, pieceToMove.ColorType));
                    if(list != null)
                    {
                        foreach (Square s in list)
                        {
                        var m = new Move(null, _board, fromSq, s, pieceToMove);
                        if(m.IsValidMove)
                            result.Add(m.ToSquare);
                    }
                    }
                    return result;
                case Piece.PieceType.Pawn:
                    result = new List<Square>();
                    list = _board.GetSquareListFromBB(GeneratePawnMoves(fromSq, pieceToMove.ColorType));
                    if(list != null)
                    {
                        foreach (Square s in list)
                        {
                        var m = new Move(null, _board, fromSq, s, pieceToMove);
                        if(m.IsValidMove)
                            result.Add(m.ToSquare);
                    }
                    }
                    return result;
                case Piece.PieceType.Knight:
                    result = new List<Square>();
                    list = _board.GetSquareListFromBB(GenerateKnightMoves(fromSq, pieceToMove.ColorType));
                    if(list != null)
                    {
                        foreach (Square s in list)
                        {
                        var m = new Move(null, _board, fromSq, s, pieceToMove);
                        if(m.IsValidMove)
                            result.Add(m.ToSquare);
                    }
                    }
                    return result;
                case Piece.PieceType.Bishop:
                    result = new List<Square>();
                    list = _board.GetSquareListFromBB(GenerateBishopMoves(fromSq, pieceToMove.ColorType));
                    if(list != null)
                    {
                        foreach (Square s in list)
                        {
                        var m = new Move(null, _board, fromSq, s, pieceToMove);
                        if(m.IsValidMove)
                            result.Add(m.ToSquare);
                    }
                    }
                    return result;
                case Piece.PieceType.Rook:
                    result = new List<Square>();
                    list = _board.GetSquareListFromBB(GenerateRookMoves(fromSq, pieceToMove.ColorType));
                    if(list != null)
                    {
                        foreach (Square s in list)
                        {
                        var m = new Move(null, _board, fromSq, s, pieceToMove);
                        if(m.IsValidMove)
                            result.Add(m.ToSquare);
                    }
                    }
                    return result;
                case Piece.PieceType.Queen:
                   result = new List<Square>();
                   list = _board.GetSquareListFromBB(GenerateQueenMoves(fromSq, pieceToMove.ColorType));
                    if(list != null)
                    {
                        foreach (Square s in list)
                        {
                        var m = new Move(null, _board, fromSq, s, pieceToMove);
                        if(m.IsValidMove)
                            result.Add(m.ToSquare);
                    }
                    }
                    return result;

                default:
                    return null;
            }
        }