Exemple #1
0
 public AntBrain(String FilePath, Ant[] Ants, Logic MyLogic)
 {
     BC = new BrainChecker(FilePath);
     BC.runCheck();
     commands = BC.getCommands();
     ants = Ants;
     myLogic = MyLogic;
     for (int i = 0; i < 10000; i++)
     {
         if (commands[i] == null)
         {
             commands[i] = new AntCommand("flip", "1", "0", "0", null, null);
         }
     }
 }
Exemple #2
0
        public void commandCheck(String sepLines)
        {
            string[] input = sepLines.Split(' ');

            // SENSE COMMAND
            if (counter == 399)
            {
                Console.Write("");
            }

            if (input[0].Equals("Sense"))
            {
                if (isDirection(input[1]))
                {
                    isI(input[2]);
                    isI(input[3]);

                    if (isCondition(input[4], input))
                    {
                        if(input[4].ToLower().Equals("Marker") && input[5] != null)
                        {
                            commands[commandCounter] = new AntCommand(input[0].ToLower(), input[1].ToLower(), input[2].ToLower(), input[3].ToLower(), input[4].ToLower(), input[5].ToLower());
                            commandCounter++;
                        }
                        else
                        {
                            commands[commandCounter] = new AntCommand(input[0].ToLower(), input[1].ToLower(), input[2].ToLower(), input[3].ToLower(), input[4].ToLower(), null);
                            commandCounter++;
                        }
                    }
                    else
                    {
                        throw new System.ArgumentException("Condition Incorrect, line " + counter);
                    }
                }
                else
                {
                    throw new System.ArgumentException("Direction Incorrect, line " + counter);
                }
            }

            // MARK COMMAND
            else if (input[0].Equals("Mark"))
            {
                if (isI(input[1]))
                {
                    if (isSt(input[2]))
                    {
                        commands[commandCounter] = new AntCommand(input[0].ToLower(), input[1].ToLower(), input[2].ToLower(), null, null, null);
                        commandCounter++;
                    }
                    else
                    {
                        throw new System.ArgumentException("Mark Incorrect, line " + counter);
                    }
                }
                else
                {
                    throw new System.ArgumentException("Mark Incorrect, line " + counter);
                }
            }

            else if (input[0].Equals("Unmark"))
            {
                if (isI(input[1]))
                {
                    if (isSt(input[2]))
                    {
                        commands[commandCounter] = new AntCommand(input[0].ToLower(), input[1].ToLower(), input[2].ToLower(), null, null, null);
                        commandCounter++;
                    }
                    else
                    {
                        throw new System.ArgumentException("Mark Incorrect, line " + counter);
                    }
                }
                else
                {
                    throw new System.ArgumentException("Mark Incorrect, line " + counter);
                }
            }

            else if (input[0].Equals("PickUp"))
            {
                if (isSt(input[1]))
                {
                    if (isSt(input[2]))
                    {
                        commands[commandCounter] = new AntCommand(input[0].ToLower(), input[1].ToLower(), input[2].ToLower(), null, null, null);
                        commandCounter++;
                    }
                    else
                    {
                        throw new System.ArgumentException("Pickup Incorrect, line " + counter);
                    }
                }
                else
                {
                    throw new System.ArgumentException("Pickup Incorrect, line " + counter);
                }
            }

            else if (input[0].Equals("Drop"))
            {
                if (isSt(input[1]))
                {
                    commands[commandCounter] = new AntCommand(input[0].ToLower(), input[1].ToLower(), null, null, null, null);
                    commandCounter++;
                }
                else
                {
                    throw new System.ArgumentException("Drop Incorrect, line " + counter);
                }
            }

            else if (input[0].Equals("Turn"))
            {
                if (isTurn(input[1]))
                {
                    if (isSt(input[2]))
                    {
                        commands[commandCounter] = new AntCommand(input[0].ToLower(), input[1].ToLower(), input[2].ToLower(), null, null, null);
                        commandCounter++;
                    }
                    else
                    {
                        throw new System.ArgumentException("Turn Incorrect, line " + counter);
                    }
                }
                else
                {
                    throw new System.ArgumentException("Turn Incorrect, line " + counter);
                }
            }

            else if (input[0].Equals("Move"))
            {
                if (isSt(input[1]))
                {
                    if (isSt(input[2]))
                    {
                        commands[commandCounter] = new AntCommand(input[0].ToLower(), input[1].ToLower(), input[2].ToLower(), null, null, null);
                        commandCounter++;
                    }
                    else
                    {
                        throw new System.ArgumentException("Move Incorrect, line " + counter);
                    }
                }
                else
                {
                    throw new System.ArgumentException("Move Incorrect, line " + counter);
                }
            }

            else if (input[0].Equals("Flip"))
            {
                if (isP(input[1]))
                {
                    if (isSt(input[2]))
                    {
                        if (isSt(input[3]))
                        {
                            commands[commandCounter] = new AntCommand(input[0].ToLower(), input[1].ToLower(), input[2].ToLower(), input[3].ToLower(), null, null);
                            commandCounter++;
                        }
                        else
                        {
                            throw new System.ArgumentException("Turn Number 2 Incorrect, line " + counter);
                        }
                    }
                    else
                    {
                        throw new System.ArgumentException("Turn Number 1 Incorrect, line " + counter);
                    }
                }
                else
                {
                    throw new System.ArgumentException("Flip Incorrect, line " + counter);
                }
            }
        }