public virtual void MoveFigure(Vector2Int prev_pos, Vector2Int new_pos, ChessSide side)
    {
        foreach (var item in boardItemsMono)
        {
            item.StopAnimation();
        }

        GetBoardItemMono(prev_pos).IsSelected = false;
        GetChessItemMono(prev_pos).MoveFigureToPosition(new Vector2Int[1] {
            new_pos
        });

        //Check for pawn becomes queen
        var ch_m = GetChessItemMono(new_pos);

        if (!ch_m.props.isNullObject && ch_m.props.type == (byte)ClassicChessItemType.pawn)
        {
            if (ch_m.props.side == ChessSide.white && ch_m.props.pos.y == boardSizeY - 1 ||
                (ch_m.props.side == ChessSide.black && ch_m.props.pos.y == 0))
            {
                ch_m.SetChessItem((byte)ClassicChessItemType.queen, ch_m.props.side);
            }
        }

        currentProps = chessItemProtertiesFactory.CreateNullChessItemProperties();
        PrevProps    = chessItemProtertiesFactory.CreateNullChessItemProperties();

        mm.SetMoveTextValue(prev_pos, new_pos);
    }
 protected void Start()
 {
     chessItemProtertiesFactory = new ChessItemPropertiesFactory();
     boardSpriteSize            = new Vector2();
     currentProps = chessItemProtertiesFactory.CreateNullChessItemProperties();
     PrevProps    = chessItemProtertiesFactory.CreateNullChessItemProperties();
     mm           = FindObjectOfType <MainMenu>();
     isMate       = false;
 }
 public void GetBoardData()
 {
     for (byte i = 0; i < boardSizeX; i++)
     {
         for (byte j = 0; j < boardSizeY; j++)
         {
             IChessItemModelShort c = iFigureOnBoard.GetFigureByPosition(new BoardPosition(i, j));
             if (!c.IsNullObject)
             {
                 board[i, j] = new ChessItemProperties(c.Pos.ToVector2Int(), c.Type, c.Side);
             }
             else
             {
                 board[i, j] = new ChessItemProperties(new Vector2Int(225, 225), c.Type, c.Side, true);
             }
         }
     }
 }
    public void RecoveryChessItem(ChessItemProperties props)
    {
        GameObject chess_obj = null;

        if (!props.isNullObject)
        {
            if (new byte[]
            {
                (byte)ClassicChessItemType.pawn,
                (byte)LosAlamosChessItemType.pawn,
                (byte)ChaturangaChessItemType.pawn,
                (byte)CircledChessItemType.pawn_left,
                (byte)CircledChessItemType.pawn_right
            }.Contains(props.type))
            {
                chess_obj      = GameObject.Instantiate(MainMenu.Singleton.GetCurrentBoardPrefabs().chessPackList[(byte)props.side].pawn) as GameObject;
                chess_obj.name = props.side.ToString() + "_chess_";
            }
            else if (new byte[]
            {
                (byte)ClassicChessItemType.rook,
                (byte)LosAlamosChessItemType.rook,
                (byte)ChaturangaChessItemType.rook,
                (byte)CircledChessItemType.rook
            }.Contains(props.type))
            {
                chess_obj      = GameObject.Instantiate(MainMenu.Singleton.GetCurrentBoardPrefabs().chessPackList[(byte)props.side].rook) as GameObject;
                chess_obj.name = props.side.ToString() + "_chess_";
            }
            else if (new byte[]
            {
                (byte)ClassicChessItemType.knight,
                (byte)LosAlamosChessItemType.knight,
                (byte)ChaturangaChessItemType.knight,
                (byte)CircledChessItemType.knight
            }.Contains(props.type))
            {
                chess_obj      = GameObject.Instantiate(MainMenu.Singleton.GetCurrentBoardPrefabs().chessPackList[(byte)props.side].knight) as GameObject;
                chess_obj.name = props.side.ToString() + "_chess_";
            }
            else if (new byte[]
            {
                (byte)ClassicChessItemType.bishop,
                (byte)CircledChessItemType.bishop
            }.Contains(props.type))
            {
                chess_obj      = GameObject.Instantiate(MainMenu.Singleton.GetCurrentBoardPrefabs().chessPackList[(byte)props.side].bishop) as GameObject;
                chess_obj.name = props.side.ToString() + "_chess_";
            }
            else if (new byte[]
            {
                (byte)ClassicChessItemType.queen,
                (byte)LosAlamosChessItemType.queen,
                (byte)ChaturangaChessItemType.queen,
                (byte)CircledChessItemType.queen
            }.Contains(props.type))
            {
                chess_obj      = GameObject.Instantiate(MainMenu.Singleton.GetCurrentBoardPrefabs().chessPackList[(byte)props.side].queen) as GameObject;
                chess_obj.name = props.side.ToString() + "_chess_";
            }
            else if (new byte[]
            {
                (byte)ClassicChessItemType.king,
                (byte)LosAlamosChessItemType.king,
                (byte)ChaturangaChessItemType.king,
                (byte)CircledChessItemType.king
            }.Contains(props.type))
            {
                chess_obj      = GameObject.Instantiate(MainMenu.Singleton.GetCurrentBoardPrefabs().chessPackList[(byte)props.side].king) as GameObject;
                chess_obj.name = props.side.ToString() + "_chess_";
            }

            ChessItemMono chess_scr = chess_obj.GetComponent <ChessItemMono>();
            chess_scr.props = props;
            chessItemsMono.Add(chess_scr);
            chess_obj.transform.SetParent(board_items_parent.transform);
            Vector3 pos = GetBoardPosition(props.pos.x, props.pos.y);
            chess_obj.transform.position = new Vector3(pos.x, pos.y, pos.z - 0.1f);

            UnityCustoms.SetSpriteRendererObjectSize(chess_obj, boardSpriteSize);
            chess_scr.RecoveryFigure();
        }
    }
    protected virtual void InitChessItems()
    {
        UnityCustoms.DestroyAllChilds(chess_items_parent = GameObject.Find(ChessConstants.ChessItemsObjectName));
        UnityCustoms.DestroyGameObjects(ChessConstants.ChessItemsObjectName);
        chess_items_parent = new GameObject(ChessConstants.ChessItemsObjectName);
        chess_items_parent.transform.SetParent(GameObject.Find(ChessConstants.BoardObjectName).transform);

        chessItemsMono = new List <ChessItemMonoBase>();
        int idx = 0;

        for (int i = 0; i < boardSizeX; i++)
        {
            for (int j = 0; j < boardSizeY; j++)
            {
                GameObject          chess_obj = null;
                ChessItemProperties props     = board[i, j];
                if (!props.isNullObject)
                {
                    if (new byte[]
                    {
                        (byte)ClassicChessItemType.pawn,
                        (byte)LosAlamosChessItemType.pawn,
                        (byte)ChaturangaChessItemType.pawn,
                    }.Contains(props.type))
                    {
                        chess_obj      = GameObject.Instantiate(MainMenu.Singleton.GetCurrentBoardPrefabs().chessPackList[(byte)props.side].pawn) as GameObject;
                        chess_obj.name = props.side.ToString() + "_chess_" + idx++;
                    }
                    else if (new byte[]
                    {
                        (byte)ClassicChessItemType.rook,
                        (byte)LosAlamosChessItemType.rook,
                        (byte)ChaturangaChessItemType.rook,
                    }.Contains(props.type))
                    {
                        chess_obj      = GameObject.Instantiate(MainMenu.Singleton.GetCurrentBoardPrefabs().chessPackList[(byte)props.side].rook) as GameObject;
                        chess_obj.name = props.side.ToString() + "_chess_" + idx++;
                    }
                    else if (new byte[]
                    {
                        (byte)ClassicChessItemType.knight,
                        (byte)LosAlamosChessItemType.knight,
                        (byte)ChaturangaChessItemType.knight,
                    }.Contains(props.type))
                    {
                        chess_obj      = GameObject.Instantiate(MainMenu.Singleton.GetCurrentBoardPrefabs().chessPackList[(byte)props.side].knight) as GameObject;
                        chess_obj.name = props.side.ToString() + "_chess_" + idx++;
                    }
                    else if (new byte[]
                    {
                        (byte)ClassicChessItemType.bishop,
                    }.Contains(props.type))
                    {
                        chess_obj      = GameObject.Instantiate(MainMenu.Singleton.GetCurrentBoardPrefabs().chessPackList[(byte)props.side].bishop) as GameObject;
                        chess_obj.name = props.side.ToString() + "_chess_" + idx++;
                    }
                    else if (new byte[]
                    {
                        (byte)ClassicChessItemType.queen,
                        (byte)LosAlamosChessItemType.queen,
                        (byte)ChaturangaChessItemType.queen,
                    }.Contains(props.type))
                    {
                        chess_obj      = GameObject.Instantiate(MainMenu.Singleton.GetCurrentBoardPrefabs().chessPackList[(byte)props.side].queen) as GameObject;
                        chess_obj.name = props.side.ToString() + "_chess_" + idx++;
                    }
                    else if (new byte[]
                    {
                        (byte)ClassicChessItemType.king,
                        (byte)LosAlamosChessItemType.king,
                        (byte)ChaturangaChessItemType.king,
                    }.Contains(props.type))
                    {
                        chess_obj      = GameObject.Instantiate(MainMenu.Singleton.GetCurrentBoardPrefabs().chessPackList[(byte)props.side].king) as GameObject;
                        chess_obj.name = props.side.ToString() + "_chess_" + idx++;
                    }


                    ChessItemMonoBase chess_scr = chess_obj.GetComponent <ChessItemMono>();
                    chess_scr.props = props;
                    chessItemsMono.Add(chess_scr);
                    chess_obj.transform.SetParent(chess_items_parent.transform);
                    Vector3 pos = GetBoardPosition(i, j);
                    chess_obj.transform.position = new Vector3(pos.x, pos.y, pos.z - 0.1f);
                    UnityCustoms.SetSpriteRendererObjectSize(chess_obj, boardSpriteSize);
                }
            }
        }
    }
    public void SelectBoardItem(Vector2Int pos)
    {
        if (!isMatchPlaying)
        {
            return;
        }
        if (isMateChecked)
        {
            return;
        }

        if (!firstStepInNewGameOrAfrerRestoreDone)
        {
            if (iChessMatchCurrentState.CurrentPlayer.Type == PlayerType.computer)
            {
                do_action = true;
                return;
            }
        }

        ChessSide side;
        byte      type;
        bool      isChessOnBoard = TryGetChessSide(pos, out side, out type);

        //if selected board item is empty
        if (!isChessOnBoard)
        {
            //if chess item was not selected
            if (currentProps.IsNullObject())
            {
                return;
            }
        }
        //if selected board item is not empty
        else
        {
            //if chess item was not selected
            if (currentProps.IsNullObject())
            {
                if (side != iChessMatchCurrentState.CurrentPlayer.Side)
                {
                    return;
                }
            }

            foreach (var item in boardItemsMono)
            {
                item.StopAnimation();
            }

            if (side == iChessMatchCurrentState.CurrentPlayer.Side)
            {
                var boardPos = pos.ToBoardPosition();
                if (GetChessItemMono(pos) == null)
                {
                    boardPos.IsNullObject = true;
                }

                List <bool> temp;
                var         possibleMoves = iFigureOnBoard.GetPossibleMoves(boardPos, out temp);
                foreach (var poss_move in possibleMoves)
                {
                    if (poss_move.ToVector2Int() != pos)
                    {
                        GetBoardItemMono(poss_move.ToVector2Int()).PossibleMoveAnimation();
                    }
                }

                possibleMoveList = possibleMoves;
                isJumpList       = temp;
            }
        }

        PrevProps = currentProps;
        if (!isChessOnBoard)
        {
            currentProps = new ChessItemProperties(pos, type, side, false);
        }
        else
        {
            currentProps = new ChessItemProperties(pos, type, side, false);
        }

        if (!firstStepInNewGameOrAfrerRestoreDone ||
            (firstStepInNewGameOrAfrerRestoreDone && iChessMatchCurrentState.CurrentPlayer.Type == PlayerType.human))
        {
            var boardPos = currentProps.pos.ToBoardPosition();
            if (GetChessItemMono(currentProps.pos) == null || GetChessItemMono(currentProps.pos).props.isNullObject)
            {
                boardPos.IsNullObject = true;
            }
            iChessAction.MakeAction(boardPos);
        }

        firstStepInNewGameOrAfrerRestoreDone = true;
    }
    private void OnFigureRecovery(object sender, ChessItemArgs e)
    {
        var new_props = new ChessItemProperties(e.ChessItem.Pos.ToVector2Int(), e.ChessItem.Type, e.ChessItem.Side, e.ChessItem.IsNullObject);

        MatchView_ControllerAPI.RecoveryChessItem(new_props);
    }