Example #1
0
        public static GameBoard CreateGame(Guid guid, int complexityLevel)
        {
            int width, height, colorCount;

            switch (complexityLevel)
            {
            case 2:
                width      = 20;
                height     = 20;
                colorCount = 12;
                break;

            case 1:
                width      = 15;
                height     = 15;
                colorCount = 9;
                break;

            case 0:
            default:
                width      = 10;
                height     = 10;
                colorCount = 6;
                break;
            }

            var boardData = RandomFieldGenerator.Create(width, height, colorCount);

            return(new GameBoard(width, height, boardData, guid, ColorPaletteGenerator.CreateHexPalette(colorCount)));
        }
Example #2
0
        public void Generate_ReturnsFieldWithGivenWidth()
        {
            var subject = new RandomFieldGenerator();

            var result = subject.Generate(3);

            Assert.AreEqual(3, result.GetLength(0));
        }
Example #3
0
        protected IGameField GenerateNewPrediction()
        {
            var builder = new GameFieldBuilder();

            foreach (var position in OpponentFieldKnowledge.EnumeratePositions())
            {
                if (OpponentFieldKnowledge[position] == true)
                {
                    builder.TryAddShipCell(position);
                }
            }

            var generator   = new RandomFieldGenerator(builder);
            var damagedShip = FindDamagedShip().ToList();

            if (damagedShip.Any())
            {
                foreach (var cell in damagedShip)
                {
                    builder.TryRemoveShipCell(cell);
                }

                var variants = new[] { 4, 3, 2, 1 }.SelectMany(x => new[]
                {
                    new { Ship = (ShipType)x, Vertical = true },
                    new { Ship = (ShipType)x, Vertical = false }
                }).SelectMany(x => GenerateContinuesForDamagedShip(damagedShip, builder, x.Vertical, x.Ship));

                foreach (var variant in variants)
                {
                    builder.TryAddFullShip(variant.Item1, variant.Item2, variant.Item3);
                    var prediction = generator.Generate(x => OpponentFieldKnowledge[x] != false);
                    if (prediction != null)
                    {
                        return(prediction);
                    }
                    builder.TryRemoveFullShip(variant.Item1, variant.Item2, variant.Item3);
                }
            }
            return(generator.Generate(x => OpponentFieldKnowledge[x] != false));
        }
 public void SetUp()
 {
     builder   = FromLines(Rules, SampleField);
     generator = new RandomFieldGenerator(builder);
 }