Ejemplo n.º 1
0
 /// <summary>
 /// Default constructor of the class,which will define the correct configration of rule factory and neighbourrule factory.
 /// </summary>
 /// <param name="grid">collectiion of cells</param>
 /// <param name="ruleFactory"> Factory to create rule. </param>
 /// <param name="neighbourRule">Factory to create neighbour rule.</param>
 public GameOfLife(ICellCollection grid, IRuleFactory ruleFactory, INeighbourRuleFactory neighbouruleFactory)
 {
     this.generationNumber = 1;
     this.grid = grid;
     this.ruleFactory = ruleFactory;
     this.neighbouruleFactory = neighbouruleFactory;
 }
Ejemplo n.º 2
0
        public bool CalcCellCollection(ICellCollection cellCollection)
        {
            var changed = false;

            for (var i = 0; i < Size - 1; i++)
            {
                var cc = cellCollection.Cells[i];
                if (cc.Value.HasValue)
                {
                    continue;
                }
                var gList = new List <Cell> {
                    cc
                };
                for (var k = i + 1; k < Size; k++)
                {
                    var ck = cellCollection.Cells[k];
                    if (ck.Value.HasValue)
                    {
                        continue;
                    }
                    if (cc.Possibilities.SequenceEqual(ck.Possibilities))
                    {
                        gList.Add(ck);
                    }
                }

                if (gList.Count != cc.Possibilities.Count)
                {
                    break;
                }

                for (var k = i + 1; k < Size; k++)
                {
                    var ck = cellCollection.Cells[k];
                    if (ck.Value.HasValue || gList.Contains(ck))
                    {
                        continue;
                    }
                    cc.Possibilities.ForEach(p => {
                        var ch = ck.Possibilities.Remove(p);
                        if (!changed && ch)
                        {
                            changed = true;
                        }
                        if (ck.Possibilities.Count == 1)
                        {
                            ck.SetValue(ck.Possibilities[0]);
                            ck.Possibilities.Clear();
                        }
                    });
                }
            }

            if (!Changed)
            {
                Changed = changed;
            }
            return(changed);
        }
Ejemplo n.º 3
0
 public Board(ICellCollection cellCollection,
              IGameState gameState,
              IPrinter printer)
 {
     _cellCollection = cellCollection;
     _gameState      = gameState;
     _printer        = printer;
 }
Ejemplo n.º 4
0
 public PossibleWins(ICellCollection cells) : this(
         new TopRightSlashWin(cells),
         new TopLeftSlashWin(cells),
         new RightColumnWin(cells),
         new CenterColumnWin(cells),
         new LeftColumnWin(cells),
         new BottomRowWin(cells),
         new CenterRowWin(cells),
         new TopRowWin(cells))
 {
 }
        public static bool TryGetCellCollection(this IControl control, out ICellCollection cellCollection)
        {
            var selectRange = (SelectionRange)control.FindControl(c => c is SelectionRange);

            if (selectRange != null)
            {
                return(control.MyAskMeAnything.TryGetCellCollection((selectRange).CurrentSelection, out cellCollection));
            }

            cellCollection = null;
            return(false);
        }
Ejemplo n.º 6
0
 public void CalculateCell(ICellCollection cellCollection)
 {
     cellCollection.Cells.ForEach(c => {
         if (c == this)
         {
             return;
         }
         if (c.Value != null)
         {
             Possibilities.Remove(c.Value.Value);
         }
     });
 }
        public void Clone_ShouldClone()
        {
            //Arrange
            ICell expected = Cell0;

            ICell[]        cells   = { expected };
            CellCollection subject = new CellCollection(cells);

            //Act
            ICellCollection actual = subject.Clone();

            //Assert
            ReferenceEquals(subject, actual).Should().BeFalse();
            ReferenceEquals(subject.At(new IntOf(0)), actual.At(new IntOf(0))).Should().BeTrue();
        }
Ejemplo n.º 8
0
        public void AvailableSpaces_ShouldHaveOnlyAvailableCells()
        {
            //Arrange
            FakePrinter   fakePrinter      = new FakePrinter.Builder().Build();
            FakeGameState fakeGameState    = new FakeGameState.Builder().Build();
            FakeCell      fakeCell         = new FakeCell.Builder().IsSelected(Bool.False).Build();
            FakeCell      fakeCellSelected = new FakeCell.Builder().IsSelected(Bool.True).Build();
            Board         subject          = new Board(new CellCollection(new ICell[] { fakeCell, fakeCellSelected }),
                                                       fakeGameState, fakePrinter);

            //Act
            ICellCollection actual = subject.AvailableSpaces();

            //Assert
            ((int)actual.Count()).Should().Be(1);
        }
