private void EndPath()
 {
     if (enemy.isBoss)
     {
         PlayerStats.Lives -= 25;
     }
     else
     {
         PlayerStats.Lives -= enemy.GetNbEnemies();
     }
     PathEnd.GetInstance().PlayExplosion();        // notify the END to play an explosion sound
     Destroy(gameObject);
 }
예제 #2
0
        /// <summary>
        /// Evaluates a Zero or More Path
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <returns></returns>
        public override BaseMultiset Evaluate(SparqlEvaluationContext context)
        {
            List <List <INode> > paths = new List <List <INode> >();
            BaseMultiset         initialInput = context.InputMultiset;
            int step = 0, prevCount = 0, skipCount = 0;

            String subjVar = PathStart.VariableName;
            String objVar = PathEnd.VariableName;
            bool   bothTerms = (subjVar == null && objVar == null);
            bool   reverse = false;

            if (subjVar == null || (context.InputMultiset.ContainsVariable(subjVar)))
            {
                // Work Forwards from the Starting Term or Bound Variable
                // OR if there is no Ending Term or Bound Variable work forwards regardless
                if (subjVar == null)
                {
                    paths.Add(((NodeMatchPattern)PathStart).Node.AsEnumerable().ToList());
                }
                else if (context.InputMultiset.ContainsVariable(subjVar))
                {
                    paths.AddRange((from s in context.InputMultiset.Sets
                                    where s[subjVar] != null
                                    select s[subjVar]).Distinct().Select(n => n.AsEnumerable().ToList()));
                }
            }
            else if (objVar == null || (context.InputMultiset.ContainsVariable(objVar)))
            {
                // Work Backwards from Ending Term or Bound Variable
                if (objVar == null)
                {
                    paths.Add(((NodeMatchPattern)PathEnd).Node.AsEnumerable().ToList());
                }
                else
                {
                    paths.AddRange((from s in context.InputMultiset.Sets
                                    where s[objVar] != null
                                    select s[objVar]).Distinct().Select(n => n.AsEnumerable().ToList()));
                }
                reverse = true;
            }

            if (paths.Count == 0)
            {
                GetPathStarts(context, paths, reverse);
            }

            // Traverse the Paths
            do
            {
                prevCount = paths.Count;
                foreach (List <INode> path in paths.Skip(skipCount).ToList())
                {
                    foreach (INode nextStep in EvaluateStep(context, path, reverse))
                    {
                        List <INode> newPath = new List <INode>(path);
                        newPath.Add(nextStep);
                        paths.Add(newPath);
                    }
                }

                // Update Counts
                // skipCount is used to indicate the paths which we will ignore for the purposes of
                // trying to further extend since we've already done them once
                step++;
                if (paths.Count == 0)
                {
                    break;
                }
                skipCount = prevCount;

                // Can short circuit evaluation here if both are terms and any path is acceptable
                if (bothTerms)
                {
                    bool exit = false;
                    foreach (List <INode> path in paths)
                    {
                        if (reverse)
                        {
                            if (PathEnd.Accepts(context, path[0]) && PathStart.Accepts(context, path[path.Count - 1]))
                            {
                                exit = true;
                                break;
                            }
                        }
                        else
                        {
                            if (PathStart.Accepts(context, path[0]) && PathEnd.Accepts(context, path[path.Count - 1]))
                            {
                                exit = true;
                                break;
                            }
                        }
                    }
                    if (exit)
                    {
                        break;
                    }
                }
            } while (paths.Count > prevCount || (step == 1 && paths.Count == prevCount));

            if (paths.Count == 0)
            {
                // If all path starts lead nowhere then we get the Null Multiset as a result
                context.OutputMultiset = new NullMultiset();
            }
            else
            {
                context.OutputMultiset = new Multiset();

                // Evaluate the Paths to check that are acceptable
                HashSet <ISet> returnedPaths = new HashSet <ISet>();
                foreach (List <INode> path in paths)
                {
                    if (reverse)
                    {
                        if (PathEnd.Accepts(context, path[0]) && PathStart.Accepts(context, path[path.Count - 1]))
                        {
                            Set s = new Set();
                            if (!bothTerms)
                            {
                                if (subjVar != null)
                                {
                                    s.Add(subjVar, path[path.Count - 1]);
                                }
                                if (objVar != null)
                                {
                                    s.Add(objVar, path[0]);
                                }
                            }
                            // Make sure to check for uniqueness
                            if (returnedPaths.Contains(s))
                            {
                                continue;
                            }
                            context.OutputMultiset.Add(s);
                            returnedPaths.Add(s);

                            // If both are terms can short circuit evaluation here
                            // It is sufficient just to determine that there is one path possible
                            if (bothTerms)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        if (PathStart.Accepts(context, path[0]) && PathEnd.Accepts(context, path[path.Count - 1]))
                        {
                            Set s = new Set();
                            if (!bothTerms)
                            {
                                if (subjVar != null)
                                {
                                    s.Add(subjVar, path[0]);
                                }
                                if (objVar != null)
                                {
                                    s.Add(objVar, path[path.Count - 1]);
                                }
                            }
                            // Make sure to check for uniqueness
                            if (returnedPaths.Contains(s))
                            {
                                continue;
                            }
                            context.OutputMultiset.Add(s);
                            returnedPaths.Add(s);

                            // If both are terms can short circuit evaluation here
                            // It is sufficient just to determine that there is one path possible
                            if (bothTerms)
                            {
                                break;
                            }
                        }
                    }
                }

                // Now add the zero length paths into
                IEnumerable <INode> nodes;
                if (subjVar != null)
                {
                    if (objVar != null)
                    {
                        nodes = (from s in context.OutputMultiset.Sets
                                 where s[subjVar] != null
                                 select s[subjVar]).Concat(from s in context.OutputMultiset.Sets
                                                           where s[objVar] != null
                                                           select s[objVar]).Distinct();
                    }
                    else
                    {
                        nodes = (from s in context.OutputMultiset.Sets
                                 where s[subjVar] != null
                                 select s[subjVar]).Distinct();
                    }
                }
                else if (objVar != null)
                {
                    nodes = (from s in context.OutputMultiset.Sets
                             where s[objVar] != null
                             select s[objVar]).Distinct();
                }
                else
                {
                    nodes = Enumerable.Empty <INode>();
                }

                if (bothTerms)
                {
                    // If both were terms transform to an Identity/Null Multiset as appropriate
                    if (context.OutputMultiset.IsEmpty)
                    {
                        context.OutputMultiset = new NullMultiset();
                    }
                    else
                    {
                        context.OutputMultiset = new IdentityMultiset();
                    }
                }

                // Then union in the zero length paths
                context.InputMultiset = initialInput;
                ZeroLengthPath zeroPath    = new ZeroLengthPath(PathStart, PathEnd, Path);
                BaseMultiset   currResults = context.OutputMultiset;
                context.OutputMultiset = new Multiset();
                BaseMultiset results = context.Evaluate(zeroPath);//zeroPath.Evaluate(context);
                context.OutputMultiset = currResults;
                foreach (ISet s in results.Sets)
                {
                    if (!context.OutputMultiset.Sets.Contains(s))
                    {
                        context.OutputMultiset.Add(s.Copy());
                    }
                }
            }

            context.InputMultiset = initialInput;
            return(context.OutputMultiset);
        }
예제 #3
0
 /// <summary>
 /// Gets the String representation of the Algebra
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return("ZeroOrMorePath(" + PathStart.ToString() + ", " + Path.ToString() + ", " + PathEnd.ToString() + ")");
 }
