public void TestIsDuplicateOrSubsetOf() { var tc1 = new TileConnection(new List<Tile>() { new Tile(new Column(1), 1), new Tile(new Column(2), 1), new Tile(new Column(3), 1), new Tile(new Column(4), 1), }); var tc2 = new TileConnection(new List<Tile>() { new Tile(new Column(0), 1), new Tile(new Column(1), 1), new Tile(new Column(2), 1), new Tile(new Column(3), 1), new Tile(new Column(4), 1), new Tile(new Column(5), 1), new Tile(new Column(6), 1) }); Assert.IsTrue(tc1.IsDuplicateOrSubsetOf(tc2)); Assert.IsTrue(!tc2.IsDuplicateOrSubsetOf(tc1)); tc1 = new TileConnection(new List<Tile>() { new Tile(new Column(1), 1), new Tile(new Column(2), 1), new Tile(new Column(3), 1), new Tile(new Column(4), 1), }); tc2 = new TileConnection(new List<Tile>() { new Tile(new Column(1), 1), new Tile(new Column(2), 1), new Tile(new Column(3), 1), new Tile(new Column(4), 1), }); Assert.IsTrue(tc1.IsDuplicateOrSubsetOf(tc2)); Assert.IsTrue(tc2.IsDuplicateOrSubsetOf(tc1)); tc1 = new TileConnection(new List<Tile>() { new Tile(new Column(0), 1), new Tile(new Column(1), 1), new Tile(new Column(2), 1), new Tile(new Column(3), 1), new Tile(new Column(4), 1), }); tc2 = new TileConnection(new List<Tile>() { new Tile(new Column(1), 1), new Tile(new Column(2), 1), new Tile(new Column(3), 1), new Tile(new Column(4), 1), new Tile(new Column(5), 1), }); Assert.IsTrue(!tc1.IsDuplicateOrSubsetOf(tc2)); Assert.IsTrue(!tc2.IsDuplicateOrSubsetOf(tc1)); }
public bool IsDuplicateOrSubsetOf(TileConnection tc) { if (_tiles.Count == 0) { return(true); } //check the if the first and last tile are within the given tc. If so we are the same //or a subset return(tc.Tiles.Contains(_tiles[0]) && tc.Tiles.Contains(_tiles[_tiles.Count - 1])); }
public void GetWinnableConnectionAround_OnEdge() { object player1 = new object(); object player2 = new object(); var tc = new TileConnection(new List<Tile>() { new Tile(new Column(0), 1, player1), new Tile(new Column(1), 1, player1), new Tile(new Column(2), 1), new Tile(new Column(3), 1), new Tile(new Column(4), 1), new Tile(new Column(5), 1), new Tile(new Column(6), 1) }); var winnable = tc.GetWinnableConnectionAround(tc.Tiles[0]); //4,1 + is out since it's too far away Assert.AreEqual(4, winnable.Tiles.Count); Assert.AreEqual("[0,1] - [3,1]", winnable.ToString()); }
public void GetWinnableConnectionAround_Simple() { object player1 = new object(); object player2 = new object(); var tc = new TileConnection(new List<Tile>() { new Tile(new Column(0), 1, player2), new Tile(new Column(1), 1), new Tile(new Column(2), 1, player1), new Tile(new Column(3), 1), new Tile(new Column(4), 1), new Tile(new Column(5), 1), new Tile(new Column(6), 1) }); var winnable = tc.GetWinnableConnectionAround(tc.Tiles[2]); //0,1 is out since it's the wrong player //6,1 is out since it's too far away Assert.AreEqual(5, winnable.Tiles.Count); Assert.AreEqual("[1,1] - [5,1]", winnable.ToString()); }
public void TestWillTokenPlacedWinGameForPlayer_TileInCentre() { var player = new Object(); var tiles = new List<Tile>(); tiles.Add(new Tile(new Column(0), 0, null)); tiles.Add(new Tile(new Column(1), 0, null)); tiles.Add(new Tile(new Column(2), 0, player)); tiles.Add(new Tile(new Column(3), 0, null)); tiles.Add(new Tile(new Column(4), 0, player)); tiles.Add(new Tile(new Column(5), 0, player)); tiles.Add(new Tile(new Column(6), 0, null)); var tileConnection = new TileConnection(tiles); Assert.IsTrue(tileConnection.WillTokenPlacedWinGameForPlayer(player, tileConnection[3])); Assert.IsFalse(tileConnection.WillTokenPlacedWinGameForPlayer(player, tileConnection[0])); Assert.IsFalse(tileConnection.WillTokenPlacedWinGameForPlayer(player, tileConnection[1])); Assert.IsFalse(tileConnection.WillTokenPlacedWinGameForPlayer(player, tileConnection[6])); Assert.IsTrue(tileConnection.HasImmediatlyWinnableConnectionForPlayer(player)); }
public void TestToString() { var tc = new TileConnection(new List<Tile>() { new Tile(new Column(0), 1), new Tile(new Column(1), 2), new Tile(new Column(2), 3) }); Assert.AreEqual("[0,1] - [2,3]", tc.ToString()); tc = new TileConnection(new List<Tile>() { new Tile(new Column(2), 1), new Tile(new Column(2), 2), new Tile(new Column(2), 3) }); Assert.AreEqual("[2,1] - [2,3]", tc.ToString()); tc = new TileConnection(new List<Tile>() { new Tile(new Column(2), 1) }); Assert.AreEqual("[2,1] - [2,1]", tc.ToString()); }
public bool IsDuplicateOrSubsetOf(TileConnection tc) { if (_tiles.Count == 0) { return true; } //check the if the first and last tile are within the given tc. If so we are the same //or a subset return (tc.Tiles.Contains(_tiles[0]) && tc.Tiles.Contains(_tiles[_tiles.Count - 1])); }