Ejemplo n.º 9
0
 public RightColumnWin(ICellCollection cells) : base(cells, TopRight, MiddleRight, BottomRight)
 {
 }
Ejemplo n.º 10
0
 public CenterColumnWin(ICellCollection cells) : base(cells, TopCenter, MiddleCenter, BottomCenter)
 {
 }
Ejemplo n.º 11
0
 public LeftColumnWin(ICellCollection cells) : base(cells, TopLeft, MiddleLeft, BottomLeft)
 {
 }
Ejemplo n.º 12
0
 public BottomRowWin(ICellCollection cells) : base(cells, BottomLeft, BottomCenter, BottomRight)
 {
 }
Ejemplo n.º 13
0
 public CenterRowWin(ICellCollection cells) : base(cells, MiddleLeft, MiddleCenter, MiddleRight)
 {
 }
Ejemplo n.º 14
0
 public TopRowWin(ICellCollection cells) : base(cells, TopLeft, TopCenter, TopRight)
 {
 }
 public IndexedCellEquality(ICellCollection cells, Int firstIndex, Int secondIndex)
 {
     _cells       = cells;
     _firstIndex  = firstIndex;
     _secondIndex = secondIndex;
 }
Ejemplo n.º 16
0
 public Cell(ICellCollection neighbours)
 {
     _neighbours = neighbours;
 }
Ejemplo n.º 17
0
 public BoardPrinter(ICellCollection cellBoard) : this(cellBoard, new ConsoleWriterBookEnd())
 {
 }
 public void LoadSheet(ICellCollection c)
 {
     m.Cells = (CellCollection)c;
     //change  view!           
 }
Ejemplo n.º 19
0
 public TopLeftSlashWin(ICellCollection cells) : base(cells, TopLeft, MiddleCenter, BottomRight)
 {
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Right now it is creating predefine object of matrix class, here we can define configurable instance for
 /// given dimension type.
 /// </summary>
 /// <param name="cellCollection"></param>
 /// <returns></returns>
 public INeighbourRule Create(ICellCollection cellCollection)
 {
     return new MatrixNeighbourCellRule((Game)cellCollection);
 }
Ejemplo n.º 21
0
 public BoardPrinter(ICellCollection cellBoard, IWriter writer)
 {
     _cellBoard = cellBoard;
     _writer    = writer;
 }
Ejemplo n.º 22
0
 private Board(ICellCollection cellCollection) : this(
         cellCollection,
         new GameState(cellCollection),
         new BoardPrinter(cellCollection))
 {
 }
Ejemplo n.º 23
0
 public AllCellsSelected(ICellCollection cellCollection) => _cellCollection = cellCollection;
Ejemplo n.º 24
0
 public GameState(ICellCollection cellCollection) : this(
         new PossibleWins(cellCollection),
         new Tie(cellCollection))
 {
 }
Ejemplo n.º 25
0
 public bool TryGetCellCollection(string name, out ICellCollection cellCollection)
 {
     cellCollection = AskRadiant.GetCellCollections().Where(c => c.Name == name).SingleOrDefault();
     return(cellCollection != null);
 }
		public void LoadSheet(ICellCollection c)
		{
			foreach (System.Windows.Forms.Control ctr in mainForm.WorksheetsTabControl.SelectedTab.Controls)
			{
				if (ctr is SpreadsheetUserControl)
				{
					SpreadsheetUserControl ActiveWS = (SpreadsheetUserControl)ctr;
					ActiveWS.Spreadsheet.SpreadsheetModel.Cells = (CellCollection)c;
					//change  view!     
				}
			}
		}
Ejemplo n.º 27
0
 public Tie(ICellCollection cellCollection) => _cellCollection = cellCollection;
Ejemplo n.º 28
0
 protected Win(ICellCollection cells, Int firstIndex, Int secondIndex, Int thirdIndex) :
     this(new IndexedCellEquality(cells, firstIndex, secondIndex), new IndexedCellEquality(cells, firstIndex, thirdIndex))
 {
 }
Ejemplo n.º 29
0
 public TestWin(ICellCollection cells, int firstIndex, int secondIndex, int thirdIndex) : base(cells, new IntOf(firstIndex), new IntOf(secondIndex), new IntOf(thirdIndex))
 {
 }
 public Builder Clone(ICellCollection expected)
 {
     _cloneItem.UpdateInvocation(expected);
     return(this);
 }