示例#1
0
	void Awake()
	{
		if (Instance != null && Instance != this)
		{
			Destroy(gameObject);
		}
		Instance = this;
		// Furthermore we make sure that we don't destroy between scenes (this is optional)
		DontDestroyOnLoad(gameObject);


		CellXPositions = new float[Width];
		CellYPositions = new float[Height];

		float gridWidth = Width * CellSpacing.x;
		gridWorldStartX = 0 - (gridWidth * 0.5f) + (CellSpacing.x * 0.5f);
		for (int x = 0; x < Width; x++)
		{
			CellXPositions[x] = gridWorldStartX + (CellSpacing.x * x);
		}

		float gridHeight = Height * CellSpacing.y;
		gridWorldStartY = (gridHeight * 0.5f) - (CellSpacing.y * 0.5f);
		for (int y = 0; y < Height; y++)
		{
			CellYPositions[y] = gridWorldStartY - (CellSpacing.y * y);
		}
	}
示例#2
0
    void Awake()
    {
        if (Instance != null && Instance != this)
        {
            Destroy(gameObject);
        }
        Instance = this;
        // Furthermore we make sure that we don't destroy between scenes (this is optional)
        DontDestroyOnLoad(gameObject);


        CellXPositions = new float[Width];
        CellYPositions = new float[Height];

        float gridWidth = Width * CellSpacing.x;

        gridWorldStartX = 0 - (gridWidth * 0.5f) + (CellSpacing.x * 0.5f);
        for (int x = 0; x < Width; x++)
        {
            CellXPositions[x] = gridWorldStartX + (CellSpacing.x * x);
        }

        float gridHeight = Height * CellSpacing.y;

        gridWorldStartY = (gridHeight * 0.5f) - (CellSpacing.y * 0.5f);
        for (int y = 0; y < Height; y++)
        {
            CellYPositions[y] = gridWorldStartY - (CellSpacing.y * y);
        }
    }
示例#3
0
        public string SetBoardConfigs()
        {
            List <Pboard>   list        = new List <Pboard>();
            Pboard          pboard      = new Pboard();
            BoardConfig     boardConfig = new BoardConfig();
            List <PlotBand> bands       = new List <PlotBand>();
            PlotBand        plotBand    = new PlotBand();

            plotBand.From  = -20;
            plotBand.To    = 120;
            plotBand.Color = "#55BF3B";
            bands.Add(plotBand);
            boardConfig.Min       = -20;
            boardConfig.Max       = 200;
            boardConfig.Title     = "℃";
            boardConfig.PlotBands = bands;
            pboard.Name           = "thermograph";
            pboard.Config         = boardConfig;
            list.Add(pboard);

            using (StringWriter sw = new StringWriter())
            {
                XmlSerializer serializer = new XmlSerializer(typeof(List <Pboard>));
                serializer.Serialize(sw, list);
                sw.Close();
                string str = sw.ToString();

                return(str);
            }
        }
 public AppMainSettings()
 {
     battleConfiguration = new BattleConfiguration();
     playerSettings      = new PlayerSettings();
     shipSetting         = new ShipSetting();
     boardConfig         = new BoardConfig();
 }
