Example #1
0
        /*
         * public CD(SimpleGrammar.ParseNode pn)
         * {
         *  if (pn == null) throw (new Exception("CD null argument"));
         *  PropList = new Hashtable();
         *  if (pn.value == "S")
         *  {
         *      if (pn.children == null) throw (new Exception("CD: S node has no children"));
         *      pn = (ParseNode)pn.children[0];
         *  }
         *  if (pn.children == null || pn.children.Count == 0) throw (new Exception("CD: CMD node has no children"));
         *  switch (pn.value)
         *  {
         *      case "CMD1":
         *          CMD1_CD(this, pn);
         *          break;
         *      case "C+OBJ":
         *          C_OBJ_CD(this, pn);
         *          break;
         *      case "GOX":
         *          goxCD(this, pn);
         *          break;
         *      case "TURNX":
         *          turnxCD(this, pn);
         *          break;
         *      default:
         *          throw (new Exception("CD: Unknown child of S"));
         *  }
         * }
         */
        /*
         * private void CMD1_CD(CD cd, ParseNode pn)
         * {
         *  SimpleGrammar.ParseNode child = (SimpleGrammar.ParseNode)pn.children[0];
         *  string command = (string)concept.all_commands[child.value];
         *  if (command == null) throw (new Exception("CMD1_CD: unrecognized command: " + child.value));
         *  cd.head = (concept)concept.all_concepts[command];
         *  if (cd.head == null) throw (new Exception("CMD1_CD: unrecognized concept: " + command));
         * }
         *
         *
         * private void C_OBJ_CD(CD cd, ParseNode pn)
         * {
         *  foreach (ParseNode child in pn.children)
         *  {
         *      if (child.value == "CMD2")
         *      {
         *          if (child.children == null || child.children.Count == 0) throw (new Exception("C_OBJ_CD: CMD2 has no children"));
         *          ParseNode cmd = (ParseNode)child.children[0];
         *          string command = (string)concept.all_commands[cmd.value];
         *          if (command == null) throw (new Exception("CMD2_CD: unrecognized command: " + cmd.value));
         *          cd.head = (concept)concept.all_concepts[command];
         *          if (cd.head == null) throw (new Exception("CMD1_CD: unrecognized concept: " + command));
         *      }
         *      else
         *      {
         *          if (child.value == "object:")
         *          {
         *              cd.PropList = new Hashtable();
         *              cd.PropList.Add("object:", objectCD(child));
         *          }
         *      }
         *  }
         *
         * }
         *
         * private CD objectCD(ParseNode pn)
         * {
         *  if (pn.children == null || pn.children.Count == 0) throw (new Exception("objectCD: object has no children"));
         *  ParseNode child = (ParseNode)pn.children[0];
         *  if (child.value == "me") return new CD("me");
         *  if (child.value != "NG") throw (new Exception("objectCD: object missing"));
         *  return ngCD(child);
         * }
         *
         * private CD ngCD(ParseNode pn)
         * {
         *  if (pn.children == null || pn.children.Count == 0) throw (new Exception("ngCD: ng has no children"));
         *  string noun = "";
         *  foreach (ParseNode child in pn.children)
         *  {
         *      if (child.value == "NOUN")
         *      {
         *          if (child.children == null || child.children.Count == 0) throw (new Exception("ngCD: NOUN has no children"));
         *          ParseNode nn = (ParseNode)child.children[0];
         *          noun = nn.value;
         *          break;
         *      }
         *  }
         *  string noun1 = (string)concept.all_nouns[noun];   // such as "ball"
         *  if (noun1 == null) throw (new Exception("ngCD: unknown noun: " + noun));
         *  CD result = new CD(noun1);
         *  foreach (ParseNode child in pn.children)
         *  {
         *      if (child.children == null || child.children.Count == 0) throw (new Exception("ngCD: no children of " + child.value));
         *      ParseNode pnspec = (ParseNode)child.children[0];
         *      string pnspecName = pnspec.value;
         *      string mod;
         *      switch ((string)child.value)
         *      {
         *          case "ART":
         *              result.PropList.Add("det:", pnspecName);
         *              break;
         *          case "ADJ":
         *              mod = (string)concept.all_modifiers[pnspecName];
         *              if (result.PropList[mod] == null) result.PropList.Add(mod, pnspecName);
         *              break;
         *          case "PN":
         *              if (pnspec.children == null || pnspec.children.Count == 0) throw (new Exception("ngCD: no children of " + pnspecName));
         *              ParseNode locSpec = (ParseNode)pnspec.children[0];
         *              string locSpecName = locSpec.value;
         *              mod = (string)concept.all_directions[locSpecName];
         *              if (pnspecName == "LOC_SPEC1")
         *              {
         *                  if (result.PropList[mod] == null) result.PropList.Add(mod, new CD("you"));
         *                  break;
         *              }
         *              if (pnspecName == "LOC+REF")
         *              {
         *                  ParseNode locSpec2 = (ParseNode)locSpec.children[0];
         *                  string locSpec2Name = locSpec2.value;
         *                  mod = (string)concept.all_directions[locSpec2Name];
         *                  if (result.PropList[mod] == null) result.PropList.Add(mod, locrefCD((ParseNode)pnspec.children[1]));
         *                  break;
         *              }
         *              throw (new Exception("ngCD: strange PN: " + pnspecName));
         *          default:
         *              break;
         *      }
         *  }
         *  return result;
         * }
         *
         * private object locrefCD(ParseNode pn)
         * {
         *  if (pn.children == null || pn.children.Count == 0) throw (new Exception("locrefCD: locref has no children"));
         *  ParseNode child = (ParseNode)pn.children[0];
         *  if (child.value == "you") return new CD("you");
         *  if (child.value != "NPH") throw (new Exception("locrefCD: ref missing"));
         *  return ngCD(child);
         * }
         *
         *
         * private void goxCD(CD cd, ParseNode pn)
         * {
         *  cd.head = (concept)concept.all_concepts["go"];
         *  cd.PropList = new Hashtable();
         *  if (pn.children == null || pn.children.Count == 0) throw (new Exception("goxCD: gox has no children"));
         *  foreach (ParseNode child in pn.children)
         *  {
         *      if (child.value == "go_direction")
         *      {
         *          ParseNode godir = (ParseNode)child.children[0];
         *          cd.PropList.Add("go_direction", godir.value);
         *      }
         *      else
         *      {
         *          if (child.value == "num:")
         *          {
         *              ParseNode num = (ParseNode)child.children[0];
         *              cd.PropList.Add("num:", concept.all_nums[num.value]);
         *          }
         *      }
         *  }
         * }
         *
         * private void turnxCD(CD cd, ParseNode pn)
         * {
         *  cd.head = (concept)concept.all_concepts["turn"];
         *  cd.PropList = new Hashtable();
         *  if (pn.children == null || pn.children.Count == 0) throw (new Exception("turnCD: turnx has no children"));
         *  foreach (ParseNode child in pn.children)
         *  {
         *      if (child.value == "turn_direction")
         *      {
         *          ParseNode turndir = (ParseNode)child.children[0];
         *          cd.PropList.Add("turn_direction", turndir.value);
         *      }
         *      else
         *      {
         *          if (child.value == "num:")
         *          {
         *              ParseNode num = (ParseNode)child.children[0];
         *              cd.PropList.Add("num:", concept.all_nums[num.value]);
         *          }
         *      }
         *  }
         * }
         */


        public string ToSexp()
        {
            string res = "(" + head.concept_name;
            string pname;
            object pval;
            string pval_string;

            if (PropList != null)
            {
                res = res + " (";
                foreach (DictionaryEntry d in PropList)
                {
                    pname = (string)d.Key;
                    pval  = d.Value;
                    if (d.Value is CD)
                    {
                        CD x = (CD)d.Value;
                        pval_string = x.ToSexp();
                    }
                    else
                    {
                        pval_string = d.Value.ToString();
                    }
                    res = res + " (" + pname + " " + pval_string + ")";
                }
                res = res + ")";
            }
            return(res + ")");
        }
