Example #1
0
        private void ParseTiles()
        {
            Tiles = new Tale[m_width, m_height];
            for (int j = 0; j < m_height; j++)
            {
                for (int i = 0; i < m_width; i++)
                {
                    if (m_array[i + j * m_width] == 1)
                    {
                        Tiles[i, j] = new Tale()
                        {
                            IsObstacle = true,
                        };
                    }
                    else
                    {
                        Tiles[i, j] = new Tale()
                        {
                            IsObstacle = false,
                            Objects    = new List <MyStaticObject>(),
                        };
                    }
                    if (m_array[i + j * m_width] == A)
                    {
                        this.PlaceAgentTo(i, j);
                    }
                }
            }

            if (Agent == null)
            {
                Console.WriteLine("Warning: no agent found in the map, placing it to [0,0]");
                this.PlaceAgentTo(0, 0);
            }
        }
 // resolve colisions
 private bool CanMakeStepTo(int toX, int toY, Tale[,] tales, float myWeight)
 {
     if (tales[toX, toY].IsObstacle)
     {
         return false;
     }
     // empty tale with no objects
     if (tales[toX, toY].Objects.Count == 0)
         return true;
     // some of objects is heavier than the agent
     for (int i = 0; i < tales[toX, toY].Objects.Count; i++)
     {
         if (tales[toX, toY].Objects[i].GetWeight() >= myWeight)
             return false;
     }
     return true;
 }
        protected bool ResolveNavigation(
            MyMovingObject agent,
            Tale[,] tales,
            AGENT_ACTIONS action)
        {
            int2 pos = agent.GetPosition();

            if (action == AGENT_ACTIONS.UP && pos.y < w.GetHeight() - 1)
            {
                if (CanMakeStepTo(pos.x, pos.y + 1, tales, agent.GetWeight()))
                {
                    agent.MoveUp();
                    return true;
                }
            }
            else if (action == AGENT_ACTIONS.DOWN && agent.GetPosition().y > 0)
            {
                if (CanMakeStepTo(pos.x, pos.y - 1, tales, agent.GetWeight()))
                {
                    agent.MoveDown();
                    return true;
                }
            }
            else if (action == AGENT_ACTIONS.LEFT && agent.GetPosition().x > 0)
            {
                if (CanMakeStepTo(pos.x - 1, pos.y, tales, agent.GetWeight()))
                {
                    agent.MoveLeft();
                    return true;
                }
            }
            else if (action == AGENT_ACTIONS.RIGHT && agent.GetPosition().x < w.GetWidth() - 1)
            {
                if (CanMakeStepTo(pos.x + 1, pos.y, tales, agent.GetWeight()))
                {
                    agent.MoveRight();
                    return true;
                }
            }
            return false;
        }
        protected bool ResolveCustomActions(MyMovingObject agent, Tale[,] tales, AGENT_ACTIONS action)
        {
            bool result = false;
            Tale t;
            if (action == AGENT_ACTIONS.BASIC)
            {
                t = tales[agent.GetPosition().x, agent.GetPosition().y];

                for (int i = 0; i < t.Objects.Count; i++)
                {
                    if (t.Objects[i] is TwoStateObjectControl)
                    {
                        if (t.Objects[i] is DoorControl)
                        {
                            if (!pars.ForceDoorSwitches)
                            {
                                ((DoorControl)t.Objects[i]).applyPressAction();
                                result = true;
                            }
                        }
                        else if (t.Objects[i] is LightsControl)
                        {
                            if (!pars.ForceLightSwitches)
                            {
                                ((LightsControl)t.Objects[i]).applyPressAction();
                                result = true;
                            }
                        }
                        else
                        {
                            ((TwoStateObjectControl)t.Objects[i]).applyPressAction();
                            result = true;
                        }
                    }
                }
            }

            if (pars.ForceDoorSwitches || pars.ForceLightSwitches)
            {
                for (int i = 0; i < tales.GetLength(0); i++)
                {
                    for (int j = 0; j < tales.GetLength(1); j++)
                    {
                        t = tales[i, j];
                        if (t.Objects != null)
                        {
                            for (int k = 0; k < t.Objects.Count; k++)
                            {
                                if (t.Objects[k] is DoorControl && pars.ForceDoorSwitches)
                                {
                                    DoorControl dc = (DoorControl)t.Objects[k];
                                    if (dc.IsOn() != pars.ForceDoorSwitchesState)
                                    {
                                        dc.applyPressAction();
                                    }
                                }
                                else if (t.Objects[k] is LightsControl && pars.ForceLightSwitches)
                                {
                                    LightsControl lc = (LightsControl)t.Objects[k];
                                    if (lc.IsOn() != pars.ForceLightSwitchesState)
                                    {
                                        lc.applyPressAction();
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return result;
        }
Example #5
0
        private void ParseTiles()
        {
            Tiles = new Tale[m_width, m_height];
            for (int j = 0; j < m_height; j++)
            {
                for (int i = 0; i < m_width; i++)
                {
                    if (m_array[i + j * m_width] == 1)
                    {
                        Tiles[i, j] = new Tale()
                        {
                            IsObstacle = true,
                        };
                    }
                    else
                    {
                        Tiles[i, j] = new Tale()
                        {
                            IsObstacle = false,
                            Objects = new List<MyStaticObject>(),
                        };
                    }
                    if (m_array[i + j * m_width] == A)
                    {
                        this.PlaceAgentTo(i, j);
                    }
                }
            }

            if (Agent == null)
            {
                Console.WriteLine("Warning: no agent found in the map, placing it to [0,0]");
                this.PlaceAgentTo(0, 0);
            }
        }