예제 #1
0
        public ChessMan GetChessManAtPosition(int x, int y)
        {
            ChessMan res = null;

            if (IsLegalBoardPosition(x, y))
            {
                res = _pieces[x, y];
            }

            return(res);
        }
예제 #2
0
 private void KillChessMan(ChessMan target)
 {
     if (target.GetType() == typeof(King)) //jeśli to król zakończ grę
     {
         GameManager.instance.Winner    = isWhiteTurn ? "White" : "Black";
         GameManager.instance.Condition = "kiling the God";
         SceneManager.LoadScene("End_Game");
     }
     //usunięcie z listy aktywnych figur
     Destroy(target.gameObject); //zniszczenie figury, automatycznie sniknie też z listy
 }
예제 #3
0
    public GameObject Create(string name, int x, int y)
    {
        GameObject obj = Instantiate(chessPiece, new Vector3(0, 0, -1), Quaternion.identity);
        ChessMan   cm  = obj.GetComponent <ChessMan>();

        cm.name = name;
        cm.SetXBoard(x);
        cm.SetYBoard(y);
        cm.Activate();
        return(obj);
    }
예제 #4
0
    void MoveChessman(int x, int y)
    {
        if (allowedMoves[x, y])
        {
            ChessMan c = chessmans [x, y];

            if (c != null && c.isWhite != isWhiteTurn)
            {
                //If this is the King
                if (c.GetType() == typeof(King))
                {
                    // End the game
                    EndGame();
                    return;
                }

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

            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);
                    selectedChessman = chessmans [x, y];
                }
            }


            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;
        BoardHighlighter.instance.HideHighlights();
        selectedChessman = null;
    }
예제 #5
0
    private void AtackChessMan(ChessMan target)
    {
        int damage = target.Hp - SelectedChessman.Dmg;

        if (damage <= 0)
        {
            KillChessMan(target);
        }
        else
        {
            target.Hp = damage;
        }
    }
예제 #6
0
        public void Move(ChessMan piece, int prevX, int prevY)
        {
            if (IsLegalBoardPosition(piece.Get_X_Coord(), piece.Get_Y_Coord()))
            {
                _pieces[prevX, prevY] = null;

                _pieces[piece.Get_X_Coord(), piece.Get_Y_Coord()] = piece;
            }
            else
            {
                piece.Set_X_Coord(prevX);
                piece.Set_Y_Coord(prevY);
            }
        }
예제 #7
0
    private void AtackChessMan(ChessMan target)
    {
        target.GetComponent <Animator>().Play("take_damage");

        int damage = target.Hp - SelectedChessman.Dmg; //zmniejszenie HP

        if (damage <= 0)
        {
            KillChessMan(target);
        }
        else
        {
            target.Hp = damage;
        }
    }
예제 #8
0
        public void Add(ChessMan pawn, int xCoordinate, int yCoordinate)
        {
            if (!IsLegalBoardPosition(xCoordinate, yCoordinate) || _pieces[xCoordinate, yCoordinate] != null)
            {
                xCoordinate = -1;
                yCoordinate = -1;
            }
            else
            {
                _pieces[xCoordinate, yCoordinate] = pawn;
            }

            pawn.Set_X_Coord(xCoordinate);
            pawn.Set_Y_Coord(yCoordinate);
        }
예제 #9
0
    /// <summary>
    /// Moves a chess man to a selected location
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    private void MoveChessMan(int x, int y)
    {
        if (SelectedChessMan.PossibleMove(x, y))
        {
            //Set the Chess Man at the index of the Selected Chess Man to null because he will be moved out of that position
            ChessMen[SelectedChessMan.CurrentX, SelectedChessMan.CurrentY] = null;
            //Change the position of the Selected Chess Man to the position of the clicked tile
            SelectedChessMan.transform.position = GetTileCenter(x, y);
            //Set the Chess Man at the index of Chess Men to that of the Selected ChessMan
            ChessMen[x, y] = SelectedChessMan;
            //Update the Position Of the Selected ChessMan to the current position it now occupies
            ChessMen[x, y].UpdatePosition(x, y);
        }

        SelectedChessMan = null;
    }
