Exemplo n.º 1
0
    private void ProcessIfPawnStepOnFinalLine(int x, int y)
    {
        if (selectedChessman.GetType() == typeof(Pawn))
        {
            // check if pawn steps on final line, it becomes Queen
            if (y == 7) // white team
            {
                int currentX = selectedChessman.CurrentX, currentY = selectedChessman.CurrentY;
                // remove selected chessman
                activeChessmans.Remove(selectedChessman.gameObject);
                Destroy(selectedChessman.gameObject);

                // spawn new chessman
                SpawnChessman(1, currentX, currentY);
                selectedChessman = Chessmans[currentX, currentY];

                // rotate the chessman
                selectedChessman.RotateEach(ROTATE_TIME);
            }
            else if (y == 0) // black team
            {
                int currentX = selectedChessman.CurrentX, currentY = selectedChessman.CurrentY;
                // remove selected chessman
                activeChessmans.Remove(selectedChessman.gameObject);
                Destroy(selectedChessman.gameObject);

                // spawn new chessman
                SpawnChessman(7, currentX, currentY);
                selectedChessman = Chessmans[currentX, currentY];

                // rotate the chessman
                // selectedChessman.RotateEach(ROTATE_TIME);
            }
        }
    }
Exemplo n.º 2
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "ChessPiece")
        {
            Chessman otherChessman = other.GetComponent <Chessman>();
            if ((this.transform.parent.GetComponent <Chessman>().isWhite != otherChessman.isWhite) && (otherChessman.isTarget))
            {
                BoardManager.Instance.activeChessMan.Remove(otherChessman.gameObject);
                Destroy(otherChessman.gameObject);

                if (this.transform.parent.GetComponent <Chessman>().isWhite)
                {
                    GameManager.WhitePlayerAddScore(GameManager.GetPieceWorth(otherChessman.GetType().ToString()));
                    GameManager.BlackPlayerRemovePiece(otherChessman.GetType().ToString());
                }
                else
                {
                    GameManager.BlackPlayerAddScore(GameManager.GetPieceWorth(otherChessman.GetType().ToString()));
                    GameManager.WhitePlayerRemovePiece(otherChessman.GetType().ToString());
                }
                if (otherChessman.GetType() == typeof(King))
                {
                    BoardManager.Instance.EndGame();
                    return;
                }
            }
            else
            {
                return;
            }
        }
    }
Exemplo n.º 3
0
    private void MoveChessMan(int x, int y)
    {
        if (allowedMoves[x, y])
        {
            //distroy piece
            Chessman c = Chessmans[x, y];
            if (c != null && c.isWhite != isWhiteTurn)
            {
                ////end Game
                //if (c.GetType() == typeof(King))
                //{
                //    EndGame();
                //    return;
                //}

                activeChessMan.Remove(c.gameObject);
                Destroy(c.gameObject);
            }
            if (selectedChessman.GetType() == typeof(Pawn))
            {
                Promotion_pawn(x, y);
            }
            Chessmans[selectedChessman.currentX, selectedChessman.currentY] = null;
            selectedChessman.transform.position = GetTileCenter(x, y);
            selectedChessman.SetPosition(x, y);
            Chessmans[x, y] = selectedChessman;
            isWhiteTurn     = !isWhiteTurn;
        }
        BoardHighlights.Instance.HideHighlights();
        selectedChessman = null;
    }
Exemplo n.º 4
0
    private void MoveChessman(int x, int y)
    {
        if (allowedMoves[x, y])
        {
            Chessman c = Chessmans[x, y];
            if (c != null && c.isWhite != isWhiteTurn)
            {
                // Capture a piece

                // If it is the king end the game
                if (c.GetType() == typeof(King))
                {
                    EndGame();
                    return;
                }
                activeChessMan.Remove(c.gameObject);
                Destroy(c.gameObject);
            }

            Chessmans[selectedChessman.CurrentX, selectedChessman.CurrentY] = null; //we move
            selectedChessman.transform.position = GetTileCenter(x, y + 1);
            selectedChessman.SetPosition(x, y);
            Chessmans[x, y] = selectedChessman;
            isWhiteTurn     = !isWhiteTurn; // swap to other value, only
        }
        BoardHighlights.Instance.Hidehighlights();
        selectedChessman = null; // unselect if click on place doesnt make sense
    }
Exemplo n.º 5
0
    private void MoveChessman(int x, int y)
    {
        //if (selectedChessman.PossibleMove (x, y)) {
        if (allowedMoves[x, y])
        {
            Chessman c = Chessmans [x, y];
            if (c != null && c.isWhite != isWhiteTurn)
            {
                if (c.GetType() == typeof(King))
                {
                    EndGame();
                    return;
                }

                activeChessman.Remove(c.gameObject);
                Destroy(c.gameObject);
            }

            Chessmans[selectedChessman.CurrentX, selectedChessman.CurrentY] = null;
            selectedChessman.transform.position = GetTileCenter(x, y);
            selectedChessman.SetPosition(x, y);
            Chessmans [x, y] = selectedChessman;
            isWhiteTurn      = !isWhiteTurn;
        }

        BoardHighlights.Instance.HideHighlights();
        selectedChessman = null;
    }
