Esempio n. 1
0
        static void Main(string[] args)
        {
            // The values will be in [0, 9]
            var domain = new Domain(10, 0);

            // Three variables
            var x   = new Variable("x", domain, 0);
            var y   = new Variable("y", domain, 0);
            var z   = new Variable("z", domain, 0);
            var set = new SetVariables <Variable>(x, y, z);

            var constraints = new List <NumberConstraint>
            {
                new SmallerThan(set, 1, 7), // y (at index 1) should be smaller than 7
                new SmallerThan(set, 2, 3)  // z (at index 2) should be smaller than 3
            };

            // Look for the largest sum of the three numbers
            // that satisfies the constraints
            var objective = new LargestSum();

            var solver = new SumSolver(set, constraints, objective);

            solver.solve(100, 600); // There is no rush so take the time to find a good solution

            int total = Enumerable
                        .Range(0, set.GetNumberVariables())
                        .Sum(i => set.GetValue(i));

            // The optimal result is 17 (x=9, y=6, z=2)
            Console.WriteLine("Computed solution = {0}, Best solution = {1}", total, 9 + 6 + 2);
            Console.ReadLine();
        }
        public static void Main( string[] args )
        {
            int mineral, gas, supply;
              Data data = new Data();

              if( args.Length != 3 )
              {
            System.Console.WriteLine( "Usage: ResourceAllocation #mineral #gas #supply" );
            //return;
            mineral = 20000;
            gas = 14000;
            supply = 380;
              }
              else
              {
            mineral = Convert.ToInt32( args[ 0 ] );
            gas = Convert.ToInt32( args[ 1 ] );
            supply = Convert.ToInt32( args[ 2 ] );
              }

              int maxSize = Math.Max( mineral / 25, Math.Max( gas / 25, supply ) );
              var domain = new ghost.Domain( maxSize, 0 );

              var listUnits = MakeTerranUnits( domain );
              var setUnits = new SetVariables( listUnits );

              var constraints = new List< Constraint > {
            new MineralConstraint( setUnits, mineral ),
            new GasConstraint( setUnits, gas ),
            new SupplyConstraint( setUnits, supply )
              };

              var objective = new MaxDPS( "max DPS", mineral, gas, supply );
              var solver = new ghost.Solver< Variable, SetVariables, Constraint >( setUnits, constraints, objective );

              Console.WriteLine( "Start solving trivial test" );
              solver.solve( 100, 2000 );

              int mineralUsed = 0;
              int gasUsed = 0;
              double supplyUsed = 0.0;
              double DPS = 0.0;

              for( int i = 0 ; i < setUnits.GetNumberVariables() ; ++i )
              {
            mineralUsed += setUnits.GetValue( i ) * data.Dataset[ setUnits.Name( i ) ].CostMineral;
            gasUsed += setUnits.GetValue( i ) * data.Dataset[ setUnits.Name( i ) ].CostGas;
            supplyUsed += setUnits.GetValue( i ) * data.Dataset[ setUnits.Name( i ) ].CostSupply;
            if( data.Dataset[ setUnits.Name( i ) ].GroundAttack > 0 )
              DPS += setUnits.GetValue( i ) * ( (double)data.Dataset[ setUnits.Name( i ) ].GroundAttack / data.Dataset[ setUnits.Name( i ) ].GroundCooldown );
              }

              DPS *= 24;
              Console.WriteLine( "DPS = " + DPS );
              Console.WriteLine( "Mineral left: " + (mineral - mineralUsed) + ", gas left: " + (gas - gasUsed) + ", supply left: " + (supply - supplyUsed) );
        }
Esempio n. 3
0
        public override double Cost(SetVariables <Variable> variables)
        {
            // Compute the sum for the current variable assignments
            var cost = Enumerable
                       .Range(0, variables.GetNumberVariables())
                       .Sum(i => variables.GetValue(i));

            // Return the inverse sum since we want to maximize it
            return(1.0f / cost);
        }
Esempio n. 4
0
    private void OnEnable()
    {
        myTarget = (SetVariables)target;
        soTarget = new SerializedObject(target);

        mainTime          = soTarget.FindProperty("mainTime");
        mainTimeEnabled   = soTarget.FindProperty("mainTimeEnabled");
        mainTimeSO        = soTarget.FindProperty("mainTimeSO");
        mainTimeEnabledSO = soTarget.FindProperty("mainTimeEnabledSO");
    }
