Пример #1
0
 // Move ant
 public void PerformMove(CurrentTask task, Location to, IGameState state)
 {
     if (!to.Equals(task.from) && !task.warp)
     {
         IssueOrder(task.from, ((List <Direction>)state.GetDirections(task.from, task.to))[0]);
     }
     task.warp     = false;
     task.resolved = true;
     nextTasks.Add(LocationToKey(to), task);
     currentTasks.Remove(LocationToKey(task.from));
 }
Пример #2
0
 // 2nd pass collision avoidance
 public bool ResolveConflict(Location loc, Location caller, Location origin, IGameState state)
 {
     if (LocationToKey(loc) == "32,72")
         LogShit("aaaaaaaa.txt", "Derp @ 32,72 in step " + currentStep);
     if (!currentTasks.ContainsKey(LocationToKey(loc)))
         LogShit("aaaaaaaa.txt", "loc = " + LocationToKey(loc) + "caller = " + LocationToKey(caller) + "origin = " + LocationToKey(origin));
     CurrentTask task = currentTasks[LocationToKey(loc)];
     task.resolving++;
     if(loc.Equals(task.to))
     {
         LogShit("Shitjeweet.txt", "A");
         PerformMove(task, task.to, state);
         task.resolving = 0;
         return false;
     }
     else if (nextTasks.ContainsKey(LocationToKey(task.to))) // Destination taken
     {
         LogShit("Shitjeweet.txt", "B");
         PerformMove(task, task.from, state);
         task.resolving = 0;
         return false;
     }
     else if (!currentTasks.ContainsKey(LocationToKey(task.to))) // Destination free
     {
         LogShit("Shitjeweet.txt", "C");
         PerformMove(task, task.to, state);
         task.resolving = 0;
         return true;
     }
     else if (currentTasks[LocationToKey(loc)].to.Equals(caller)) // Ant at loc wants to loc of caller and vice versa
     {
         LogShit("Shitjeweet.txt", "D");
         task.warp = true;
         PerformMove(task, caller, state);
         currentTasks[LocationToKey(caller)].warp = true;
         task.resolving = 0;
         return true;
     }
     else if (task.to.Equals(origin) && caller != null) // Loop detected to original caller (possible)
     {
         LogShit("Shitjeweet.txt", "E");
         PerformMove(task, task.to, state);
         task.resolving = 0;
         return true;
     }
     else if (task.resolving > 1) // Loop detected (futurally possible)
     {
         LogShit("Shitjeweet.txt", "F");
         // Resolve directly?
         task.resolving = 0;
         return false;
     }
     else if (ResolveConflict(task.to, loc, origin, state)) // Check if destination will be free
     {
         LogShit("Shitjeweet.txt", "G");
         bool notWarp = !task.warp;
         PerformMove(task, task.to, state);
         task.resolving = 0;
         return notWarp;
     }
     else
     {
         LogShit("Shitjeweet.txt", "H");
         if (caller == null)
             PerformMove(task, task.from, state);
         task.resolving = 0;
         return false;
     }
 }
Пример #3
0
        // 2nd pass collision avoidance
        public bool ResolveConflict(Location loc, Location caller, Location origin, IGameState state)
        {
            if (LocationToKey(loc) == "32,72")
            {
                LogShit("aaaaaaaa.txt", "Derp @ 32,72 in step " + currentStep);
            }
            if (!currentTasks.ContainsKey(LocationToKey(loc)))
            {
                LogShit("aaaaaaaa.txt", "loc = " + LocationToKey(loc) + "caller = " + LocationToKey(caller) + "origin = " + LocationToKey(origin));
            }
            CurrentTask task = currentTasks[LocationToKey(loc)];

            task.resolving++;
            if (loc.Equals(task.to))
            {
                LogShit("Shitjeweet.txt", "A");
                PerformMove(task, task.to, state);
                task.resolving = 0;
                return(false);
            }
            else if (nextTasks.ContainsKey(LocationToKey(task.to))) // Destination taken
            {
                LogShit("Shitjeweet.txt", "B");
                PerformMove(task, task.from, state);
                task.resolving = 0;
                return(false);
            }
            else if (!currentTasks.ContainsKey(LocationToKey(task.to))) // Destination free
            {
                LogShit("Shitjeweet.txt", "C");
                PerformMove(task, task.to, state);
                task.resolving = 0;
                return(true);
            }
            else if (currentTasks[LocationToKey(loc)].to.Equals(caller)) // Ant at loc wants to loc of caller and vice versa
            {
                LogShit("Shitjeweet.txt", "D");
                task.warp = true;
                PerformMove(task, caller, state);
                currentTasks[LocationToKey(caller)].warp = true;
                task.resolving = 0;
                return(true);
            }
            else if (task.to.Equals(origin) && caller != null) // Loop detected to original caller (possible)
            {
                LogShit("Shitjeweet.txt", "E");
                PerformMove(task, task.to, state);
                task.resolving = 0;
                return(true);
            }
            else if (task.resolving > 1) // Loop detected (futurally possible)
            {
                LogShit("Shitjeweet.txt", "F");
                // Resolve directly?
                task.resolving = 0;
                return(false);
            }
            else if (ResolveConflict(task.to, loc, origin, state)) // Check if destination will be free
            {
                LogShit("Shitjeweet.txt", "G");
                bool notWarp = !task.warp;
                PerformMove(task, task.to, state);
                task.resolving = 0;
                return(notWarp);
            }
            else
            {
                LogShit("Shitjeweet.txt", "H");
                if (caller == null)
                {
                    PerformMove(task, task.from, state);
                }
                task.resolving = 0;
                return(false);
            }
        }
Пример #4
0
 // Move ant
 public void PerformMove(CurrentTask task, Location to, IGameState state)
 {
     if (!to.Equals(task.from) && !task.warp)
         IssueOrder(task.from, ((List<Direction>)state.GetDirections(task.from, task.to))[0]);
     task.warp = false;
     task.resolved = true;
     nextTasks.Add(LocationToKey(to), task);
     currentTasks.Remove(LocationToKey(task.from));
 }