private void EndMove()
 {
     foreach (cell item in _canMovecells)
     {
         item.SetCellState(Ecell_state.NORMAL);
     }
     foreach (cell item in _target)
     {
         item.SetCellState(Ecell_state.NORMAL);
     }
     _currentCell.SetCellState(Ecell_state.NORMAL);
 }
    public virtual void AI_move(cell moveto)
    {
        mousePos = moveto.transform.position;
        cell old_cell = _currentCell;

        if (moveto.CurrentPiece == null)
        {
            moveto.SetPieces(this);
            _currentCell.SetPieces(null);
            _currentCell = moveto;
            Location     = mousePos;
            //Sound_CTL.Current.PlaySound(Esound.MOVE);
        }
        else
        {
            ChessBoard.Current.All_piece.Remove(moveto.CurrentPiece);
            moveto.CurrentPiece.Is_it_active = false;
            if (moveto.CurrentPiece.Player == Eplayer.BLACK)
            {
                ChessBoard.Current.Black_Pieces.Remove(moveto.CurrentPiece);
            }
            else
            {
                ChessBoard.Current.White_Pieces.Remove(moveto.CurrentPiece);
            }
            if (moveto.CurrentPiece.Type == Etype.KING)
            {
                BaseGameCTL.Current.end_game(Player);
            }
            Destroy(moveto.CurrentPiece.gameObject);
            moveto.SetPieces(this);
            _currentCell.SetPieces(null);
            _currentCell = moveto;
            Location     = mousePos;
            //Sound_CTL.Current.PlaySound(Esound.HIT);
        }
        if (BaseGameCTL.Current.CheckGameState() == Egame_state.PLAYING)
        {
            BaseGameCTL.Current.SwitchTurn();
        }
        is_it_moved = true;
        old_cell.SetCellState(Ecell_state.SELECTED);
    }
    protected virtual void OnMouseUp()
    {
        if (BaseGameCTL.Current.CheckGameState() != Egame_state.PLAYING ||
            BaseGameCTL.Current.CurrentPlayer != Player || side == Eside.AI)
        {
            return;
        }
        mouse_down = false;
        //làm tròn tọa độ cho khớp vô ô cờ
        mousePos.x = Mathf.Round(transform.position.x);
        mousePos.y = Mathf.Round(transform.position.y);

        //Lưu lại biến ô cờ sắp bị thay đổi
        cell old_cell = this._currentCell;

        cell new_cell = ChessBoard.Current.cells[(int)mousePos.x][(int)mousePos.y];

        if (_canMovecells.Contains(new_cell))
        {
            this._currentCell = new_cell;
            this._currentCell.SetPieces(this);
            old_cell.SetPieces(null);
            if (!ChessBoard.Current.HUMAN_King.isInCheck())
            {
                this.Location = mousePos;
                Sound_CTL.Current.PlaySound(Esound.MOVE);
            }
            else
            {
                this._currentCell = old_cell;
                old_cell.SetPieces(this);
                new_cell.SetPieces(null);
            }
        }
        else if (_target.Contains(new_cell))
        {
            new_cell.CurrentPiece.Is_it_active = false;
            if (!ChessBoard.Current.HUMAN_King.isInCheck())
            {
                ChessBoard.Current.All_piece.Remove(new_cell.CurrentPiece);
                new_cell.CurrentPiece.Is_it_active = false;
                if (new_cell.CurrentPiece.Player == Eplayer.BLACK)
                {
                    ChessBoard.Current.Black_Pieces.Remove(new_cell.CurrentPiece);
                }
                else
                {
                    ChessBoard.Current.White_Pieces.Remove(new_cell.CurrentPiece);
                }
                if (new_cell.CurrentPiece.Type == Etype.KING)
                {
                    BaseGameCTL.Current.end_game(this.Player);
                }
                Destroy(new_cell.CurrentPiece.gameObject);
                this._currentCell = new_cell;
                this._currentCell.SetPieces(this);
                old_cell.SetPieces(null);
                this.Location = mousePos;
                Sound_CTL.Current.PlaySound(Esound.HIT);
            }
            else
            {
                new_cell.CurrentPiece.Is_it_active = true;
            }
        }

        mousePos           = this.Location;
        mousePos.z         = -1;
        transform.position = mousePos;
        EndMove();
        if (_currentCell != old_cell)
        {
            is_it_moved = true;
            BaseGameCTL.Current.SwitchTurn();
            old_cell.SetCellState(Ecell_state.SELECTED);
        }
    }