예제 #1
0
        public override Move Move(Virus percept)
        {
            VirusBoard currentState = percept.GetBoardCopy();

            Move[] actions = currentState.GetPossibleMoves(playerNumber);
            Move   action  = actions[0];

            double max = double.NegativeInfinity;

            foreach (Move a in actions)
            {
                VirusBoard newState = currentState.GetUpdated(a);
                double     q        = 0;
                if (Q.ContainsKey(currentState.CustomHash()))
                {
                    if (Q[currentState.CustomHash()].ContainsKey(a.CustomHash()))
                    {
                        q = Q[currentState.CustomHash()][a.CustomHash()];
                    }
                }
                q += MinValue(newState, 0);
                if (q > max)
                {
                    max    = q;
                    action = a;
                }
                if (max == 1)
                {
                    break;
                }
            }

            return(action);
        }
예제 #2
0
        public override Move Move(Virus percept)
        {
            //Stopwatch watch = new Stopwatch();
            //watch.Start();
            VirusBoard currentState = percept.GetBoardCopy();

            Move[] actions = currentState.GetPossibleMoves(playerNumber);
            Move   action  = actions[0];

            double max = double.NegativeInfinity;

            foreach (Move a in actions)
            {
                VirusBoard newState = currentState.GetUpdated(a);
                double     q        = Utility(currentState, newState);
                q += MinValue(newState, 0);
                if (q > max)
                {
                    max    = q;
                    action = a;
                }
                if (max == double.PositiveInfinity)
                {
                    break;
                }
            }
            //watch.Stop();

            //StreamWriter timeWriter = new StreamWriter("mmTimeLog",true);
            //timeWriter.WriteLine(watch.ElapsedMilliseconds); // + " ; " + watch.ElapsedTicks);
            //timeWriter.Close();
            return(action);
        }
예제 #3
0
        //Calc maxValue
        private double MaxValue(VirusBoard state, int iteration)
        {
            iteration++;
            if (state.winner == playerNumber)
            {
                return(double.PositiveInfinity);
            }
            if (state.winner != playerNumber && state.winner != 0)
            {
                return(double.NegativeInfinity);
            }

            if (iteration < searchLength)
            {
                Move[] actions = state.GetPossibleMoves(playerNumber);

                double max = double.NegativeInfinity;
                foreach (Move a in actions)
                {
                    VirusBoard newState = state.GetUpdated(a);

                    double q = Utility(state, newState);
                    if (Q.ContainsKey(state.CustomHash()))
                    {
                        if (Q[state.CustomHash()].ContainsKey(a.CustomHash()))
                        {
                            q = Q[state.CustomHash()][a.CustomHash()];
                        }
                    }

                    q += MinValue(newState, iteration);
                    if (q > max)
                    {
                        max = q;
                    }
                    if (max == double.PositiveInfinity)
                    {
                        return(max);
                    }
                }

                return(max);
            }
            else
            {
                return(0);
            }
        }
예제 #4
0
        // Calc minValue
        private double MinValue(VirusBoard state, int iteration)
        {
            iteration++;
            if (state.winner == playerNumber)
            {
                return(double.PositiveInfinity);
            }
            if (state.winner != playerNumber && state.winner != 0)
            {
                return(double.NegativeInfinity);
            }

            if (iteration < searchLength)
            {
                byte   opponent = (playerNumber == 1) ? (byte)2 : (byte)1;
                Move[] actions  = state.GetPossibleMoves(opponent);

                double min = double.PositiveInfinity;
                foreach (Move a in actions)
                {
                    VirusBoard newState = state.GetUpdated(a);
                    double     q        = Utility(state, newState);
                    q += MaxValue(newState, iteration);
                    if (q < min)
                    {
                        min = q;
                    }
                    if (min == double.NegativeInfinity)
                    {
                        return(min);
                    }
                }

                return(min);
            }
            else
            {
                return(0);
            }
        }