예제 #10
0
    /// <summary>
    /// Selects a Chess Man at a location
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    private void SelectChessMan(int x, int y)
    {
        //Check if a chessman exists at that position
        if (ChessMen[x, y] == null)
        {
            return;
        }

        //Check if the right party is making the move
        if (ChessMen[x, y].isWhite != isWhiteTurn)
        {
            return;
        }

        //Select the Chess Man at that position
        SelectedChessMan = ChessMen[x, y];
    }
예제 #11
0
    } //gra sprawdza na jakie pole kliknął gracz

    private void SelectChessman(int x, int y)
    {
        if (ChessMens[x, y] == null) //sprawdzenie czy na wybranej pozycji jest pion
        {
            return;
        }
        if (ChessMens[x, y].isWhite != isWhiteTurn) //sprawdzenie czy pion ma kolor danego gracza
        {
            return;
        }

        BoardHighlitghs.Instance.HideAll();
        SelectedChessman = ChessMens[x, y];                                                                             //zmiana wybranego piona
        ChessMens[x, y].UpdateMove();                                                                                   //sprawdzenie jakie ruchy,ataki są dozwolone

        BoardHighlitghs.Instance.HighlightAllowedMoves(SelectedChessman.PossibleMove, SelectedChessman.PossibleAtacks); //podświetlenie planczy
    }
예제 #12
0
    private void MoveChessman(int x, int y)
    {
        ChessMan target = ChessMens[x, y];

        if (SelectedChessman.PossibleMove[x, y])                                    // można wykonać taki ruch?
        {
            ChessMens[SelectedChessman.CurrentX, SelectedChessman.CurrentY] = null; //wybrany pion 'znika' z aktualnej pozycji
            SelectedChessman.transform.position = GetTileCenter(x, y);
            SelectedChessman.SetPosition(x, y);
            ChessMens[x, y] = SelectedChessman;
            UpdateMove();


            if (SelectedChessman.firstmove) //wykonanie pierwszego ruchu potrzebne przy pionach
            {
                SelectedChessman.firstmove = false;
            }
        }
        if (SelectedChessman.PossibleAtacks[x, y])                                                                     //można atakować
        {
            if (SelectedChessman.GetComponent <Distance>() == null)                                                    //jeśli pion nie atakuje z dystasnu musi przemieścić się w kierunku przeciwnika
            {
                int[] newPositions = CalculateNewPosition(x, y, SelectedChessman.CurrentX, SelectedChessman.CurrentY); //funkcja sprawia że pion zostaję na pozycji "przed" celem

                ChessMens[SelectedChessman.CurrentX, SelectedChessman.CurrentY] = null;                                //wybrany pion 'znika' z aktualnej pozycji
                SelectedChessman.transform.position = GetTileCenter(newPositions[0], newPositions[1]);
                SelectedChessman.SetPosition(newPositions[0], newPositions[1]);

                ChessMens[newPositions[0], newPositions[1]] = SelectedChessman;
            }

            AtackChessMan(target);

            UpdateMove();

            if (SelectedChessman.firstmove) //wykonanie pierwszego ruchu potrzebne przy pionach
            {
                SelectedChessman.firstmove = false;
            }
        }
        BoardHighlitghs.Instance.HideAll();
        SelectedChessman = null; //klinięcie w inne niż możliwe miejsce anuluje wybór
    }
예제 #13
0
    private void SelectChessman(int x, int y)
    {
        if (ChessMens[x, y] == null) //sprawdzenie czy na wybranej pozycji jest pion
        {
            return;
        }
        if (ChessMens[x, y].isWhite != isWhiteTurn) //sprawdzenie czy pion ma kolor danego gracza
        {
            return;
        }

        BoardHighlitghs.Instance.HideAll();
        SelectedChessman = ChessMens[x, y];
        ChessMens[x, y].UpdateMove();

        allowedMoves  = ChessMens[x, y].PosssibleMove;
        allowedAtacks = ChessMens[x, y].PossibleAtacks;

        BoardHighlitghs.Instance.HighlightAllowedMoves(allowedMoves, allowedAtacks);
    }
