コード例 #1
0
        //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        public void nighbors(ref SortedDictionary <String, node> closed, ref priority_queue queue, bool huristic, ref SortedDictionary <String, node> to_del)
        {
            int row    = zero_placeXY[0];
            int coloum = zero_placeXY[1];

            if (row == 0 && coloum == 0)
            {
                //-------------------------------- probability (1) in corner top left and will move down -------------------------------------------
                this.move_down(huristic);
                search_exist_befor(ref closed, ref queue, huristic, "down", ref to_del);
                //------------------------------------------------------------------------------------------------------------------------------------
                //-------------------------------//1 probability (1) in corner top left and will move right//---------------------------------------------
                this.move_right(huristic);
                search_exist_befor(ref closed, ref queue, huristic, "right", ref to_del);
            }
            //=================================================================================================================================================================
            // corner top right
            else if (row == 0 && coloum == puzzle_size - 1)//lo f el corner -> 2 a7tmal
            {
                // 2 probability in corner top right and will move down
                this.move_down(huristic);
                search_exist_befor(ref closed, ref queue, huristic, "down", ref to_del);
                //----------------------------------------------------------------------------------------------------------------------------
                // 2 probability in corner top right and will move left
                this.move_left(huristic);
                search_exist_befor(ref closed, ref queue, huristic, "left", ref to_del);
            }
            //=================================================================================================================================================================
            //corner down left
            else if (row == puzzle_size - 1 && coloum == 0)//lo f el corner -> 2 a7tmal
            {
                //3 probability in corner down left and move up
                this.move_up(huristic);
                search_exist_befor(ref closed, ref queue, huristic, "up", ref to_del);
                //--------------------------------------------------------------------------------------------------------------
                //3 probability in corner down left and move right
                this.move_right(huristic);
                search_exist_befor(ref closed, ref queue, huristic, "right", ref to_del);
            }
            //=================================================================================================================================================================

            //4 probability in corner down right
            //corner down right
            else if (row == puzzle_size - 1 && coloum == puzzle_size - 1)//lo f el corner -> 2 a7tmal
            {
                //4 probability in corner down right and move up
                this.move_up(huristic);
                search_exist_befor(ref closed, ref queue, huristic, "up", ref to_del);
                //------------------------------------------------------------------------------------------------------
                //4 probability in corner down right and move left
                this.move_left(huristic);
                search_exist_befor(ref closed, ref queue, huristic, "left", ref to_del);
            }
            //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
            // edge up
            else if (row == 0 && (coloum != 0 || coloum != puzzle_size - 1))//lo 3la 7arf w m4 f el zoiah -> 3 a7tmlat
            {
                //edge up then -> not move up but left , right and down
                // move left
                this.move_left(huristic);
                search_exist_befor(ref closed, ref queue, huristic, "left", ref to_del);
                //********************************************************************************************************************
                // move right
                this.move_right(huristic);
                search_exist_befor(ref closed, ref queue, huristic, "right", ref to_del);
                //********************************************************************************************************************
                // move down
                this.move_down(huristic);
                search_exist_befor(ref closed, ref queue, huristic, "down", ref to_del);
            }
            //********************************************************edge down**************************************************************************************
            else if (row == puzzle_size - 1)//lo 3la 7arf w m4 f el zoiah -> 3 a7tmlat
            {
                // edge down -> move up or left or right
                //move up
                this.move_up(huristic);
                search_exist_befor(ref closed, ref queue, huristic, "up", ref to_del);
                //-----------------------------------------------------------------------------------------------------------------------------
                //move left
                this.move_left(huristic);
                search_exist_befor(ref closed, ref queue, huristic, "left", ref to_del);
                //-----------------------------------------------------------------------------------------------------------------------------------
                //move right
                this.move_right(huristic);
                search_exist_befor(ref closed, ref queue, huristic, "right", ref to_del);
            }
            //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
            //***************************************edge left*******************************************************************
            //edge left
            else if (coloum == 0)//lo 3la 7arf w m4 f el zoiah -> 3 a7tmlat
            {
                //edge is left -> move up or down or right
                // move up
                this.move_up(huristic);
                search_exist_befor(ref closed, ref queue, huristic, "up", ref to_del);
                //---------------------------------------------------------------------------------------------------------------------------------
                //move down
                this.move_down(huristic);
                search_exist_befor(ref closed, ref queue, huristic, "down", ref to_del);
                //-------------------------------------------------------------------------------------------------------------------------------------
                //move right
                this.move_right(huristic);
                search_exist_befor(ref closed, ref queue, huristic, "right", ref to_del);
            }
            //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
            //**********************edge right*************************************************
            else if (coloum == puzzle_size - 1)//lo 3la 7arf w m4 f el zoiah -> 3 a7tmlat
            {
                //edge is right -> left or down or up
                //--------------------------------------------------------------------------------------------------------------------------------------------------------
                //move left
                this.move_left(huristic);
                search_exist_befor(ref closed, ref queue, huristic, "left", ref to_del);
                //---------------------------------------------------------------------------------------------------------------------------------------------------------
                //move up
                this.move_up(huristic);
                search_exist_befor(ref closed, ref queue, huristic, "up", ref to_del);
                //---------------------------------------------------------------------------------------------------------------------
                //move down
                this.move_down(huristic);
                search_exist_befor(ref closed, ref queue, huristic, "down", ref to_del);
            }
            //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
            //****************************************in middle of puzzle************************************************************
            else
            {
                //in the middle -> left or right or up or down
                //-----------------------------------------------------------------------------------------------------------------------------------------------
                //move left
                this.move_left(huristic);
                search_exist_befor(ref closed, ref queue, huristic, "left", ref to_del);
                //----------------------------------------------------------------------------------------------------------------------------------------------------------------
                //move right
                this.move_right(huristic);
                search_exist_befor(ref closed, ref queue, huristic, "right", ref to_del);
                //-------------------------------------------------------------------------------------------------------------------------------------------------------------------
                //move up
                this.move_up(huristic);
                search_exist_befor(ref closed, ref queue, huristic, "up", ref to_del);
                //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
                //move down
                this.move_down(huristic);
                search_exist_befor(ref closed, ref queue, huristic, "down", ref to_del);
            }
        }//end of nighbor function