Esempio n. 5
0
        public SetBetaWindow(SetVariables setVariables)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //

            this.setVariables = setVariables;
        }
Esempio n. 6
0
        public void UnbuildableTest()
        {
            var set = new SetVariables(list, 10, 10, new SetVariables.Point(5, 5), new SetVariables.Point(0, 0));

            set.Unbuildable(4, 4);

            for (int i = 0; i < 10; ++i)
            {
                for (int j = 0; j < 10; ++j)
                {
                    if (i == 4 && j == 4)
                    {
                        Assert.AreEqual(-1, set.Domain(0).IndexOf(i * 10 + j));
                    }
                    else
                    {
                        Assert.AreNotEqual(-1, set.Domain(0).IndexOf(i * 10 + j));
                    }
                }
            }

            var listPoint = new List <SetVariables.Point> {
                new SetVariables.Point(3, 9), new SetVariables.Point(8, 7), new SetVariables.Point(1, 1)
            };

            set.Unbuildable(listPoint);
            for (int i = 0; i < 10; ++i)
            {
                for (int j = 0; j < 10; ++j)
                {
                    if ((i == 4 && j == 4)
                        ||
                        (i == 3 && j == 9)
                        ||
                        (i == 8 && j == 7)
                        ||
                        (i == 1 && j == 1))
                    {
                        Assert.AreEqual(-1, set.Domain(0).IndexOf(i * 10 + j));
                    }
                    else
                    {
                        Assert.AreNotEqual(-1, set.Domain(0).IndexOf(i * 10 + j));
                    }
                }
            }
#if DEBUG
            set.Print();
#endif
        }
Esempio n. 7
0
        public mainScreen()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //

            vars          = new UIVars();
            setVariables  = new SetVariables();
            this.executer = new ExecuterThread(this.origIm.Image, this.rIm.Image, this);
        }
Esempio n. 8
0
        static void Main( string[] args )
        {
            var unbuildables = new List< SetVariables.Point > {
            new SetVariables.Point( 7, 12 ),
            new SetVariables.Point( 7, 13 ),
            new SetVariables.Point( 7, 14 ),
            new SetVariables.Point( 7, 15 ),
            new SetVariables.Point( 8, 10 ),
            new SetVariables.Point( 8, 11 ),
            new SetVariables.Point( 8, 12 ),
            new SetVariables.Point( 8, 13 ),
            new SetVariables.Point( 8, 14 ),
            new SetVariables.Point( 8, 15 ),
            new SetVariables.Point( 9, 10 ),
            new SetVariables.Point( 9, 11 ),
            new SetVariables.Point( 9, 12 ),
            new SetVariables.Point( 9, 13 ),
            new SetVariables.Point( 9, 14 ),
            new SetVariables.Point( 9, 15 ),
            new SetVariables.Point( 10, 8 ),
            new SetVariables.Point( 10, 9 ),
            new SetVariables.Point( 10, 10 ),
            new SetVariables.Point( 10, 11 ),
            new SetVariables.Point( 10, 12 ),
            new SetVariables.Point( 10, 13 ),
            new SetVariables.Point( 10, 14 ),
            new SetVariables.Point( 10, 15 ),
            new SetVariables.Point( 11, 8 ),
            new SetVariables.Point( 11, 9 ),
            new SetVariables.Point( 11, 10 ),
            new SetVariables.Point( 11, 11 ),
            new SetVariables.Point( 11, 12 ),
            new SetVariables.Point( 11, 13 ),
            new SetVariables.Point( 11, 14 ),
            new SetVariables.Point( 11, 15 )
              };

              var domain = new ghost.Domain( 16 * 12, 0 );

              var listBuildings = MakeTerranBuildings( domain );

              var setBuildings = new SetVariables( listBuildings,
                                           12,
                                           16,
                                           new SetVariables.Point( 11, 7 ),
                                           new SetVariables.Point( 6, 15 ) );

              setBuildings.Unbuildable( unbuildables );

              var constraints = new List< Constraint > {
            new OverLap( setBuildings ),
            new Buildable( setBuildings ),
            new WallShape( setBuildings ),
            new StartingTargetTiles( setBuildings )
              };

              var objective = new GapObjective();

              var solver = new ghost.Solver< Variable, SetVariables, Constraint >( setBuildings, constraints, objective );

              Console.WriteLine( "Start solving trivial test" );
              solver.solve( 20, 150, false );

            // 3.4 GHz, mono 20,150 7 tours 44 iterations
            //            C++      12 tours 400 iteratons
        }