예제 #14
0
    private void CheckMove(ChessMan current_chess, bool[,] moves, bool[,] atacks, int _newX, int _newY, int hit)
    {
        ChessMan c;

        c = BoardManager.Instance.ChessMens[_newX, _newY];
        if (c == null)
        {
            moves[_newX, _newY] = true;
        }
        if (c != null && current_chess.isWhite == c.isWhite) //jeśli na lini jest sojusznik nie można ruszyć dalej
        {
            hits[hit] = false;
        }
        if (c != null && current_chess.isWhite != c.isWhite) //jeśli na lini jest przeciwnik zbij go
        {
            atacks[_newX, _newY] = true;
            moves[_newX, _newY]  = false;
            hits[hit]            = false;
        }
    }
예제 #15
0
    private void MoveChessman(int x, int y)
    {
        ChessMan target = ChessMens[x, y];

        if (allowedMoves[x, y])                                                     // można wykonać taki ruch?
        {
            ChessMens[SelectedChessman.CurrentX, SelectedChessman.CurrentY] = null; //wybrany pion 'znika' z aktualnej pozycji
            SelectedChessman.transform.position = GetTileCenter(x, y);
            SelectedChessman.SetPosition(x, y);
            ChessMens[x, y] = SelectedChessman;
            UpdateMove();
            Debug.Log(SelectedChessman.CurrentX);
            Debug.Log(SelectedChessman.CurrentY);
            Debug.Log(x);
            Debug.Log(y);

            if (SelectedChessman.firstmove) //wykonanie pierwszego ruchu potrzebne przy pionach
            {
                SelectedChessman.firstmove = false;
            }
        }
        if (allowedAtacks[x, y]) //można atakować
        {
            int[] newPositions = CalculateNewPosition(x, y, SelectedChessman.CurrentX, SelectedChessman.CurrentY);
            ChessMens[SelectedChessman.CurrentX, SelectedChessman.CurrentY] = null; //wybrany pion 'znika' z aktualnej pozycji
            SelectedChessman.transform.position = GetTileCenter(newPositions[0], newPositions[1]);
            SelectedChessman.SetPosition(newPositions[0], newPositions[1]);
            ChessMens[newPositions[0], newPositions[1]] = SelectedChessman;

            AtackChessMan(target);
            UpdateMove();

            if (SelectedChessman.firstmove) //wykonanie pierwszego ruchu potrzebne przy pionach
            {
                SelectedChessman.firstmove = false;
            }
        }
        BoardHighlitghs.Instance.HideAll();
        SelectedChessman = null; //klinięcie w inne niż możliwe miejsce anuluje wybór
    }
예제 #16
0
    void SelectChessman(int x, int y)
    {
        if (chessmans [x, y] == null)
        {
            return;
        }

        if (chessmans [x, y].isWhite != isWhiteTurn)
        {
            return;
        }

        bool hasAtLeastOneMove = false;

        allowedMoves = chessmans [x, y].PossibleMove();
        for (int i = 0; i < 8; i++)
        {
            for (int j = 0; j < 8; j++)
            {
                if (allowedMoves [i, j])
                {
                    hasAtLeastOneMove = true;
                }
            }
        }

        if (!hasAtLeastOneMove)
        {
            return;
        }

        selectedChessman        = chessmans [x, y];
        previousMat             = selectedChessman.GetComponent <MeshRenderer> ().material;
        selectedMat.mainTexture = previousMat.mainTexture;
        selectedChessman.GetComponent <MeshRenderer> ().material = selectedMat;
        BoardHighlighter.instance.HighlightAllowedMoves(allowedMoves);
    }
