Esempio n. 1
0
 protected State Expand(Board Game)
 {
     // maybe the next move
     int MoveId;
     // until the game ends play it
     while (Game.TestVictory() == State.empty)
     {
         List<int> ValidMoves = Game.GetValidMoves();
         MoveId = Rnd.Next(0, ValidMoves.Count - 1);
         Game.Move(ValidMoves[MoveId]);
     }
     // return the winner
     return Game.TestVictory();
 }
Esempio n. 2
0
        /// <summary>
        /// internal score of move
        /// </summary>
        /// <param name="Situation">current game situation</param>
        /// <param name="Move">move to do</param>
        /// <param name="deep">current deep</param>
        /// <returns>value of move</returns>
        protected float ScoreMove(Board Situation, int Move, int deep)
        {
            // game finished?
            State Result = Situation.TestVictory();
            // if game is finished ...
            if (Result != State.empty)
            {
                // is draw?
                if (Result == State.draw)
                    return 0.0f;
                // else return score 1.0f for winning and -1.0f for loosing
                return (Result == Situation.CurrentPlayer) ? 1f : -1f;
            }
            // cut deep
            if (deep == MAX_DEEP)
            {
                // adjust strength dynamically
                int S = Convert.ToInt32(Strength / ((double)Math.Pow(7, MAX_DEEP)));
                Scores.SetStrength(S);
                // Score Board due monte carlo
                return Scores.Evaluate(Situation, Move);

            }

            Situation.Move(Move);                                   // do move
            List<int> CandidateMoves = Situation.GetValidMoves();   // new situation, so new possible moves

            float val = float.MinValue;                             // temp alpha value

            foreach (int M in CandidateMoves)
            {
                val = Math.Max(val, -1f * ScoreMove(Situation, M, deep + 1)); // evaluate each move by recursion
            }

            Situation.UnMove(Move);                               // redo move
            return val;                                           // return value
        }