Ejemplo n.º 1
0
 public static int NextStep(State CurrentState)
 {
     if (CurrentState.Child.Count == 1)
     {
         return(0);                              //no next step to go
     }
     else
     {
         int CurrentMaxScore = 5000;
         int BestChild       = -1;
         for (int i = 1; i < CurrentState.Child.Count; i++)
         {
             int MaxScoreGet = GetMaxScore(CurrentState.Child[i]);
             if (MaxScoreGet < CurrentMaxScore)//better because enemy get smaller score
             {
                 BestChild = i;
             }
             else if (MaxScoreGet == CurrentMaxScore)                                                                                                                     //Two steps will result in enemy get same max score
             {
                 if (Alg_1.GetScore(CurrentState.NextPlayer, CurrentState.Child[i].Board) > Alg_1.GetScore(CurrentState.NextPlayer, CurrentState.Child[BestChild].Board)) //Better if it self get higher score
                 {
                     BestChild = i;
                 }
             }
         }
         return(BestChild);
     }
 }
Ejemplo n.º 2
0
        private int Play(int numReceived)
        {
            NextStateGet = true;
            int AssumeChild = 0;
            int nextMove    = 0;
            int total       = numReceived;
            int x           = total / 8;
            int y           = total % 8;

            //int y = Int32.Parse(textBox2.Text);
            Steps += 2;

            if (Steps != 4)
            {
                EnemyMatch(x, y);//global "Current" is the enemy's state now, update enemy state's board;
            }

            Current.GenerateChild();//Initialzie the states which self may put, the available position is also calculated

            if (Current.AvailablePosition[0].Count != 0)
            {
                for (int i = 1; i < Current.AvailablePosition[0].Count + 1; i++)
                {
                    Current.Child[i].GenerateChild();//Initialize all the enemy's state after each self state;
                }

                AssumeChild = Alg_1.NextStep(Current);
                nextMove    = Current.AvailablePosition[0][AssumeChild - 1] * 8 + Current.AvailablePosition[1][AssumeChild - 1];
            }
            else
            {
                Current.Child[0].GenerateChild();
                AssumeChild = 0;
                nextMove    = 64;
            }
            Current = Current.Child[AssumeChild];

            NextStateGet = false;

            UpdateChessBoard(Current);

            return(nextMove);
        }
Ejemplo n.º 3
0
        private void ProcessNext()
        {
            int total = Int32.Parse(textBox1.Text);
            int x     = total / 8;
            int y     = total % 8;

            //int y = Int32.Parse(textBox2.Text);
            Steps += 2;
            int AssumeChild = 0;
            int nextMove    = 0;

            if (Steps != 4)
            {
                EnemyMatch(x, y);//global "Current" is the enemy's state now, update enemy state's board;
            }

            Current.GenerateChild();//Initialzie the states which self may put, the available position is also calculated

            if (Current.AvailablePosition[0].Count != 0)
            {
                for (int i = 1; i < Current.AvailablePosition[0].Count + 1; i++)
                {
                    Current.Child[i].GenerateChild();//Initialize all the enemy's state after each self state;
                }

                AssumeChild = Alg_1.NextStep(Current);
                nextMove    = Current.AvailablePosition[0][AssumeChild - 1] * 8 + Current.AvailablePosition[1][AssumeChild - 1];
            }
            else
            {
                Current.Child[0].GenerateChild();
                AssumeChild = 0;
                nextMove    = 64;
                MessageBox.Show("I have no way to go");
                //Do not need to update the state;
            }
            Current = Current.Child[AssumeChild];

            NextStateGet = false;

            UpdateChessBoard(Current);
        }