Exemplo n.º 6
0
    private void MoveChessman(int x, int y)
    {
        //Debug.Log("MoveChessman , " + x + "  " + y+" , "+Chessmans[x, y]+ "  "+ selectedChessman);
        //Debug.Log("allowedMove"+allowedMoves[x,y]);
        if (allowedMoves[x, y])
        {
            Chessman c = Chessmans[x, y];
            if (c != null && c.isWhite != isWhiteTurn)
            {
                //Capture a piece
                //If it is the king
                if (c.GetType() == typeof(King))
                {
                    EndGame();
                    return;
                }

                activechessman.Remove(c.gameObject);
                Destroy(c.gameObject);
            }
            //Debug.Log("MoveChessman , " + x + "  " + y+" , "+Chessmans[x, y]+ "  "+ selectedChessman);
            Chessmans[selectedChessman.CurrentX, selectedChessman.CurrentY] = null;
            selectedChessman.transform.position = GetTileCenter(x, y);
            selectedChessman.SetPosition(x, y);
            Chessmans[x, y] = selectedChessman;
            isWhiteTurn     = !isWhiteTurn;
        }
        BoardHighlights.Instance.HideHighlights();
        selectedChessman = null;
    }
Exemplo n.º 7
0
    public bool KnightThreat(int x, int y)
    {
        if (x >= 0 && y >= 0 && x <= 7 && y <= 7)
        {
            Chessman piece = BoardManager.Instance.Chessmans[x, y];
            // If the cell is empty
            if (piece == null)
            {
                return(false);
            }

            // If the piece is from same team
            if (piece.isWhite == isWhite)
            {
                return(false);
            }

            // The piece is from Opponent team
            // If the opponent piece is Knight
            if (piece.GetType() == typeof(Knight))
            {
                Debug.Log("Threat from Knight");
                return(true);        // Yes, there is a Knight threat
            }
        }

        return(false);
    }
Exemplo n.º 8
0
    private void MoveChess(int x, int y)
    {
        if (allowedMove[x, y])//teraz dostępne tylko allowed ruchy
        {
            //usuwanie obiektów
            Chessman c = Chessmans[x, y];
            if (c != null && c.ifWhite != whiteTurn)
            {
                activeChessman.Remove(c.gameObject);
                Destroy(c.gameObject);
                if (c.GetType() == typeof(King))
                {
                    EndGame();
                    return;
                }
            }


            Chessmans [selected.CurrentX, selected.CurrentY] = null;
            selected.transform.position = GetCenter(x, y);
            selected.Position(x, y);
            Chessmans[x, y] = selected;
            whiteTurn       = !whiteTurn;
        }
        BoardProcessing.Instance.ProcessHide();
        selected = null;
        //zmiana kolejki ruch_biały -> ruch czarny LOOP
    }
Exemplo n.º 9
0
    private void MoveChessman(int x, int y)
    {
        if (allowedMoves[x, y])
        {
            Chessman c = Chessmans[x, y];
            if (c != null && c.isWhite != isWhiteTurn)
            {
                //capture the piece

                if (c.GetType() == typeof(KingBehavior))
                {
                    EndGame(c);
                    return;
                }

                activeChessman.Remove(c.gameObject);
                Destroy(c.gameObject);
                audioSource.clip = killSound;
                audioSource.Play();
            }
            else
            {
                audioSource.clip = moveSound;
                audioSource.Play();
            }
            Chessmans[selectedChessman.currentX, selectedChessman.currentY] = null;
            selectedChessman.transform.position = GetTileCenter(x, y);
            Chessmans[x, y] = selectedChessman;
            selectedChessman.setPostion(x, y);
            isWhiteTurn = !isWhiteTurn;
        }
        BoardHighlights.Instance.HideHighlights();
        selectedChessman = null;
        // PrintChessmans();
    }
    private void MoveChessman(int x, int z)
    {
        Debug.Log("trying to move");
        if (allowedMoves[x, z])
        {
            //Debug.Log("it is allowed move");
            Chessman enemy = Chessmans[x, z];
            if (enemy != null) //if there is an enemy
            {
                //Debug.Log("destroying enemy");
                activeChessmans.Remove(enemy.gameObject);
                //Destroy(enemy.gameObject); //removing from board
                enemy.transform.position = getDestroyPosition(enemy);
                Chessmans[x, z]          = null; //removing from chessman 2d array

                if (enemy.GetType() == typeof(King))
                {
                    //end game
                    EndGame();
                }
            }
            isMoving = true;
            //Debug.Log("no enemy found");
            target = getObjectPosition(selectedChessman.index, x, z);
            BoardHighlight.Instance.Hidehighlights();
            return;
        }
        Debug.Log("not allowed move");
        selectedChessman = null;
        BoardHighlight.Instance.Hidehighlights();
        Slectchessman(selectionX, selectionZ);
        //Debug.Log("selected chessmen null");
    }
Exemplo n.º 11
0
    private void MoveChessman(int x, int y)
    {
        //if (selectedChessman.PossibleMove (x, y))
        if (allowedMoves[x, y])
        {
            Chessman c = Chessmans [x, y];

            if (c != null && c.isWhite != isWhiteTurn)
            {
                // Capture a piece

                // If it is the king
                if (c.GetType() == typeof(King))
                {
                    //End the game
                    EndGame();
                    return;
                }

                activeChessman.Remove(c.gameObject);
                Destroy(c.gameObject);
            }

            Chessmans[selectedChessman.CurrentX, selectedChessman.CurrentY] = null;
            selectedChessman.transform.position = GetTileCenter(x, y);
            selectedChessman.SetPosition(x, y);
            Chessmans [x, y] = selectedChessman;

            isWhiteTurn = !isWhiteTurn;
        }

//		selectedChessman.GetComponent<MeshRenderer> ().material = previousMat;
        BoardHighlights.Instance.HideHighlights();
        selectedChessman = null;
    }
