コード例 #1
0
ファイル: MainForm.cs プロジェクト: red81/asteroids_ai
        private void CalcNextShipState(int turnNumber, ShipState ss)
        {
            if (turnNumber == calcTurn)
            {
                ShipState putss = ShipState.getFromPool();
                putss.set(ss);
                all_combinations.Add(putss);
                return;
            }
            ShipState newss = ShipState.getFromPool();

            for (int thr = 0; thr <= divThrust; thr++)
            {
                for (int tur = 0; tur <= divTurn; tur++)
                {
                    newss.set(ss);
                    newss.move(thr * maxThrust / divThrust, tur * (2 * maxTurn) / divTurn - maxTurn);
                    CalcNextShipState(turnNumber + 1, newss);
                }
            }
            newss.putToPool();
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: red81/asteroids_ai
        private void CalcAllShipStates(int turnNumber, Node <ShipState> parentNode)
        {
            allNodesNumber++;

            for (int thr = 0; thr <= divThrust; thr++)
            {
                for (int tur = 0; tur <= divTurn; tur++)
                {
                    ShipState newss = ShipState.getFromPool();
                    newss.set(parentNode.value);
                    newss.move(thr * maxThrust / divThrust, tur * (2 * maxTurn) / divTurn - maxTurn);
                    Node <ShipState> newnode = new Node <ShipState>(newss, parentNode);
                    if (turnNumber + 1 == calcTurn)
                    {
                        allNodesNumber++;
                    }
                    else
                    {
                        CalcAllShipStates(turnNumber + 1, newnode);
                    }
                }
            }
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: red81/asteroids_ai
        private void drawBackBuffer()
        {
            if (_backBuffer != null &&
                (_backBuffer.Width != panel1.ClientSize.Width ||
                 _backBuffer.Height != panel1.ClientSize.Height)
                )
            {
                _backBuffer.Dispose();
                _backBuffer = null;
            }
            if (_backBuffer == null)
            {
                _backBuffer = new Bitmap(panel1.ClientSize.Width, panel1.ClientSize.Height);
            }

            Graphics gr = Graphics.FromImage(_backBuffer);

            prepareGraphics(gr);
            cleanLists();
            DateTime startTime = DateTime.Now;

            rootNode       = new Node <ShipState>(ShipState.getFromPool());
            allNodesNumber = 0;
            CalcAllShipStates(0, rootNode);
            TimeSpan deltaTime = DateTime.Now.Subtract(startTime);

            //CalcNextShipState(0, ShipState.getFromPool());

            //int comb_count = all_combinations.Count;

            //if(true)
            //{
            //    ShipState ssNext = ShipState.getFromPool();
            //    foreach (ShipState ss in all_combinations)
            //    {
            //        ssNext.set(ss);
            //        ssNext.move(0,0);
            //        gr.DrawLine(Pens.Green,
            //            (int)(ss.xpos * 50), (int)(ss.ypos * 50),
            //            (int)(ssNext.xpos * 50), (int)(ssNext.ypos * 50));

            //    }
            //    ssNext.putToPool();
            //}
            //foreach (ShipState ss in all_combinations)
            //{
            //    gr.FillRectangle(Brushes.White, (int)(ss.xpos * scale), (int)(ss.ypos * scale), 1, 1);
            //}
            drawGraphics = gr;

            for (drawTurn = calcTurn; drawTurn >= 1; drawTurn--)
            {
                Color color = Color.FromArgb(50, 50, 50);
                if (drawTurn - 1 < colors.Count)
                {
                    color = colors[drawTurn - 1];
                }
                drawBrush = new SolidBrush(color);
                DrawShipsForTurn(0, rootNode);
            }

            gr.Dispose();

            label7.Text  = Convert.ToString(allNodesNumber);
            label14.Text = "?";
            label9.Text  = Convert.ToString((int)deltaTime.TotalMilliseconds);
        }