Exemple #1
0
        public void GetCells()
        {
            var u = new Unit(new[] {new Cell(0, 0), new Cell(1, 0), new Cell(1, 1)}, new Cell(0, 0));
            var us = new UnitState(new Cell(2, 2), 0);
            var cells = us.GetCells(u);
            Assert.IsTrue(cells.Contains(new Cell(2, 2)));
            Assert.IsTrue(cells.Contains(new Cell(3, 2)));
            Assert.IsTrue(cells.Contains(new Cell(3, 3)));

            us = new UnitState(new Cell(2, 2), 1);
            cells = us.GetCells(u);
            Assert.IsTrue(cells.Contains(new Cell(2, 2)));
            Assert.IsTrue(cells.Contains(new Cell(2, 1)));
            Assert.IsTrue(cells.Contains(new Cell(3, 1)));

            us = new UnitState(new Cell(2, 3), 0);
            cells = us.GetCells(u);
            Assert.IsTrue(cells.Contains(new Cell(2, 3)));
            Assert.IsTrue(cells.Contains(new Cell(3, 3)));
            Assert.IsTrue(cells.Contains(new Cell(4, 4)));

            u = new Unit(new[] { new Cell(0, 1), new Cell(1, 1), new Cell(2, 2) }, new Cell(0, 1));
            us = new UnitState(new Cell(2, 2), 0);
            cells = us.GetCells(u);
            Assert.IsTrue(cells.Contains(new Cell(2, 2)));
            Assert.IsTrue(cells.Contains(new Cell(3, 2)));
            Assert.IsTrue(cells.Contains(new Cell(3, 3)));
        }
Exemple #2
0
        public void Symmetry()
        {
            var unit = new Unit(new Cell[] { new Cell(2, 0), new Cell(0, 0) }, new Cell(1, 0));

            Assert.AreEqual(new Cell(0, 0), unit.GetRotatedCells(0)[0]);
            Assert.AreEqual(new Cell(2, 0), unit.GetRotatedCells(0)[1]);
            Assert.AreEqual(0, unit.GetCanonicalRotation(0));

            Assert.AreEqual(new Cell(1, -1), unit.GetRotatedCells(1)[0]);
            Assert.AreEqual(new Cell(0, 1), unit.GetRotatedCells(1)[1]);
            Assert.AreEqual(1, unit.GetCanonicalRotation(1));

            Assert.AreEqual(new Cell(0, -1), unit.GetRotatedCells(2)[0]);
            Assert.AreEqual(new Cell(1, 1), unit.GetRotatedCells(2)[1]);
            Assert.AreEqual(2, unit.GetCanonicalRotation(2));

            Assert.AreEqual(new Cell(0, 0), unit.GetRotatedCells(3)[0]);
            Assert.AreEqual(new Cell(2, 0), unit.GetRotatedCells(3)[1]);
            Assert.AreEqual(0, unit.GetCanonicalRotation(3));

            Assert.AreEqual(new Cell(1, -1), unit.GetRotatedCells(4)[0]);
            Assert.AreEqual(new Cell(0, 1), unit.GetRotatedCells(4)[1]);
            Assert.AreEqual(1, unit.GetCanonicalRotation(4));

            Assert.AreEqual(new Cell(0, -1), unit.GetRotatedCells(5)[0]);
            Assert.AreEqual(new Cell(1, 1), unit.GetRotatedCells(5)[1]);
            Assert.AreEqual(2, unit.GetCanonicalRotation(5));
        }
