RecessRule.cs :  » Game » SokoSolve-Sokoban » SokoSolve » Core » Analysis » DeadMap » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » SokoSolve Sokoban 
SokoSolve Sokoban » SokoSolve » Core » Analysis » DeadMap » RecessRule.cs
using System;
using System.Collections.Generic;
using System.Text;
using SokoSolve.Common.Math;
using SokoSolve.Common.Structures;
using SokoSolve.Common.Structures.Evaluation.Strategy;
using SokoSolve.Core.Analysis.Solver;
using SokoSolve.Core.Analysis.Solver.SolverStaticAnalysis;

namespace SokoSolve.Core.Analysis.DeadMap{
    /// <summary>
    /// Check which nodes form a recess without any goals. This rule assumes that the Corner rule evaluates first
    /// </summary>
    public class RecessRule : StrategyRule<DeadMapState>
    {
        public RecessRule(StrategyPatternBase<DeadMapState> strategy): base(strategy, "Dead Recess: Count(Crate) > Count(Goals)")
        {
        }


        /// <summary>
        /// Evaluate the recess rule
        /// </summary>
        /// <param name="StateContext"></param>
        /// <returns></returns>
        public override RuleResult Evaluate(DeadMapState StateContext)
        {
            if (!StateContext.IsDynamic)
            {
                foreach (Recess recess in StateContext.StaticAnalysis.Recesses)
                {
                    // Is Statically dead?
                    if (recess.GoalCount == 0)
                    {
                        foreach (VectorInt recessCell in recess.TruePositions)
                        {
                            StateContext[recessCell] = true;
                        }
                    }
                }
            }
            else
            {
                // Using StaticAnalysis recess list find dead positions
                Bitmap hits = StateContext.StaticAnalysis.RecessMap.BitwiseAND(StateContext.CrateMap);
                if (hits.Count > 0)
                {
                    // Crates on recesses, check
                    foreach (VectorInt recessCrate in hits.TruePositions)
                    {
                        Recess recess = FindRecess(StateContext.StaticAnalysis, recessCrate);
                        int crateCount = StateContext.CrateMap.BitwiseAND(recess).Count;
                        if (crateCount > recess.GoalCount)
                        {
                            // Dead recess
                            foreach (VectorInt recessCell in recess.TruePositions)
                            {
                                StateContext[recessCell] = true;
                            }
                        }
                    }
                }    
            }
            

            return RuleResult.Success;
        }

        /// <summary>
        /// Helper
        /// </summary>
        /// <param name="staticAnalysis"></param>
        /// <param name="cellPos"></param>
        /// <returns></returns>
        private Recess FindRecess(StaticAnalysis staticAnalysis, VectorInt cellPos)
        {
            foreach (Recess recess in staticAnalysis.Recesses)
            {
                if (recess[cellPos] == true) return recess;
            }
            return null;
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.