示例#1
0
文件: Program.cs 项目: mipo47/Monster
        void PrintCellArea(CellArea cellArea)
        {
            Console.SetCursorPosition(0, 0);
            Console.Write("   ");
            for (int w = 0; w < cellArea.Width; w++)
            {
                Console.Write(w % 10);
            }
            Console.WriteLine();

            var top = cellArea.Monsters.OrderBy(m => - m.Energy).ToList();

            for (int h = 0; h < cellArea.Height; h++)
            {
                Console.Write(h);
                Console.Write(' ');
                if (h < 10)
                {
                    Console.Write(' ');
                }

                for (int w = 0; w < cellArea.Width; w++)
                {
                    Cell cell = cellArea.GetCellAt(w, h);
                    switch (cell.ContentType)
                    {
                    case ContentType.Empty:
                        Console.Write('.');
                        break;

                    case ContentType.Food:
                        Console.Write('+');
                        break;

                    case ContentType.Monster:
                        int place = top.IndexOf(cell.Content as IMonster);
                        if (place >= 10)
                        {
                            Console.Write('M');
                        }
                        else
                        {
                            Console.Write(place);
                        }
                        break;

                    case ContentType.Wall:
                        Console.Write('#');
                        break;
                    }
                }
                Console.WriteLine();
            }

            foreach (IMonster monster in top.Take(32))
            {
                Console.WriteLine(monster.AreaInfo + ": " + monster.Energy.ToString("f1") + "               ");
            }
            Console.Out.Flush();
        }
示例#2
0
        public void NextStep()
        {
            StepInfo stepInfo = area.NextStep();

            foreach (Cell cell in stepInfo.ChangedCells)
            {
                if (!rectangles.ContainsKey(cell))
                {
                    continue;
                }

                Rectangle rectangle = rectangles[cell];
                Cell      realCell  = area.GetCellAt(cell.AreaInfo);
                if (rectangle != null)
                {
                    RefreshRectangle(rectangle, realCell);
                }
            }
        }
示例#3
0
        void timer_Tick(object sender, EventArgs e)
        {
            //int stepCount = MainArea.Area.Monsters.Count;
            //if (stepCount == 0)
            //    stepCount = 1;

            if (checkBoxEvolution.IsChecked == true)
            {
                MainArea.MultiStep(200);
            }
            else
            {
                MainArea.NextStep();
            }

            CellArea area       = MainArea.Area;
            double   usedEnergy = 0;
            double   mEnergy    = 0;
            double   fEnergy    = 0;

            for (int x = 0; x < area.Width; x++)
            {
                for (int y = 0; y < area.Height; y++)
                {
                    Cell cell = area.GetCellAt(x, y);
                    if (cell.ContentType == ContentType.Food)
                    {
                        usedEnergy += CellArea.FOOD_ENERGY;
                        fEnergy    += CellArea.FOOD_ENERGY;
                    }
                    else if (cell.ContentType == ContentType.Monster)
                    {
                        IMonster monster = (IMonster)cell.Content;
                        usedEnergy += monster.Energy;
                        mEnergy    += monster.Energy;
                    }
                }
            }

            if (area.Monsters.Count > 0)
            {
                double   avgEnergy   = mEnergy / area.Monsters.Count;
                double   best        = area.Monsters.Max(m => m.Energy);
                IMonster bestMonster = area.Monsters.First(m => m.Energy == best);
                int      bestMemory  = bestMonster.Brain.Genome.BrainStructure.TypeID;

                double perf = 100.0 * mEnergy / area.TotalEnergy;

                int      oldest        = area.Monsters.Max(m => m.Age);
                IMonster oldestMonster = area.Monsters.First(m => m.Age == oldest);
                int      oldestMemory  = oldestMonster.Brain.Genome.BrainStructure.TypeID;
                Title = string.Format("{0:f0} : {1:f1} ; {2:f2} / {3:f1} - {4} |{5}|{6} ; {7:f0}", area.TotalEnergy, perf, avgEnergy, best, oldest, oldestMemory, bestMemory, sliderEvolution.Value);

                if (checkBoxEvolution.IsChecked == true)
                {
                    double aimPerf = sliderEvolution.Value;
                    if (perf > aimPerf || 4000.0 - MainArea.TotalEnergy >= aimPerf - perf)
                    {
                        MainArea.TotalEnergy -= perf - aimPerf;
                    }
                }
            }
        }