Esempio n. 9
0
 public void FitAtTest( int pos )
 {
     var set = new SetVariables( list, 5, 10, new SetVariables.Point( 4, 5 ), new SetVariables.Point( 0, 0 ) );
       Assert.That( set.FitAt( 1, pos ), Is.True );
 }
Esempio n. 10
0
        public void UnbuildableTest()
        {
            var set = new SetVariables( list, 10, 10, new SetVariables.Point( 5, 5 ), new SetVariables.Point( 0, 0 ) );
              set.Unbuildable( 4, 4 );

              for( int i = 0 ; i < 10 ; ++i )
            for( int j = 0 ; j < 10 ; ++j )
              if( i == 4 && j == 4 )
            Assert.That( set.Domain( 0 ).IndexOf( i * 10 + j ), Is.EqualTo( -1 ) );
              else
            Assert.That( set.Domain( 0 ).IndexOf( i * 10 + j ), Is.Not.EqualTo( -1 ) );

              var listPoint = new List<SetVariables.Point> { new SetVariables.Point( 3, 9 ), new SetVariables.Point( 8, 7 ), new SetVariables.Point( 1, 1 )};
              set.Unbuildable( listPoint );
              for( int i = 0 ; i < 10 ; ++i )
            for( int j = 0 ; j < 10 ; ++j )
              if( ( i == 4 && j == 4 )
             ||
             ( i == 3 && j == 9 )
             ||
             ( i == 8 && j == 7 )
             ||
             ( i == 1 && j == 1 ) )
            Assert.That( set.Domain( 0 ).IndexOf( i * 10 + j ), Is.EqualTo( -1 ) );
              else
            Assert.That( set.Domain( 0 ).IndexOf( i * 10 + j ), Is.Not.EqualTo( -1 ) );
            #if DEBUG
              set.Print();
            #endif
        }
