Ejemplo n.º 1
0
        private void CalculateSwitchCosts()
        {
            int rooms = model.modelRooms.Count;

            //Parallel.For(0, rooms, index => {
            for (int index = 0; index < rooms; index++)
            {
                for (int secondindex = index + 1; secondindex < rooms; secondindex++)
                {
                    //Parallel.For(index + 1, rooms, secondindex => {
                    MyRoom r1        = model.modelRooms.ElementAt(index);
                    MyRoom r2        = model.modelRooms.ElementAt(secondindex);
                    MyRoom r1target  = null;
                    MyRoom r2target  = null;
                    Model  tempModel = model.DeepCopy(r1, r2, out r1target, out r2target);
                    tempModel.SwitchRooms(ref r1target, ref r2target);
                    if (!tempModel.IsInInvalidState)
                    {
                        double cost = CostCalculationService.CalculateCost(tempModel).First();
                        lock (locker) {
                            Actions.Add(new Switch(ref r1, ref r2, cost));
                        }
                    }
                    //});
                }
            }
            //});
        }
Ejemplo n.º 2
0
 void Start()
 {
     searshing = (((string)FengGameManagerMKII.settings[265]).Split(new char[] { ',' })).EmptyD();
     ShowSet   = new bool[] { false, false, false, false, false, false };
     setting   = new int[] { 0, 0, 0, 0, 0, 0 };
     RoomList  = new List <RoomInfo>();
     PanelInformer.instance.Add(INC.la("chage_serv_plc"), PanelInformer.LOG_TYPE.INFORMAION);
     password        = string.Empty;
     myRoom          = new MyRoom();
     timerupdatelist = 3f;
     Filter          = string.Empty;
     posPanel        = base.gameObject.transform.localPosition;
     if ((int)FengGameManagerMKII.settings[267] == 1)
     {
         ShowPanel();
     }
     else
     {
         HidePanel();
     }
     CyanPanelRect = new Rect(Screen.width / 2 - 440, Screen.height / 2 - 250, 880, 500);
     if (UIMainReferences.instance != null || NGUITools.GetActive(UIMainReferences.instance.panelMain))
     {
         NGUITools.SetActive(UIMainReferences.instance.panelMain, false);
     }
 }
Ejemplo n.º 3
0
 public GameClient()
 {
     GameTCPClient            = new GameTCPClient();
     GameTCPClient.NetMsgRev += (sender, netmsg) => _onMsgRecv(netmsg);
     MyInfo = new PlayerInfo();
     Room   = new MyRoom();
 }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            ClassRoom x = new ClassRoom(15, 12, 15);
            ClassRoom y = new ClassRoom(12, 30, 80);

            if (x.CompareTo(y) > 0)
            {
                Console.WriteLine("У x больше площадь");
            }
            else
            {
                Console.WriteLine("У y больше площадь");
            }

            List <ClassRoom> okna = new List <ClassRoom>();


            MyRoom x1 = new MyRoom(10, 7, 12);
            MyRoom y1 = new MyRoom(12, 30, 23);

            if (x1.CompareTo(y1) > 0)
            {
                Console.WriteLine("У x больше площадь");
            }
            else
            {
                Console.WriteLine("У y больше площадь");
            }
        }
Ejemplo n.º 5
0
 private Model MergeRooms(Model mMod, MyRoom room, MyRoom modelRoom)
 {
     //Model m = mMod.DeepCopy();
     mMod = RemoveCommonWalls(mMod, room, modelRoom);
     //MergeBoundaryLineListToSmallerIdRooms();
     return(mMod);
 }