Exemplo n.º 12
0
    private void MoveChessman(int x, int y)
    {
        if (allowedMoves[x, y])
        {
            Chessman c = Chessmans [x, y];

            if (c != null && c.isWhite != isWhiteTurn)
            {
                if (c.GetType() == typeof(King))
                {
                    EndGame();
                    return;
                }

                activeChessman.Remove(c.gameObject);
                Destroy(c.gameObject);
            }

            // Выбор шахматной фигуры

            Chessmans [selectedChessman.CurrentX, selectedChessman.CurrentY] = null;
            selectedChessman.transform.position = GetTileCenter(x, y);
            selectedChessman.SetPosition(x, y);
            Chessmans [x, y] = selectedChessman;
            isWhiteTurn      = !isWhiteTurn;
        }


        selectedChessman.GetComponent <MeshRenderer> ().material = previousMat;
        BoardHighLights.Instance.Hidehighlights();
        selectedChessman = null;
    }
Exemplo n.º 13
0
    IEnumerator CoroutineAnimationChangePiecePosition(int x, int y, Chessman selectedChessman)
    {
        movingAnimation = true;
        Chessman sc       = selectedChessman;
        Vector3  endPlace = GetTileCenter(x, y);
        var      xEnd     = GetTileCenter(sc.CurrentX, y); //for knight square move

        if (sc.GetType() == typeof(Knight))
        {
            while (sc.transform.position != xEnd)
            {
                sc.transform.position = Vector3.MoveTowards(sc.transform.position, xEnd, Time.deltaTime * animSpeed);
                yield return(new WaitForEndOfFrame());
            }
            while (sc.transform.position != endPlace)
            {
                sc.transform.position = Vector3.MoveTowards(sc.transform.position, endPlace, Time.deltaTime * animSpeed);
                yield return(new WaitForEndOfFrame());
            }
        }
        else
        {
            while (sc.transform.position != endPlace)
            {
                sc.transform.position = Vector3.MoveTowards(sc.transform.position, endPlace, Time.deltaTime * animSpeed);
                yield return(new WaitForEndOfFrame());
            }
        }
        movingAnimation = false;
        yield return(new WaitForEndOfFrame());
    }
Exemplo n.º 14
0
    // move the selected chess piece
    private void MoveChessman(int x, int y)
    {
        if (allowedMoves[x, y])
        {
            Chessman c = Chessmans[x, y];

            // if there's a piece there and it's not your team
            if (c != null && c.isWhite != isWhiteTurn)
            {
                if (c.GetType() == typeof(King))
                {
                    // End the game
                    return;
                }

                // capture a piece
                activeChessman.Remove(c.gameObject);
                Destroy(c.gameObject);
            }

            // remove the piece from it's original position in the 2d array
            Chessmans[selectedChessman.CurrentX, selectedChessman.CurrentY] = null;

            // get the position of the selected piece
            selectedChessman.transform.position = GetTileCenter(x, y);

            //
            selectedChessman.SetPosition(x, y);
            Chessmans[x, y] = selectedChessman;
            isWhiteTurn     = !isWhiteTurn;
        }
        BoardHighlights.Instance.HideHighlights();
        selectedChessman = null;
    }
Exemplo n.º 15
0
    public void MoveChessman(int x, int y)
    {
        if (allowedMoves[x, y])
        {
            if (chessMate != null)
            {
                BoardHighlights.Instance.HideCheckedHighlight();
                chessMate.HidePowerEffect();
                chessMate = null;
            }

            Chessman c      = Chessmans[x, y];
            float    delays = 0f;

            // Check EnPassantMove
            ProcessEnPassantMove(c, x, y, out delays);

            // Eat chessman
            bool isEatChess = false;
            if (c != null && c.isWhite != isWhiteTurn)
            {
                delays = DELAY_TIME;
                c.RotateEach(ROTATE_TIME);
                c.DestroyAfter(delays);

                BoardHighlights.Instance.ShowKillerHighlight(new Vector3(x + 0.5f, 0, y + 0.5f));
                BoardHighlights.Instance.HideKillerHighlightAfter(delays);
                isEatChess = true;

                if (c.GetType() == typeof(King))
                {
                    EndGame();
                    return;
                }
            }

            BoardHighlights.Instance.ShowHoverHighlight(new Vector3(x + 0.5f, 0, y + 0.5f));

            // check if pawn step on final line
            ProcessIfPawnStepOnFinalLine(x, y);

            // Move selected chessman to x, y position
            MoveSelectedChessmanTo(x, y, delays);

            // Checkmate
            if (!IsCheckmate(Chessmans[x, y].PossibleMove()) && isEatChess)
            {
                selectedChessman.PlayPowerEffectFor(DELAY_TIME);
            }
            ProcessCheckmate(x, y);

            // Change turn
            isWhiteTurn = !isWhiteTurn;
        }

        BoardHighlights.Instance.HideHighlights();
        selectedChessman = null;
    }
Exemplo n.º 16
0
    private void MoveChessman(int x, int y)
    {
        if (allowedMoves[x, y])
        {
            Chessman c = Chessmans [x, y];
            if (c != null && c.isWhite != isWhiteTurn)
            {
                //capture a piece

                //if it is the king
                if (c.GetType() == typeof(King))
                {
                    EndGame();
                    return;
                }

                activeChessman.Remove(c.gameObject);
                Destroy(c.gameObject);
            }
            //EnPassantMove [1] = -1;
            //EnPassantMove [1] = -1;
            if (selectedChessman.GetType() == typeof(Pawns))
            {
                if (y == 7)
                {
                    activeChessman.Remove(selectedChessman.gameObject);
                    Destroy(selectedChessman.gameObject);
                    SpawnChessman(1, x, y);
                    selectedChessman = Chessmans [x, y];
                }
                if (y == 0)
                {
                    activeChessman.Remove(selectedChessman.gameObject);
                    Destroy(selectedChessman.gameObject);
                    SpawnChessman(7, x, y);
                    selectedChessman = Chessmans [x, y];
                }
                //if(selectedChessman.CurrentY == 1&& y ==3){
                //EnPassantMove [1] = x;
                //EnPassantMove [1] = y - 1;

                //}
                //else if (selectedChessman.CurrentY == 6&& y ==4){
                //EnPassantMove [1] = x;
                //EnPassantMove [1] = y + 1;
                //}
            }

            Chessmans [selectedChessman.CurrentX, selectedChessman.CurrentY] = null;
            selectedChessman.transform.position = GetTileCenter(x, y);
            selectedChessman.SetPosition(x, y);
            Chessmans [x, y] = selectedChessman;
            isWhiteTurn      = !isWhiteTurn;
        }
        selectedChessman.GetComponent <MeshRenderer> ().material = previousMat;
        BoardHighlights.Instance.Hidehighlights();
        selectedChessman = null;
    }