예제 #4
0
 // Use this for initialization
 void Start()
 {
     instance        = this;
     explosionSoundG = explosionSound;
     audioSource     = GetComponent <AudioSource>();
 }
예제 #5
0
        /// <summary>
        /// Evaluates a Zero Length Path.
        /// </summary>
        /// <param name="context">Evaluation Context.</param>
        /// <returns></returns>
        public override BaseMultiset Evaluate(SparqlEvaluationContext context)
        {
            if (AreBothTerms())
            {
                if (AreSameTerms())
                {
                    return(new IdentityMultiset());
                }
                else
                {
                    return(new NullMultiset());
                }
            }

            String subjVar = PathStart.VariableName;
            String objVar  = PathEnd.VariableName;

            context.OutputMultiset = new Multiset();

            // Determine the Triples to which this applies
            if (subjVar != null)
            {
                // Subject is a Variable
                if (context.InputMultiset.ContainsVariable(subjVar))
                {
                    // Subject is Bound
                    if (objVar != null)
                    {
                        // Object is a Variable
                        if (context.InputMultiset.ContainsVariable(objVar))
                        {
                            // Both Subject and Object are Bound
                            foreach (ISet s in context.InputMultiset.Sets.Where(x => x[subjVar] != null && x[objVar] != null && PathStart.Accepts(context, x[subjVar]) && PathEnd.Accepts(context, x[objVar])))
                            {
                                ISet x = new Set();
                                x.Add(subjVar, x[subjVar]);
                                context.OutputMultiset.Add(x);
                                x = new Set();
                                x.Add(objVar, x[objVar]);
                                context.OutputMultiset.Add(x);
                            }
                        }
                        else
                        {
                            // Subject is bound but Object is Unbound
                            foreach (ISet s in context.InputMultiset.Sets.Where(x => x[subjVar] != null && PathStart.Accepts(context, x[subjVar])))
                            {
                                ISet x = s.Copy();
                                x.Add(objVar, x[subjVar]);
                                context.OutputMultiset.Add(x);
                            }
                        }
                    }
                    else
                    {
                        // Object is a Term
                        // Preseve sets where the Object Term is equal to the currently bound Subject
                        INode objTerm = ((NodeMatchPattern)PathEnd).Node;
                        foreach (ISet s in context.InputMultiset.Sets)
                        {
                            INode temp = s[subjVar];
                            if (temp != null && temp.Equals(objTerm))
                            {
                                context.OutputMultiset.Add(s.Copy());
                            }
                        }
                    }
                }
                else
                {
                    // Subject is Unbound
                    if (objVar != null)
                    {
                        // Object is a Variable
                        if (context.InputMultiset.ContainsVariable(objVar))
                        {
                            // Object is Bound but Subject is unbound
                            foreach (ISet s in context.InputMultiset.Sets.Where(x => x[objVar] != null && PathEnd.Accepts(context, x[objVar])))
                            {
                                ISet x = s.Copy();
                                x.Add(subjVar, x[objVar]);
                                context.OutputMultiset.Add(x);
                            }
                        }
                        else
                        {
                            // Subject and Object are Unbound
                            HashSet <INode> nodes = new HashSet <INode>();
                            foreach (Triple t in context.Data.Triples)
                            {
                                nodes.Add(t.Subject);
                                nodes.Add(t.Object);
                            }
                            foreach (INode n in nodes)
                            {
                                Set s = new Set();
                                s.Add(subjVar, n);
                                s.Add(objVar, n);
                                context.OutputMultiset.Add(s);
                            }
                        }
                    }
                    else
                    {
                        // Object is a Term
                        // Create a single set with the Variable bound to the Object Term
                        Set s = new Set();
                        s.Add(subjVar, ((NodeMatchPattern)PathEnd).Node);
                        context.OutputMultiset.Add(s);
                    }
                }
            }
            else if (objVar != null)
            {
                // Subject is a Term but Object is a Variable
                if (context.InputMultiset.ContainsVariable(objVar))
                {
                    // Object is Bound
                    // Preseve sets where the Subject Term is equal to the currently bound Object
                    INode subjTerm = ((NodeMatchPattern)PathStart).Node;
                    foreach (ISet s in context.InputMultiset.Sets)
                    {
                        INode temp = s[objVar];
                        if (temp != null && temp.Equals(subjTerm))
                        {
                            context.OutputMultiset.Add(s.Copy());
                        }
                    }
                }
                else
                {
                    // Object is Unbound
                    // Create a single set with the Variable bound to the Suject Term
                    Set s = new Set();
                    s.Add(objVar, ((NodeMatchPattern)PathStart).Node);
                    context.OutputMultiset.Add(s);
                }
            }
            else
            {
                // Should already have dealt with this earlier (the AreBothTerms() and AreSameTerms() branch)
                throw new RdfQueryException("Reached unexpected point of ZeroLengthPath evaluation");
            }

            return(context.OutputMultiset);
        }