Ejemplo n.º 1
0
        private void Initialize()
        {
            // 아래팀
            for (int i = 0; i < boardWidthHeight; i++)
            {
                board[i, 0] = new ChessPieceInformation(DataManager.Team.Black, DataManager.pieceNameArray[i]);
            }

            // 아래팀 폰
            for (int i = 0; i < boardWidthHeight; i++)
            {
                board[i, 1] = new ChessPieceInformation(DataManager.Team.Black, DataManager.PieceName.Pawn);
            }

            // 중간
            for (int i = 2; i <= 5; i++)
            {
                for (int j = 0; j < boardWidthHeight; j++)
                {
                    board[j, i] = new ChessPieceInformation(DataManager.Team.None, DataManager.PieceName.None);
                }
            }

            // 위팀 폰
            for (int i = 0; i < boardWidthHeight; i++)
            {
                board[i, 6] = new ChessPieceInformation(DataManager.Team.White, DataManager.PieceName.Pawn);
            }

            // 위팀
            for (int i = 0; i < boardWidthHeight; i++)
            {
                board[i, 7] = new ChessPieceInformation(DataManager.Team.White, DataManager.pieceNameArray[i]);
            }
        }
Ejemplo n.º 2
0
        private List <Vector2> King(int xPos, int zPos)
        {
            List <Vector2> result = new List <Vector2>();

            #region King
            ChessPieceInformation[,] board = boardManager.GetBoard();

            // 위
            try
            {
                for (int i = xPos - 1; i <= xPos + 1; i++)
                {
                    ChessPieceInformation manager = board[i, zPos + 1];
                    Vector2 tempResult            = new Vector2(i, zPos + 1);
                    if (manager.PieceName == DataManager.PieceName.None)
                    {
                        result.Add(tempResult);
                    }
                    else
                    {
                        if (currentTeam != manager.Team)
                        {
                            result.Add(tempResult);
                            continue;
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }
            catch (IndexOutOfRangeException) { /* do nothing */ }

            // 중간
            try
            {
                for (int i = xPos - 1; i <= xPos + 1; i++)
                {
                    ChessPieceInformation manager = board[i, zPos];
                    Vector2 tempResult            = new Vector2(i, zPos);
                    if (i == xPos)
                    {
                        continue;
                    }

                    if (manager.PieceName == DataManager.PieceName.None)
                    {
                        result.Add(tempResult);
                    }
                    else
                    {
                        if (currentTeam != manager.Team)
                        {
                            result.Add(tempResult);
                            continue;
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }
            catch (IndexOutOfRangeException) { /* do nothing */ }

            // 아래
            try
            {
                for (int i = xPos - 1; i <= xPos + 1; i++)
                {
                    ChessPieceInformation manager = board[i, zPos - 1];
                    Vector2 tempResult            = new Vector2(i, zPos - 1);
                    if (manager.PieceName == DataManager.PieceName.None)
                    {
                        result.Add(tempResult);
                    }
                    else
                    {
                        if (currentTeam != manager.Team)
                        {
                            result.Add(tempResult);
                            continue;
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }
            catch (IndexOutOfRangeException) { /* do nothing */ }
            #endregion
            return(result);
        }
Ejemplo n.º 3
0
        private List <Vector2> Knight(int xPos, int zPos)
        {
            List <Vector2> result = new List <Vector2>();

            #region Knight

            ChessPieceInformation[,] board = boardManager.GetBoard();

            List <Vector2> positionList = new List <Vector2>();
            // 상
            positionList.Add(new Vector2(xPos - 1, zPos + 2));
            positionList.Add(new Vector2(xPos + 1, zPos + 2));

            // 하
            positionList.Add(new Vector2(xPos - 1, zPos - 2));
            positionList.Add(new Vector2(xPos + 1, zPos - 2));

            // 좌
            positionList.Add(new Vector2(xPos - 2, zPos - 1));
            positionList.Add(new Vector2(xPos - 2, zPos + 1));

            // 우
            positionList.Add(new Vector2(xPos + 2, zPos - 1));
            positionList.Add(new Vector2(xPos + 2, zPos + 1));

            foreach (Vector2 elem in positionList)
            {
                int x = (int)elem.x;
                int z = (int)elem.y;
                if (x > 7 || x < 0 || z > 7 || z < 0)
                {
                    continue;
                }
                ChessPieceInformation manager = board[x, z];
                Vector2 tempReuslt            = new Vector2(x, z);
                if (manager.PieceName.Equals(DataManager.PieceName.None))
                {
                    result.Add(tempReuslt);
                }
                else
                {
                    if (currentTeam != manager.Team && manager.Team != DataManager.Team.None)
                    {
                        result.Add(tempReuslt);
                        continue;
                    }
                }
            }
            #region backup

            /*
             * ChessPieceManager[,] board = boardManager.GetBoard();
             *
             * // z + 2 일 때
             * try
             * {
             *  for (int i = xPos - 1; i < xPos + 1; i++)
             *  {
             *      if (i == xPos)
             *      {
             *          continue;
             *      }
             *      if (board[i, zPos + 2].PieceName == DataManager.PieceName.NONE)
             *      {
             *          result.Add(new Vector2(i, zPos + 2));
             *      }
             *  }
             * }
             * catch (IndexOutOfRangeException)
             * {
             *
             * }
             *
             * // z - 2 일 때
             * try
             * {
             *  for (int i = xPos - 1; i < xPos + 1; i++)
             *  {
             *      if (i == xPos)
             *      {
             *          continue;
             *      }
             *      if (board[i, zPos - 2].PieceName == DataManager.PieceName.NONE)
             *      {
             *          result.Add(new Vector2(i, zPos - 2));
             *      }
             *  }
             * }
             * catch (IndexOutOfRangeException)
             * {
             *
             * }
             *
             * // x + 2 일 때
             * try
             * {
             *  for (int i = zPos - 1; i < zPos + 1; i++)
             *  {
             *      if (i == zPos)
             *      {
             *          continue;
             *      }
             *      if (board[xPos + 2, i].PieceName == DataManager.PieceName.NONE)
             *      {
             *          result.Add(new Vector2(xPos + 2, i));
             *      }
             *  }
             * }
             * catch (IndexOutOfRangeException)
             * {
             *
             * }
             *
             * try
             * {
             *  for (int i = zPos - 1; i < zPos + 1; i++)
             *  {
             *      if (i == zPos)
             *      {
             *          continue;
             *      }
             *      if (board[xPos - 2, i].PieceName == DataManager.PieceName.NONE)
             *      {
             *          result.Add(new Vector2(xPos + 2, i));
             *      }
             *  }
             * }
             * catch (IndexOutOfRangeException)
             * {
             *
             * }
             */
            #endregion
            #endregion
            return(result);
        }
Ejemplo n.º 4
0
        private List <Vector2> Bishop(int xPos, int zPos)
        {
            List <Vector2> result = new List <Vector2>();

            #region Bishop
            ChessPieceInformation[,] board = boardManager.GetBoard();

            // 좌상
            int lu_x = xPos;
            int lu_z = zPos;
            while (true)
            {
                try
                {
                    int x = --lu_x;
                    int z = ++lu_z;
                    ChessPieceInformation manager = board[x, z];
                    Vector2 tempResult            = new Vector2(x, z);
                    if (manager.PieceName.Equals(DataManager.PieceName.None))
                    {
                        result.Add(tempResult);
                    }
                    else
                    {
                        if (currentTeam != manager.Team)
                        {
                            result.Add(tempResult);
                            break;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    break;
                }
            }

            // 우상
            int ru_x = xPos;
            int ru_z = zPos;
            while (true)
            {
                try
                {
                    int x = ++ru_x;
                    int z = ++ru_z;
                    ChessPieceInformation manager = board[x, z];
                    Vector2 tempResult            = new Vector2(x, z);
                    if (manager.PieceName.Equals(DataManager.PieceName.None))
                    {
                        result.Add(tempResult);
                    }
                    else
                    {
                        if (currentTeam != manager.Team)
                        {
                            result.Add(tempResult);
                            break;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    break;
                }
            }

            // 우하
            int rd_x = xPos;
            int rd_z = zPos;
            while (true)
            {
                try
                {
                    int x = ++rd_x;
                    int z = --rd_z;
                    ChessPieceInformation manager = board[x, z];
                    Vector2 tempResult            = new Vector2(x, z);
                    if (manager.PieceName.Equals(DataManager.PieceName.None))
                    {
                        result.Add(tempResult);
                    }
                    else
                    {
                        if (currentTeam != manager.Team)
                        {
                            result.Add(tempResult);
                            break;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    break;
                }
            }

            // 좌하
            int ld_x = xPos;
            int ld_z = zPos;
            while (true)
            {
                try
                {
                    int x = --ld_x;
                    int z = --ld_z;
                    ChessPieceInformation manager = board[x, z];
                    Vector2 tempResult            = new Vector2(x, z);
                    if (manager.PieceName.Equals(DataManager.PieceName.None))
                    {
                        result.Add(tempResult);
                    }
                    else
                    {
                        if (currentTeam != manager.Team)
                        {
                            result.Add(tempResult);
                            break;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    break;
                }
            }
            #endregion
            return(result);
        }
Ejemplo n.º 5
0
        private List <Vector2> Rook(int xPos, int zPos)
        {
            List <Vector2> result = new List <Vector2>();

            #region Rook
            ChessPieceInformation[,] board = boardManager.GetBoard();
            // 상
            if (zPos != 7)
            {
                try
                {
                    for (int i = zPos + 1; i <= max; i++)
                    {
                        ChessPieceInformation manager = board[xPos, i];
                        Vector2 tempResult            = new Vector2(xPos, i);
                        if (manager.PieceName.Equals(DataManager.PieceName.None))
                        {
                            result.Add(tempResult);
                        }
                        else
                        {
                            if (currentTeam != manager.Team)
                            {
                                result.Add(tempResult);
                                break;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                catch (IndexOutOfRangeException) { /* do nothing */ }
            }

            // 하
            if (zPos != 0)
            {
                try
                {
                    for (int i = zPos - 1; i <= max; i--)
                    {
                        Debug.Log($"rook//down// xPos : {xPos}, i : {i}");
                        ChessPieceInformation manager = board[xPos, i];
                        Vector2 tempResult            = new Vector2(xPos, i);
                        if (manager.PieceName.Equals(DataManager.PieceName.None))
                        {
                            result.Add(tempResult);
                        }
                        else
                        {
                            if (currentTeam != manager.Team)
                            {
                                result.Add(tempResult);
                                break;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                catch (IndexOutOfRangeException) { /* do nothing */ }
            }

            // 좌
            if (xPos != 0)
            {
                try
                {
                    for (int i = xPos - 1; i >= min; i--)
                    {
                        ChessPieceInformation manager = board[i, zPos];
                        Vector2 tempResult            = new Vector2(i, zPos);
                        if (manager.PieceName == DataManager.PieceName.None)
                        {
                            result.Add(tempResult);
                        }
                        else
                        {
                            if (currentTeam != manager.Team)
                            {
                                result.Add(tempResult);
                                break;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                catch (IndexOutOfRangeException) { /* do nothing */ }
            }

            // 우
            if (xPos != 7)
            {
                try
                {
                    for (int i = xPos + 1; i <= max; i++)
                    {
                        ChessPieceInformation manager = board[i, zPos];
                        Vector2 tempResult            = new Vector2(i, zPos);
                        if (manager.PieceName == DataManager.PieceName.None)
                        {
                            result.Add(tempResult);
                            Debug.Log($"// rook, right // first if");
                        }
                        else
                        {
                            Debug.Log($"// rook, right // first else");
                            if (currentTeam != manager.Team)
                            {
                                result.Add(tempResult);
                                break;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                catch (IndexOutOfRangeException) { /* do nothing */ }
            }
            #endregion
            return(result);
        }
Ejemplo n.º 6
0
        private List <Vector2> Queen(int xPos, int zPos)
        {
            List <Vector2> result = new List <Vector2>();

            #region Queen
            ChessPieceInformation[,] board = boardManager.GetBoard();
            // 상
            if (zPos != 7)
            {
                try
                {
                    for (int i = zPos + 1; i <= max; i++)
                    {
                        ChessPieceInformation manager = board[xPos, i];
                        Vector2 tempResult            = new Vector2(xPos, i);
                        if (manager.PieceName.Equals(DataManager.PieceName.None))
                        {
                            result.Add(tempResult);
                        }
                        else
                        {
                            if (currentTeam != manager.Team)
                            {
                                result.Add(tempResult);
                                break;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                catch (IndexOutOfRangeException) { /* do nothing */ }
            }

            // 하
            if (zPos != 0)
            {
                try
                {
                    for (int i = zPos - 1; i <= max; i--)
                    {
                        ChessPieceInformation manager = board[xPos, i];
                        Vector2 tempResult            = new Vector2(xPos, i);
                        if (manager.PieceName.Equals(DataManager.PieceName.None))
                        {
                            result.Add(tempResult);
                        }
                        else
                        {
                            if (currentTeam != manager.Team)
                            {
                                result.Add(tempResult);
                                break;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                catch (IndexOutOfRangeException) { /* do nothing */ }
            }

            // 좌
            if (xPos != 0)
            {
                try
                {
                    for (int i = xPos - 1; i >= min; i--)
                    {
                        ChessPieceInformation manager = board[i, zPos];
                        Vector2 tempResult            = new Vector2(i, zPos);
                        if (manager.PieceName == DataManager.PieceName.None)
                        {
                            result.Add(tempResult);
                        }
                        else
                        {
                            if (currentTeam != manager.Team)
                            {
                                result.Add(tempResult);
                                break;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                catch (IndexOutOfRangeException) { /* do nothing */ }
            }

            // 우
            if (xPos != 7)
            {
                try
                {
                    for (int i = xPos + 1; i <= max; i++)
                    {
                        ChessPieceInformation manager = board[i, zPos];
                        Vector2 tempResult            = new Vector2(i, zPos);
                        if (manager.PieceName == DataManager.PieceName.None)
                        {
                            result.Add(tempResult);
                        }
                        else
                        {
                            if (currentTeam != manager.Team)
                            {
                                result.Add(tempResult);
                                break;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                catch (IndexOutOfRangeException) { /* do nothing */ }

                // 좌상
                int lu_x = xPos;
                int lu_z = zPos;
                while (true)
                {
                    try
                    {
                        int x = --lu_x;
                        int z = ++lu_z;
                        ChessPieceInformation manager = board[x, z];
                        Vector2 tempResult            = new Vector2(x, z);
                        if (manager.PieceName.Equals(DataManager.PieceName.None))
                        {
                            result.Add(tempResult);
                        }
                        else
                        {
                            if (currentTeam != manager.Team)
                            {
                                result.Add(tempResult);
                                break;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    catch (IndexOutOfRangeException)
                    {
                        break;
                    }
                }

                // 우상
                int ru_x = xPos;
                int ru_z = zPos;
                while (true)
                {
                    try
                    {
                        int x = ++ru_x;
                        int z = ++ru_z;
                        ChessPieceInformation manager = board[x, z];
                        Vector2 tempResult            = new Vector2(x, z);
                        if (manager.PieceName.Equals(DataManager.PieceName.None))
                        {
                            result.Add(tempResult);
                        }
                        else
                        {
                            if (currentTeam != manager.Team)
                            {
                                result.Add(tempResult);
                                break;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    catch (IndexOutOfRangeException)
                    {
                        break;
                    }
                }

                // 우하
                int rd_x = xPos;
                int rd_z = zPos;
                while (true)
                {
                    try
                    {
                        int x = ++rd_x;
                        int z = --rd_z;
                        ChessPieceInformation manager = board[x, z];
                        Vector2 tempResult            = new Vector2(x, z);
                        if (manager.PieceName.Equals(DataManager.PieceName.None))
                        {
                            result.Add(tempResult);
                        }
                        else
                        {
                            if (currentTeam != manager.Team)
                            {
                                result.Add(tempResult);
                                break;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    catch (IndexOutOfRangeException)
                    {
                        break;
                    }
                }

                // 좌하
                int ld_x = xPos;
                int ld_z = zPos;
                while (true)
                {
                    try
                    {
                        int x = --ld_x;
                        int z = --ld_z;
                        ChessPieceInformation manager = board[x, z];
                        Vector2 tempResult            = new Vector2(x, z);
                        if (manager.PieceName.Equals(DataManager.PieceName.None))
                        {
                            result.Add(tempResult);
                        }
                        else
                        {
                            if (currentTeam != manager.Team)
                            {
                                result.Add(tempResult);
                                break;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    catch (IndexOutOfRangeException)
                    {
                        break;
                    }
                }
            }
            #endregion
            return(result);
        }
Ejemplo n.º 7
0
        public void ChangeState(Vector3 firstPosition, Vector3 lastPositon)
        {
            float distance = DataManager.ChessPieceInfo.distance;

            // 첫번째
            int first_xOffset = (int)(firstPosition.x / distance);
            int first_zOffset = (int)(firstPosition.z / distance);

            #region catch bugs
            float remain_x = firstPosition.x % distance;
            float remain_z = firstPosition.z % distance;
            if (remain_x >= 0.03f)
            {
                first_xOffset++;
            }
            if (remain_z >= 0.03f)
            {
                first_zOffset++;
            }
            #endregion

            ChessPieceInformation firstState = board[first_xOffset, first_zOffset];

            DataManager.Team      first_team      = firstState.Team;
            DataManager.PieceName first_pieceName = firstState.PieceName;

            // 두번째
            int last_xOffset = (int)(lastPositon.x / distance);
            int last_zOffset = (int)(lastPositon.z / distance);

            #region catch bugs 2
            float re_x = lastPositon.x % distance;
            float re_z = lastPositon.z % distance;
            if (re_x >= 0.03f)
            {
                last_xOffset++;
            }
            if (re_z >= 0.03f)
            {
                last_zOffset++;
            }
            #endregion

            ChessPieceInformation lastState = board[last_xOffset, last_zOffset];

            DataManager.Team      last_team      = lastState.Team;
            DataManager.PieceName last_pieceName = lastState.PieceName;

            if (firstState.Team != lastState.Team && lastState.Team != DataManager.Team.None)
            {
                // kill piece
                // GameObject.FindGameObjectWithTag("GameManager").GetComponent<NetworkManager>().SetActiveFalseObject(last_team, last_pieceName, last_xOffset, last_zOffset);
                // GetOrCreateManager<NetworkManager>().
                board[first_xOffset, first_zOffset] = new ChessPieceInformation(DataManager.Team.None, DataManager.PieceName.None);
                board[last_xOffset, last_zOffset]   = firstState;
            }
            else
            {
                // switching
                board[first_xOffset, first_zOffset] = lastState;
                board[last_xOffset, last_zOffset]   = firstState;
            }
        }