Exemple #3
0
        public void TestSpawnUnit()
        {
            var f = new Field(100, 5);
            var u = new Unit(new[] { new Cell(0, 0) }, new Cell(0, 0));
            Assert.AreEqual(new Cell(2, 0), f.SpawnUnit(u).Pivot);

            u = new Unit(new[] { new Cell(0, 0), new Cell(0, 1) }, new Cell(0, 0));
            Assert.AreEqual(new Cell(2, 0), f.SpawnUnit(u).Pivot);

            u = new Unit(new[] { new Cell(2, 2), new Cell(4, 3) }, new Cell(3, 4));
            Assert.AreEqual(new Cell(2, 2), f.SpawnUnit(u).Pivot);

            u = new Unit(new[] { new Cell(1, 1), new Cell(4, 2) }, new Cell(2, 3));
            Assert.AreEqual(new Cell(2, 2), f.SpawnUnit(u).Pivot);

            u = new Unit(new[] { new Cell(1, 1), new Cell(4, 2) }, new Cell(2, 2));
            Assert.AreEqual(new Cell(1, 1), f.SpawnUnit(u).Pivot);

            u = new Unit(new[] { new Cell(1, 3), new Cell(2, 1) }, new Cell(3, 3));
            Assert.AreEqual(new Cell(3, 2), f.SpawnUnit(u).Pivot);

            f = new Field(100, 4, new Cell(3, 0));
            u = new Unit(new[] { new Cell(1, 3), new Cell(2, 1) }, new Cell(3, 3));
            Assert.AreEqual(new Cell(3, 2), f.SpawnUnit(u).Pivot);

            u = new Unit(new[] { new Cell(1, 1), new Cell(2, 4) }, new Cell(2, 2));
            Assert.AreEqual(new Cell(1, 1), f.SpawnUnit(u).Pivot);

            u = new Unit(new[] { new Cell(0, 2), new Cell(3, 2) }, new Cell(2, 2));
            Assert.IsNull(f.SpawnUnit(u));
        }
Exemple #4
0
 public void MoveW()
 {
     var unit = new Unit(new[] { new Cell(10, 0), new Cell(11, 0) }, new Cell(12, 0));
     var unitState = new UnitState(unit.pivot, 0);
     unitState = UnitState.MoveW(unitState);
     var cells = unitState.GetCells(unit);
     Assert.IsTrue(cells.Contains(new Cell(9, 0)));
     Assert.IsTrue(cells.Contains(new Cell(10, 0)));
 }
Exemple #5
0
 public void MoveE()
 {
     var unit = new Unit(new[] { new Cell(10, 0), new Cell(11, 1) }, new Cell(12, 2));
     var unitState = new UnitState(unit.pivot, 0);
     unitState = UnitState.MoveE(unitState);
     var cells = unitState.GetCells(unit);
     Assert.IsTrue(cells.Contains(new Cell(11, 0)));
     Assert.IsTrue(cells.Contains(new Cell(12, 1)));
     Assert.AreEqual(new Cell(13, 2), unitState.Pivot);
 }
Exemple #6
0
 public void MoveSW()
 {
     var unit = new Unit(new[] { new Cell(10, 4), new Cell(11, 5) }, new Cell(12, 6));
     var unitState = new UnitState(unit.pivot, 0);
     unitState = UnitState.MoveSW(unitState);
     var cells = unitState.GetCells(unit);
     Assert.AreEqual(2, cells.Length);
     Assert.IsTrue(cells.Contains(new Cell(9, 5)));
     Assert.IsTrue(cells.Contains(new Cell(11, 6)));
     Assert.AreEqual(new Cell(11, 7), unitState.Pivot);
 }
Exemple #7
0
 public void SingleZero()
 {
     var unit = new Unit(new Cell[] { new Cell(0, 0) }, new Cell(0, 0));
     for (int rotation = 0; rotation < 6; ++rotation)
     {
         Cell[] cells = unit.GetRotatedCells(rotation);
         Assert.AreEqual(1, cells.Length);
         Assert.AreEqual(cells[0], new Cell(0, 0));
         Assert.AreEqual(0, unit.GetCanonicalRotation(rotation));
     }
 }