Exemplo n.º 17
0
    private void ChangePiecePosition(int x, int y)
    {
        previousLocation = new Vector2Int(selectedChessman.CurrentX, selectedChessman.CurrentY);
        Chessman c = Chessmen[x, y];

        if (c != null && c.isWhite != isWhiteTurn)
        {
            activeChessman.Remove(c.gameObject);
            c.gameObject.SetActive(false);
            var k = c.gameObject.transform.GetChild(0).gameObject;
            k.transform.parent = transform;
            k.SetActive(true);
            SoundManager.Instance.ShatterSound();
            Destroy(k.gameObject, 2f);
        }
        Chessmen[selectedChessman.CurrentX, selectedChessman.CurrentY] = null;
        //selectedChessman.transform.position = GetTileCenter(x, y);
        StartCoroutine(CoroutineAnimationChangePiecePosition(x, y, selectedChessman));
        selectedChessman.SetPosition(x, y);
        Chessmen[x, y] = selectedChessman;
        if (selectedChessman.GetType() == typeof(King))
        {
            if (isWhiteTurn)
            {
                whiteKing = new Vector2Int(x, y);
            }
            else
            {
                blackKing = new Vector2Int(x, y);
            }
        }
    }
Exemplo n.º 18
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "ChessPiece")
        {
            Chessman otherChessman = other.GetComponent <Chessman>();
            if ((this.GetComponent <Chessman>().isWhite != otherChessman.isWhite) && (otherChessman.isTarget))
            {
                print("I hit an enemy");
                BoardManager.Instance.activeChessMan.Remove(otherChessman.gameObject);

                CrumbleAudio.Play();
                ScreamAudio.Play();
                Instantiate(Flash, transform.position, Quaternion.identity);
                Destroy(otherChessman.gameObject);
            }



            if (this.GetComponent <Chessman>().isWhite)
            {
                GameManager.WhitePlayerAddScore(GameManager.GetPieceWorth(otherChessman.GetType().ToString()));
                GameManager.BlackPlayerRemovePiece(otherChessman.GetType().ToString());
            }
            else
            {
                GameManager.BlackPlayerAddScore(GameManager.GetPieceWorth(otherChessman.GetType().ToString()));
                GameManager.WhitePlayerRemovePiece(otherChessman.GetType().ToString());
            }
            if (otherChessman.GetType() == typeof(King))
            {
                BoardManager.Instance.EndGame();
                return;
            }
        }
        else
        {
            return;
        }
    }
Exemplo n.º 19
0
    public bool ThreatenedSpace(int x, int y)
    {
        bool threatened = false;

        bool[,] possibleMovesList = new bool[8, 8];

        foreach (GameObject chessman in activeChessman)
        {
            Chessman ch = chessman.GetComponent <Chessman>();
            if (ch.GetType() != typeof(King))
            {
                if (ch.isWhite != isWhiteTurn)
                {
                    possibleMovesList = ch.PossibleMove();
                    if (possibleMovesList[x, y])
                    {
                        threatened = true;
                    }
                }
            }
        }
        return(threatened);
    }
Exemplo n.º 20
0
    private void DisplayHelp()
    {
        GameObject display = GameObject.FindGameObjectWithTag("DisplayHelp");

        if (isWhiteTurn)
        {
            display.transform.eulerAngles = new Vector3(0, 0, 180);
        }
        else
        {
            display.transform.eulerAngles = new Vector3(0, 0, 0);
        }
        if (selectedChessman != null)
        {
            if (selectedChessman.GetType() == typeof(King))
            {
                display.GetComponent <Renderer>().material.mainTexture = guideImages[0];
            }
            else if (selectedChessman.GetType() == typeof(Queen))
            {
                display.GetComponent <Renderer>().material.mainTexture = guideImages[1];
            }
            else if (selectedChessman.GetType() == typeof(Rook))
            {
                display.GetComponent <Renderer>().material.mainTexture = guideImages[2];
            }
            else if (selectedChessman.GetType() == typeof(Bishop))
            {
                display.GetComponent <Renderer>().material.mainTexture = guideImages[3];
            }
            else if (selectedChessman.GetType() == typeof(Knight))
            {
                display.GetComponent <Renderer>().material.mainTexture = guideImages[4];
            }
            else if (selectedChessman.GetType() == typeof(Pawn))
            {
                display.GetComponent <Renderer>().material.mainTexture = guideImages[5];
            }
        }
        else
        {
            display.GetComponent <Renderer>().material.mainTexture = guideImages[6];
        }
    }
Exemplo n.º 21
0
    private void MoveChessman(int x, int y)
    {
        if (allowedMoves [x, y])
        {
            Chessman c = Chessmans [x, y];
            if (c != null && c.isWhite != isWhiteTurn)
            {
                // SI c'est le ROI
                if (c.GetType() == typeof(King))
                {
                    // FIN de la Partie
                    EndGame();
                    return;
                }

                //Capturer une piece
                activeChessman.Remove(c.gameObject);
                Destroy(c.gameObject);
            }


            Chessmans [selectedChessman.CurrentX, selectedChessman.CurrentY] = null;
            selectedChessman.transform.position = GetTileCenter(x, y);
            //
            selectedChessman.SetPosition(x, y);
            Chessmans [x, y] = selectedChessman;
            //Changer le tour apres un deplacement
            isWhiteTurn = !isWhiteTurn;
            message_tour_humains.enabled = true;
            StartCoroutine("endMoveHumains");
        }
        BoardHighlights.Instance.Hidehighlights();
        selectedChessman            = null;
        message_tour_enfers.enabled = true;
        StartCoroutine("endMoveEnfers");
    }
