public void ForceAddTile(DominoTileEntity tile) { if (head == null && tail == null) { head = tail = tile; return; } if (head == tail && tile.GetUnlinkedValues().Any(x => x == head.FirstValue)) { tile.Link(head); tail = tile; return; } if (head.MatchesUnlinkedValue(tile)) { tile.Link(head); head = tile; return; } if (tail.MatchesUnlinkedValue(tile)) { tail.Link(tile); tail = tile; return; } throw new ApplicationException($"Illegal move. Head nor tail matches '{tile}'"); }
public void Link_TilesOnEachSide_NoUnlinkedValues() { var tileOne = new DominoTileEntity(1, 2); var tileTwo = new DominoTileEntity(2, 3); var tileThree = new DominoTileEntity(1, 4); tileOne.Link(tileTwo); tileOne.Link(tileThree); Assert.Equal(0, tileOne.GetUnlinkedValues().Count()); }
protected void AddTile( PlayerTrain playerTrain, DominoTileEntity tile) { tile.Link(playerTrain.head); playerTrain.head = tile; }
public void Link_DoubleWithTileOnEachSide_CorrectSequence() { var tile1 = new DominoTileEntity(11, 0); var tile2 = new DominoTileEntity(0, 0); var tile3 = new DominoTileEntity(0, 4); tile1.Link(tile2); tile2.Link(tile3); }
public void Link_EngineWithMatching_CorrectLink() { var engine = new DominoTileEntity(12, 12, true); var tile = new DominoTileEntity(12, 11); tile.Link(engine); Assert.Equal(engine, tile.GetLinkedTiles().First()); Assert.Equal("HalfLinkedState", tile.GetStateType().Name); Assert.Equal(1, tile.GetUnlinkedValues().Count()); Assert.Equal(11, tile.GetUnlinkedValues().First()); }
public void Link_WhenHalfLinkedToUnorderedTile_TilesAreFlippedSoValuesAlign() { var engine = new DominoTileEntity(7, 7, isEngine: true); var tileTwo = new DominoTileEntity(2, 7); var tileThree = new DominoTileEntity(9, 2); tileTwo.Link(engine); tileThree.Link(tileTwo); Assert.Equal(7, tileTwo.FirstValue); Assert.Equal(2, tileThree.FirstValue); }
public void Link_OnAlreadyLinkedValue_ThrowsException() { var tileOne = new DominoTileEntity(1, 2); var tileTwo = new DominoTileEntity(2, 3); var tileThree = new DominoTileEntity(2, 4); tileOne.Link(tileTwo); Action linkThreeOnTwo = () => tileTwo.Link(tileThree); Action linkTwoOnThree = () => tileThree.Link(tileTwo); Assert.Equal(1, tileTwo.GetUnlinkedValues().Count()); Assert.Equal(3, tileTwo.GetUnlinkedValues().First()); Assert.Equal("HalfLinkedState", tileTwo.GetStateType().Name); Assert.ThrowsAny <Exception>(linkThreeOnTwo); Assert.ThrowsAny <Exception>(linkTwoOnThree); }
public void Link_ThreeTiles_LinkedRefsAreCorrect() { var engine = new DominoTileEntity(12, 12, true); var tileOne = new DominoTileEntity(12, 11); var tileTwo = new DominoTileEntity(11, 10); tileOne.Link(engine); tileTwo.Link(tileOne); Assert.True(tileOne.IsLinked(engine)); Assert.True(tileTwo.IsLinked(tileOne)); Assert.Equal("FullyLinkedState", tileOne.GetStateType().Name); Assert.Equal("HalfLinkedState", tileTwo.GetStateType().Name); Assert.Equal(1, tileTwo.GetUnlinkedValues().Count()); Assert.Equal(10, tileTwo.GetUnlinkedValues().First()); }
public void Link_TwoMatching_CorrectLink() { var tileOne = new DominoTileEntity(1, 2); var tileTwo = new DominoTileEntity(2, 3); tileTwo.Link(tileOne); Assert.Equal(tileOne, tileTwo.GetLinkedTiles().First()); Assert.Equal("HalfLinkedState", tileTwo.GetStateType().Name); Assert.Equal(1, tileTwo.GetUnlinkedValues().Count()); Assert.Equal(3, tileTwo.GetUnlinkedValues().First()); Assert.Equal(tileTwo, tileOne.GetLinkedTiles().First()); Assert.Equal("HalfLinkedState", tileOne.GetStateType().Name); Assert.Equal(1, tileOne.GetUnlinkedValues().Count()); Assert.Equal(1, tileOne.GetUnlinkedValues().First()); }