Exemplo n.º 1
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            while (((gamenode.ActivePlayer == 0 && checkBox0.Checked) || (gamenode.ActivePlayer == 1 && checkBox1.Checked)) && gamenode.GameInProgress())
            {
                Draw("Thinking...");
                int move = gamenode.PickNextMove((int)numericUpDown1.Value);
                gamenode = gamenode.DoMove(move) as ReversiNode;
                Thread.Sleep(10);
            }
            string msg = "Your turn";

            if (!gamenode.GameInProgress())
            {
                switch (gamenode.Winner())
                {
                case 0:
                    msg = "White wins";
                    break;

                case 1:
                    msg = "Black wins";
                    break;

                default:
                    msg = "It's a tie";
                    break;
                }
            }
            Draw(msg);
        }
Exemplo n.º 2
0
 private void panel1_MouseClick(object sender, MouseEventArgs e)
 {
     if (!gamenode.GameInProgress())
     {
         NewGame();
         return;
     }
     if ((gamenode.ActivePlayer == 0 && !checkBox0.Checked) || (gamenode.ActivePlayer == 1 && !checkBox1.Checked))
     {
         int x = ReversiNode.size * e.Location.X / panel1.Width;
         int y = ReversiNode.size * e.Location.Y / panel1.Height;
         y = ReversiNode.size - 1 - y;
         int move = ReversiNode.size * x + y;
         if (!gamenode.MoveIsLegal(move))
         {
             return;
         }
         gamenode = gamenode.DoMove(move) as ReversiNode;
         backgroundWorker1.RunWorkerAsync();
     }
 }