public GameBoard GetBoard() => new GameBoard( Players .ToDictionary( p => p.Id, p => p.Name), Players .Select(p => p.Train) .ToDictionary( t => t.Id, t => new Tuple <Type, IEnumerable <DominoTileEntity> >(t.GetStateType(), t.GetTiles())), new KeyValuePair <Guid, IEnumerable <DominoTileEntity> >( MexicanTrain.Id, MexicanTrain.GetTiles()), Enumerable.Empty <DominoTileEntity>(), Players .ToDictionary( p => p.Id, p => p.Train.Id), Players .FirstOrDefault(p => p .GetStateType() .Name .Equals("HasTurnPlayerState", StringComparison.Ordinal)) ?.Id ?? Guid.Empty, GetStateType(), Id);
public void SetUpAllTests() { playerOne = new Hand(); playerOneTrain = new PlayerTrain(playerOne, 12); mexiTrain = new MexicanTrain(12); mustFlip = false; }
static void Main(string[] args) { List <Domino> dominos = new List <Domino>(); dominos.Add(new Domino(1, 1)); dominos.Add(new Domino(3, 4)); dominos.Add(new Domino(2, 2)); dominos.Add(new Domino(5, 6)); dominos.Add(new Domino(0, 1)); dominos.Sort(); Console.WriteLine("Testing IComparable, dominos should be sorted."); foreach (Domino d in dominos) { Console.WriteLine(d.Score); } Console.WriteLine("Testing IEnumerable, dominos should be sorted."); Train mt = new MexicanTrain(4); Hand h = new Hand(); h.AddDomino(new Domino(1, 2)); h.AddDomino(new Domino(1, 4)); h.AddDomino(new Domino(1, 4)); h.AddDomino(new Domino(6, 1)); h.AddDomino(new Domino(4, 6)); mt.Play(h, h.Discard(h.NumDominos - 1)); mt.Play(h, h.Discard(h.NumDominos - 1)); mt.Play(h, h.Discard(h.NumDominos - 1)); mt.Play(h, h.Discard(h.NumDominos - 1)); mt.Play(h, h.Discard(h.NumDominos - 1)); foreach (Domino d in mt) { Console.WriteLine(d.ToString()); } }
private static void TestSortTrain() { Console.WriteLine("Test MexicanTrain Sort()"); Console.WriteLine(); Random rndGen = new Random(); int engVal = rndGen.Next(1, 7); MexicanTrain test = new MexicanTrain(engVal); const int MAXDOTS = 6; BoneYard b = new BoneYard(MAXDOTS); b.Shuffle(); const int LOOPS = 10; for (int i = 0; i < LOOPS; i++) { test.Add(b.Draw()); } Console.WriteLine("Before sort: \n" + test.ToString()); Console.WriteLine(); test.Sort(); Console.WriteLine("After sort: \n" + test.ToString()); Console.WriteLine(); }
private static void TestForeach() { Console.WriteLine("Test Foreach"); Console.WriteLine(); Random rndGen = new Random(); int engVal = rndGen.Next(1, 7); MexicanTrain test = new MexicanTrain(engVal); const int MAXDOTS = 6; BoneYard b = new BoneYard(MAXDOTS); b.Shuffle(); const int LOOPS = 10; for (int i = 0; i < LOOPS; i++) { test.Add(b.Draw()); } Console.WriteLine("Foreach:"); Console.WriteLine(); foreach (Domino d in test) { Console.WriteLine(d.ToString()); } }
public void AddTile_ThreeTiles_FourTilesIncludingEngineExists() { var engine = new DominoTileEntity(12, 12, true); var game = new GameEntity( Guid.NewGuid(), Enumerable.Empty <PlayerEntity>(), MexicanTrain.Create(), engine, new Stack <DominoTileEntity>()); Games.Add(game.Id, game); var playerId = Guid.NewGuid(); var sut = new PlayerTrain(engine, playerId); var tileOne = new DominoTileEntity(12, 11); var tileTwo = new DominoTileEntity(11, 10); var tileThree = new DominoTileEntity(10, 9); sut.Open(); sut.AddTile(tileOne, playerId); sut.AddTile(tileTwo, playerId); sut.AddTile(tileThree, playerId); Assert.Equal(tileThree, sut.GetTiles().First()); Assert.True(sut.GetTiles().First().IsLinked(tileTwo)); Assert.True(sut.GetTiles().Skip(1).First().IsLinked(tileOne)); Assert.True(sut.GetTiles().Skip(2).First().IsLinked(engine)); Assert.Equal(4, sut.GetTiles().Count()); }
public void AddTileNonMatchingTile_WhenOpen_ExceptionThrown() { var engine = new DominoTileEntity(12, 12, true); var game = new GameEntity( Guid.NewGuid(), Enumerable.Empty <PlayerEntity>(), MexicanTrain.Create(), engine, new Stack <DominoTileEntity>()); Games.Add(game.Id, game); var playerId = Guid.NewGuid(); var sut = new PlayerTrain(engine, playerId); var tileOne = new DominoTileEntity(12, 11); var tileTwo = new DominoTileEntity(11, 10); var tileThree = new DominoTileEntity(11, 3); sut.AddTile(tileOne, playerId); sut.Open(); sut.AddTile(tileTwo, playerId); Action addTile = () => sut.AddTile(tileThree, playerId); Assert.ThrowsAny <Exception>(addTile); }
public void ToString_ThreeTilesAddes_AlignedTiles() { var engine = new DominoTileEntity(12, 12, true); var game = new GameEntity( Guid.NewGuid(), Enumerable.Empty <PlayerEntity>(), MexicanTrain.Create(), engine, new Stack <DominoTileEntity>()); Games.Add(game.Id, game); var playerId = Guid.NewGuid(); var sut = new PlayerTrain(engine, playerId); var tileOne = new DominoTileEntity(11, 12); var tileTwo = new DominoTileEntity(10, 11); sut.Open(); sut.AddTile(tileOne, playerId); sut.AddTile(tileTwo, playerId); var result = sut.ToString(); Assert.Equal("[12|12], [12|11], [11|10]", result); }
public void GetTiles_ThreeTilesInTrain_CorrectTilesReceived() { var engine = new DominoTileEntity(12, 12, true); var game = new GameEntity( Guid.NewGuid(), Enumerable.Empty <PlayerEntity>(), MexicanTrain.Create(), engine, new Stack <DominoTileEntity>()); Games.Add(game.Id, game); var playerId = Guid.NewGuid(); var sut = new PlayerTrain(engine, playerId); var tileOne = new DominoTileEntity(12, 11); var tileTwo = new DominoTileEntity(11, 10); sut.Open(); sut.AddTile(tileOne, playerId); sut.AddTile(tileTwo, playerId); var result = sut.GetTiles(); Assert.Equal(tileTwo, result.First()); Assert.Equal(tileOne, result.Skip(1).First()); Assert.Equal(engine, result.Skip(2).First()); }
public void TestConstructors() { Assert.AreEqual(7, mexicanTrain.EngineValue); MexicanTrain newTrain = new MexicanTrain(4); Assert.AreEqual(4, newTrain.EngineValue); }
public void TestCount() { Assert.AreEqual(0, mexicanTrain.Count); MexicanTrain newTrain = new MexicanTrain(8); Assert.AreEqual(0, newTrain.Count); }
public void TestIsEmpty() { Assert.True(mexicanTrain.IsEmpty); MexicanTrain newTrain = new MexicanTrain(7); Assert.True(newTrain.IsEmpty); }
internal DominoTileEntity GetPlayedTile(long tileId) => Players .SelectMany(p => p .Train .GetTiles()) .Union(MexicanTrain .GetTiles()) .First(t => t.Id == tileId);
public void TestPlayableValue() { MexicanTrain a = new MexicanTrain(6); Assert.IsTrue(a.PlayableValue == 6); a.Add(new Domino(3, 3)); Assert.IsTrue(a.PlayableValue == 3); }
public void SetUpAllTests() { def = new MexicanTrain(); overloaded = new MexicanTrain(1); defBoneYard = new BoneYard(); overloadedBoneYard = new BoneYard(13); defHand = new Hand(); }
public void SetUpAllTests() { d00 = new Domino(); d22 = new Domino(2, 2); d27 = new Domino(2, 7); hand = new Hand(); mexicanTrain = new MexicanTrain(7); }
public void TestEngineValue() { MexicanTrain a = new MexicanTrain(6); PlayerTrain b = new PlayerTrain(hand1, 5); Assert.True(a.EngineValue == 6); Assert.True(b.EngineValue == 5); }
public void AddTile_FirstTileInTrain_CorrectTileExists() { var sut = MexicanTrain.Create(); var tile = new DominoTileEntity(1, 2); sut.AddTile(tile, Guid.NewGuid()); Assert.Equal(1, sut.GetTiles().Count()); }
public void SetUpAllTests() { mT = new MexicanTrain(); mT1 = new MexicanTrain(12); d = new Domino(10, 10); d1 = new Domino(5, 5); d3 = new Domino(12, 12); d4 = new Domino(12, 0); }
public void OverloadedConstructor() { // Tests the constructor, it should change the engine // value to three, not add three dominos to the train MexicanTrain m = new MexicanTrain(3); Assert.AreEqual(m.EngineValue, 3); Assert.AreNotEqual(m.EngineValue, 10); }
public void SetUpAllTests() { hand1 = new Hand(); hand2 = new Hand(); aMexicanTrain = new MexicanTrain(); aPlayerTrain = new PlayerTrain(hand1); anotherPlayerTrain = new PlayerTrain(hand2); reallyBigHand = new BoneYard(6); }
public void AddTile_MissmatchingTile_ThrowsException() { var sut = MexicanTrain.Create(); var tile1 = new DominoTileEntity(1, 2); var tile2 = new DominoTileEntity(4, 5); sut.AddTile(tile1, Guid.NewGuid()); Action action = () => sut.AddTile(tile2, Guid.NewGuid()); Assert.Throws <ApplicationException>(action); }
public void AddTile_OpeningAndClosingDouble_CorrectTilesOnTrain() { var sut = MexicanTrain.Create(); var tile1 = new DominoTileEntity(11, 0); var tile2 = new DominoTileEntity(0, 0); var tile3 = new DominoTileEntity(0, 4); sut.AddTile(tile1, Guid.NewGuid()); sut.AddTile(tile2, Guid.NewGuid()); sut.AddTile(tile3, Guid.NewGuid()); }
public void ToString_MatchesOnLeftButUnaligned_AlignedAsMatchingTiles() { var sut = MexicanTrain.Create(); var tile1 = new DominoTileEntity(2, 1); var tile2 = new DominoTileEntity(2, 10); sut.AddTile(tile1, Guid.NewGuid()); sut.AddTile(tile2, Guid.NewGuid()); Assert.Equal("[10|2], [2|1]", sut.ToString()); }
public void TestConstructor() { MexicanTrain engVal3 = new MexicanTrain(3); Assert.AreEqual(12, mexiTrain.EngineValue); Assert.AreEqual(3, engVal3.EngineValue); Assert.AreEqual(mexiTrain.EngineValue, playerOneTrain.EngineValue); Assert.AreNotEqual(mexiTrain.EngineValue, engVal3.EngineValue); }
public void SetUpAllTests() { mtEmpty = new MexicanTrain(0); mt = new MexicanTrain(0); h = new Hand(); d01 = new Domino(0, 1); d11 = new Domino(1, 1); mt.Add(d01); h.Add(d11); }
public void TestPlay() { MexicanTrain a = new MexicanTrain(4); hand1.Add(new Domino(4, 5)); a.Play(hand1, hand1[0]); Assert.True(a.EngineValue == 4); Assert.True(a[0].Side1 == 4); Assert.True(a[0].Side2 == 5); a.Play(hand1, hand1[0]); Assert.True(a[1].Side1 == 5); Assert.True(a[0].Side2 == 4); }
public void ToString_ThreeMatchingNonAlignedTiles_AlignedAsMatchingTiles() { var sut = MexicanTrain.Create(); var tile1 = new DominoTileEntity(2, 1); var tile2 = new DominoTileEntity(3, 2); var tile3 = new DominoTileEntity(3, 4); sut.AddTile(tile1, Guid.NewGuid()); sut.AddTile(tile2, Guid.NewGuid()); sut.AddTile(tile3, Guid.NewGuid()); Assert.Equal("[4|3], [3|2], [2|1]", sut.ToString()); }
public void ToString_ThreeMatchingNonAlignedTilesFromBothSides_AlignedAsMatchingTiles() { var sut = MexicanTrain.Create(); var tile1 = new DominoTileEntity(1, 2); var tile2 = new DominoTileEntity(2, 3); var tile3 = new DominoTileEntity(1, 11); sut.AddTile(tile1, Guid.NewGuid()); sut.AddTile(tile2, Guid.NewGuid()); sut.AddTile(tile3, Guid.NewGuid()); Assert.Equal("[11|1], [1|2], [2|3]", sut.ToString()); }
public void SetUpAllTests() { by = new BoneYard(9); d11 = new Domino(1, 1); d22 = new Domino(2, 2); def = new Hand(); count1 = new Hand(); count2 = new Hand(); mt = new MexicanTrain(1); count1.Add(d11); count2.Add(d11); count2.Add(d22); mt.Add(d11); }