private void RpcMovePieceModel(Vector3 from, Vector3 to)
    {
        if (currentlySelectedPiece == null)
        {
            return;
        }

        moveModel.MovePiece(from, to);
        TookPiece();

        if (isServer)
        {
            RpcMark(from, to);
        }
        else
        {
            CmdMark(from, to);
        }

        currentlySelectedPiece.SetPosition(to);
        moveTime    = Time.time;
        isPieceMove = true;

        DrawPiece.ClearHighlight();
        drawBoard.ClearHighlights();

        board.UpdateBoardThreat(null, Vector2.down);
    }
Beispiel #2
0
    protected void MovePieceModel(Vector3 from, Vector3 to)
    {
        if (currentlySelectedPiece == null)
        {
            return;
        }

        moveModel.MovePiece(from, to);
        TookPiece();
        board.Mark(to, currentlySelectedPiece);
        board.UnMark(from);

        TogglePromoteMenu();

        currentlySelectedPiece.SetPosition(to);
        movePieceTo = movePieceFrom = Vector3.down;
        moveTime    = Time.time;
        isPieceMove = true;

        DrawPiece.ClearHighlight();
        drawBoard.ClearHighlights();


        board.UpdateBoardThreat(null, Vector2.down);
        if (KingInCheck.IsBlackInCheck() == true || KingInCheck.IsWhiteInCheck() == true)
        {
            CheckMate();
        }
    }
Beispiel #3
0
 protected virtual void PromoteMenuSelect()
 {
     board.Mark(currentlySelectedPiece.GetPiecePosition(), Promote.Promotes(promoteType, (Pawn)currentlySelectedPiece));
     drawPiece.ChangeModelType(currentlySelectedPiece.GetPiecePosition(), promoteType, currentlySelectedPiece.GetTeam());
     DrawPiece.ClearHighlight();
     promoteMenu.SetActive(false);
     //SwitchTurnDisplay();
 }
Beispiel #4
0
 // Update is called once per frame
 protected virtual void Update()
 {
     //handles moving a piece
     if ((DrawBoard.IsClicked || DrawPiece.IsClicked) && movePieceFrom != Vector3.down)
     {
         //here must disallow moving pieces to anywhere other than a legal square
         if (legalMovesForAPiece != null)
         {
             movePieceTo = DrawBoard.IsClicked ? DrawBoard.SquarePosition : DrawPiece.PiecePosition;
             DrawPiece.ClearHighlight();
             if (board.IsOccupied(movePieceTo))
             {
                 //if the color of the piece matches the current turn
                 if (board.GetPieceAt(movePieceTo).GetTeam() == gameState.getState())
                 {
                     movePieceTo   = Vector3.down;
                     movePieceFrom = Vector3.down;
                     drawBoard.ClearHighlights();
                     return;
                 }
             }
             else
             {
                 drawBoard.ClearHighlights();
             }
             if (!legalMovesForAPiece.Contains(movePieceTo))
             {
                 movePieceTo            = Vector3.down;
                 currentlySelectedPiece = null;
             }
         }
     }
     //handles clicking a piece
     else if (DrawPiece.IsClicked)
     {
         SelectPiece();
     }
     // If the user has clicked on a space to move and a piece to move, move the piece and reset the vectors to numbers the user cannot choose.
     // In the real game we would also have to check if it is a valid move.
     if (movePieceFrom != Vector3.down && movePieceTo != Vector3.down)
     {
         MovePieceModel(movePieceFrom, movePieceTo);
     }
 }
    private void RpcUpdate()
    {
        //handles moving a piece
        if ((DrawBoard.IsClicked || DrawPiece.IsClicked) && (movePieceFrom != Vector3.down || localFrom != Vector3.down))
        {
            currentlySelectedPiece = board.GetPieceAt(localFrom);
            //here must disallow moving pieces to anywhere other than a legal square
            if (legalMovesForAPiece != null)
            {
                foreach (Vector3 move in legalMovesForAPiece)
                {
                    Debug.Log(move);
                }

                movePieceTo = DrawBoard.IsClicked ? DrawBoard.SquarePosition : DrawPiece.PiecePosition;
                localTo     = movePieceTo;
                DrawPiece.ClearHighlight();
                if (board.IsOccupied(localTo))
                {
                    //if the color of the piece matches the current turn
                    if (board.GetPieceAt(movePieceTo).GetTeam() == gameState.getState())
                    {
                        movePieceTo = movePieceFrom = localTo = localFrom = Vector3.down;
                        drawBoard.ClearHighlights();
                        return;
                    }
                }
                else
                {
                    drawBoard.ClearHighlights();
                }
                if (!legalMovesForAPiece.Contains(localTo))
                {
                    currentlySelectedPiece = null;
                    movePieceTo            = localTo = Vector3.down;
                }
            }
        }
        //handles clicking a piece
        else if (DrawPiece.IsClicked)
        {
            if (isLocalPlayer)
            {
                if (isServer)
                {
                    RpcSelectPiece();
                }
                else
                {
                    CmdSelectPiece();
                }
            }
        }
        // If the user has clicked on a space to move and a piece to move, move the piece and reset the vectors to numbers the user cannot choose.
        // In the real game we would also have to check if it is a valid move.
        if (movePieceFrom != Vector3.down && movePieceTo != Vector3.down && isServer)
        {
            RpcMovePieceModel(movePieceFrom, movePieceTo);
        }
        else if (localFrom != Vector3.down && localTo != Vector3.down && !isServer)
        {
            CmdMovePieceModel(localFrom, localTo);
        }
    }
