コード例 #1
0
ファイル: Form1.cs プロジェクト: Vuducvi1999/Othello_AI
        private void button5_Click(object sender, EventArgs e)
        {
            count_time_1 = 21000;
            count_time_2 = 21000;
            RandomGame();

            {
                Undo.Push(board.Copy());

                Save_Board.RemoveRange(Count, Save_Board.Count - Count);
                Save_Point.RemoveRange(Count, Save_Point.Count - Count);
                Count = Save_Board.Count;

                //nước đi của máy
                {
                    board.Draw(panel1, IsDrawHelp, Board.WHITE);
                    EvCompStep.BeginInvoke(new AsyncCallback(EndCompStep), null); // phương thức không đồng bộ
                    ShowPoints();

                    //toolStripStatusLabel1.Text = "Tới lượt máy";
                    label26.Text = "Lượt Máy";

                    panelColor.BackColor        = Color.White;
                    toolStripProgressBar1.Style = ProgressBarStyle.Marquee;
                    toolStripProgressBar1.MarqueeAnimationSpeed = (int)numericUpDown1.Value * 10;
                }
                int      m        = listView1.Items.Count + 1;
                string[] stritems = { m.ToString(), "Đen", Convert.ToChar(65) + (1).ToString() };

                ListViewItem newitem = new ListViewItem(stritems);
                listView1.Items.Add(newitem);
                listView1.EnsureVisible(m - 1);// scroll list view xuống dưới
                listView1.Items[m - 1].Selected = true;
                for (int i = 0; i < m - 1; i++)
                {
                    listView1.Items[i].Selected = false;
                }
            }

            Invoke(new EnableTimerDelegate(EnableTimer), false);
            /////////////////////////////////////////////
            //Save_Board.Clear();
            //Save_Point.Clear();
            //Save_View.Clear();
            //Count = 0;
            /////////////////////////////////////////////////
            Undo_Point.Push(new tuple(-1, -1));
            Save_Board.Add(board.Copy());
            Save_Point.Add(new tuple(-1, -1));
            Count = 1;
            ///////////////////////////////////////////////
            checkBox1.Enabled = true;
            checkBox1.Checked = true;
            board.Draw(panel1, IsDrawHelp, Board.BLACK);
            listView1.Items.Clear();
            label1.Text            = "3";
            label2.Text            = "3";
            numericUpDown1.Enabled = false;
            started         = true;
            button5.Enabled = false;

            //toolStripStatusLabel1.Text = "Tới lượt bạn";
            toolStripStatusLabel1.Text = "Limit: 35 phút";
            label26.Text = "Lượt Bạn";
            toolStripProgressBar1.Style = ProgressBarStyle.Marquee;
            panelColor.BackColor        = Color.Black;
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: Vuducvi1999/Othello_AI
        /// <summary>
        /// Thực hiện nước đi của người
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void panel1_MouseClick(object sender, MouseEventArgs e)
        {
            if (started)
            {
                numericUpDown1.Enabled = false;

                if (flag)
                {
                    return;
                }
                Undo.Push(board.Copy());

                int x = e.X / Board.WIDTH;
                int y = e.Y / Board.WIDTH;

                if (helped == 1)
                {
                    //Save_Board.Clear();
                    //Save_Point.Clear();
                    //Save_View.Clear(); // Save_View không quan trọng !
                    //Count = 0;
                    //Save_Board.Add(board.Copy());
                    //Save_Point.Add(new tuple(board.X_Pre, board.Y_Pre));
                    //Count = 1;
                    Save_Board.RemoveRange(Count, Save_Board.Count - Count);
                    Save_Point.RemoveRange(Count, Save_Point.Count - Count);
                    Count = Save_Board.Count;
                }
                helped = 0;

                if (board.Move(x, y, Board.BLACK, true) > 0)
                {
                    flag        = true;
                    bugcuoicung = 0;
                    //nước đi của máy
                    {
                        board.X_Pre = x;
                        board.Y_Pre = y;

                        board.Draw(panel1, IsDrawHelp, Board.WHITE);
                        EvCompStep.BeginInvoke(new AsyncCallback(EndCompStep), null); // phương thức không đồng bộ
                        ShowPoints();

                        //toolStripStatusLabel1.Text = "Tới lượt máy";
                        label26.Text = "Lượt Máy";

                        panelColor.BackColor        = Color.White;
                        toolStripProgressBar1.Style = ProgressBarStyle.Marquee;
                        toolStripProgressBar1.MarqueeAnimationSpeed = (int)numericUpDown1.Value * 10;
                    }
                }
                else
                {
                    if (IsDrawHelp && (board.WhiteCount + board.BlackCount) < 64 && bugcuoicung == 0)
                    {
                        Invoke(new ShowMessageDelegate(ShowMessage), "           # Đi sai nước.\n ~ Hãy đi vào ô sáng màu ~", "Đi sai nước"
                               , MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        if ((board.WhiteCount + board.BlackCount) < 64 && bugcuoicung == 0)
                        {
                            Invoke(new ShowMessageDelegate(ShowMessage), "                 # Đi sai nước.\nHãy chọn chế độ xem nước đi hợp lệ !", "Đi sai nước"
                                   , MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    return;
                }

                int      m        = listView1.Items.Count + 1;
                string[] stritems = { m.ToString(), "Đen", Convert.ToChar(x + 65) + (y + 1).ToString() };

                ListViewItem newitem = new ListViewItem(stritems);
                listView1.Items.Add(newitem);
                listView1.EnsureVisible(m - 1);// scroll list view xuống dưới
                listView1.Items[m - 1].Selected = true;
                for (int i = 0; i < m - 1; i++)
                {
                    listView1.Items[i].Selected = false;
                }
            }
        }