Ejemplo 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);
        }
Ejemplo n.º 2
0
        public override Node GetNextState(int move)
        {
            int x = move / size;
            int y = move % size;

            int[,] nextBoard = (int[, ])board.Clone();
            PerformFlipsIfLegal(x, y, 1, 0, nextBoard);
            PerformFlipsIfLegal(x, y, 1, 1, nextBoard);
            PerformFlipsIfLegal(x, y, 0, 1, nextBoard);
            PerformFlipsIfLegal(x, y, -1, 1, nextBoard);
            PerformFlipsIfLegal(x, y, -1, 0, nextBoard);
            PerformFlipsIfLegal(x, y, -1, -1, nextBoard);
            PerformFlipsIfLegal(x, y, 0, -1, nextBoard);
            PerformFlipsIfLegal(x, y, 1, -1, nextBoard);
            ReversiNode nextState = new ReversiNode(nextBoard, 1 - ActivePlayer);

            if (nextState.HasLegalMove())
            {
                return(nextState);
            }
            ReversiNode alternateNextState = new ReversiNode(nextBoard, ActivePlayer);

            if (alternateNextState.HasLegalMove())
            {
                return(alternateNextState);
            }
            return(nextState);
        }
Ejemplo n.º 3
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();
     }
 }
Ejemplo n.º 4
0
 void NewGame()
 {
     gamenode = new ReversiNode();
     Draw("New game");
 }