Exemplo n.º 22
0
    }           //Selecting the chessman.

    private void MoveChessman(int x, int y)
    {
        if (allowedMoves[x, y])
        {
            Chessman c = Chessmans[x, y];

            if (c != null && c.isWhite != isWhiteTurn)
            {
                if (c.GetType() == typeof(King))
                {
                    EndGame();
                    return;
                }

                ActiveChesses.Remove(c.gameObject);
                Destroy(c.gameObject);
            }

            Chessmans[selectedChessman.CurrentX, selectedChessman.CurrentY] = null;
            selectedChessman.transform.position = GetCenter(x, y);
            selectedChessman.CurrentX           = x;
            selectedChessman.CurrentY           = y;
            Chessmans[x, y] = selectedChessman;
            isWhiteTurn     = !isWhiteTurn;
            cameraBlindTime = 3f;
        }

        foreach (GameObject go in BoardHighlight.Instance.Highlights)
        {
            Destroy(go);
        }

        BoardHighlight.Instance.Highlights.Clear();
        Chessmans[selectedChessman.CurrentX, selectedChessman.CurrentY].GetComponentInChildren <Light>().intensity = 0;
        selectedChessman = null;
    }             //Move the chessman.
Exemplo n.º 23
0
    private int ChessmanObjToEnum(Chessman c)
    {
        int aux = -1;

        if (c == null)
        {
            return(aux);
        }

        if (c.GetType() == typeof(KingBehavior))
        {
            aux = (int)ChessmansEnum.wking;
        }
        else if (c.GetType() == typeof(QueenBehavior))
        {
            aux = (int)ChessmansEnum.wqueen;
        }
        else if (c.GetType() == typeof(BishopBehavior))
        {
            aux = (int)ChessmansEnum.wbishop;
        }
        else if (c.GetType() == typeof(KnightBehavior))
        {
            aux = (int)ChessmansEnum.wknight;
        }
        else if (c.GetType() == typeof(RookBehavior))
        {
            aux = (int)ChessmansEnum.wrook;
        }
        else if (c.GetType() == typeof(PawnBehavior))
        {
            aux = (int)ChessmansEnum.wpawn;
        }

        if (!c.isWhite)
        {
            return(aux + 6);
        }
        return(aux);
    }
Exemplo n.º 24
0
    /// <summary>
    /// Сделать ход
    /// </summary>
    /// <param name="x">Координата X</param>
    /// <param name="y">Координата Y</param>
    private void MoveChessman(int x, int y)
    {
        // Можно ли сделать ход на выбранную клетку
        if (allowedMoves[x, y])
        {
            // На выбранной клетке нет фигур или есть фигура противоположного цвета
            Chessman c = Chessmans[x, y];
            if (c != null && c.isWhite != isWhiteTurn)
            {
                // На выбранной клетке стоит Король противоположного цвета
                if (c.GetType() == typeof(King))
                {
                    // Конец игры
                    activeChessman.Remove(c.gameObject);
                    Destroy(c.gameObject);
                    EndGame();
                    return;
                }

                activeChessman.Remove(c.gameObject);
                Destroy(c.gameObject);
            }


            // Ходит Король
            if (selectedChessman.GetType() == typeof(King) && ((King)selectedChessman).isRavirovka)
            {
                // Король больше не может рокироваться
                ((King)selectedChessman).isRavirovka = false;

                if (x == selectedChessman.CurrentX + 2) // Рокировка вправо
                {
                    Chessman rook = Chessmans[7, selectedChessman.CurrentY];
                    Chessmans[rook.CurrentX, rook.CurrentY] = null;
                    rook.transform.position = GetTileCenter(x - 1, y);
                    rook.SetPosition(x - 1, y);
                    Chessmans[x - 1, y] = rook;
                }
                else if (x == selectedChessman.CurrentX - 2) // Рокировка влево
                {
                    Chessman rook = Chessmans[0, selectedChessman.CurrentY];
                    Chessmans[rook.CurrentX, rook.CurrentY] = null;
                    rook.transform.position = GetTileCenter(x + 1, y);
                    rook.SetPosition(x + 1, y);
                    Chessmans[x + 1, y] = rook;
                }
            }
            // Ход Ладьёй
            else if (selectedChessman.GetType() == typeof(Rook) &&
                     ((Rook)selectedChessman).isRavirovka)
            {
                // Ладья больше не может рокироваться
                ((Rook)selectedChessman).isRavirovka = false;
            }


            // Переместить фигуру
            Chessmans[selectedChessman.CurrentX, selectedChessman.CurrentY] = null; // На выбранной клетке больше нет фигуры
            selectedChessman.transform.position = GetTileCenter(x, y);              // Переместить выбранную фигуру на новое место
            selectedChessman.SetPosition(x, y);                                     // Установить новое положение на доске у фиуры
            Chessmans[x, y] = selectedChessman;                                     // Установить на данной позиции новую фигуру

            // Замена пешки на другую фигуру, если она дошла до
            // противоположного края доски
            if (selectedChessman.GetType() == typeof(Pawn) &&
                (y == 7 || y == 0))
            {
                // Запомнить пешку, которую нужно заменить
                deleteChessman = selectedChessman;
                // Отобразить UI замены пешки
                ReplacePawn.gameIsPaused = true;
            }

            // Изменить условие, чей цвет ходит
            isWhiteTurn = !isWhiteTurn;
        }

        // Установить стандартный материал на выбранной фигуре
        selectedChessman.GetComponent <MeshRenderer>().material = previousMat;

        // Скрыть доступные ходы
        BoardHighLights.Instance.Hidehighlights();
        // Сбросить выделенную фигуру (никакая фигура не выбрана)
        selectedChessman = null;
    }