예제 #17
0
 public Decision(underDecision dec, ChessMan piece)
 {
     chess    = piece;
     decision = dec;
 }
예제 #18
0
    public Decision Evaluate(ChessMan chess, Case [,] board)
    {
        int x = chess.position.x;
        int y = chess.position.y;

        List <Case> possibleCase = chess.GetPossibleMovement(board);

        List <underDecision> underDecs = new List <underDecision>();
        int initialsMoves = GetListOfPossibleMove(chess.color).Count;

        EchecThreat isThreatened = PieceEchec(board, chess);

        foreach (Case c in possibleCase)
        {
            underDecision d = new underDecision(0, c);

            //here we found out that we can get a special piece with a priority, but take care, it might put us in a bad situation
            if (c.currPiece != null && c.currPiece.color != chess.color)
            {
                d.value += c.currPiece.Priority; d.SetReason("getting piece with priority : " + c.currPiece.Priority);
            }
            //that's a bad decision and even more, an unaceptable move since its our own piece, dont even listen to this
            else if (c.currPiece != null)
            {
                continue;
            }


            //create a simulation that we will simulate later on
            Simulation s = new Simulation(board[x, y], c);

            //i am already in echec

            if (isThreatened != null)
            {
                //simulate, so we can check if i can find some good situations
                //this move can send me out of echec, we should consider it
                if (PieceEchec(board, s) == null)
                {
                    d.value += chess.Priority; d.SetReason("getting out of echec add : " + chess.Priority); Debug.Log(chess.ToString() + " not getting out of echec ??" + d.value);
                }
                //this move cant get me ouf of echec, we delete some priority to it, but it might be usefull on a certain sutaiton
                else
                {
                    d.value -= chess.Priority; d.SetReason("cant get out, del : " + chess.Priority);
                }
            }
            else
            {
                //i was not in an echec move but im going into it? remove some value to this move
                if (PieceEchec(board, s) != null)
                {
                    d.value -= chess.Priority; d.SetReason("going in echec intentionnaly del : " + chess.Priority);
                }
            }

            //get all of the move that come from our team after the simulation
            List <Case> moves   = GetListOfPossibleMove(chess.color);
            bool        covered = false;

            foreach (Case cover in moves)
            {
                if (cover == c)
                {
                    covered = true;
                }
            }
            // calculate how many moves we opened up by doing this (because it means we have more possible movements out of this
            int difference = (moves.Count - initialsMoves) / 2;
            d.value += difference; d.SetReason("add some cases to play" + difference);

            if (StaticClass.m_sTools.GetPossibleMove(!chess.color) <= 0)
            {
                d.value += 1000; d.SetReason("put ennemy in mat");
            }


            //now found out if we can put ennemy pieces in echec out of this move
            List <Case> SimulatedMove = chess.GetPossibleMovement(m_sCase.setupBoard.board, false);

            foreach (Case simulatedCase in SimulatedMove)
            {
                EchecThreat simulatedThreat = PieceEchec(board, simulatedCase.currPiece);
                if (simulatedCase.currPiece != null && simulatedCase.currPiece.color != chess.color)
                {
                    //we can actually put a piece in echec out of this, that's pretty good, even more if we are covered by another piece
                    d.value += simulatedCase.currPiece.Priority / (covered == true ? 2 : 10);
                    d.SetReason("put an piece in echec : " + (simulatedCase.currPiece.Priority / (covered == true ? 2 : 10)));
                }

                //if we can cover an ally piece that is in echec do it
                else if (simulatedCase.currPiece != null && simulatedThreat != null)
                {
                    d.value += simulatedCase.currPiece.Priority / 2;
                    d.SetReason("helped a piece in echec : " + simulatedCase.currPiece.Priority / 2);
                }
            }

            s.Delete();
            underDecs.Add(d);
        }

        underDecision bestUdec = null;

        foreach (underDecision d in underDecs)
        {
            if (bestUdec == null)
            {
                bestUdec = d;
            }
            else if (bestUdec.value < d.value)
            {
                bestUdec = d;
            }
            else if (bestUdec.value == d.value)
            {
                if (Random.Range(0, 2) == 1)
                {
                    bestUdec = d;
                }
            }
        }

        return(new Decision(bestUdec, chess));
    }
