public void ReallySwapActivePlayers_AfterMiss()
        {
            var target = new CellPosition(5, 6);

            A.CallTo(() => player2.SelfField.Shoot(target)).Returns(ShotResult.Miss(target));
            A.CallTo(() => player2.SelfField.SurvivedShips.Values).Returns(new[] { 1 });
            gameController.Shoot(target);

            var knowledge = new GameFieldKnowledge(gameController.Rules.FieldSize);

            A.CallTo(() => player2.OpponentFieldKnowledge).Returns(knowledge);
            var affectedCells = new[] { new CellPosition(2, 2), new CellPosition(1, 8) };

            A.CallTo(() => player1.SelfField.Shoot(target)).Returns(ShotResult.Hit(target, affectedCells));
            gameController.Shoot(target);

            foreach (var position in knowledge.EnumeratePositions())
            {
                var expected = position.Equals(target)
                    ? true
                    : (affectedCells.Contains(position)
                        ? (bool?)false
                        : null);
                knowledge[position].Should().Be(expected);
            }
        }
        public void NotResetGameFinishedState_WhenAskedTwice()
        {
            var target = new CellPosition(5, 6);

            A.CallTo(() => player2.SelfField.Shoot(target)).Returns(ShotResult.Miss(target));

            gameController.Shoot(target);
            gameController.GameFinished.Should().BeTrue();
            gameController.GameFinished.Should().BeTrue();
        }
        public void FinishGame_WhenOpponentKilled()
        {
            var target = new CellPosition(5, 6);

            A.CallTo(() => player2.SelfField.Shoot(target)).Returns(ShotResult.Miss(target));
            A.CallTo(() => player2.SelfField.SurvivedShips.Values).Returns(new[] { 0 });

            gameController.Shoot(target);
            gameController.GameFinished.Should().BeTrue();
        }
        public void ContainSamePlayersAsFirstAndSecond_AfterMiss()
        {
            var target = new CellPosition(5, 6);

            A.CallTo(() => player2.SelfField.Shoot(target)).Returns(ShotResult.Miss(target));
            A.CallTo(() => player2.SelfField.SurvivedShips.Values).Returns(new[] { 1 });
            gameController.Shoot(target);

            gameController.FirstPlayer.Should().Be(player1);
            gameController.SecondPlayer.Should().Be(player2);
        }
        public void SwapActivePlayers_AfterMiss()
        {
            var target = new CellPosition(5, 6);

            A.CallTo(() => player2.SelfField.Shoot(target)).Returns(ShotResult.Miss(target));
            A.CallTo(() => player2.SelfField.SurvivedShips.Values).Returns(new[] { 1 });
            gameController.Shoot(target);

            gameController.CurrentPlayer.Should().Be(player2);
            gameController.OpponentPlayer.Should().Be(player1);
        }
        public void RememberTarget_AfterMiss()
        {
            var knowledge = new GameFieldKnowledge(gameController.Rules.FieldSize);

            A.CallTo(() => player1.OpponentFieldKnowledge).Returns(knowledge);

            var target     = new CellPosition(5, 6);
            var shotResult = ShotResult.Miss(target);

            A.CallTo(() => player2.SelfField.Shoot(target)).Returns(shotResult);

            gameController.Shoot(target).Should().Be(shotResult);

            foreach (var position in knowledge.EnumeratePositions())
            {
                knowledge[position].Should().Be(position.Equals(target) ? (bool?)false : null);
            }
        }