Beispiel #6
0
    // Update is called once per frame
    protected override void Update()
    {
        bool pieceDoneMoving = Time.time - moveTime > waitTime && isPieceMove == true;

        if (pieceDoneMoving)
        {
            startMoveTime = Time.time;
            isPieceMove   = false;
            SwitchTurnDisplay();
        }

        if (gameState.getState() == GameState.WHITE_TURN)
        {
            //handles moving a piece
            if ((DrawBoard.IsClicked || DrawPiece.IsClicked) && movePieceFrom != Vector3.down)
            {
                //here must disallow moving pieces to anywhere other than a legal square
                if (legalMovesForAPiece != null)
                {
                    movePieceTo = DrawBoard.IsClicked ? DrawBoard.SquarePosition : DrawPiece.PiecePosition;
                    DrawPiece.ClearHighlight();
                    if (board.IsOccupied(movePieceTo))
                    {
                        //if the color of the piece matches the current turn
                        if (board.GetPieceAt(movePieceTo).GetTeam() == gameState.getState())
                        {
                            movePieceTo   = Vector3.down;
                            movePieceFrom = Vector3.down;
                            drawBoard.ClearHighlights();
                            return;
                        }
                    }
                    else
                    {
                        drawBoard.ClearHighlights();
                    }
                    if (!legalMovesForAPiece.Contains(movePieceTo))
                    {
                        movePieceTo = Vector3.down;
                    }
                }
            }
            //handles clicking a piece
            else if (DrawPiece.IsClicked)
            {
                SelectPiece();
            }
            // If the user has clicked on a space to move and a piece to move, move the piece and reset the vectors to numbers the user cannot choose.
            // In the real game we would also have to check if it is a valid move.
            if (movePieceFrom != Vector3.down && movePieceTo != Vector3.down)
            {
                MovePieceModel(movePieceFrom, movePieceTo);
                aiMoved = false;
            }
        }
        else if (gameState.getState() == GameState.BLACK_TURN && !aiMoved)
        {
            //SwitchTurnDisplay();
            GetAIMove();
        }
        else if (gameState.getState() == GameState.BLACK_TURN && aiMoved)
        {
            bool choseMove = movePieceFrom != Vector3.down && movePieceTo != Vector3.down;
            if (!enemyAI.IsThinking() && !choseMove)
            {
                movePieceFrom          = enemyAI.GetBestMove().src;
                movePieceTo            = enemyAI.GetBestMove().des;
                currentlySelectedPiece = board.GetPieceAt(movePieceFrom);
            }
            else if (choseMove)
            {
                MovePieceModel(movePieceFrom, movePieceTo);
            }
        }
    }