public void TestChangesRegisteredProperlyAfterOneMoveWhite() { List <int[]> moves = new List <int[]> { ar(1, 3) }; fd = new FakeDice(moves); bg = new BackgammonGame(BackgammonGame.DefaultGameBoard, fd); bg.Move(White, 6, 3); var changes = bg.GetChanges(); Assert.AreEqual(3, changes.Count()); var c1 = changes[0]; var c2 = changes[1]; var c3 = changes[2]; Assert.IsTrue(c1.IsDiceState(), "c1 is not dice state"); Assert.IsTrue(c2.IsMove(), "c2 is not move"); Assert.IsTrue(c3.IsDiceState(), "c3 is not dice state"); Assert.IsTrue(arrayEqual(ar(1, 3), c1.AsDiceState().GetDiceValues()), "Expected 1,3 but got " + string.Join(",", c1.AsDiceState().GetDiceValues())); Assert.AreEqual("w 6 3", c2.AsMove().DebugString(), "Expected w 6 3, got " + c2.AsMove().DebugString()); Assert.IsTrue(arrayEqual(new int[] { 1 }, c3.AsDiceState().GetDiceValues())); }
public void TestChangesRegisteredProperlyCompundMovesOfMultipleSmallerMoves() { List <int[]> moves = new List <int[]>() { ar(1, 3), ar(4, 4) }; fd = new FakeDice(moves); bg = new BackgammonGame(BackgammonGame.DefaultGameBoard, fd); bg.Move(White, 13, 9); var changes = bg.GetChanges(); Assert.AreEqual(5, changes.Count()); var c1 = changes[0]; var c2 = changes[1]; var c3 = changes[2]; var c4 = changes[3]; var c5 = changes[4]; Assert.IsTrue(c1.IsDiceState(), "c1 is not dice state"); Assert.IsTrue(c2.IsMove(), "c2 is not move"); Assert.IsTrue(c3.IsDiceState(), "c3 is not dice state"); Assert.IsTrue(arrayEqual(ar(1, 3), c1.AsDiceState().GetDiceValues()), "Expected 1,3 but got " + string.Join(",", c1.AsDiceState().GetDiceValues())); Assert.AreEqual("w 13 10", c2.AsMove().DebugString()); Assert.IsTrue(arrayEqual(new int[] { 1 }, c3.AsDiceState().GetDiceValues())); Assert.AreEqual("w 10 9", c4.AsMove().DebugString()); Assert.IsTrue(arrayEqual(new int[] { 4, 4, 4, 4 }, c5.AsDiceState().GetDiceValues())); }
public void Initialize() { this.fakeDice = new FakeDice(); this.player = new Player("Horse"); this.board = new ClassicBoard(); this.turn = new Turn(this.fakeDice, this.player, this.board); }
private void PlayerTakesTurnRollingA(Int32 roll) { dice = new FakeDice(new[] { new FakeRoll(roll, 0) }); var turn = new NormalTurn(playerId, dice, jailRoster, board); turn.Take(); }
public void TestGetPreviousTurnWhenNoLegalMoves() { //When it becomes black's turn, there will be no legal moves, but the turn should change to white //before bg.EndTurn(Black) is called int[] board = new int[] { -15, 2, 2, 2, 2, 2, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; List <int[]> moves = new List <int[]>() { ar(1, 3), ar(5, 3) }; fd = new FakeDice(moves); bg = new BackgammonGame(board, fd); bg.Move(White, 8, 5); bg.Move(White, 8, 7); var turn = bg.GetPreviousTurn(); Assert.AreEqual(White, turn.color); Assert.IsTrue(arrayEquals(ar(1, 3), turn.dice.ToArray())); Assert.AreEqual(2, turn.moves.Count()); bg.EndTurn(Black); turn = bg.GetPreviousTurn(); Assert.AreEqual(Black, turn.color); Assert.IsTrue(arrayEquals(ar(5, 3), turn.dice.ToArray())); Assert.AreEqual(0, turn.moves.Count()); }
public JailTests() { player = new Player("Name", 1500); player.BuyingStrategy = new NeverBuyStrategy(); goToJail = new GoToJail(ClassicBoard.GoToJailLocation, ClassicBoard.JailLocation); dice = new FakeDice(); turn = new Turn(dice, player, new ClassicBoard()); }
public void Initialize() { fd = new FakeDice(new int[] { 1, 2 }); initialGameBoard = new int[] { -2, 0, 0, 0, 0, 5, 0, 3, 0, 0, 0, -5, 5, 0, 0, 0, -3, 0, -5, 0, 0, 0, 0, 2 }; }
public void TestChangesRegisteredProperlyAfterRolledTwoEqualDiceAndAllMovesConsumed() { List <int[]> moves = new List <int[]> { ar(2, 2), ar(1, 5) }; fd = new FakeDice(moves); bg = new BackgammonGame(BackgammonGame.DefaultGameBoard, fd); bg.Move(White, 6, 4); bg.Move(White, 6, 4); bg.Move(White, 13, 11); bg.Move(White, 24, 22); var changes = bg.GetChanges(); Assert.AreEqual(9, changes.Count()); var c1 = changes[0]; var c2 = changes[1]; var c3 = changes[2]; var c4 = changes[3]; var c5 = changes[4]; var c6 = changes[5]; var c7 = changes[6]; var c8 = changes[7]; var c9 = changes[8]; Assert.IsTrue(c1.IsDiceState(), "c1 is not dice state"); Assert.IsTrue(c2.IsMove(), "c2 is not move"); Assert.IsTrue(c3.IsDiceState(), "c3 is not dice state"); Assert.IsTrue(c4.IsMove(), "c4 is not move"); Assert.IsTrue(c5.IsDiceState(), "c5 is not dice state"); Assert.IsTrue(c6.IsMove()); Assert.IsTrue(c7.IsDiceState()); Assert.IsTrue(c8.IsMove()); Assert.IsTrue(c9.IsDiceState()); Assert.IsTrue(arrayEqual(new int[] { 2, 2, 2, 2 }, c1.AsDiceState().GetDiceValues()), "Expected 1,3 but got " + string.Join(",", c1.AsDiceState().GetDiceValues())); Assert.AreEqual("w 6 4", c2.AsMove().DebugString()); Assert.IsTrue(arrayEqual(new int[] { 2, 2, 2 }, c3.AsDiceState().GetDiceValues())); Assert.AreEqual("w 6 4", c4.AsMove().DebugString()); Assert.IsTrue(arrayEqual(ar(2, 2), c5.AsDiceState().GetDiceValues())); Assert.AreEqual("w 13 11", c6.AsMove().DebugString()); Assert.IsTrue(arrayEqual(new int[] { 2 }, c7.AsDiceState().GetDiceValues())); Assert.AreEqual("w 24 22", c8.AsMove().DebugString()); Assert.IsTrue(arrayEqual(ar(1, 5), c9.AsDiceState().GetDiceValues())); }
public void TestChangesRegisteredProperlyAfterBothWhiteAndBlackMoves() { List <int[]> moves = new List <int[]> { ar(1, 3), ar(4, 5), ar(6, 3) }; fd = new FakeDice(moves); bg = new BackgammonGame(BackgammonGame.DefaultGameBoard, fd); bg.Move(White, 6, 3); bg.Move(White, 6, 5); bg.Move(Black, 19, 23); bg.Move(Black, 17, 22); var changes = bg.GetChanges(); Assert.AreEqual(9, changes.Count()); var c1 = changes[0]; var c2 = changes[1]; var c3 = changes[2]; var c4 = changes[3]; var c5 = changes[4]; var c6 = changes[5]; var c7 = changes[6]; var c8 = changes[7]; var c9 = changes[8]; Assert.IsTrue(c1.IsDiceState(), "c1 is not dice state"); Assert.IsTrue(c2.IsMove(), "c2 is not move"); Assert.IsTrue(c3.IsDiceState(), "c3 is not dice state"); Assert.IsTrue(c4.IsMove(), "c4 is not move"); Assert.IsTrue(c5.IsDiceState(), "c5 is not dice state"); Assert.IsTrue(c6.IsMove()); Assert.IsTrue(c7.IsDiceState()); Assert.IsTrue(c8.IsMove()); Assert.IsTrue(c9.IsDiceState()); Assert.IsTrue(arrayEqual(ar(1, 3), c1.AsDiceState().GetDiceValues()), "Expected 1,3 but got " + string.Join(",", c1.AsDiceState().GetDiceValues())); Assert.AreEqual("w 6 3", c2.AsMove().DebugString(), "Expected w 6 3, got " + c2.AsMove().DebugString()); Assert.IsTrue(arrayEqual(new int[] { 1 }, c3.AsDiceState().GetDiceValues())); Assert.AreEqual("w 6 5", c4.AsMove().DebugString()); Assert.IsTrue(arrayEqual(ar(4, 5), c5.AsDiceState().GetDiceValues())); Assert.AreEqual("b 19 23", c6.AsMove().DebugString()); Assert.IsTrue(arrayEqual(new int[] { 5 }, c7.AsDiceState().GetDiceValues())); Assert.AreEqual("b 17 22", c8.AsMove().DebugString()); Assert.IsTrue(arrayEqual(ar(6, 3), c9.AsDiceState().GetDiceValues())); }
public void TestChangesRegisteredProperlyAfterNotifyViewFlushesChanges() { List <int[]> moves = new List <int[]>() { ar(1, 3), ar(4, 4) }; fd = new FakeDice(moves); bg = new BackgammonGame(BackgammonGame.DefaultGameBoard, fd); bg.Move(White, 6, 3); var changes = bg.GetChanges(); Assert.AreEqual(3, changes.Count()); var c1 = changes[0]; var c2 = changes[1]; var c3 = changes[2]; Assert.IsTrue(c1.IsDiceState(), "c1 is not dice state"); Assert.IsTrue(c2.IsMove(), "c2 is not move"); Assert.IsTrue(c3.IsDiceState(), "c3 is not dice state"); Assert.IsTrue(arrayEqual(ar(1, 3), c1.AsDiceState().GetDiceValues()), "Expected 1,3 but got " + string.Join(",", c1.AsDiceState().GetDiceValues())); Assert.AreEqual("w 6 3", c2.AsMove().DebugString(), "Expected w 6 3, got " + c2.AsMove().DebugString()); Assert.IsTrue(arrayEqual(new int[] { 1 }, c3.AsDiceState().GetDiceValues())); //At least one view has to be present for backgammon game to flush the recent changes View view = new DummyView(); bg.ConnectView(view); bg.NotifyAllViews(); //Disconnecting the view again so that we may read the changes bg.DisconnectView(view); changes = bg.GetChanges(); Assert.AreEqual(0, changes.Count()); bg.Move(White, 6, 5); changes = bg.GetChanges(); Assert.AreEqual(2, changes.Count()); var c4 = changes[0]; var c5 = changes[1]; Assert.IsTrue(c4.IsMove()); Assert.IsTrue(c5.IsDiceState()); Assert.AreEqual("w 6 5", c4.AsMove().DebugString()); Assert.IsTrue(arrayEqual(new int[] { 4, 4, 4, 4 }, c5.AsDiceState().GetDiceValues())); }
public void initialize() { moves = new List <int[]>() { ar(1, 2), ar(4, 3), ar(1, 1), ar(1, 1), ar(6, 5), ar(3, 3) }; fd = new FakeDice(moves); bg = new BackgammonGame(BackgammonGame.DefaultGameBoard, fd); }
public void Initialize() { List <int[]> moves = new List <int[]>() { ar(1, 3), ar(5, 3), ar(6, 1), ar(1, 2) }; fd = new FakeDice(moves); bg = new BackgammonGame(BackgammonGame.DefaultGameBoard, fd); }
public void SetUp() { var faker = new MotherFaker(); jailRoster = faker.JailRoster; banker = faker.Banker; gameBoard = faker.GameBoard; dice = faker.Dice; PutPlayerInJail(); }
public void TestPlayerThrowsNonDoublesLandsOnGoToJailWithBalanceNotChangingAndTurnIsOver() { var fakeDice = new FakeDice(new [] { new FakeRoll(30, 0) }); var turn = CreateTurnWith(fakeDice); turn.Take(); Assert.That(banker.GetBalanceFor(playerId), Is.EqualTo(1500)); Assert.That(board.GetLocationIndexFor(playerId), Is.EqualTo(10)); }
public TurnServiceTests() { fakeDice = new FakeDice(); fakeBailAdvisor = new FakeBailAdvisor(); board = new Board(fakeDice); moveService = new MoveService(board); player = new Player("horse"); var mortgageBroker = new MortgageBroker(); var mortgageAdvisor = new MortgageAdvisor(); var mortgageService = new MortgageService(board, mortgageAdvisor, mortgageBroker); turnService = new TurnService(moveService, mortgageService, fakeBailAdvisor); }
public void SetUp() { banker = new TraditionalBanker(new[] { 0 }); jailRoster = new TraditionalJailRoster(banker); board = new GameBoard(banker); var dice = new FakeDice(); var cardDeckFactory = new FakeCardDeckFactory(CreateCards()); communityChest = new CardDraw(0, "Community Chest", banker, cardDeckFactory.GetCommunityChestDeck()); var traditionalLocationFactory = new TraditionalLocationFactory(banker, dice, jailRoster, board, cardDeckFactory); board.SetLocations(traditionalLocationFactory.GetLocations(), traditionalLocationFactory.GetRailroads(), traditionalLocationFactory.GetUtilities()); }
public virtual void SetUp() { playerOneId = 0; playerTwoId = 1; playerThreeId = 2; playerFourId = 3; playerFiveId = 4; banker = new TraditionalBanker(new[] { playerOneId, playerTwoId, playerThreeId, playerFourId, playerFiveId }); jailRoster = new TraditionalJailRoster(banker); gameBoard = new GameBoard(banker); dice = new FakeDice(); var cardDeckFactory = new TraditionalCardDeckFactory(banker, jailRoster, gameBoard, dice); var locationFactory = new TraditionalLocationFactory(banker, dice, jailRoster, gameBoard, cardDeckFactory); gameBoard.SetLocations(locationFactory.GetLocations(), locationFactory.GetRailroads(), locationFactory.GetUtilities()); }
public void PlayerPaysRentToOwnerWhenBothUtilitiesAreOwned() { var startingMoney = new Money(100); var owner = new Player("car", startingMoney); var player = new Player("horse", startingMoney); var fakeProperty = new FakeProperty(owner: owner); var fakeDice = new FakeDice(); fakeDice.LoadRoll(3, 7); fakeDice.Roll(); var expectedRent = new Money(10 * fakeDice.LastRoll.Total); var expectedOwnerMoney = startingMoney.Add(expectedRent); var expectedPlayerMoney = startingMoney.Remove(expectedRent); var rentAction = new UtilityRentAction(new FakeBoard(numberOfUtilitiesOwned: 2), fakeDice); rentAction.ProcessAction(player, fakeProperty); Assert.AreEqual(expectedOwnerMoney, owner.Balance); Assert.AreEqual(expectedPlayerMoney, player.Balance); }
public void TestChangesRegisteredProperlyAfterTwoMovesBlack() { List <int[]> moves = new List <int[]> { ar(1, 3), ar(4, 5) }; fd = new FakeDice(moves); bg = new BackgammonGame(BackgammonGame.DefaultGameBoard, fd, 0, 0, 0, 0, Black); bg.Move(Black, 19, 22); bg.Move(Black, 19, 20); var changes = bg.GetChanges(); Assert.AreEqual(5, changes.Count()); var c1 = changes[0]; var c2 = changes[1]; var c3 = changes[2]; var c4 = changes[3]; var c5 = changes[4]; Assert.IsTrue(c1.IsDiceState(), "c1 is not dice state"); Assert.IsTrue(c2.IsMove(), "c2 is not move"); Assert.IsTrue(c3.IsDiceState(), "c3 is not dice state"); Assert.IsTrue(c4.IsMove(), "c4 is not move"); Assert.IsTrue(c5.IsDiceState(), "c5 is not dice state"); Assert.IsTrue(arrayEqual(ar(1, 3), c1.AsDiceState().GetDiceValues()), "Expected 1,3 but got " + string.Join(",", c1.AsDiceState().GetDiceValues())); Assert.AreEqual("b 19 22", c2.AsMove().DebugString(), "Expected w 6 3, got " + c2.AsMove().DebugString()); Assert.IsTrue(arrayEqual(new int[] { 1 }, c3.AsDiceState().GetDiceValues())); Assert.AreEqual("b 19 20", c4.AsMove().DebugString()); Assert.IsTrue(arrayEqual(ar(4, 5), c5.AsDiceState().GetDiceValues())); }
public void TestGetBackgammonPreviousTurnWithDoubleRoll() { fd = new FakeDice(ar(2, 2)); bg = new BackgammonGame(BackgammonGame.DefaultGameBoard, fd); bg.Move(White, 6, 4); bg.Move(White, 6, 4); bg.Move(White, 6, 4); bg.Move(White, 6, 4); var turn = bg.GetPreviousTurn(); Assert.AreEqual(White, turn.color); Assert.IsTrue(arrayEquals(ar(2, 2, 2, 2), turn.dice.ToArray())); var moves = turn.moves; Assert.AreEqual(4, moves.Count()); Assert.AreEqual("w 6 4", moves[0].DebugString()); Assert.AreEqual("w 6 4", moves[1].DebugString()); Assert.AreEqual("w 6 4", moves[2].DebugString()); Assert.AreEqual("w 6 4", moves[3].DebugString()); }
public void SetupDice() { fakeDice = new FakeDice(); dice = new Dice(); }
public void SetupGameTest() { dice = new FakeDice(); game = new Game(dice); horse = new Player("horse"); car = new Player("car"); player3 = new Player("Player 3"); }
public GameTests() { fakeBoard = new FakeBoard(); fakeDice = new FakeDice(); fakeTurnService = new FakeTurnService(); }
public BoardTests() { var dice = new FakeDice(); board = new Board(dice); }