コード例 #1
0
ファイル: CellAutomataGA.cs プロジェクト: TNK2718/SWARM2
 // 評価をする
 public void Evaluate()
 {
     Parallel.For(0, POPULATION, i => {
         CellAutomataGame cellAutomataGame = new CellAutomataGame(
             intArrayChromosomes.ReadChromosomeAsRule(i), rulesForEvalate, boardSize, INITIAL_RESOURCES);
         cellAutomataGame.InitializeBoards();
         for (int n = 0; n < EPISODES_FOR_EVALATION; n++)
         {
             cellAutomataGame.UpdateGameBoard();
         }
         intArrayChromosomes.SetScore(i, EvaluateFunction(cellAutomataGame));
     });
 }
コード例 #2
0
 public void Evaluate()
 {
     for (int i = 0; i < POPULATION; i++)
     {
         CellAutomataGame cellAutomataGame = new CellAutomataGame(intArrayChromosomes.ReadChromosomeAsRule(i), rulesForEvalate);
         cellAutomataGame.InitializeBoards();
         for (int n = 0; n < EPISODESFOREVALATION; n++)
         {
             cellAutomataGame.UpdateGameBoard();
         }
         scores[i] = EvaluateFunction(cellAutomataGame);
     }
 }
コード例 #3
0
        private double EvaluateFunction(CellAutomataGame cellAutomataGame)
        {
            double score = 0;

            for (int x = 0; x < cellAutomataGame.BOARDSIZE; x++)
            {
                for (int y = 0; y < cellAutomataGame.BOARDSIZE; y++)
                {
                    score += cellAutomataGame.board2.GetCell(cellAutomataGame.board2.board, x, y);
                }
            }
            score = (cellAutomataGame.BOARDSIZE * cellAutomataGame.BOARDSIZE - score) / (cellAutomataGame.BOARDSIZE * cellAutomataGame.BOARDSIZE);
            score = score * score;
            return(score);
        }
コード例 #4
0
ファイル: CellAutomataGA.cs プロジェクト: TNK2718/SWARM2
        // 評価関数
        private double EvaluateFunction(CellAutomataGame cellAutomataGame)
        {
            double score1 = 0;
            double score2 = 0;

            for (int x = 0; x < cellAutomataGame.boardSize; x++)
            {
                for (int y = 0; y < cellAutomataGame.boardSize; y++)
                {
                    if (cellAutomataGame.myCellGrid.GetCell(true, x, y) != 0)
                    {
                        score1++;
                    }
                    score2 += cellAutomataGame.enemyCellGrid.GetCell(true, x, y);
                }
            }
            return(Math.Abs(score1 / Math.Pow(cellAutomataGame.boardSize, 2) / score2));
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: TNK2718/CellAutomataGA
        static void Main(string[] args)
        {
            CellAutomataGA cellAutomataGA = new CellAutomataGA();

            for (int i = 0; i < 50; i++)
            {
                cellAutomataGA.NextGeneration();
                Console.Write("Episode:");
                Console.WriteLine(i);
                cellAutomataGA.ShowScores();
                cellAutomataGA.ShowEliteScores();
            }
            Console.ReadLine();
            CellAutomataGame cellAutomataGame = new CellAutomataGame(cellAutomataGA.EliteRule(), cellAutomataGA.rulesForEvalate);

            cellAutomataGame.InitializeBoards();
            for (int i = 0; i < 100; i++)
            {
                cellAutomataGame.Draw();
                cellAutomataGame.UpdateGameBoard();
            }
            Console.Read();
        }