コード例 #1
0
ファイル: Strips.cs プロジェクト: DeJaVoo/strips-froniture
 /// <summary>
 /// Checks if predicate rectangle is clean
 /// </summary>
 /// <param name="cleanPredicate"></param>
 /// <returns></returns>
 private bool CheckClean(PClean cleanPredicate)
 {
     return this.board.IsEmpty(cleanPredicate.CleanRect);
 }
コード例 #2
0
ファイル: Strips.cs プロジェクト: DeJaVoo/strips-froniture
        /// <summary>
        /// strips step
        /// returns the executed operation.
        /// if there was no Operation in the current step returns null
        /// </summary>
        private Operation StripsStep()
        {
            var item = stack.Peek();
            bool satisfied = false;
            bool allArePredicateKind = CheckAllArePredicate(item);
            if (allArePredicateKind)
                satisfied = GoalsAreSatisfied(item);

            //case 1- goals is satisfied- pop and return
            if (allArePredicateKind && satisfied)
            {
                stack.Pop();
                return null;
            }
            //case 2- goals is unsatisfied and conjunctive- order goals by heuristic and add each one to stack
            if (allArePredicateKind && item.Count > 1 && !satisfied)
            {
                // the list is ordered in the order of the execution
                IList<StackItem> ordered = heuristics.OrderPredicates(item);

                // push the items in the list in reverse order so we will get in the top of the stack
                // the first item to execute
                for (int i = ordered.Count - 1; i >= 0; i--)
                {
                    var tempList = new List<StackItem>();
                    tempList.Add(ordered[i]);
                    stack.Push(tempList);
                }
                return null;
            }
            // case 3- goal is a single unsatisfied goal- choose an operation push it and all its pre condtiotions
            if (allArePredicateKind && item.Count == 1 && !satisfied)
            {
                Operation operation = heuristics.ChooseOperation(board, (Predicate) item[0]);
                stack.Push(new List<StackItem> {operation});

                // push it's pre condition into stack - need to implement a function that calculates precondition per move
                if (operation is Move)
                {
                    Rectangle rectToBeClean = ((Move) operation).CalculateRectDiff();
                    var clean = new PClean(rectToBeClean);
                    clean.Forbbiden = operation.ForbbidenDirections();
                    stack.Push(new List<StackItem> {clean});
                }
                    // Rotate
                else
                {
                    Rectangle rect = ((Rotate) operation).CalculateRectToBeCleanByDirection();
                    var clean = new PClean(rect);
                    clean.Forbbiden = operation.ForbbidenDirections();
                    stack.Push(new List<StackItem> {clean});
                }
                return null;
            }
            //case 4- item is an operation- pop it, execute it and add to operation list
            if (item.Count == 1 && item.First() is Operation)
            {
                var operation = stack.Pop().First();

                ((Operation) operation).Execute();
                return (Operation) operation;
            }

            return null;
        }