Exemplo n.º 25
0
    public void MoveChessmanAI()
    {
        // Cancello l'highlight dell'ultima mossa
        BoardHighlights.Instance.Hidelastmove();

        // Posizione finale
        Chessman c = Chessmans[pendingX, pendingY];

        // Cattura pezzo
        if (c != null)
        {
            // Se è il re
            if (c.GetType() == typeof(King))
            {
                // End the game
                //EndGame();
                return;
            }

            activeChessman.Remove(c.gameObject);
            Destroy(c.gameObject);
            selectedChessman = null;
        }
        BoardHighlights.Instance.Hidelastmove();
        // Evidenzia la mossa
        bool[,] lastMove = new bool[8, 8];
        lastMove[selectionX, selectionY] = true;
        lastMove[pendingX, pendingY]     = true;
        BoardHighlights.Instance.HighlightLastMove(lastMove);
        // Partenza
        selectedChessman          = Chessmans[selectionX, selectionY];
        selectedChessman.CurrentX = selectionX;
        selectedChessman.CurrentY = selectionY;
        Chessmans[selectedChessman.CurrentX, selectedChessman.CurrentY] = null;

        // Arrocco
        if (selectedChessman.GetType() == typeof(KingUci) && canCastling_AI)
        {
            Castling_AI();
        }
        // EnPassant
        if (selectedChessman.GetType() == typeof(PawnUci) && c == null)
        {
            EnPassant_AI(pendingX, pendingY);
        }
        // Arrivo
        selectedChessman.transform.position = Utility.Instance.GetTileCenter(pendingX, pendingY);
        selectedChessman.SetPosition(pendingX, pendingY);
        Chessmans[pendingX, pendingY] = selectedChessman;

        // Cambio turno
        isPending   = false;
        isWhiteTurn = !isWhiteTurn;

        // Cambio Materiale
        previousMat             = selectedChessman.GetComponent <MeshRenderer>().material;
        selectedMat.mainTexture = previousMat.mainTexture;
        selectedChessman.GetComponent <MeshRenderer>().material = selectedMat;
        selectedChessman.GetComponent <MeshRenderer>().material = previousMat;

        // reset
        selectedChessman = null;
    }
Exemplo n.º 26
0
    private void MoveChessman(int x, int y)
    {
        if (allowedMoves[x, y])
        {
            Chessman c = Chessmans[x, y];

            if (c != null && c.isWhite != isWhiteTurn)
            {
                // Cattura pezzo

                // Se è il re
                if (c.GetType() == typeof(KingUci))
                {
                    // End the game
                    //EndGame();
                    return;
                }
                // Tolgo il pezzo
                activeChessman.Remove(c.gameObject);
                Destroy(c.gameObject);
            }

            // Prendo la posizione iniziale del pezzo
            initialX = selectedChessman.CurrentX;
            initialY = selectedChessman.CurrentY;

            string initial   = Utility.Instance.Translate(initialX, initialY);
            string ending    = Utility.Instance.Translate(x, y);
            string finalMove = initial + ending;
            Debug.Log(finalMove);
            //---MOSSE LEGALI---

            /*
             * if (!(IsLegal(finalMove)))
             * {
             *  Debug.Log("Mossa illegale!");
             *  return;
             * }*/

            // Metto a null la casa da cui muovo
            Chessmans[selectedChessman.CurrentX, selectedChessman.CurrentY] = null;
            // Muovo effettivamente il pezzo
            selectedChessman.transform.position = Utility.Instance.GetTileCenter(x, y);
            selectedChessman.SetPosition(x, y);
            Chessmans[x, y] = selectedChessman;

            // Arrocco
            if (selectedChessman.GetType() == typeof(KingUci) && canCastling)
            {
                Castling(finalMove);
            }
            // Promozione
            if (selectedChessman.GetType() == typeof(PawnUci) && ending[1] == '8')
            {
                Promote(finalMove, x, y);
                return;
            }
            // EnPassant
            if (selectedChessman.GetType() == typeof(PawnUci) && c == null)
            {
                EnPassant(x, y);
            }

            // Invio la mossa al server
            Middleware.Instance.DoMove(finalMove);
            //Cambio turno
            isWhiteTurn = !isWhiteTurn;
        }
        // Togli l'evidenzia
        selectedChessman.GetComponent <MeshRenderer>().material = previousMat;
        // Eliminazione degli highlight
        BoardHighlights.Instance.Hidehighlights();

        selectedChessman = null;
    }
