Exemplo n.º 1
0
        public void step_x(List <float> x, int index)
        {
            info.WriteLine("Ход x: " + index);

            if (net.neurons.Count <= 0)
            {
                int i = game.setRandom(GUI.TYPE_STEP.O);
                info.WriteLine("Ход o: " + i);
                info.WriteLine("Нейрон не активен");
            }
            else
            {
                int     o_index = net.Recognize(x, info.listBox);
                Boolean b_rect  = game.CheckRect(o_index);

                if (b_rect)
                {
                    info.WriteLine("Ход о: " + o_index);
                    game.setO(o_index);
                    info.WriteLine("Нейрон активен");
                }
                else if (!b_rect)
                {
                    int i = game.setRandom(GUI.TYPE_STEP.O);
                    info.WriteLine("Ход o: " + i);
                    info.WriteLine("Нейрон не активен");
                }
            }
        }
Exemplo n.º 2
0
        private void timer_Tick(object sender, EventArgs e)
        {
            form.Text = "Tic-Tac-Toe Round[" + game.count_round + "] X[" + game.count_win_x + "] O[" + game.count_win_o + "] N[" + net.neurons.Count + "]";
            count_step++;

            if (count_step >= 9)
            {
                count_step = 0;
                game.Clear();
                game.count_round++;
            }
            else
            {
                int index = 0;

                if (game.present_step == TYPE_STEP.X)
                {
                    index = game.setRandom(TYPE_STEP.X);
                }
                else if (game.present_step == TYPE_STEP.O)
                {
                    index = net.Recognize(game.getVectorX(), info.listBox);

                    if (game.CheckRect(index))
                    {
                        game.setO(index);
                        info.WriteLine("Нейрон активирован");
                    }
                    else
                    {
                        index = game.setRandom(TYPE_STEP.O);
                        info.WriteLine("Нейрон активирован");
                    }
                }

                mHistory.add(game.getTableConvertHistory(), index, game.getVectorX());

                if (game.CheckWinX())
                {
                    count_step = 0;
                    info.WriteLine("Победил X!");
                    win_x();

                    game.count_win_x++;
                    game.Clear();
                    mHistory.Clear();
                    game.present_step = TYPE_STEP.X;
                }
                else if (game.CheckWinO())
                {
                    count_step = 0;
                    info.WriteLine("Победил O!");
                    win_o();

                    game.count_win_o++;
                    game.Clear();
                    mHistory.Clear();
                    game.present_step = TYPE_STEP.X;
                }
                else if (game.CheckNoWin())
                {
                    count_step = 0;
                    info.WriteLine("Ничья!");
                    win_x();
                    game.Clear();
                    game.count_no_win++;
                    mHistory.Clear();
                    game.present_step = TYPE_STEP.X;
                }

                if (info.listBox.Items.Count >= 5000)
                {
                    info.listBox.Items.Clear();
                }
            }
        }