Esempio n. 11
0
        public void MatrixIndexTests()
        {
            var set = new SetVariables( list, 5, 10, new SetVariables.Point( 4, 5 ), new SetVariables.Point( 0, 0 ) );
              set.SetValue( 1, 14 );

              for( int i = 0 ; i < 5 ; ++i )
            for( int j = 0 ; j < 10 ; ++j )
              if( ( i == 1 && j == 4 )
              ||
              ( i == 1 && j == 5 )
              ||
              ( i == 1 && j == 6 )
              ||
              ( i == 2 && j == 4 )
              ||
              ( i == 2 && j == 5 )
              ||
              ( i == 2 && j == 6 ) )
              {
            var l = set.BuildingsAt( i, j );
            Assert.That( l.Count, Is.EqualTo( 1 ) );
            Assert.That( l[ 0 ], Is.EqualTo( 1 ) );
              }
              else
              {
            var l = set.BuildingsAt( i, j );
            Assert.That( l.Count, Is.Zero );
              }

              set.ShiftValue( 1 );

              for( int i = 0 ; i < 5 ; ++i )
            for( int j = 0 ; j < 10 ; ++j )
              if( ( i == 1 && j == 7 )
             ||
             ( i == 1 && j == 5 )
             ||
             ( i == 1 && j == 6 )
             ||
             ( i == 2 && j == 7 )
             ||
             ( i == 2 && j == 5 )
             ||
             ( i == 2 && j == 6 ) )
              {
            var l = set.BuildingsAt( i, j );
            Assert.That( l.Count, Is.EqualTo( 1 ) );
            Assert.That( l[ 0 ], Is.EqualTo( 1 ) );
              }
              else
              {
            var l = set.BuildingsAt( i, j );
            Assert.That( l.Count, Is.Zero );
              }

              set.UnshiftValue( 1 );

              for( int i = 0 ; i < 5 ; ++i )
            for( int j = 0 ; j < 10 ; ++j )
              if( ( i == 1 && j == 4 )
             ||
             ( i == 1 && j == 5 )
             ||
             ( i == 1 && j == 6 )
             ||
             ( i == 2 && j == 4 )
             ||
             ( i == 2 && j == 5 )
             ||
             ( i == 2 && j == 6 ) )
              {
            var l = set.BuildingsAt( i, j );
            Assert.That( l.Count, Is.EqualTo( 1 ) );
            Assert.That( l[ 0 ], Is.EqualTo( 1 ) );
              }
              else
              {
            var l = set.BuildingsAt( i, j );
            Assert.That( l.Count, Is.Zero );
              }

              set.SetValue( 1, 27 );

              for( int i = 0 ; i < 5 ; ++i )
            for( int j = 0 ; j < 10 ; ++j )
              if( ( i == 3 && j == 7 )
             ||
             ( i == 3 && j == 8 )
             ||
             ( i == 3 && j == 9 )
             ||
             ( i == 2 && j == 7 )
             ||
             ( i == 2 && j == 8 )
             ||
             ( i == 2 && j == 9 ) )
              {
            var l = set.BuildingsAt( i, j );
            Assert.That( l.Count, Is.EqualTo( 1 ) );
            Assert.That( l[ 0 ], Is.EqualTo( 1 ));
              }
              else
              {
            var l = set.BuildingsAt( i, j );
            Assert.That( l.Count, Is.Zero );
              }

              set.ShiftValue( 1 );

              for( int i = 0 ; i < 5 ; ++i )
            for( int j = 0 ; j < 10 ; ++j )
              if( ( i == 3 && j == 0 )
             ||
             ( i == 3 && j == 1 )
             ||
             ( i == 3 && j == 2 )
             ||
             ( i == 4 && j == 0 )
             ||
             ( i == 4 && j == 1 )
             ||
             ( i == 4 && j == 2 ) )
              {
            var l = set.BuildingsAt( i, j );
            Assert.That( l.Count, Is.EqualTo( 1 ) );
            Assert.That( l[ 0 ], Is.EqualTo( 1 ) );
              }
              else
              {
            var l = set.BuildingsAt( i, j );
            Assert.That( l.Count, Is.Zero );
              }

              set.UnshiftValue( 1 );

              for( int i = 0 ; i < 5 ; ++i )
            for( int j = 0 ; j < 10 ; ++j )
              if( ( i == 3 && j == 7 )
             ||
             ( i == 3 && j == 8 )
             ||
             ( i == 3 && j == 9 )
             ||
             ( i == 2 && j == 7 )
             ||
             ( i == 2 && j == 8 )
             ||
             ( i == 2 && j == 9 ) )
              {
            var l = set.BuildingsAt( i, j );
            Assert.That( l.Count, Is.EqualTo( 1 ) );
            Assert.That( l[ 0 ], Is.EqualTo( 1 ) );
              }
              else
              {
            var l = set.BuildingsAt( i, j );
            Assert.That( l.Count, Is.Zero );
              }

              set.ShiftValue( 1 );
              set.SetValue( 2, 22 );
              set.SetValue( 3, 37 );

              int overlaps;
              int unbuild;

              set.Shift( 2, out overlaps, out unbuild );
              Assert.That( overlaps, Is.EqualTo( -2 ) );
              Assert.That( unbuild, Is.Zero );

              Assert.That( set.GetBuildingsAround( 2 ).Contains( 1 ), Is.True );
              Assert.That( set.GetBuildingsAround( 2 ).Contains( 3 ), Is.True );
              Assert.That( set.GetBuildingsAround( 1 ).Contains( 2 ), Is.True );
              Assert.That( set.GetBuildingsAround( 3 ).Contains( 2 ), Is.True );
              Assert.That( set.GetBuildingsAround( 2 ).Count, Is.EqualTo( 2 ) );
              Assert.That( set.GetBuildingsAround( 3 ).Count, Is.EqualTo( 1 ) );
              Assert.That( set.GetBuildingsAround( 1 ).Count, Is.EqualTo( 1 ) );

              set.Shift( 2, out overlaps, out unbuild );
              Assert.That( overlaps, Is.EqualTo( 2 ) );
              Assert.That( unbuild, Is.Zero );

              var listSmallBuildings = new List<Variable> { new Variable( "X", "xxx", 1, 1, 0, 0, 0, 0, Race.Unknown, 0, 0 ),
            new Variable( "X", "xxx", 1, 1, 0, 0, 0, 0, Race.Unknown, 0, 0 ),
            new Variable( "X", "xxx", 1, 1, 0, 0, 0, 0, Race.Unknown, 0, 0 ),
            new Variable( "X", "xxx", 1, 1, 0, 0, 0, 0, Race.Unknown, 0, 0 ),
            new Variable( "X", "xxx", 1, 1, 0, 0, 0, 0, Race.Unknown, 0, 0 ) };

              set = new SetVariables( listSmallBuildings, 5, 10, new SetVariables.Point( 4, 5 ), new SetVariables.Point( 0, 0 ) );
              set.SetValue( 0, 25 );
              set.SetValue( 1, 26 );
              set.SetValue( 2, 35 );
              set.SetValue( 3, 24 );
              set.SetValue( 4, 15 );

              Assert.That( set.GetBuildingsOnRight( 0 ).Contains( 1 ), Is.True );
              Assert.That( set.GetBuildingsBelow( 0 ).Contains( 2 ), Is.True );
              Assert.That( set.GetBuildingsOnLeft( 0 ).Contains( 3 ), Is.True );
              Assert.That( set.GetBuildingsAbove( 0 ).Contains( 4 ), Is.True );
              Assert.That( set.GetBuildingsOnRight( 0 ).Count, Is.EqualTo( 1 ) );
              Assert.That( set.GetBuildingsBelow( 0 ).Count, Is.EqualTo( 1 ) );
              Assert.That( set.GetBuildingsOnLeft( 0 ).Count, Is.EqualTo( 1 ) );
              Assert.That( set.GetBuildingsAbove( 0 ).Count, Is.EqualTo( 1 ) );
              Assert.That( set.CountAround( 0 ), Is.EqualTo( 4 ) );

              Assert.That( set.GetBuildingsOnLeft( 1 ).Contains( 0 ), Is.True );
              Assert.That( set.GetBuildingsOnLeft( 1 ).Contains( 2 ), Is.True );
              Assert.That( set.GetBuildingsOnLeft( 1 ).Contains( 4 ), Is.True );
              Assert.That( set.GetBuildingsOnRight( 1 ).Count, Is.Zero );
              Assert.That( set.GetBuildingsBelow( 1 ).Count, Is.Zero );
              Assert.That( set.GetBuildingsOnLeft( 1 ).Count, Is.EqualTo( 3 ) );
              Assert.That( set.GetBuildingsAbove( 1 ).Count, Is.Zero );
              Assert.That( set.CountAround( 1 ), Is.EqualTo( 3 ) );

              Assert.That( set.GetBuildingsOnRight( 2 ).Contains( 1 ), Is.True );
              Assert.That( set.GetBuildingsOnLeft( 2 ).Contains( 3 ), Is.True );
              Assert.That( set.GetBuildingsAbove( 2 ).Contains( 0 ), Is.True );
              Assert.That( set.GetBuildingsOnRight( 2 ).Count, Is.EqualTo( 1 ) );
              Assert.That( set.GetBuildingsBelow( 2 ).Count, Is.Zero );
              Assert.That( set.GetBuildingsOnLeft( 2 ).Count, Is.EqualTo( 1 ) );
              Assert.That( set.GetBuildingsAbove( 2 ).Count, Is.EqualTo( 1 ) );
              Assert.That( set.CountAround( 2 ), Is.EqualTo( 3 ) );

              Assert.That( set.GetBuildingsOnRight( 3 ).Contains( 0 ), Is.True );
              Assert.That( set.GetBuildingsOnRight( 3 ).Contains( 2 ), Is.True );
              Assert.That( set.GetBuildingsOnRight( 3 ).Contains( 4 ), Is.True );
              Assert.That( set.GetBuildingsOnRight( 3 ).Count, Is.EqualTo( 3 ) );
              Assert.That( set.GetBuildingsBelow( 3 ).Count, Is.Zero );
              Assert.That( set.GetBuildingsOnLeft( 3 ).Count, Is.Zero );
              Assert.That( set.GetBuildingsAbove( 3 ).Count, Is.Zero );
              Assert.That( set.CountAround( 3 ), Is.EqualTo( 3 ) );

              Assert.That( set.GetBuildingsOnRight( 4 ).Contains( 1 ), Is.True );
              Assert.That( set.GetBuildingsBelow( 4 ).Contains( 0 ), Is.True );
              Assert.That( set.GetBuildingsOnLeft( 4 ).Contains( 3 ), Is.True );
              Assert.That( set.GetBuildingsOnRight( 4 ).Count, Is.EqualTo( 1 ) );
              Assert.That( set.GetBuildingsBelow( 4 ).Count, Is.EqualTo( 1 ) );
              Assert.That( set.GetBuildingsOnLeft( 4 ).Count, Is.EqualTo( 1 ) );
              Assert.That( set.GetBuildingsAbove( 4 ).Count, Is.Zero );
              Assert.That( set.CountAround( 4 ), Is.EqualTo( 3 ) );

              Assert.That( set.IsOnStartingOrTargetTile( 0 ), Is.False );
              set.SetValue( 0, 0 );
              Assert.That( set.IsOnStartingOrTargetTile( 0 ), Is.True );
              set.SetValue( 0, 1 );
              Assert.That( set.IsOnStartingOrTargetTile( 0 ), Is.False );
              set.SetValue( 0, 45 );
              Assert.That( set.IsOnStartingOrTargetTile( 0 ), Is.True );
        }