Example #2
0
        public void find_object()
        {
            CD target_CD = (CD)taskArgs.PropList["object:"];

            if (target_CD == null)
            {
                //            myMind.mySynth.SpeakAsync("No target specified");
                return;
            }
            AliveObject target;
            float       conf;
            int         fx, fy; //frontier point coordinates

            Console.WriteLine("Looking for: " + target_CD.ToSexp());
            bool new_objects_flag = true;

            for (int i = 0; i < 10; i++)
            {
                if (new_objects_flag)
                {
                    conf = dogTricks.selectKnowObject(myMind, target_CD, out target);
                    if (conf == 0 || target == null)
                    {
                        Console.WriteLine("Known objects do not match the description");
                    }
                    else
                    {
                        Console.WriteLine(target.name + " matches with conf " + conf.ToString());
                    }
                    if (conf > .3)
                    {
                        Console.WriteLine(target.name + " is the best target with conf " + conf.ToString());
                        dogTricks.walk_to_point(myMind, target);
                        myMind.myDog.TurnTo(target.X, target.Y);
                        myMind.myContext.last_focus = target;
                        Console.WriteLine("At the target");

                        // Wei Chen 2010-04-21
                        if (myMind.myDog.PickupObject(target))
                        {
                            Console.WriteLine("Carried the target");
                        }

                        // Wei Chen 2010-04-21
                        dogTricks.walk_to_point(myMind, Convert.ToSingle(128), Convert.ToSingle(128));
                        myMind.myDog.DropObject(target);

                        return;
                    }
                }
                Console.WriteLine("Explore new ground");
                if (dogTricks.find_unexplored(myMind, target_CD, out fx, out fy, 25) == false)
                {
                    break;
                }
                dogTricks.walkTo(myMind, fx, fy, 10);
                myMind.update_explored();
                if (myMind.myContext.new_objects == null || myMind.myContext.new_objects.Count == 0)
                {
                    new_objects_flag = false;
                }
            }
            //      myMind.mySynth.SpeakAsync("I can't find the right target");
            Console.WriteLine("Gave up on finding the target");
        }