Exemple #8
0
        public void SingleShiftedPivot()
        {
            var unit = new Unit(new Cell[] { new Cell(1, 5) }, new Cell(4, 5));
            for (int rotation = 0; rotation < 6; ++rotation)
            {
                Cell[] cells = unit.GetRotatedCells(rotation);
                Assert.AreEqual(1, cells.Length);
                Assert.AreEqual(rotation, unit.GetCanonicalRotation(rotation));
            }

            Assert.AreEqual(unit.GetRotatedCells(0)[0], new Cell(1, 5));
            Assert.AreEqual(unit.GetRotatedCells(1)[0], new Cell(3, 8));
            Assert.AreEqual(unit.GetRotatedCells(2)[0], new Cell(6, 8));
            Assert.AreEqual(unit.GetRotatedCells(3)[0], new Cell(7, 5));
            Assert.AreEqual(unit.GetRotatedCells(4)[0], new Cell(6, 2));
            Assert.AreEqual(unit.GetRotatedCells(5)[0], new Cell(3, 2));
        }
Exemple #9
0
        public void TestConstructor()
        {
            var f = new Field(3, 3, new Cell(0, 1), new Cell(2, 1));
            var us = new UnitState(new Cell(0, 0), 0);
            var u = new Unit(new[] {new Cell(0, 0)}, new Cell(0, 0));

            var bfss = new BestStateInfo(f, u, new BfsState(us, new Cell(0, 2)));
            Assert.AreEqual(0, bfss.KilledRows);
            Assert.AreEqual(5, bfss.JoinedCellsCount);
            Assert.AreEqual(0, bfss.NewHolesCount);

            bfss = new BestStateInfo(f, u, new BfsState(us, new Cell(1, 1)));
            Assert.AreEqual(1, bfss.KilledRows);
            Assert.AreEqual(2, bfss.JoinedCellsCount);
            Assert.AreEqual(1, bfss.NewHolesCount);

            bfss = new BestStateInfo(f, u, new BfsState(us, new Cell(1, 1), new Cell(0, 2), new Cell(1, 2), new Cell(2, 2)));
            Assert.AreEqual(2, bfss.KilledRows);
            Assert.AreEqual(9, bfss.JoinedCellsCount);
            Assert.AreEqual(0, bfss.NewHolesCount);

            bfss = new BestStateInfo(f, u, new BfsState(us,  new Cell(1, 2)));
            Assert.AreEqual(0, bfss.KilledRows);
            Assert.AreEqual(3, bfss.JoinedCellsCount);
            Assert.AreEqual(1, bfss.NewHolesCount);

            bfss = new BestStateInfo(f, u, new BfsState(us, new Cell(0, 0), new Cell(1, 0), new Cell(1, 1), new Cell(1, 2)));
            Assert.AreEqual(1, bfss.KilledRows);
            Assert.AreEqual(6, bfss.JoinedCellsCount);
            Assert.AreEqual(2, bfss.NewHolesCount);

            f = new Field(3, 3, new Cell(0, 1));
            bfss = new BestStateInfo(f, u, new BfsState(us, new Cell(1, 2), new Cell(1, 1), new Cell(2, 0)));
            Assert.AreEqual(0, bfss.KilledRows);
            Assert.AreEqual(4, bfss.JoinedCellsCount);
            Assert.AreEqual(2, bfss.NewHolesCount);

            f = new Field(4, 4, new Cell(0, 3), new Cell(1, 3), new Cell(2, 3));
            bfss = new BestStateInfo(f, u, new BfsState(us, new Cell(0, 0), new Cell(0, 1), new Cell(1, 1), new Cell(0, 2), new Cell(2, 2)));
            Assert.AreEqual(0, bfss.KilledRows);
            Assert.AreEqual(7, bfss.JoinedCellsCount);
            Assert.AreEqual(1, bfss.NewHolesCount);
        }
