static void Main() { // Forms boilerplate Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Make a real brain if needed, dummy otherwise CBrain brain; IRobot robot; if (INIT_BRAIN) { brain = new CBrain(); brain.simulatorMapFile = ""; brain.simulatorType = "MobileSim"; brain.robotHostName = ""; brain.cameraPort = ""; brain.useCamera = false; brain.useRemoteVoice = false; brain.voicePort = ""; brain.configFileName = @"C:\Users\Administrator\checkout\SubSimNL\SubSimNLDemo\BrainInterface.exe.config"; brain.Init(IntPtr.Zero, ""); robot = brain.Robot; } else { brain = null; robot = null; } // Start the subsim CSubSimProcessorLanguage nlInput = new CSubSimProcessorLanguage(brain); nlInput.standalone = true; nlInput.Init(brain, robot); nlInput.Run(); }
/// <summary> /// Make a new goal. The goal is not added to the brain until <c>Commit</c> is called. /// </summary> /// <param name="name">Name of the goal, the leading "g" is added automatically</param> /// <param name="brain">The brain to create the goal in when Commit is called.</param> public GoalBuilder(string name, CBrain brain) { this.brain = brain; rules = new List<CRule>(); // Make a new non-decaying production goal = new CProduction(); goal.decays = false; goal.Name = this.name = "g" + name; }
/// <summary> /// Process the parse as an unconditional action goal. /// </summary> /// <param name="parse">Parse to process</param> /// <param name="brain">Brain to add goals to</param> /// <returns>The name of the goal created; null if no goal could be made.</returns> public static string ParseActionGoal(Command command, CBrain brain) { // If there's no target, give up if (command.targets.Length == 0) { return null; } TransitiveAction antecedent = new TransitiveAction(); TransitiveAction consequent = new TransitiveAction(); consequent.action = command.action; // TODO Expand to handle multiple targets consequent.target = command.targets[0]; return AddGoal(antecedent, consequent, brain); }
public CAIPlayer(CLocalServer local_server) { this.local_server = local_server; this.brain = new CBrain(); this.hand_cards = new List<CCard>(); this.floor_card_manager = new CFloorCardManager(); reset(); this.packet_handler = new Dictionary<PROTOCOL, PacketFn>(); this.packet_handler.Add(PROTOCOL.LOCAL_SERVER_STARTED, ON_LOCAL_SERVER_STARTED); this.packet_handler.Add(PROTOCOL.BEGIN_CARD_INFO, ON_BEGIN_CARD_INFO); this.packet_handler.Add(PROTOCOL.START_TURN, ON_START_TURN); this.packet_handler.Add(PROTOCOL.SELECT_CARD_ACK, ON_SELECT_CARD_ACK); this.packet_handler.Add(PROTOCOL.FLIP_DECK_CARD_ACK, ON_FLIP_DECK_CARD_ACK); this.packet_handler.Add(PROTOCOL.TURN_RESULT, ON_TURN_RESULT); this.packet_handler.Add(PROTOCOL.ASK_GO_OR_STOP, ON_ASK_GO_OR_STOP); this.packet_handler.Add(PROTOCOL.ASK_KOOKJIN_TO_PEE, ON_ASK_KOOKJIN_TO_PEE); this.packet_handler.Add(PROTOCOL.GAME_RESULT, ON_GAME_RESULT); }
public CAIPlayer(CLocalServer local_server) { this.local_server = local_server; this.brain = new CBrain(); this.hand_cards = new List <CCard>(); this.floor_card_manager = new CFloorCardManager(); reset(); this.packet_handler = new Dictionary <PROTOCOL, PacketFn>(); this.packet_handler.Add(PROTOCOL.LOCAL_SERVER_STARTED, ON_LOCAL_SERVER_STARTED); this.packet_handler.Add(PROTOCOL.BEGIN_CARD_INFO, ON_BEGIN_CARD_INFO); this.packet_handler.Add(PROTOCOL.START_TURN, ON_START_TURN); this.packet_handler.Add(PROTOCOL.SELECT_CARD_ACK, ON_SELECT_CARD_ACK); this.packet_handler.Add(PROTOCOL.FLIP_DECK_CARD_ACK, ON_FLIP_DECK_CARD_ACK); this.packet_handler.Add(PROTOCOL.TURN_RESULT, ON_TURN_RESULT); this.packet_handler.Add(PROTOCOL.ASK_GO_OR_STOP, ON_ASK_GO_OR_STOP); this.packet_handler.Add(PROTOCOL.ASK_KOOKJIN_TO_PEE, ON_ASK_KOOKJIN_TO_PEE); this.packet_handler.Add(PROTOCOL.GAME_RESULT, ON_GAME_RESULT); }
GameObject Breed(GameObject parent1, GameObject parent2) { Vector3 startingPos = new Vector3(this.transform.position.x, this.transform.position.y, this.transform.position.z); GameObject offspring = Instantiate(botPrefab, startingPos, this.transform.rotation); CBrain b = offspring.GetComponent <CBrain>(); b.Init(); if (Random.Range(0, 50) == 1) { b.dna.Mutate(); } else { b.dna.Combine(parent1.GetComponent <CBrain>().dna, parent2.GetComponent <CBrain>().dna); } return(offspring); }
/// <summary> /// Add a goal to the brain. /// </summary> /// <param name="antecedent">Antecedent of goal. If there is no antecendent, an empty TransitiveAction can be given.</param> /// <param name="consequent">Consequent of goal</param> /// <param name="brain">Brain to create goal in</param> /// <returns>Name of the goal created</returns> private static string AddGoal(TransitiveAction antecedent, TransitiveAction consequent, CBrain brain) { // Simple validation: if the consequent has a null action, give up if (consequent.action == null) { return null; } // Set up the goal string name = MakeGoalName(antecedent, consequent); GoalBuilder goal = new GoalBuilder("NL" + name, brain); int ruleIndex = goal.AddRule("NL" + name); // Convert consequents to goals if (goWords.Contains(consequent.action)) { brain.Mind.addFact(new CFact("(CurrentDestination Arg Value=" + consequent.target + ";1)")); return "gGotoX"; } else if (tellWords.Contains(consequent.action)) { if (experienceWords.Contains(antecedent.action)) { string type = TitleCase(antecedent.target); string matchVar = "NotToldAbout" + type; goal.AddAndAntecedent(ruleIndex, matchVar + "? " + type + " *=*;1"); goal.AddNegatedAndAntecedent(ruleIndex, "?" + matchVar + " " + type + " ToldAbout=*;1 *=*;1"); goal.AddAndAntecedent(ruleIndex, "CurrentView State " + type + "s=*?" + matchVar + "_*;1 *=*;1"); goal.AddConsequent(ruleIndex, "Execs", "Voice Say \"Commander, I see a " + type + ".\""); goal.AddConsequent(ruleIndex, "Set", "?" + matchVar + ".Name " + type + " ToldAbout=true"); // Add a default Wait rule so the rule doesn't spin int defaultRuleIndex = goal.AddRule("Default" + goal.Name); goal.AddConsequent(defaultRuleIndex, "Wait", "1000"); // Confirm the plan back int confirmRuleIndex = goal.AddRule("Initialize" + goal.Name); goal.AddConsequent(confirmRuleIndex, "Execs", "Voice Say \"Okay, if I see a " + antecedent.target + ", I'll let you know.\""); goal.AddConsequent(confirmRuleIndex, "DisableRule", "self"); // This rule doesn't have a quit as it should stay standing } else { // Say we don't know how to do it brain.Mind.addFact(new CFact("(DontKnow Arg Value=" + antecedent.action + ";1)")); return "gDontKnowHowToX"; } } else if (consequent.action != null) { // Say we don't know how to do it brain.Mind.addFact(new CFact("(DontKnow Arg Value=" + consequent.action + ";1)")); return "gDontKnowHowToX"; } else { return null; } // Commit the goal if we made it through goal.Commit(); return goal.Name; }
/// <summary> /// Initializes a new instance of the CSubSimProcessorLanguage class. /// </summary> /// <param name="brain">The brain the SubSim is operating in</param> public CSubSimProcessorLanguage(CBrain brain) : base(brain) { standalone = false; }
/// <summary> /// Create a parser and default goals. /// </summary> /// <param name="brain">The brain</param> /// <param name="robot">The robot</param> public override void Init(Brain.CBrain brain, IRobot robot) { this.brain = brain; this.robot = robot; // Load external NLP systems in their own threads restorerLoaded = new AutoResetEvent(false); parserLoaded = new AutoResetEvent(false); Thread parserLoader = new Thread(InitParser); Thread restorerLoader = new Thread(InitRestorer); parserLoader.Start(); restorerLoader.Start(); // Load up other systems in the meantime this.tokenizer = new EnglishMaximumEntropyTokenizer(sharpNLPPath + "EnglishTok.nbin"); this.tagger = new EnglishMaximumEntropyPosTagger(sharpNLPPath + "EnglishPOS.nbin", sharpNLPPath + @"\Parser\tagdict"); // Make default goals GoalBuilder gotoGoal = new GoalBuilder("GotoX", brain); int ruleIndex = gotoGoal.AddRule("GotoX"); gotoGoal.AddAndAntecedent(ruleIndex, "CurrentDestination Arg *=*;1"); gotoGoal.AddConsequent(ruleIndex, "Execs", "Voice Say \"Going to the $CurrentDestination_\""); gotoGoal.AddConsequent(ruleIndex, "Execs", "Motion GoTo $CurrentDestination close"); gotoGoal.AddConsequent(ruleIndex, "Execs", "Voice Say \"Commander, I finished moving to the $CurrentDestination_\""); gotoGoal.AddConsequent(ruleIndex, "Remove", "CurrentDestination Arg"); gotoGoal.AddConsequent(ruleIndex, "Quit", ""); gotoGoal.Commit(); failureGoal = new GoalBuilder("DidNotUnderstand", brain); ruleIndex = failureGoal.AddRule("DidNotUnderstand"); failureGoal.AddConsequent(ruleIndex, "Execs", "Voice Say \"I didn't understand what you said.\""); failureGoal.AddConsequent(ruleIndex, "Quit", ""); failureGoal.Commit(); GoalBuilder goingToGoal = new GoalBuilder("SayGoingToX", brain); ruleIndex = goingToGoal.AddRule("SayGoingToX"); goingToGoal.AddAndAntecedent(ruleIndex, "CurrentDestination Arg *=*;1"); goingToGoal.AddConsequent(ruleIndex, "Execs", "Voice Say \"I'm Going to the $CurrentDestination_\""); goingToGoal.AddConsequent(ruleIndex, "Quit", ""); goingToGoal.Commit(); GoalBuilder goingNowhereGoal = new GoalBuilder("SayGoingNowhere", brain); ruleIndex = goingNowhereGoal.AddRule("SayGoingNowhere"); goingNowhereGoal.AddConsequent(ruleIndex, "Execs", "Voice Say \"I'm not going anywhere right now.\""); goingNowhereGoal.AddConsequent(ruleIndex, "Quit", ""); goingNowhereGoal.Commit(); GoalBuilder dontKnowGoal = new GoalBuilder("DontKnowHowToX", brain); ruleIndex = dontKnowGoal.AddRule("DontKnowHowToX"); dontKnowGoal.AddAndAntecedent(ruleIndex, "DontKnow Arg *=*;1"); dontKnowGoal.AddConsequent(ruleIndex, "Execs", "Voice Say \"Sorry, but I don't know how to $DontKnow_\""); dontKnowGoal.AddConsequent(ruleIndex, "Remove", "DontKnow Arg"); dontKnowGoal.AddConsequent(ruleIndex, "Quit", ""); dontKnowGoal.Commit(); // Wait for all systems to finish loading restorerLoaded.WaitOne(); parserLoaded.WaitOne(); this.semantics = new SemanticsInterface(); }