コード例 #2
0
        //--------------------------------------------------------------------------------
        public void search_exist_befor(ref SortedDictionary <String, node> closed, ref priority_queue queue, bool huristic, String direction, ref SortedDictionary <String, node> to_del)
        {
            if (closed.ContainsKey(this.puzzle_string))
            {
                node temp = new node();
                temp = closed[this.puzzle_string];

                if (temp.flag_open_or_closed == true) ////exit in open list
                {
                    if (temp.fn > this.fn)
                    {
                        to_del.Add(this.puzzle_string, closed[this.puzzle_string]);
                        closed.Remove(this.puzzle_string);

                        node nody = new node(this);
                        nody.node_direction = direction;

                        queue.add_to_priority_queue(nody, huristic);
                        closed.Add(this.puzzle_string, nody);
                    }
                }
                else          //exist in closed list
                {
                    if (temp.fn > this.fn)
                    {
                        closed.Remove(this.puzzle_string);

                        node nody = new node(this);
                        nody.node_direction = direction;

                        queue.add_to_priority_queue(nody, huristic);
                        closed.Add(this.puzzle_string, nody);
                    }
                }
            }
            else
            {
                node success_node = new node(this);
                success_node.node_direction = direction;

                queue.add_to_priority_queue(success_node, huristic);
                closed.Add(success_node.puzzle_string, success_node);
            }
            //##################################################
            if (direction == "down")
            {
                this.move_up(huristic);
            }
            else if (direction == "up")
            {
                this.move_down(huristic);
            }
            else if (direction == "left")
            {
                this.move_right(huristic);
            }
            else
            {
                this.move_left(huristic);
            }
            //#####################################################
            this.moves--;
            this.moves--;
            this.calculate_fn(huristic);
        }