Exemple #10
0
        public void TurnClockwise()
        {
            var unit = new Unit(new[] { new Cell(3, 0) }, new Cell(2, 3));
            var unitState = new UnitState(unit.pivot, 0);
            unitState = UnitState.TurnClockwise(unitState);
            Assert.AreEqual(new Cell(2, 3), unitState.Pivot);
            Assert.AreEqual(new Cell(5, 2), unitState.GetCells(unit)[0]);
            unitState = UnitState.TurnClockwise(unitState);
            Assert.AreEqual(new Cell(4, 5), unitState.GetCells(unit)[0]);
            unitState = UnitState.TurnClockwise(unitState);
            Assert.AreEqual(new Cell(2, 6), unitState.GetCells(unit)[0]);
            unitState = UnitState.TurnClockwise(unitState);
            Assert.AreEqual(new Cell(0, 4), unitState.GetCells(unit)[0]);
            unitState = UnitState.TurnClockwise(unitState);
            Assert.AreEqual(new Cell(0, 1), unitState.GetCells(unit)[0]);

            unit = new Unit(new[] { new Cell(0, 2), new Cell(4, 2) }, new Cell(2, 2));
            unitState = new UnitState(unit.pivot, 0);
            unitState = UnitState.TurnClockwise(unitState);
            var cells = unitState.GetCells(unit);
            Assert.AreEqual(2, cells.Length);
            Assert.IsTrue(cells.Contains(new Cell(1, 0)));
            Assert.IsTrue(cells.Contains(new Cell(3, 4)));
            unitState = UnitState.TurnClockwise(unitState);
            cells = unitState.GetCells(unit);
            Assert.IsTrue(cells.Contains(new Cell(3, 0)));
            Assert.IsTrue(cells.Contains(new Cell(1, 4)));
        }
Exemple #11
0
        public void TurnCounter()
        {
            var unit = new Unit(new[] { new Cell(3, 0) }, new Cell(2, 3));
            var unitState = new UnitState(unit.pivot, 0);
            unitState = UnitState.TurnCounter(unitState);
            var cells = unitState.GetCells(unit);
            Assert.AreEqual(3, unitState.Pivot.y);
            Assert.AreEqual(2, unitState.Pivot.x);
            Assert.AreEqual(1, cells[0].y);
            Assert.AreEqual(0, cells[0].x);
            unitState = UnitState.TurnCounter(unitState);
            Assert.AreEqual(new Cell(0, 4), unitState.GetCells(unit)[0]);
            unitState = UnitState.TurnCounter(unitState);
            Assert.AreEqual(new Cell(2, 6), unitState.GetCells(unit)[0]);
            unitState = UnitState.TurnCounter(unitState);
            Assert.AreEqual(new Cell(4, 5), unitState.GetCells(unit)[0]);
            unitState = UnitState.TurnCounter(unitState);
            Assert.AreEqual(new Cell(5, 2), unitState.GetCells(unit)[0]);

            unit = new Unit(new[] { new Cell(0, 2), new Cell(4, 2) }, new Cell(2, 2));
            unitState = new UnitState(unit.pivot, 0);
            unitState = UnitState.TurnCounter(unitState);
            cells = unitState.GetCells(unit);
            Assert.IsTrue(cells.Contains(new Cell(1, 4)));
            Assert.IsTrue(cells.Contains(new Cell(3, 0)));
            unitState = UnitState.TurnCounter(unitState);
            cells = unitState.GetCells(unit);
            Assert.IsTrue(cells.Contains(new Cell(3, 4)));
            Assert.IsTrue(cells.Contains(new Cell(1, 0)));
        }