예제 #19
0
    /// <summary>
    /// Spawns all the chess men on the board
    /// </summary>
    private void SpawnAllChessMen()
    {
        //Clear the list of Active Chess men
        ActiveChessMan.Clear();

        //Create a new Array to hold the List of Chess Men
        ChessMen = new ChessMan[8, 8];

        //Spawn the White Men

        //King
        SpawnChessman(0, 3, 0);

        //Queen
        SpawnChessman(1, 4, 0);

        //Rooks
        SpawnChessman(2, 0, 0);
        SpawnChessman(2, 7, 0);

        //Bishops
        SpawnChessman(3, 2, 0);
        SpawnChessman(3, 5, 0);

        //Knights
        SpawnChessman(4, 1, 0);
        SpawnChessman(4, 6, 0);

        //Pawns
        for (int i = 0; i < 8; i++)
        {
            SpawnChessman(5, i, 1);
        }


        //Spawn the Black Men

        //King
        SpawnChessman(4, 3, 7);

        //Queen
        SpawnChessman(5, 4, 7);

        //Rooks
        SpawnChessman(6, 0, 7);
        SpawnChessman(6, 7, 7);

        //Bishops
        SpawnChessman(9, 2, 7);
        SpawnChessman(9, 5, 7);

        //Knights
        SpawnChessman(10, 1, 7);
        SpawnChessman(10, 6, 7);

        //Pawns
        for (int i = 0; i < 8; i++)
        {
            SpawnChessman(11, i, 6);
        }
    }
예제 #20
0
    public void setPosition(GameObject obj)
    {
        ChessMan cm = obj.GetComponent <ChessMan>();

        positions[cm.GetXBoard(), cm.getYBoard()] = obj;
    }
예제 #21
0
 public FakeMove(Piece newPiece, ChessMan newPieceChessMan, Piece selectedPiece, ChessMan selectedChessMan)
 {
     NewPiece         = newPiece;
     NewPieceChessMan = newPieceChessMan;
     SelectedPiece    = selectedPiece;
     SelectedChessMan = selectedChessMan;
 }
예제 #22
0
 public void Add(ChessMan _threater)
 {
     threater.Add(_threater);
 }
예제 #23
0
파일: Piece.cs 프로젝트: Vacuum113/Chess
 public void SetChessMan(ChessMan chessMan)
 {
     _chessMan = chessMan;
 }
예제 #24
0
 public Decision(int val, Case deci, ChessMan piece)
 {
     decision.value  = val;
     decision.choice = deci;
     chess           = piece;
 }
예제 #25
0
 public EchecThreat(ChessMan _threatened)
 {
     threatened = _threatened;
 }
예제 #26
0
    private void MoveChessman(int x, int y)
    {
        if (allowedMoves[x, y])
        {
            ChessMan c = Chessmans[x, y];

            if (c != null)
            {
                // Comer una pieza

                // Si es el rey
                if (c.GetType() == typeof(King))
                {
                    // Fin de juego y retornar
                    EndGame();
                    return;
                }

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

            if (x == EnPassantMove[0] && y == EnPassantMove[1])
            {
                if (isWhiteTurn)
                {
                    c = Chessmans[x, y - 1];
                }
                else
                {
                    c = Chessmans[x, 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);
                    selectedChessman = Chessmans[x, y];
                }
                if (selectedChessman.CurretnY == 1 && y == 3)
                {
                    EnPassantMove[0] = x;
                    EnPassantMove[1] = y - 1;
                }
                else if (selectedChessman.CurretnY == 6 && y == 4)
                {
                    EnPassantMove[0] = x;
                    EnPassantMove[1] = y + 1;
                }
            }

            Chessmans[selectedChessman.CurrentX, selectedChessman.CurretnY] = 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;
    }