Exemplo n.º 27
0
    private void MoveChessman(int x, int y)
    {
        if (allowedMoves[x, y])
        {
            Chessman c = Chessmans[x, y];

            if (c != null && c.isWhite != isWhiteTurn)
            {
                //Capture a piece
                activeChessPieces.Remove(c.gameObject);
                Destroy(c.gameObject);
                destroySound.Play();
            }

            // enpassant move
            if (x == EnPassantMove[0] && y == EnPassantMove[1])
            {
                if (isWhiteTurn)
                {
                    c = Chessmans[x, y - 1];
                }
                else
                {
                    c = Chessmans[x, y + 1];
                }

                activeChessPieces.Remove(c.gameObject);
                Destroy(c.gameObject);
                destroySound.Play();
            }
            EnPassantMove[0] = -1;
            EnPassantMove[1] = -1;
            if (selectedChessman.GetType() == typeof(Pawn))
            {
                // promote for white rook
                if (y == 7)
                {
                    activeChessPieces.Remove(selectedChessman.gameObject);
                    Destroy(selectedChessman.gameObject);
                    SpawnChessPieces(0, x, y);
                    selectedChessman = Chessmans[x, y];
                    promotionSound.Play();
                }
                // promote for black rook
                else if (y == 0)
                {
                    activeChessPieces.Remove(selectedChessman.gameObject);
                    Destroy(selectedChessman.gameObject);
                    SpawnChessPieces(2, x, y);
                    selectedChessman = Chessmans[x, y];
                    promotionSound.Play();
                }

                if (selectedChessman.CurrentY == 1 && y == 3)
                {
                    EnPassantMove[0] = x;
                    EnPassantMove[1] = y - 1;
                }
                else if (selectedChessman.CurrentY == 6 && y == 4)
                {
                    EnPassantMove[0] = x;
                    EnPassantMove[1] = y + 1;
                }
            }

            Chessmans[selectedChessman.CurrentX, selectedChessman.CurrentY] = null;
            selectedChessman.transform.position = GetTileCenter(x, y);
            selectedChessman.SetPosition(x, y);
            Chessmans[x, y] = selectedChessman;
            isWhiteTurn     = !isWhiteTurn;
            moveSound.Play();
        }

        selectedChessman.GetComponent <MeshRenderer>().material = previousMat;
        BoardHighlights.Instance.HideHighlights();
        selectedChessman = null;
    }
Exemplo n.º 28
0
    private void MoveChessman(int x, int y)
    {
        if (allowedMoves[x, y])
        {
            Chessman c = Chessmans [x, y];

            if (c != null && c.isWhite != isWhiteTurn)
            {
                // CAPTURE A PIECE

                // IF IT IS THE KING
                if (c.GetType() == typeof(King))
                {
                    EndGame();
                    return;
                }

                activeChessman.Remove(c.gameObject);
                Destroy(c.gameObject);
            }

            if (x == EnPassantMove[0] && y == EnPassantMove[1])
            {
                c = Chessmans[x, isWhiteTurn ? y - 1 : y + 1];

                activeChessman.Remove(c.gameObject);
                Destroy(c.gameObject);
            }
            EnPassantMove[0] = -1;
            EnPassantMove[1] = -1;
            if (selectedChessman.GetType() == typeof(Pawn))
            {
                if (y == 7)
                {
                    activeChessman.Remove(selectedChessman.gameObject);
                    Destroy(selectedChessman.gameObject);
                    SpawnChessman(1, x, y);
                    selectedChessman = Chessmans[x, y];
                }

                else if (y == 0)
                {
                    activeChessman.Remove(selectedChessman.gameObject);
                    Destroy(selectedChessman.gameObject);
                    SpawnChessman(7, x, y);
                }

                if (selectedChessman.CurrentY == 1 && y == 3)
                {
                    EnPassantMove[0] = x;
                    EnPassantMove[1] = y - 1;
                }
                else if (selectedChessman.CurrentY == 6 && y == 4)
                {
                    EnPassantMove[0] = x;
                    EnPassantMove[1] = y + 1;
                }
            }

            Chessmans[selectedChessman.CurrentX, selectedChessman.CurrentY] = null;
            selectedChessman.transform.position = GetTileCenter(x, y);
            selectedChessman.SetPosition(x, y);
            Chessmans[x, y] = selectedChessman;
            isWhiteTurn     = !isWhiteTurn;
        }

        selectedChessman.GetComponent <MeshRenderer>().material = previousMat;
        BoardHighlights.Instance.HideHighlights();
        selectedChessman = null;
    }
Exemplo n.º 29
0
    public void eval()
    {
        piece[X].sc = new int[8, 8];
        Chessman c2;

        for (int i = 0; i < 8; i++)
        {
            for (int j = 0; j < 8; j++)
            {
                c2 = BoardManager.Instance.Chessmans[i, j];
                if (piece[X].pm[i, j] == true && rw[i, j] == true)
                {
                    piece[X].sc[i, j] = -15;
                }

                if (c2 != null && !c2.isWhite && rw[i, j] == true)
                {
                    if (c2.GetType() == typeof(King))
                    {
                        if (-1 > piece[X].sc[i, j])
                        {
                            piece[X].sc[i, j] = -1;
                            break;
                        }
                    }
                    else if (c2.GetType() == typeof(Queen))
                    {
                        if (-2 > piece[X].sc[i, j])
                        {
                            piece[X].sc[i, j] = -2;
                        }
                    }
                    else if (c2.GetType() == typeof(Rook))
                    {
                        if (-3 > piece[X].sc[i, j])
                        {
                            piece[X].sc[i, j] = -3;
                        }
                    }
                    else if (c2.GetType() == typeof(Knight))
                    {
                        if (-4 > piece[X].sc[i, j])
                        {
                            piece[X].sc[i, j] = -4;
                        }
                    }
                    else if (c2.GetType() == typeof(Bishop))
                    {
                        if (-5 > piece[X].sc[i, j])
                        {
                            piece[X].sc[i, j] = -5;
                        }
                    }
                    else if (c2.GetType() == typeof(Pawn))
                    {
                        if (-14 > piece[X].sc[i, j])
                        {
                            piece[X].sc[i, j] = -14;
                        }
                    }
                }

                if (c2 != null && c2.isWhite && piece[X].pm[i, j] == true)
                {
                    if (c2.GetType() == typeof(King))
                    {
                        if (-1 >= piece[X].sc[i, j])
                        {
                            piece[X].sc[i, j] = -1;
                            break;
                        }
                    }
                    else if (c2.GetType() == typeof(Queen))
                    {
                        if (-3 >= piece[X].sc[i, j])
                        {
                            piece[X].sc[i, j] = -3;
                        }
                    }
                    else if (c2.GetType() == typeof(Rook))
                    {
                        if (-4 >= piece[X].sc[i, j])
                        {
                            piece[X].sc[i, j] = -4;
                        }
                    }
                    else if (c2.GetType() == typeof(Knight))
                    {
                        if (-5 >= piece[X].sc[i, j])
                        {
                            piece[X].sc[i, j] = -5;
                        }
                    }
                    else if (c2.GetType() == typeof(Bishop))
                    {
                        if (-6 >= piece[X].sc[i, j])
                        {
                            piece[X].sc[i, j] = -6;
                        }
                    }
                    else if (c2.GetType() == typeof(Pawn))
                    {
                        if (-8 >= piece[X].sc[i, j])
                        {
                            piece[X].sc[i, j] = -8;
                        }
                    }
                }
                if (c2 == null && rw[i, j] == false && piece[X].pm[i, j] == true)
                {
                    System.Random rand = new System.Random();
                    piece[X].sc[i, j] = -(rand.Next(5, 14));
                }
            }
        }

        best(piece[X].sc);
    }