Exemple #12
0
        public void TestUpdate()
        {
            var f = new Field(2, 2);
            var u = new Unit(new[] {new Cell(0, 0)}, new Cell(0, 0));
            var us = new UnitState(new Cell(1, 1), 0);
            Assert.AreEqual(2, f.MinFilledRow);
            f.Update(u, us);
            Assert.AreEqual(true, f[1][1]);
            Assert.AreEqual(false, f[1][0]);
            Assert.AreEqual(1, f.MinFilledRow);
            Assert.IsTrue(f.RowCells(1).Contains(1));
            Assert.IsFalse(f.RowCells(1).Contains(0));
            Assert.AreEqual(f.RowCells(1).Count, 1);
            Assert.IsFalse(f.RowCells(0).Contains(0));
            Assert.IsFalse(f.RowCells(0).Contains(1));
            Assert.AreEqual(f.RowCells(0).Count, 0);
            Assert.AreEqual(1, f.Score);

            u = new Unit(new[] { new Cell(0, 0), new Cell(1, 0), new Cell(0, 1) }, new Cell(0, 0));
            us = new UnitState(new Cell(0, 0), 0);
            f.Update(u, us);
            Assert.AreEqual(false, f[0][0]);
            Assert.AreEqual(false, f[0][1]);
            Assert.AreEqual(false, f[1][0]);
            Assert.AreEqual(false, f[1][1]);
            Assert.AreEqual(2, f.MinFilledRow);
            Assert.IsFalse(f.RowCells(1).Contains(1));
            Assert.IsFalse(f.RowCells(1).Contains(0));
            Assert.IsFalse(f.RowCells(0).Contains(0));
            Assert.IsFalse(f.RowCells(0).Contains(1));
            Assert.AreEqual(304, f.Score);

            u = new Unit(new[] { new Cell(0, 0), new Cell(1, 0), new Cell(0, 1), new Cell(1, 1) }, new Cell(0, 0));
            us = new UnitState(new Cell(0, 0), 0);
            f.Update(u, us);
            Assert.AreEqual(false, f[0][0]);
            Assert.AreEqual(false, f[0][1]);
            Assert.AreEqual(false, f[1][0]);
            Assert.AreEqual(false, f[1][1]);
            Assert.AreEqual(2, f.MinFilledRow);
            Assert.IsFalse(f.RowCells(1).Contains(1));
            Assert.IsFalse(f.RowCells(1).Contains(0));
            Assert.IsFalse(f.RowCells(0).Contains(0));
            Assert.IsFalse(f.RowCells(0).Contains(1));
            Assert.AreEqual(638, f.Score);

            u = new Unit(new[] {new Cell(1, 0), new Cell(0, 1), new Cell(1, 1) }, new Cell(0, 0));
            us = new UnitState(new Cell(0, 0), 0);
            f.Update(u, us);
            Assert.AreEqual(false, f[0][0]);
            Assert.AreEqual(false, f[0][1]);
            Assert.AreEqual(false, f[1][0]);
            Assert.AreEqual(true, f[1][1]);
            Assert.AreEqual(1, f.MinFilledRow);
            Assert.IsTrue(f.RowCells(1).Contains(1));
            Assert.IsFalse(f.RowCells(1).Contains(0));
            Assert.IsFalse(f.RowCells(0).Contains(0));
            Assert.IsFalse(f.RowCells(0).Contains(1));
            Assert.AreEqual(751, f.Score);

            u = new Unit(new[] { new Cell(0, 0), new Cell(1, 0) }, new Cell(0, 0));
            us = new UnitState(new Cell(0, 0), 0);
            f.Update(u, us);
            Assert.AreEqual(false, f[0][0]);
            Assert.AreEqual(false, f[0][1]);
            Assert.AreEqual(false, f[1][0]);
            Assert.AreEqual(true, f[1][1]);
            Assert.AreEqual(1, f.MinFilledRow);
            Assert.IsTrue(f.RowCells(1).Contains(1));
            Assert.IsFalse(f.RowCells(1).Contains(0));
            Assert.IsFalse(f.RowCells(0).Contains(0));
            Assert.IsFalse(f.RowCells(0).Contains(1));
            Assert.AreEqual(853, f.Score);

            Assert.AreEqual(13, f.TotalBricks);
            Assert.AreEqual(2, f.RowsKilled[1]);
            Assert.AreEqual(2, f.RowsKilled[2]);
        }