Esempio n. 12
0
 public NumberConstraint(SetVariables <Variable> variables) : base(variables)
 {
 }
Esempio n. 13
0
        public readonly int _value; // Value that this variable must be less than

        public SmallerThan(SetVariables <Variable> variables, int index, int value)
            : base(variables)
        {
            _index = index;
            _value = value;
        }
Esempio n. 14
0
        public void MatrixIndexTests()
        {
            var set = new SetVariables(list, 5, 10, new SetVariables.Point(4, 5), new SetVariables.Point(0, 0));

            set.SetValue(1, 14);

            for (int i = 0; i < 5; ++i)
            {
                for (int j = 0; j < 10; ++j)
                {
                    if ((i == 1 && j == 4)
                        ||
                        (i == 1 && j == 5)
                        ||
                        (i == 1 && j == 6)
                        ||
                        (i == 2 && j == 4)
                        ||
                        (i == 2 && j == 5)
                        ||
                        (i == 2 && j == 6))
                    {
                        var l = set.BuildingsAt(i, j);
                        Assert.AreEqual(1, l.Count);
                        Assert.AreEqual(1, l[0]);
                    }
                    else
                    {
                        var l = set.BuildingsAt(i, j);
                        Assert.AreEqual(0, l.Count);
                    }
                }
            }

            set.ShiftValue(1);

            for (int i = 0; i < 5; ++i)
            {
                for (int j = 0; j < 10; ++j)
                {
                    if ((i == 1 && j == 7)
                        ||
                        (i == 1 && j == 5)
                        ||
                        (i == 1 && j == 6)
                        ||
                        (i == 2 && j == 7)
                        ||
                        (i == 2 && j == 5)
                        ||
                        (i == 2 && j == 6))
                    {
                        var l = set.BuildingsAt(i, j);
                        Assert.AreEqual(1, l.Count);
                        Assert.AreEqual(1, l[0]);
                    }
                    else
                    {
                        var l = set.BuildingsAt(i, j);
                        Assert.AreEqual(0, l.Count);
                    }
                }
            }

            set.UnshiftValue(1);

            for (int i = 0; i < 5; ++i)
            {
                for (int j = 0; j < 10; ++j)
                {
                    if ((i == 1 && j == 4)
                        ||
                        (i == 1 && j == 5)
                        ||
                        (i == 1 && j == 6)
                        ||
                        (i == 2 && j == 4)
                        ||
                        (i == 2 && j == 5)
                        ||
                        (i == 2 && j == 6))
                    {
                        var l = set.BuildingsAt(i, j);
                        Assert.AreEqual(1, l.Count);
                        Assert.AreEqual(1, l[0]);
                    }
                    else
                    {
                        var l = set.BuildingsAt(i, j);
                        Assert.AreEqual(0, l.Count);
                    }
                }
            }

            set.SetValue(1, 27);

            for (int i = 0; i < 5; ++i)
            {
                for (int j = 0; j < 10; ++j)
                {
                    if ((i == 3 && j == 7)
                        ||
                        (i == 3 && j == 8)
                        ||
                        (i == 3 && j == 9)
                        ||
                        (i == 2 && j == 7)
                        ||
                        (i == 2 && j == 8)
                        ||
                        (i == 2 && j == 9))
                    {
                        var l = set.BuildingsAt(i, j);
                        Assert.AreEqual(1, l.Count);
                        Assert.AreEqual(1, l[0]);
                    }
                    else
                    {
                        var l = set.BuildingsAt(i, j);
                        Assert.AreEqual(0, l.Count);
                    }
                }
            }

            set.ShiftValue(1);

            for (int i = 0; i < 5; ++i)
            {
                for (int j = 0; j < 10; ++j)
                {
                    if ((i == 3 && j == 0)
                        ||
                        (i == 3 && j == 1)
                        ||
                        (i == 3 && j == 2)
                        ||
                        (i == 4 && j == 0)
                        ||
                        (i == 4 && j == 1)
                        ||
                        (i == 4 && j == 2))
                    {
                        var l = set.BuildingsAt(i, j);
                        Assert.AreEqual(1, l.Count);
                        Assert.AreEqual(1, l[0]);
                    }
                    else
                    {
                        var l = set.BuildingsAt(i, j);
                        Assert.AreEqual(0, l.Count);
                    }
                }
            }

            set.UnshiftValue(1);

            for (int i = 0; i < 5; ++i)
            {
                for (int j = 0; j < 10; ++j)
                {
                    if ((i == 3 && j == 7)
                        ||
                        (i == 3 && j == 8)
                        ||
                        (i == 3 && j == 9)
                        ||
                        (i == 2 && j == 7)
                        ||
                        (i == 2 && j == 8)
                        ||
                        (i == 2 && j == 9))
                    {
                        var l = set.BuildingsAt(i, j);
                        Assert.AreEqual(1, l.Count);
                        Assert.AreEqual(1, l[0]);
                    }
                    else
                    {
                        var l = set.BuildingsAt(i, j);
                        Assert.AreEqual(0, l.Count);
                    }
                }
            }

            set.ShiftValue(1);
            set.SetValue(2, 22);
            set.SetValue(3, 37);

            int overlaps;
            int unbuild;

            set.Shift(2, out overlaps, out unbuild);
            Assert.AreEqual(-2, overlaps);
            Assert.AreEqual(0, unbuild);

            Assert.IsTrue(set.GetBuildingsAround(2).Contains(1));
            Assert.IsTrue(set.GetBuildingsAround(2).Contains(3));
            Assert.IsTrue(set.GetBuildingsAround(1).Contains(2));
            Assert.IsTrue(set.GetBuildingsAround(3).Contains(2));
            Assert.AreEqual(2, set.GetBuildingsAround(2).Count);
            Assert.AreEqual(1, set.GetBuildingsAround(3).Count);
            Assert.AreEqual(1, set.GetBuildingsAround(1).Count);

            set.Shift(2, out overlaps, out unbuild);
            Assert.AreEqual(2, overlaps);
            Assert.AreEqual(0, unbuild);

            var listSmallBuildings = new List <Variable> {
                new Variable("X", "xxx", 1, 1, 0, 0, 0, 0, Race.Unknown, 0, 0),
                new Variable("X", "xxx", 1, 1, 0, 0, 0, 0, Race.Unknown, 0, 0),
                new Variable("X", "xxx", 1, 1, 0, 0, 0, 0, Race.Unknown, 0, 0),
                new Variable("X", "xxx", 1, 1, 0, 0, 0, 0, Race.Unknown, 0, 0),
                new Variable("X", "xxx", 1, 1, 0, 0, 0, 0, Race.Unknown, 0, 0)
            };

            set = new SetVariables(listSmallBuildings, 5, 10, new SetVariables.Point(4, 5), new SetVariables.Point(0, 0));
            set.SetValue(0, 25);
            set.SetValue(1, 26);
            set.SetValue(2, 35);
            set.SetValue(3, 24);
            set.SetValue(4, 15);

            Assert.IsTrue(set.GetBuildingsOnRight(0).Contains(1));
            Assert.IsTrue(set.GetBuildingsBelow(0).Contains(2));
            Assert.IsTrue(set.GetBuildingsOnLeft(0).Contains(3));
            Assert.IsTrue(set.GetBuildingsAbove(0).Contains(4));
            Assert.AreEqual(1, set.GetBuildingsOnRight(0).Count);
            Assert.AreEqual(1, set.GetBuildingsBelow(0).Count);
            Assert.AreEqual(1, set.GetBuildingsOnLeft(0).Count);
            Assert.AreEqual(1, set.GetBuildingsAbove(0).Count);
            Assert.AreEqual(4, set.CountAround(0));

            Assert.IsTrue(set.GetBuildingsOnLeft(1).Contains(0));
            Assert.IsTrue(set.GetBuildingsOnLeft(1).Contains(2));
            Assert.IsTrue(set.GetBuildingsOnLeft(1).Contains(4));
            Assert.AreEqual(0, set.GetBuildingsOnRight(1).Count);
            Assert.AreEqual(0, set.GetBuildingsBelow(1).Count);
            Assert.AreEqual(3, set.GetBuildingsOnLeft(1).Count);
            Assert.AreEqual(0, set.GetBuildingsAbove(1).Count);
            Assert.AreEqual(3, set.CountAround(1));

            Assert.IsTrue(set.GetBuildingsOnRight(2).Contains(1));
            Assert.IsTrue(set.GetBuildingsOnLeft(2).Contains(3));
            Assert.IsTrue(set.GetBuildingsAbove(2).Contains(0));
            Assert.AreEqual(1, set.GetBuildingsOnRight(2).Count);
            Assert.AreEqual(0, set.GetBuildingsBelow(2).Count);
            Assert.AreEqual(1, set.GetBuildingsOnLeft(2).Count);
            Assert.AreEqual(1, set.GetBuildingsAbove(2).Count);
            Assert.AreEqual(3, set.CountAround(2));

            Assert.IsTrue(set.GetBuildingsOnRight(3).Contains(0));
            Assert.IsTrue(set.GetBuildingsOnRight(3).Contains(2));
            Assert.IsTrue(set.GetBuildingsOnRight(3).Contains(4));
            Assert.AreEqual(3, set.GetBuildingsOnRight(3).Count);
            Assert.AreEqual(0, set.GetBuildingsBelow(3).Count);
            Assert.AreEqual(0, set.GetBuildingsOnLeft(3).Count);
            Assert.AreEqual(0, set.GetBuildingsAbove(3).Count);
            Assert.AreEqual(3, set.CountAround(3));

            Assert.IsTrue(set.GetBuildingsOnRight(4).Contains(1));
            Assert.IsTrue(set.GetBuildingsBelow(4).Contains(0));
            Assert.IsTrue(set.GetBuildingsOnLeft(4).Contains(3));
            Assert.AreEqual(1, set.GetBuildingsOnRight(4).Count);
            Assert.AreEqual(1, set.GetBuildingsBelow(4).Count);
            Assert.AreEqual(1, set.GetBuildingsOnLeft(4).Count);
            Assert.AreEqual(0, set.GetBuildingsAbove(4).Count);
            Assert.AreEqual(3, set.CountAround(4));

            Assert.IsFalse(set.IsOnStartingOrTargetTile(0));
            set.SetValue(0, 0);
            Assert.IsTrue(set.IsOnStartingOrTargetTile(0));
            set.SetValue(0, 1);
            Assert.IsFalse(set.IsOnStartingOrTargetTile(0));
            set.SetValue(0, 45);
            Assert.IsTrue(set.IsOnStartingOrTargetTile(0));

//      set.SetValue( 0, 25 );
//      Assert.IsFalse( set.IsNeighborOfSTTBuildings( 0 ) );
//      set.SetValue( 0, 11 );
//      Assert.IsTrue( set.IsNeighborOfSTTBuildings( 0 ) );
//      set.SetValue( 0, 44 );
//      Assert.IsTrue( set.IsNeighborOfSTTBuildings( 0 ) );
        }
Esempio n. 15
0
        public void DontFitAtTest(int pos)
        {
            var set = new SetVariables(list, 5, 10, new SetVariables.Point(4, 5), new SetVariables.Point(0, 0));

            Assert.IsFalse(set.FitAt(1, pos));
        }
Esempio n. 16
0
        public void FitAtTest(int pos)
        {
            var set = new SetVariables(list, 5, 10, new SetVariables.Point(4, 5), new SetVariables.Point(0, 0));

            Assert.That(set.FitAt(1, pos), Is.True);
        }