Ejemplo n.º 6
0
 private bool DoTheyHaveCommmonWall(MyRoom room, MyRoom modelRoom)
 {
     if (room.BoundaryLines.Intersect(modelRoom.BoundaryLines).Any())
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 7
0
 void StartGame()
 {
     if (!HasRoom)
     {
         return;
     }
     MyRoom.StartGame();
     synchronizer.ForceRefresh();
 }
    // Find the doors of the room

    public void findDoors(GameObject room)
    {
        MyRoom mr        = room.GetComponent <MyRoom>();
        MyDoor enterDoor = null;
        MyDoor exitDoor  = null;

        if (mr.enterDoor != null)
        {
            enterDoor = mr.enterDoor.GetComponent <MyDoor>();
        }

        if (mr.exitDoor != null)
        {
            exitDoor = mr.exitDoor.GetComponent <MyDoor>();
        }

        if ((enterDoor != null && enterDoor.side == 0) || (exitDoor != null && exitDoor.side == 0))
        {
            doorAtZero = true;
        }

        else
        {
            doorAtZero = false;
        }

        if ((enterDoor != null && enterDoor.side == 1) || (exitDoor != null && exitDoor.side == 1))
        {
            doorAtOne = true;
        }

        else
        {
            doorAtOne = false;
        }

        if ((enterDoor != null && enterDoor.side == 2) || (exitDoor != null && exitDoor.side == 2))
        {
            doorAtTwo = true;
        }

        else
        {
            doorAtTwo = false;
        }

        if ((enterDoor != null && enterDoor.side == 3) || (exitDoor != null && exitDoor.side == 3))
        {
            doorAtThree = true;
        }

        else
        {
            doorAtThree = false;
        }
    }
Ejemplo n.º 9
0
        private void SimulationStepSwitch()
        {
            Dictionary <MyRoom, double> RoomCosts = new Dictionary <MyRoom, double>();

            double actualCost           = CostCalculationService.CalculateCost(model).First();
            double mincost              = actualCost;
            int    rooms                = model.modelRooms.Count;
            MyRoom switchThisMyRoomFrom = null;
            MyRoom switchThisMyRoomTo   = null;

            Parallel.For(0, rooms,
                         index => {
                Parallel.For(index + 1, rooms, secondindex => {
                    MyRoom r1       = model.modelRooms.ElementAt(index);
                    MyRoom r2       = model.modelRooms.ElementAt(secondindex);
                    MyRoom r1target = null;
                    MyRoom r2target = null;
                    Model tempModel = model.DeepCopy(r1, r2, out r1target, out r2target);
                    tempModel.SwitchRooms(ref r1target, ref r2target);

                    double cost = CostCalculationService.CalculateCost(tempModel).First();
                    lock (locker) {
                        RoomCosts.Add(r1, cost);
                        if (mincost >= cost)
                        {
                            mincost = cost;
                            //this might need to be switched later
                            switchThisMyRoomFrom = r1;
                            switchThisMyRoomTo   = r2;
                        }
                    }
                });
            });

            if (mincost >= actualCost)
            {
                actualSimulationThreshold++;
            }


            if (switchThisMyRoomFrom != null && switchThisMyRoomTo != null)
            {
                model.SwitchRooms(ref switchThisMyRoomFrom, ref switchThisMyRoomTo);
            }
            else
            {
                MessageBox.Show("no room to switch");
            }

            double[] costArray = CostCalculationService.CalculateCost(model);

            SimulationCosts.Add(new Costs(actualSimulationIndex, costArray[0], costArray[1], costArray[2], costArray[3]));
            actualSimulationIndex++;
        }
Ejemplo n.º 10
0
        public void SwitchRoom(ref MyRoom r1, ref MyRoom r2)
        {
            Action a = new Switch(ref r1, ref r2);

            a.Step(model);
            double[] costs = CostCalculationService.CalculateCost(model);

            actualCost       = costs[0];
            actualAreaCost   = costs[1];
            actualLayoutCost = costs[2];
            HandleModelChangeUpdate();
        }
Ejemplo n.º 11
0
        void InitHiddenRooms()
        {
            foreach (BaseEntity item in GameObject.FindObjectsOfType <BaseEntity>())
            {
                if (true)
                {
                    //JakePlugin.Write(string.Format("{0} Found, has {1}", item.ShortPrefabName, item.GetEntityLinks(false).Count));
                }
            }
            foreach (BuildingBlock floor in GameObject.FindObjectsOfType <BuildingBlock>())
            {
                //JakePlugin.Write(floor.ShortPrefabName);
                if (floorPrefabNames.Contains(floor.ShortPrefabName))
                {
                    MyRoom room = new MyRoom();
                    room.floor = floor;
                    Stack <BaseEntity> queueToCheck = new Stack <BaseEntity>();
                    queueToCheck.Push(floor);
                    floor.gameObject.transform.DestroyAllChildren();
                    //JakePlugin.Write(string.Format("{0} has {1} entity links", floor.ShortPrefabName, ));
                    if (floor.children != null)
                    {
                        JakePlugin.Write(string.Format("{1} has {0} children", floor.children.Count, floor.ShortPrefabName));
                    }
                    while (queueToCheck.Count > 0)
                    {
                        BaseEntity current = queueToCheck.Pop();
                        if (current.children != null)
                        {
                            foreach (BaseEntity item in current.children)
                            {
                                queueToCheck.Push(item);
                                room.contents.Add(item);
                            }
                        }
                    }
                    if (!individualRooms.ContainsKey(room.floor.net.ID))
                    {
                        individualRooms.Add(room.floor.net.ID, room);
                    }
                    else
                    {
                        JakePlugin.Write("Room already exists!");
                    }

                    JakePlugin.Write(string.Format("Room has {0} children", room.contents.Count));
                }
            }
            JakePlugin.Write(string.Format("{0} rooms", individualRooms.Count));
            InitConnectRooms();
        }
Ejemplo n.º 12
0
        public List <Model> MergeAllRoomPairs(Model m_mod)
        {
            int missinglargest = 0;

            m_mod.CalculateAllRooms();
            IEnumerable <int> enumerable = fullist.Except(m_mod.modelRooms.Select(i => i.GetNumberAsInt()));

            if (enumerable.Any())
            {
                missinglargest = enumerable.Max();
            }
            //missinglargest = m_mod.modelRooms.Select(i => int.Parse(i.Number)).Union(fullist).Max();
            List <Model> returnList = new List <Model>();

            for (var i = 0; i < m_mod.modelRooms.Count; i++)
            {
                MyRoom room = m_mod.modelRooms[i];
                if (room.GetNumberAsInt() < missinglargest)
                {
                    continue;
                }

                for (var j = i + 1; j < m_mod.modelRooms.Count; j++)
                {
                    MyRoom modelRoom = m_mod.modelRooms[j];
                    if (modelRoom.GetNumberAsInt() < missinglargest)
                    {
                        continue;
                    }
                    //if (room2.Guid == room1.Guid) continue;

                    bool a = DoTheyHaveCommmonWall(room, modelRoom);
                    if (!a)
                    {
                        continue;
                    }

                    else
                    {
                        MyRoom room2;
                        MyRoom modelRoom2;
                        Model  m_mod2 = m_mod.DeepCopy(room, modelRoom, out room2, out modelRoom2);

                        Model newModel = MergeRooms(m_mod2, room2, modelRoom2);
                        returnList.Add(newModel);
                    }
                }
            }

            return(returnList);
        }
Ejemplo n.º 13
0
        private void SwitchRoomClick(object sender, RoutedEventArgs e)
        {
            //SimulationStepSwitch();
            int roomcount = s.model.modelRooms.Count;

            if (roomcount >= 2)
            {
                Random r  = new Random(10);
                MyRoom r1 = s.model.modelRooms.ElementAt(0); //r.Next(s.model.modelRooms.Count));
                MyRoom r2 = s.model.modelRooms.ElementAt(1); //r.Next(s.model.modelRooms.Count));

                s.SwitchRoom(ref r1, ref r2);
            }
            Paint();
        }
    public void createRoom()
    {
        newRoomPosition = mapRooms[cont - 1].transform.position; // Before choose the place where is gonna be displayed the room it needs to displayed somewhere else


        mapRooms[cont] = Instantiate(roomPrefab, newRoomPosition, Quaternion.identity); // Display the room in the same position of the last one

        oldRoom = mapRooms[cont - 1].GetComponent <MyRoom>();
        newRoom = mapRooms[cont].GetComponent <MyRoom>();


        // Registering the room number for each room
        oldRoom.roomNumber = cont - 1;
        newRoom.roomNumber = cont;

        placeRoom(mapRooms[cont]);
    }
    // Change current room
    public void changeRoom(int side, GameObject room)
    {
        currentRoom = room;

        if (side == 0)
        {
            transform.position = room.transform.position + new Vector3(4.48f, 0, 0);
        }

        if (side == 1)
        {
            transform.position = room.transform.position - new Vector3(0, 2.6f, 0);
        }

        if (side == 2)
        {
            transform.position = room.transform.position - new Vector3(4.48f, 0, 0);
        }

        if (side == 3)
        {
            transform.position = room.transform.position + new Vector3(0, 2.6f, 0);
        }

        targetPosition = transform.position;

        MyRoom mr = room.GetComponent <MyRoom>();

        if (mr.numberOfEnemies > 0)
        {
            if (mr.enterDoor != null)
            {
                mr.enterDoor.GetComponent <MyDoor>().openDoor();
                mr.enterDoor.GetComponent <MyDoor>().closeDoorDelayed();
            }

            if (mr.exitDoor != null)
            {
                mr.exitDoor.GetComponent <MyDoor>().openDoor();
                mr.exitDoor.GetComponent <MyDoor>().closeDoorDelayed();
            }
        }

        findDoors(room);
    }
Ejemplo n.º 16
0
    public override void Move(Vector2 delta)
    {
        // NO TravelMind? Trim/bloat me to fit within Room!
        if (!HasTravelMind())
        {
            Rect pr = GetMyRectBL(); // prev MyRect (bottom-left aligned).
            Rect nr = GetMyRectBL(); // new MyRect (bottom-left aligned).
            nr.position += delta;    // Move.

            // INCREASE size.
            Rect camBounds = MyRoom.GetCameraBoundsLocal();
            Rect bA        = MathUtils.BloatRect(camBounds, -0.8f); // bloated inward
            Rect bB        = MathUtils.BloatRect(camBounds, 0.8f);  // bloated outward
            if (pr.xMin <= bA.xMin && nr.xMin >= bB.xMin)
            {
                nr.xMin = bB.xMin;
            }
            if (pr.xMax >= bA.xMax && nr.xMax <= bB.xMax)
            {
                nr.xMax = bB.xMax;
            }
            if (pr.yMin <= bA.yMin && nr.yMin >= bB.yMin)
            {
                nr.yMin = bB.yMin;
            }
            if (pr.yMax >= bA.yMax && nr.yMax <= bB.yMax)
            {
                nr.yMax = bB.yMax;
            }

            // DECREASE size.
            nr = TrimmedRectToRoomBounds(nr, MyRoom); // finally, cut off the sides that aren't in bounds!

            // Return!
            nr.position = nr.center; // offset to CENTER aligned.
            SetSize(nr.size);
            SetPos(nr.position);
        }
        // YES TravelMind! Just use base Move.
        else
        {
            base.Move(delta);
        }
    }
Ejemplo n.º 17
0
        private Model RemoveCommonWalls(Model m, MyRoom room1, MyRoom room2)
        {
            List <MyLine> common = room1.BoundaryLines.Intersect(room2.BoundaryLines).ToList();

            foreach (MyLine line in common)
            {
                room1.BoundaryLines.Remove(line);
                room2.BoundaryLines.Remove(line);
                m.modelLines.Remove(line);
                foreach (MyRoom room in m.modelRooms)
                {
                    room.BoundaryLines.Remove(line);
                }
                line.EndMyPoint.RelatedLines.Remove(line);
                line.StartMyPoint.RelatedLines.Remove(line);
            }
            room1.BoundaryLines.AddRange(room2.BoundaryLines);
            room2.BoundaryLines.AddRange(room1.BoundaryLines);

            int  result1;
            int  result2;
            bool parsed1 = int.TryParse(room1.Number, out result1);
            bool parsed2 = int.TryParse(room2.Number, out result2);

            if (parsed1 && parsed2 && (result1 < result2 && room2.GetNumberAsInt() != 2))
            {
                m.modelRooms.Remove(room2);
                foreach (MyLine line in m.modelLines)
                {
                    line.relatedRooms.Remove(room2);
                }
            }
            else
            {
                m.modelRooms.Remove(room1);
                foreach (MyLine line in m.modelLines)
                {
                    line.relatedRooms.Remove(room1);
                }
            }

            return(m);
        }
Ejemplo n.º 18
0
    //protected Vector2 GravityForce =
    //override protected Vector2 Gravity { get { return base.Gravity * FlipDir; } }
    //override protected float JumpForce { get { return base.JumpForce * FlipDir; } }
    //override public bool IsGrounded() {
    //    return myWhiskers.OnSurface(FlipDir<0 ? Sides.T : Sides.B);
    //}
    //override protected float WallSlideMinYVel { get { return FlipDir<0 ? Mathf.NegativeInfinity : -0.11f; } }
    //override protected float WallSlideMaxYVel { get { return FlipDir<0 ? 0.11f : Mathf.Infinity; } }
    //override protected Vector2 WallKickForce { get { return new Vector2(0.35f, 0.46f*FlipDir); } }
    //protected override Vector2 GetVelForWallKick() {
    //    if (FlipDir < 0) {
    //        return new Vector2(-myWhiskers.DirLastTouchedWall*WallKickForce.x, Mathf.Min(vel.y, WallKickForce.y));
    //    }
    //    return base.GetVelForWallKick();
    //}
    //private static int FlipDir=1; // 1 or -1.

    //   private void OnDrawGizmos() {
    //	if (myRoom==null) { return; }
    //	Gizmos.color = Color.cyan;
    //	Gizmos.DrawWireCube (myRoom.PosGlobal+camBoundsLocal.center, new Vector3(camBoundsLocal.size.x,camBoundsLocal.size.y, 10));
    //}

    // ----------------------------------------------------------------
    //  Start
    // ----------------------------------------------------------------
    //override protected void Start () {
    //	base.Start();

    //	SetSize (new Vector2(1.5f, 1.8f));
    //}
    public void InitializeAsPlayer(Room _myRoom, PlayerData data)
    {
        base.InitializeAsPlatformCharacter(_myRoom, data);

        // Give huge linear/angular drag to my rigidbody.
        Rigidbody2D myRB = GetComponent <Rigidbody2D>();

        myRB.drag        = 999999;
        myRB.angularDrag = 999999;

        DirFacing            = data.dirFacing;
        timeStoppedWallSlide = Mathf.NegativeInfinity;

        // Set camBoundsLocal!
        const float boundsBloat = 0f;         // I have to like *really* be off-screen for this to register.

        camBoundsLocal           = MyRoom.GetCameraBoundsLocal();
        camBoundsLocal.size     += new Vector2(boundsBloat, boundsBloat) * 2f;
        camBoundsLocal.position -= new Vector2(boundsBloat, boundsBloat);

        GameManagers.Instance.DataManager.UnlockPlayerType(PlayerType()); // TEMP: Also unlock this PlayerType here (and only here).
    }
Ejemplo n.º 19
0
        void InitConnectRooms()
        {
            foreach (MyRoom room in individualRooms.Values)
            {
                if (room.connectedRooms.rooms == null)
                {
                    room.connectedRooms.rooms = new HashSet <MyRoom>();
                    room.connectedRooms.rooms.Add(room);
                }
                List <EntityLink> entityLinks = room.floor.GetEntityLinks(true);
                //JakePlugin.Write("Entity Links:", entityLinks.Count);
                for (int i = 0; i < entityLinks.Count; i++)
                {
                    //JakePlugin.Write(entityLinks[i].name);
                }
                if (entityLinks.Count == 9) //Triangle
                {
                    for (int i = 0; i < 3; i++)
                    {
                        //JakePlugin.Write(entityLinks[i].name);
                        if (entityLinks[i + 6].IsEmpty())    //Wall is empty
                        {
                            if (entityLinks[i].IsOccupied()) //Foundation Is attached
                            {
                                BuildingBlock connectedFloor = entityLinks[i].connections[0].owner as BuildingBlock;
                                MyRoom        adjacentRoom   = individualRooms[connectedFloor.net.ID];
                                if (adjacentRoom.connectedRooms.rooms != null)
                                {
                                    room.connectedRooms.rooms.UnionWith(adjacentRoom.connectedRooms.rooms);
                                    adjacentRoom.connectedRooms = room.connectedRooms;
                                }
                                else
                                {
                                    room.connectedRooms.rooms.Add(adjacentRoom);
                                    adjacentRoom.connectedRooms = room.connectedRooms;
                                }
                            }
                            else
                            {
                                room.connectedRooms.visibleOutside = true;
                            }
                        }
                        //JakePlugin.Write(string.Format("Slot {0} empty, {1}", i, entityLinks[i].gender));
                    }
                }
            }

            foreach (MyRoom room in individualRooms.Values)
            {
                JakePlugin.Write(room.connectedRooms.rooms.Count, "rooms connected");
                completeRooms.Add(room.connectedRooms);
            }

            int count = 0;

            foreach (CompletedRoom room in completeRooms)
            {
                count++;
                if (room.visibleOutside)
                {
                    JakePlugin.Write("Room visible outside");
                }
                else
                {
                    JakePlugin.Write("Room invisible");
                }
            }

            JakePlugin.Write(completeRooms.Count, "individual rooms");
        }
Ejemplo n.º 20
0
        private static double CalculateLayoutCost()
        {
            double wallLength = 0.0;

            foreach (MyLine seg in localModel.modelLines)
            {
                if (seg.relatedRooms.Count > 1)
                {
                    wallLength += Math.Sqrt((seg.GetLength() / 100)) / 10;
                }
                else
                {
                    wallLength += Math.Sqrt((seg.GetLength() / 100)) * 3;
                }
            }

            Dictionary <RoomType, Dictionary <RoomType, int> > asd = new Dictionary <RoomType, Dictionary <RoomType, int> >();

            asd.Add(RoomType.LivingRoom, new Dictionary <RoomType, int>()
            {
                { RoomType.Kitchen, -20 }, { RoomType.BedRoom, -20 }, { RoomType.CorridorRoom, -100 }, { RoomType.RestRoom, -100 }
            });
            asd.Add(RoomType.Kitchen, new Dictionary <RoomType, int>()
            {
                { RoomType.LivingRoom, -20 }, { RoomType.BedRoom, 1000 }, { RoomType.CorridorRoom, -100 }, { RoomType.RestRoom, 100 }
            });
            asd.Add(RoomType.BedRoom, new Dictionary <RoomType, int>()
            {
                { RoomType.LivingRoom, -20 }, { RoomType.Kitchen, 1000 }, { RoomType.CorridorRoom, -100 }, { RoomType.RestRoom, -100 }
            });
            asd.Add(RoomType.RestRoom, new Dictionary <RoomType, int>()
            {
                { RoomType.LivingRoom, -100 }, { RoomType.Kitchen, 1000 }, { RoomType.CorridorRoom, -100 }, { RoomType.RestRoom, -100 }
            });
            asd.Add(RoomType.CorridorRoom, new Dictionary <RoomType, int>()
            {
                { RoomType.LivingRoom, -100 }, { RoomType.Kitchen, -100 }, { RoomType.BedRoom, -100 }, { RoomType.RestRoom, -100 }
            });


            double layoutcost = 0.0;

            foreach (MyLine modelLine in localModel.modelLines)
            {
                var count = modelLine.relatedRooms.Count;
                if (count > 1)
                {
                    for (var index = 0; index < count; index++)
                    {
                        MyRoom r1 = modelLine.relatedRooms[index];
                        for (int i = index + 1; i < count; i++)
                        {
                            //TODO: make a 2D grid and choose based on the combination. I dont know the solution
                            MyRoom r2 = modelLine.relatedRooms[i];

                            Dictionary <RoomType, int> asd2 = new Dictionary <RoomType, int>();
                            bool isIn = asd.TryGetValue(r1.type, out asd2);

                            if (isIn)
                            {
                                int  value     = 0;
                                bool isInOther = asd2.TryGetValue(r2.type, out value);
                                layoutcost += value;
                            }
                        }
                    }
                    //have linear 2fold combination of list, and calculate value based on the 2d array/datasheet
                }
            }

            //elrendezésszintű
            double passagewaycost = 0.0;

            passagewaycost = CalculatePassageWayCost();
            //ajtókat, nyílásokat letenni...(kérdés)
            //bejárhatóság generálás
            double privacygradientcost = 0.0;
            //kerületszámítás
            //minimális optimum kerület = sqrt(minden szoba area összege)*4
            double summary = passagewaycost + privacygradientcost + wallLength + layoutcost;

            summary = Math.Round(summary, 2);
            return(summary);
        }
Ejemplo n.º 21
0
 public Switch(ref MyRoom r1, ref MyRoom r2)
 {
     this.r1 = r1;
     this.r2 = r2;
 }
Ejemplo n.º 22
0
 public Switch(ref MyRoom r1, ref MyRoom r2, double cost)
 {
     this.r1   = r1;
     this.r2   = r2;
     this.cost = cost;
 }