示例#5
0
    protected override void OnUpdate()
    {
        // config
        BoardConfig config = new BoardConfig();

        Entities.ForEach((in BoardConfig c) => config = c).WithoutBurst().Run();

        // elements 収集
        int allCount   = allQuery.CalculateEntityCount();
        int alphaCount = alphaQuery.CalculateEntityCount();
        int betaCount  = betaQuery.CalculateEntityCount();

        var size        = config.size;
        var size2       = size * 2;
        var allElements = new NativeArray <NativeQuadTree.QuadElement <int> >(
            allCount, Allocator.TempJob);
        var alphaElements = new NativeArray <NativeQuadTree.QuadElement <int> >(
            alphaCount, Allocator.TempJob);
        var betaElements = new NativeArray <NativeQuadTree.QuadElement <int> >(
            betaCount, Allocator.TempJob);

        Entities.ForEach(
            (int entityInQueryIndex, in Translation t, in Force f) => {
            allElements[entityInQueryIndex] =
                new NativeQuadTree.QuadElement <int> {
                pos     = t.Value.xz + float2(size),
                element = entityInQueryIndex
            };
        })
示例#6
0
 void Start()
 {
     BoardConfig = GetComponentInParent <BoardConfig>() as BoardConfig;
     if (BoardConfig == null)
     {
         throw new UnityException("MatchChecker must have a BoardConfig component attached or as a parent.");
     }
 }
示例#7
0
	void Start () 
	{
		BoardConfig = GetComponentInParent<BoardConfig>() as BoardConfig;
		if (BoardConfig == null)
		{
			throw new UnityException("MatchChecker must have a BoardConfig component attached or as a parent.");
		}
	}
示例#8
0
	public PuzzleBoard(BoardConfig config)
	{
		BoardConfig = config;
		Board = new BoardCell[config.Width * config.Height];
		for (int index = 0; index < config.Width * config.Height; index++)
		{
			var cell = new BoardCell();
			Board[index] = cell;
		}
	}
示例#9
0
 public PuzzleBoard(BoardConfig config)
 {
     BoardConfig = config;
     Board       = new BoardCell[config.Width * config.Height];
     for (int index = 0; index < config.Width * config.Height; index++)
     {
         var cell = new BoardCell();
         Board[index] = cell;
     }
 }
示例#10
0
	// Use this for initialization
	public void InitialiseBoard()
	{
		boardConfig = BoardConfig.Instance;
		Grid = new GridCell[boardConfig.Width * boardConfig.Height];
		for (int index = 0; index < boardConfig.Width * boardConfig.Height; index++)
		{
			var pos = new Vector3(boardConfig.GetPosXFromIndex(index), boardConfig.GetPosYFromIndex(index), 0f);
			var cell = new GridCell(boardConfig.GetGridXFromIndex(index), boardConfig.GetGridYFromIndex(index), index, pos);
			Grid[index] = cell;
		}
	}
示例#11
0
    static void ApplyLevel(ref Translation translation, BoardConfig config)
    {
        var t     = config.heightMap;
        var uv    = GetUVFromLocalPoint(config.size, translation.Value);
        var level = Pick(t, uv) * config.heightScale;

        translation.Value = float3(
            translation.Value.x,
            level + 0.2f,
            translation.Value.z);
    }
示例#12
0
        public void CreateBoard()
        {
            BoardConfig boardConfig = new BoardConfig
            {
                RowsNumber    = -1,
                ColumnsNumber = -3
            };
            Board board = new Board(boardConfig);

            Assert.AreEqual(0, board.ShipsOnBoard);
        }
示例#13
0
        public void CheckClearBoard()
        {
            BoardConfig boardConfig = new BoardConfig
            {
                RowsNumber    = 1,
                ColumnsNumber = 3
            };
            Board board = new Board(boardConfig);

            Assert.AreEqual(true, board.IsClear);
        }
示例#14
0
        public void ShouldThrowArgumentExceptionWhenBoardConfigIsInvalid(int shieldSize, int totalRows)
        {
            //Arrange
            var boardConfig = new BoardConfig(shieldSize, totalRows);

            //Act
            var action = new Action(() => new DecodingBoard(boardConfig));

            //Assert
            action.Should().Throw <ArgumentException>();
        }
示例#15
0
 // Use this for initialization
 public void InitialiseBoard()
 {
     boardConfig = BoardConfig.Instance;
     Grid        = new GridCell[boardConfig.Width * boardConfig.Height];
     for (int index = 0; index < boardConfig.Width * boardConfig.Height; index++)
     {
         var pos  = new Vector3(boardConfig.GetPosXFromIndex(index), boardConfig.GetPosYFromIndex(index), 0f);
         var cell = new GridCell(boardConfig.GetGridXFromIndex(index), boardConfig.GetGridYFromIndex(index), index, pos);
         Grid[index] = cell;
     }
 }
示例#16
0
        public void CheckBoardFieldStatusEmpty()
        {
            BoardConfig boardConfig = new BoardConfig
            {
                RowsNumber    = 1,
                ColumnsNumber = 1
            };
            Board      board      = new Board(boardConfig);
            BoardField boardField = board.GetField(0, 0);

            Assert.AreEqual(BoardField.State.Fine, boardField.Status);
        }
示例#17
0
        public void ResultOfHitNullShip()
        {
            BoardConfig boardConfig = new BoardConfig
            {
                RowsNumber    = 3,
                ColumnsNumber = 3
            };
            Board      board      = new Board(boardConfig);
            BoardField boardField = board.GetField(0, 0);

            Assert.AreEqual(Shot.Result.Missed, boardField.Shoot());
        }
示例#18
0
        public void CheckBoardFieldStatusHit()
        {
            BoardConfig boardConfig = new BoardConfig
            {
                RowsNumber    = 3,
                ColumnsNumber = 3
            };
            Board      board      = new Board(boardConfig);
            BoardField boardField = board.GetField(0, 0);

            boardField.Shoot();
            Assert.AreEqual(BoardField.State.ShotDown, boardField.Status);
        }
示例#19
0
 private void GetAllComponents()
 {
     BoardConfig = GetComponentInParent <BoardConfig>() as BoardConfig;
     if (BoardConfig == null)
     {
         throw new UnityException("PuzzleBoardController must have a BoardConfig component attached or as a parent.");
     }
     MatchChecker = GetComponent <MatchChecker>() as MatchChecker;
     if (MatchChecker == null)
     {
         throw new UnityException("PuzzleBoardController must have a MatchChecker component attached.");
     }
 }
示例#20
0
	private void GetAllComponents()
	{
		BoardConfig = GetComponentInParent<BoardConfig>() as BoardConfig;
		if (BoardConfig == null)
		{
			throw new UnityException("PuzzleBoardController must have a BoardConfig component attached or as a parent.");
		}
		MatchChecker = GetComponent<MatchChecker>() as MatchChecker;
		if (MatchChecker == null)
		{
			throw new UnityException("PuzzleBoardController must have a MatchChecker component attached.");
		}
	}
示例#21
0
        public void CheckNotClearBoard()
        {
            BoardConfig boardConfig = new BoardConfig
            {
                RowsNumber    = 1,
                ColumnsNumber = 3
            };
            Board       board       = new Board(boardConfig);
            OneMastShip oneMastShip = new OneMastShip();

            board.LocateShip(oneMastShip);
            Assert.AreEqual(false, board.IsClear);
        }
 void Start()
 {
     if (instance)
     {
         Debug.Log("Another BoardConfig was attempted to be instantiated");
         Destroy(this);
     }
     else
     {
         instance = this;
         Camera.main.backgroundColor = visuals.normalSkyboxColor;
     }
 }
示例#23
0
 public static void calculateLevelHeuristics(ref List<BCTree<BoardConfig>> lNodes)
 {
     for (int i = 0; i < lNodes.Count; ++i)
     {
         if ((lNodes[i].Level % 2) == 0) // Calculate heuristics of level 2 or level 0, so MAX of children
         {
             if (lNodes[i].isLeaf)
             {
                 BoardConfig tempBC = new BoardConfig(lNodes[i].data);
                 int tempHeuristic = lNodes[i].data.EvaluateBCHeuristic();
                 tempBC.heuristic = tempHeuristic;
                 lNodes[i].data = tempBC;
             }
             else
             {
                 BoardConfig tempBC = new BoardConfig(lNodes[i].data);
                 int MAXHeuristic = lNodes[i].children[0].data.heuristic;
                 for (int j = 1; j < lNodes[i].children.Count; ++j)
                 {
                     if (lNodes[i].children[j].data.heuristic > MAXHeuristic)
                         MAXHeuristic = lNodes[i].children[j].data.heuristic;
                 }
                 tempBC.heuristic = MAXHeuristic;
                 lNodes[i].data = tempBC;
             }
         }
         else if ((lNodes[i].Level % 2) == 1) // Calculate heuristics of level 3 or level 1, so MIN of children (or just calculate heuristic for level 3)
         {
             if (lNodes[i].isLeaf)
             {
                 BoardConfig tempBC = new BoardConfig(lNodes[i].data);
                 int tempHeuristic = lNodes[i].data.EvaluateBCHeuristic();
                 tempBC.heuristic = tempHeuristic;
                 lNodes[i].data = tempBC;
             }
             else
             {
                 BoardConfig tempBC = new BoardConfig(lNodes[i].data);
                 int MINHeuristic = lNodes[i].children[0].data.heuristic;
                 for (int j = 1; j < lNodes[i].children.Count; ++j)
                 {
                     if (lNodes[i].children[j].data.heuristic < MINHeuristic)
                         MINHeuristic = lNodes[i].children[j].data.heuristic;
                 }
                 tempBC.heuristic = MINHeuristic;
                 lNodes[i].data = tempBC;
             }
         }
     }
 }
示例#24
0
 protected override void OnUpdate() {
     // config
     BoardConfig config = new BoardConfig();
     Entities.ForEach((in BoardConfig c) => config = c).WithoutBurst().Run();
     if (config.sdfTexture == null) { return; }
     
     Entities
         .ForEach((ref Translation translation) =>
         {
             ApplyWall(ref translation, config);
         })
         .WithoutBurst()
         .Run();
 }
示例#25
0
        public void CheckAmountOfShipsOnBoard()
        {
            BoardConfig boardConfig = new BoardConfig
            {
                RowsNumber    = 10,
                ColumnsNumber = 10
            };
            Board       board       = new Board(boardConfig);
            OneMastShip oneMastShip = new OneMastShip();

            board.LocateShip(oneMastShip);
            board.DecreaseShipsNumber();
            Assert.AreEqual(0, board.ShipsOnBoard);
        }
示例#26
0
    static void ApplyWall(ref Translation translation, BoardConfig config) {
        var uv = GetUVFromLocalPoint(config.size, translation.Value);
        var z = Pick(config.sdfTexture, uv);

        if (0.5f < z) {
            // do nothing
        } else {
            // Debug.Log($"outside {z}");
            var g = Gradient(config.sdfTexture, uv);
            var location = GetLocalPointFromUV(
                config.size, uv + g * (0.5f - z));
            translation.Value = location;
        }
    }
示例#27
0
        public void ShouldThrowArgumentNullExceptionWhenCodeMakerShieldIsNull()
        {
            //Arrange
            var boardConfig   = new BoardConfig(4, 10);
            var decodingBoard = new DecodingBoard(boardConfig);

            //Act
            void Action() => decodingBoard.CodeMaker(null);

            var exception = Record.Exception(Action);

            //Assert
            exception.Should().NotBeNull();
            exception.Should().BeOfType <ArgumentNullException>();
        }
示例#28
0
        public void CheckLocateTwoShipsOnBoard()
        {
            BoardConfig boardConfig = new BoardConfig
            {
                RowsNumber    = 6,
                ColumnsNumber = 6
            };
            Board       board       = new Board(boardConfig);
            TwoMastShip twoMastShip = new TwoMastShip();
            OneMastShip oneMastShip = new OneMastShip();

            board.LocateShip(twoMastShip);
            board.LocateShip(oneMastShip);
            Assert.AreEqual(2, board.ShipsOnBoard);
        }
示例#29
0
        public void ShouldCreateShieldWhenCodeMakerPlaysValidShield()
        {
            //Arrange
            var boardConfig   = new BoardConfig(4, 10);
            var decodingBoard = new DecodingBoard(boardConfig);

            var colors = new CodePeg[4];
            var shield = new Shield(colors);

            //Act
            decodingBoard.CodeMaker(shield);

            //Assert
            decodingBoard.Shield.Should().NotBeNull();
            decodingBoard.Shield.Should().Be(shield);
        }
示例#30
0
        static void Main(string[] args)
        {
            List <Counter> gameCounter = new List <Counter>();

            for (int i = 0; i < 300; i++)
            {
                BoardConfig  board   = new BoardConfig();
                PlayerConfig players = new PlayerConfig(
                    new BasePlayer(1, BehaviorList.Impulsive), new BasePlayer(2, BehaviorList.Demanding), new BasePlayer(3, BehaviorList.Impulsive), new BasePlayer(4, BehaviorList.Unpredictable)
                    );
                board.LoadBoard();
                if (board.boardProperties.Count == 0)
                {
                    Console.WriteLine(@"Não é possível executar o teste pois o arquivo de configuração não está presente.");
                    return;
                }
                Console.WriteLine("=#=#=#=#=#=#=#=#=#=#=#=#  Game Start #=#=#=#=#=#=#=#=#=#=#=#=");
                players.PlayerList.Shuffle();
                foreach (var p in players.PlayerList)
                {
                    Console.WriteLine(p.ToString());
                }
                GameService game = new GameService(board.boardProperties, players.PlayerList, gameCounter);
                game.GameFlow();
            }

            MetricsService metrics    = new MetricsService(gameCounter);
            PlayerConfig   playerList = new PlayerConfig(
                new BasePlayer(1, BehaviorList.Impulsive), new BasePlayer(2, BehaviorList.Demanding), new BasePlayer(3, BehaviorList.Impulsive), new BasePlayer(4, BehaviorList.Unpredictable)
                );

            var TimeOuts = metrics.TimeOutGames();

            Console.WriteLine($"O número de partidas finalizadas por limite de turnos é de: {TimeOuts}.");
            var TurnsToWin = metrics.TurnAverage();

            Console.WriteLine($"A média de turnos que uma partida demora para ser concluída é de: {TurnsToWin}");
            List <WinPercentage> WinPercentageByPlayer = metrics.WinPercentageAllPlayers(playerList.PlayerList);

            foreach (WinPercentage register in WinPercentageByPlayer)
            {
                Console.WriteLine($"O Jogador {register.Player.Id} venceu {Math.Round(register.WPercentage * 100,2)}% das vezes.");
            }
            BasePlayer mostWinner = metrics.MostWinningPlayer(WinPercentageByPlayer);

            Console.WriteLine($"O Jogador com mais vitórias foi o Jogador { mostWinner.Id } com o comportamento {mostWinner.Behavior}.");
        }
示例#31
0
        public void ShouldThrowArgumentExceptionWhenCodeMakerShieldIsDifferentThanConfig(int shieldSize)
        {
            //Arrange
            var boardConfig   = new BoardConfig(4, 10);
            var decodingBoard = new DecodingBoard(boardConfig);

            var colors = new CodePeg[shieldSize];
            var shield = new Shield(colors);

            //Act
            void Action() => decodingBoard.CodeMaker(shield);

            var exception = Record.Exception(Action);

            //Assert
            exception.Should().BeOfType <ArgumentException>();
        }
示例#32
0
        public void ShouldFindThreeWhiteKeyPegsWhenCodeColorMatchesThreeOtherShieldPositions(CodePeg[] code)
        {
            //Arrange
            var boardConfig   = new BoardConfig(4, 10);
            var decodingBoard = new DecodingBoard(boardConfig);

            var colors = new[] { CodePeg.Black, CodePeg.Blue, CodePeg.Green, CodePeg.White };
            var shield = new Shield(colors);

            decodingBoard.CodeMaker(shield);

            //Act
            var result = decodingBoard.CodeBreaker(code);

            //Assert
            result.Should().NotBeNull();
            result.WhiteKeyPegs.Should().Be(3);
        }
示例#33
0
    protected override void OnUpdate()
    {
        // config
        BoardConfig config = new BoardConfig();

        Entities.ForEach((in BoardConfig c) => config = c).WithoutBurst().Run();
        if (config.heightMap == null)
        {
            return;
        }

        Entities
        .WithoutBurst()
        .ForEach((ref Force force, in Translation translation) =>
        {
            ApplyFall(ref force, in translation, config);
        })
        .Run();
    }
示例#34
0
        public void ShouldNotSolveSecretCodeWhenResponseBlackPegsNotEqualsShieldCount(int blackKeyPegs, int whiteKeyPegs)
        {
            //Arrange
            var boardConfig   = new BoardConfig(4, 10);
            var decodingBoard = new DecodingBoard(boardConfig);

            var colors = new[] { CodePeg.Black, CodePeg.Blue, CodePeg.Green, CodePeg.White };
            var shield = new Shield(colors);

            decodingBoard.CodeMaker(shield);

            var response = new Response(blackKeyPegs, whiteKeyPegs);

            //Act
            var result = decodingBoard.HasSolvedSecretCode(response);

            //Assert
            result.Should().BeFalse();
        }
示例#35
0
        public void ShouldThrowArgumentNullExceptionWhenCodeBreakerCodeIsNull()
        {
            //Arrange
            var boardConfig   = new BoardConfig(4, 10);
            var decodingBoard = new DecodingBoard(boardConfig);

            var colors = new[] { CodePeg.Black, CodePeg.Blue, CodePeg.Green, CodePeg.White };
            var shield = new Shield(colors);

            decodingBoard.CodeMaker(shield);

            //Act
            void Action() => decodingBoard.CodeBreaker(null);

            var exception = Record.Exception(Action);

            //Assert
            exception.Should().BeOfType <ArgumentNullException>();
        }
示例#36
0
    protected override void OnUpdate()
    {
        // config
        BoardConfig config = new BoardConfig();

        Entities.ForEach((in BoardConfig c) => config = c).WithoutBurst().Run();
        var size = float2(config.size);

        Entities.ForEach(
            (Entity entity, int entityInQueryIndex, ref Pawn p) => {
            if (2.0f <= p.HitEffectInterval)
            {
                hitEffects.Add(p.HitEffectPosition - size);
                p.HitEffectInterval = 0;
            }
        })
        .WithoutBurst()
        .Run();
    }
示例#37
0
        public void SerialiseTest()
        {
            BoardSetup a = new BoardSetup
            {
                Name = "a",
                Timer = null,
                Create = true,
                Disabled = false,
                Pages = 5,
                Repeat = true,
                SaveDirectory = @"C:\Temp\",
                Sleep = 20
            };

            BoardSetup b = new BoardSetup
            {
                Name = "b",
                Timer = new BoardTimer { Days = 0, Hours = 0, Minutes = 0, Seconds = 0, Disabled = true },
                Create = true,
                Disabled = false,
                Pages = 5,
                Repeat = true,
                SaveDirectory = @"C:\Temp\",
                Filter = new BoardThreadFilter { ImageCount = 3 },
                Sleep = 30
            };

            BoardSetup c = new BoardSetup
            {
                Name = "c",
                Timer = new BoardTimer { Days = 0, Hours = 0, Minutes = 0, Seconds = 0, Disabled = true },
                Create = true,
                Disabled = true,
                Pages = 10,
                Repeat = false,
                SaveDirectory = @"C:\Temp2\",
                Filter = new BoardThreadFilter { ImageCount = 10 },
                Sleep = 30
            };

            BoardSetup d = new BoardSetup
            {
                Name = "d",
                Timer = new BoardTimer { Days = 0, Hours = 0, Minutes = 20, Seconds = 0, Disabled = false },
                Create = false,
                Disabled = false,
                Pages = 5,
                Repeat = true,
                SaveDirectory = @"C:\Temp2\",
                Filter = new BoardThreadFilter { ImageCount = 3 },
                Sleep = 60
            };

            BoardSetup e = new BoardSetup
            {
                Name = "e",
                Timer = new BoardTimer { Days = 0, Hours = 0, Minutes = 20, Seconds = 0, Disabled = true },
                Create = false,
                Disabled = false,
                Pages = 15,
                Repeat = true,
                SaveDirectory = @"C:\Temp2\",
                Filter = new BoardThreadFilter { ImageCount = 3 },
                Sleep = 10
            };

            var config = new BoardConfig { Boards = new List<BoardSetup>() { a, b, c, d } };

            using (var writer = new StreamWriter(Environment.CurrentDirectory + "\\config.xml"))
            {
                new XmlSerializer(typeof(BoardConfig)).Serialize(writer, config);
            }

            using (var reader = new StreamReader(Environment.CurrentDirectory + "\\config.xml"))
            {
                object deserialize = new XmlSerializer(typeof(BoardConfig)).Deserialize(reader);

                config = deserialize as BoardConfig;

                Assert.NotNull(config);
            }

            foreach(var board in config.Boards)
            {
                Assert.NotNull(board.Timer);
            }
        }
示例#38
0
        // TODO make method less repetitive
        public static void generateBirdsChildren(ref BCTree<BoardConfig> parentNode, int lvl, Board Board)
        {
            //Console.Write("ParentNode Larva = " + GetScoreForPos(parentNode.data.LarvaPos));
            for (int i = 0; i < parentNode.data.BirdsPos.Length; ++i)
            {
                //Console.Write(", Bird " + (i + 1) + " = " + GetScoreForPos(parentNode.data.BirdsPos[i]));
            }
            //Console.WriteLine();

            Position bird1LeftPosition = new Position(parentNode.data.BirdsPos[0].Row - 1, parentNode.data.BirdsPos[0].Col - 1);
            if (Board.IsValidPosition(bird1LeftPosition) && parentNode.data.IsCellEmpty(bird1LeftPosition))
            {
                BoardConfig tempBC = new BoardConfig(parentNode.data);
                tempBC.Level = lvl;
                tempBC.BirdsPos[0] = bird1LeftPosition;
                parentNode.AddChild(tempBC);
                //Console.WriteLine("Bird 1 left position = " + GetScoreForPos(bird1LeftPosition));
            }

            Position bird1RightPosition = new Position(parentNode.data.BirdsPos[0].Row - 1, parentNode.data.BirdsPos[0].Col + 1);
            if (Board.IsValidPosition(bird1RightPosition) && parentNode.data.IsCellEmpty(bird1RightPosition))
            {
                BoardConfig tempBC = new BoardConfig(parentNode.data);
                tempBC.Level = lvl;
                tempBC.BirdsPos[0] = bird1RightPosition;
                parentNode.AddChild(tempBC);
                //Console.WriteLine("Bird 1 right position = " + GetScoreForPos(bird1RightPosition));
            }

            Position bird2LeftPosition = new Position(parentNode.data.BirdsPos[1].Row - 1, parentNode.data.BirdsPos[1].Col - 1);
            if (Board.IsValidPosition(bird2LeftPosition) && parentNode.data.IsCellEmpty(bird2LeftPosition))
            {
                BoardConfig tempBC = new BoardConfig(parentNode.data);
                tempBC.Level = lvl;
                tempBC.BirdsPos[1] = bird2LeftPosition;
                parentNode.AddChild(tempBC);
                //Console.WriteLine("Bird 2 left position = " + GetScoreForPos(bird2LeftPosition));
            }

            Position bird2RightPosition = new Position(parentNode.data.BirdsPos[1].Row - 1, parentNode.data.BirdsPos[1].Col + 1);
            if (Board.IsValidPosition(bird2RightPosition) && parentNode.data.IsCellEmpty(bird2RightPosition))
            {
                BoardConfig tempBC = new BoardConfig(parentNode.data);
                tempBC.Level = lvl;
                tempBC.BirdsPos[1] = bird2RightPosition;
                parentNode.AddChild(tempBC);
                //Console.WriteLine("Bird 2 right position = " + GetScoreForPos(bird2RightPosition));
            }

            Position bird3LeftPosition = new Position(parentNode.data.BirdsPos[2].Row - 1, parentNode.data.BirdsPos[2].Col - 1);
            if (Board.IsValidPosition(bird3LeftPosition) && parentNode.data.IsCellEmpty(bird3LeftPosition))
            {
                BoardConfig tempBC = new BoardConfig(parentNode.data);
                tempBC.Level = lvl;
                tempBC.BirdsPos[2] = bird3LeftPosition;
                parentNode.AddChild(tempBC);
                //Console.WriteLine("Bird 3 left position = " + GetScoreForPos(bird3LeftPosition));
            }

            Position bird3RightPosition = new Position(parentNode.data.BirdsPos[2].Row - 1, parentNode.data.BirdsPos[2].Col + 1);
            if (Board.IsValidPosition(bird3RightPosition) && parentNode.data.IsCellEmpty(bird3RightPosition))
            {
                BoardConfig tempBC = new BoardConfig(parentNode.data);
                tempBC.Level = lvl;
                tempBC.BirdsPos[2] = bird3RightPosition;
                parentNode.AddChild(tempBC);
                //Console.WriteLine("Bird 3 right position = " + GetScoreForPos(bird3RightPosition));
            }

            Position bird4LeftPosition = new Position(parentNode.data.BirdsPos[3].Row - 1, parentNode.data.BirdsPos[3].Col - 1);
            if (Board.IsValidPosition(bird4LeftPosition) && parentNode.data.IsCellEmpty(bird4LeftPosition))
            {
                BoardConfig tempBC = new BoardConfig(parentNode.data);
                tempBC.Level = lvl;
                tempBC.BirdsPos[3] = bird4LeftPosition;
                parentNode.AddChild(tempBC);
                //Console.WriteLine("Bird 4 left position = " + GetScoreForPos(bird4LeftPosition));
            }

            Position bird4RightPosition = new Position(parentNode.data.BirdsPos[3].Row - 1, parentNode.data.BirdsPos[3].Col + 1);
            if (Board.IsValidPosition(bird4RightPosition) && parentNode.data.IsCellEmpty(bird4RightPosition))
            {
                BoardConfig tempBC = new BoardConfig(parentNode.data);
                tempBC.Level = lvl;
                tempBC.BirdsPos[3] = bird4RightPosition;
                parentNode.AddChild(tempBC);
                //Console.WriteLine("Bird 4 right position = " + GetScoreForPos(bird4RightPosition));
            }
        }
示例#39
0
        public BoardConfig AIBirdsMove(Larva Larva, Bird[] Birds, Board Board)
        {
            // Get original positions
            Position origLarvaPosition = Larva.Pos;

            Position[] origBirdsPosition = new Position[Birds.Length];

            for (int i = 0; i < Birds.Length; ++i)
            {
                origBirdsPosition[i] = Birds[i].Pos;
            }

            BoardConfig origBC = new BoardConfig(0, origLarvaPosition, origBirdsPosition);

            BCTree<BoardConfig> MiniMaxTree = new BCTree<BoardConfig>(origBC);

            // Get level 1 kids for the Birds
            Utilities.generateBirdsChildren(ref MiniMaxTree, 1, Board);

            List<BCTree<BoardConfig>> level1Nodes = new List<BCTree<BoardConfig>>();
            Utilities.drill(MiniMaxTree, 0, 1, ref level1Nodes);
            //Console.WriteLine("Count of nodes at Level 1 given by drill method = " + level1Nodes.Count);

            // Get level 2 kids for the Larva
            for (int i = 0; i < level1Nodes.Count; ++i)
            {
                var temp = level1Nodes[i];
                Utilities.generateLarvaChildren(ref temp, 2, Board);
            }

            List<BCTree<BoardConfig>> level2Nodes = new List<BCTree<BoardConfig>>();
            Utilities.drill(MiniMaxTree, 0, 2, ref level2Nodes);
            //Console.WriteLine("Count of nodes at Level 2 given by drill method = " + level2Nodes.Count);

            // Get level 3 kids for the Birds
            for (int i = 0; i < level2Nodes.Count; ++i)
            {
                var temp = level2Nodes[i];
                Utilities.generateBirdsChildren(ref temp, 3, Board);
            }

            List<BCTree<BoardConfig>> level3Nodes = new List<BCTree<BoardConfig>>();
            Utilities.drill(MiniMaxTree, 0, 3, ref level3Nodes);
            //Console.WriteLine("Count of nodes at Level 3 given by drill method = " + level3Nodes.Count);

            //Console.WriteLine("Calculating level 3 heuristics...");
            Utilities.calculateLevelHeuristics(ref level3Nodes);

            for (int i = 0; i < level3Nodes.Count; i++)
            {
                //Console.WriteLine(i + " " + level3Nodes[i].data.heuristic);
            }

            //Console.WriteLine("Calculating level 2 heuristics...");
            Utilities.calculateLevelHeuristics(ref level2Nodes);

            for (int i = 0; i < level2Nodes.Count; i++)
            {
                //Console.WriteLine(i + " " + level2Nodes[i].data.heuristic);
            }

            //Console.WriteLine("Calculating level 1 heuristics...");
            Utilities.calculateLevelHeuristics(ref level1Nodes);

            for (int i = 0; i < level1Nodes.Count; i++)
            {
                //Console.WriteLine(i + " " + level1Nodes[i].data.heuristic);
            }

            Console.WriteLine();
            Console.Write("Current Positions - Larva = " + Utilities.GetScoreForPos(MiniMaxTree.data.LarvaPos));
            for (int i = 0; i < MiniMaxTree.data.BirdsPos.Length; ++i)
            {
                Console.Write(", Bird " + (i + 1) + " = " + Utilities.GetScoreForPos(MiniMaxTree.data.BirdsPos[i]));
            }
            Console.WriteLine();
            Console.WriteLine("Calculating best move for Birds...");
            BoardConfig nextConfig = Utilities.getBestMove(level1Nodes, ref MiniMaxTree, false);
            int birdToMove = getBirdToMove(nextConfig, origBC);
            Position nextBirdPosition = nextConfig.BirdsPos[birdToMove];

            Utilities.PreOrderPrintBirds(MiniMaxTree);

            Console.WriteLine("The best next move for the Birds is for Bird " + (birdToMove + 1) + " to go to position " + Utilities.GetScoreForPos(nextBirdPosition));
            Console.WriteLine();

            return nextConfig;
        }
示例#40
0
        // TODO make method less repetitive
        public static void generateLarvaChildren(ref BCTree<BoardConfig> parentNode, int lvl, Board Board)
        {
            //Console.Write("ParentNode Larva = " + GetScoreForPos(parentNode.data.LarvaPos));
            for (int i = 0; i < parentNode.data.BirdsPos.Length; ++i)
            {
                //Console.Write(", Bird " + (i + 1) + " = " + GetScoreForPos(parentNode.data.BirdsPos[i]));
            }
            //Console.WriteLine();

            Position topLeftPosition = new Position(parentNode.data.LarvaPos.Row - 1, parentNode.data.LarvaPos.Col - 1);
            if (Board.IsValidPosition(topLeftPosition) && parentNode.data.IsCellEmpty(topLeftPosition))
            {
                BoardConfig tempBC = new BoardConfig(parentNode.data);
                tempBC.Level = lvl;
                tempBC.LarvaPos = topLeftPosition;
                parentNode.AddChild(tempBC);
                //Console.WriteLine("Top left position = " + GetScoreForPos(topLeftPosition));
            }

            Position topRightPosition = new Position(parentNode.data.LarvaPos.Row - 1, parentNode.data.LarvaPos.Col + 1);
            if (Board.IsValidPosition(topRightPosition) && parentNode.data.IsCellEmpty(topRightPosition))
            {
                BoardConfig tempBC = new BoardConfig(parentNode.data);
                tempBC.Level = lvl;
                tempBC.LarvaPos = topRightPosition;
                parentNode.AddChild(tempBC);
                //Console.WriteLine("Top right position = " + GetScoreForPos(topRightPosition));
            }

            Position bottomLeftPosition = new Position(parentNode.data.LarvaPos.Row + 1, parentNode.data.LarvaPos.Col - 1);
            if (Board.IsValidPosition(bottomLeftPosition) && parentNode.data.IsCellEmpty(bottomLeftPosition))
            {
                BoardConfig tempBC = new BoardConfig(parentNode.data);
                tempBC.Level = lvl;
                tempBC.LarvaPos = bottomLeftPosition;
                parentNode.AddChild(tempBC);
                //Console.WriteLine("Bottom left position = " + GetScoreForPos(bottomLeftPosition));
            }

            Position bottomRightPosition = new Position(parentNode.data.LarvaPos.Row + 1, parentNode.data.LarvaPos.Col + 1);
            if (Board.IsValidPosition(bottomRightPosition) && parentNode.data.IsCellEmpty(bottomRightPosition))
            {
                BoardConfig tempBC = new BoardConfig(parentNode.data);
                tempBC.Level = lvl;
                tempBC.LarvaPos = bottomRightPosition;
                parentNode.AddChild(tempBC);
                //Console.WriteLine("Bottom right position = " + GetScoreForPos(bottomRightPosition));
            }
        }
示例#41
0
 private int getBirdToMove(BoardConfig nextConfig, BoardConfig origBC)
 {
     for (int i = 0; i < nextConfig.BirdsPos.Length; ++i)
     {
         if (!(origBC.BirdsPos[i].Equals(nextConfig.BirdsPos[i])))
         {
             return i;
         }
     }
     return -1;
 }
示例#42
0
 public static BoardConfig getBestMove(List<BCTree<BoardConfig>> level1Nodes, ref BCTree<BoardConfig> rootNode, bool larva)
 {
     // Calculate MAX of children and place it in root, as well as return Board Configuration of MAX child
     if (rootNode.isLeaf)
     {
         BoardConfig tempBC = new BoardConfig(rootNode.data);
         int tempHeuristic = rootNode.data.EvaluateBCHeuristic();
         tempBC.heuristic = tempHeuristic;
         rootNode.data = tempBC;
         //Console.WriteLine("Root is a leaf");
         return rootNode.data;
     }
     else
     {
         BoardConfig tempBC = new BoardConfig(rootNode.data);
         int MAXHeuristic = rootNode.children[0].data.heuristic;
         BoardConfig MAXConfig = rootNode.children[0].data;
         for (int i = 1; i < rootNode.children.Count; ++i)
         {
             if (larva)
             {
                 if (rootNode.children[i].data.heuristic > MAXHeuristic)
                 {
                     MAXHeuristic = rootNode.children[i].data.heuristic;
                     MAXConfig = rootNode.children[i].data;
                 }
             }
             else
             {
                 if (rootNode.children[i].data.heuristic < MAXHeuristic)
                 {
                     MAXHeuristic = rootNode.children[i].data.heuristic;
                     MAXConfig = rootNode.children[i].data;
                 }
             }
         }
         rootNode.data = MAXConfig;
         return MAXConfig;
     }
 }