Exemplo n.º 30
0
    public void MoveChessman(int x, int y)
    {
        if (allowedMoves[x, y])
        {
            Chessman opponent = Chessmans[x, y];

            if (opponent != null)
            {
                // Capture an opponent piece
                ActiveChessmans.Remove(opponent.gameObject);
                Destroy(opponent.gameObject);
            }
            // -------EnPassant Move Manager------------
            // If it is an EnPassant move than Destroy the opponent
            if (EnPassant[0] == x && EnPassant[1] == y && SelectedChessman.GetType() == typeof(Pawn))
            {
                if (isWhiteTurn)
                {
                    opponent = Chessmans[x, y + 1];
                }
                else
                {
                    opponent = Chessmans[x, y - 1];
                }

                ActiveChessmans.Remove(opponent.gameObject);
                Destroy(opponent.gameObject);
            }

            // Reset the EnPassant move
            EnPassant[0] = EnPassant[1] = -1;

            // Set EnPassant available for opponent
            if (SelectedChessman.GetType() == typeof(Pawn))
            {
                //-------Promotion Move Manager------------
                if (y == 7)
                {
                    ActiveChessmans.Remove(SelectedChessman.gameObject);
                    Destroy(SelectedChessman.gameObject);
                    SpawnChessman(10, new Vector3(x, 0, y));
                    SelectedChessman = Chessmans[x, y];
                }
                if (y == 0)
                {
                    ActiveChessmans.Remove(SelectedChessman.gameObject);
                    Destroy(SelectedChessman.gameObject);
                    SpawnChessman(4, new Vector3(x, 0, y));
                    SelectedChessman = Chessmans[x, y];
                }
                //-------Promotion Move Manager Over-------

                if (SelectedChessman.currentY == 1 && y == 3)
                {
                    EnPassant[0] = x;
                    EnPassant[1] = y - 1;
                }
                if (SelectedChessman.currentY == 6 && y == 4)
                {
                    EnPassant[0] = x;
                    EnPassant[1] = y + 1;
                }
            }
            // -------EnPassant Move Manager Over-------

            // -------Castling Move Manager------------
            // If the selectef chessman is King and is trying Castling move which needs two steps
            if (SelectedChessman.GetType() == typeof(King) && System.Math.Abs(x - SelectedChessman.currentX) == 2)
            {
                // King Side (towards (0, 0))
                if (x - SelectedChessman.currentX < 0)
                {
                    // Moving Rook1
                    Chessmans[x + 1, y] = Chessmans[x - 1, y];
                    Chessmans[x - 1, y] = null;
                    Chessmans[x + 1, y].SetPosition(x + 1, y);
                    Chessmans[x + 1, y].transform.position = new Vector3(x + 1, 0, y);
                    Chessmans[x + 1, y].isMoved            = true;
                }
                // Queen side (away from (0, 0))
                else
                {
                    // Moving Rook2
                    Chessmans[x - 1, y] = Chessmans[x + 2, y];
                    Chessmans[x + 2, y] = null;
                    Chessmans[x - 1, y].SetPosition(x - 1, y);
                    Chessmans[x - 1, y].transform.position = new Vector3(x - 1, 0, y);
                    Chessmans[x - 1, y].isMoved            = true;
                }
                // Note : King will move as a SelectedChessman by this function later
            }
            // -------Castling Move Manager Over-------

            Chessmans[SelectedChessman.currentX, SelectedChessman.currentY] = null;
            Chessmans[x, y] = SelectedChessman;
            SelectedChessman.SetPosition(x, y);
            SelectedChessman.transform.position = new Vector3(x, 0, y);
            SelectedChessman.isMoved            = true;
            isWhiteTurn = !isWhiteTurn;

            // to be deleted
            // printBoard();
        }

        // De-select the selected chessman
        SelectedChessman = null;
        // Disabling all highlights
        BoardHighlights.Instance.DisableAllHighlights();

        // ------- King Check Alert Manager -----------
        // Is it Check to the King
        // If now White King is in Check
        if (isWhiteTurn)
        {
            if (WhiteKing.InDanger())
            {
                BoardHighlights.Instance.SetTileCheck(WhiteKing.currentX, WhiteKing.currentY);
            }
        }
        // If now Black King is in Check
        else
        {
            if (BlackKing.InDanger())
            {
                BoardHighlights.Instance.SetTileCheck(BlackKing.currentX, BlackKing.currentY);
            }
        }
        // ------- King Check Alert Manager Over ----


        // Check if it is Checkmate
        isCheckmate();
    }