Exemplo n.º 1
0
        public List <Move> Stage1(FeaturesState s0, int nTroops)
        {
            List <Country> OwnedCountries = new List <Country>();

            FeaturesState currentSate = s0;
            FeaturesState movingState = s0;
            List <Move>   Moves       = new List <Move>();
            int           FreeTroops  = nTroops;

            for (int i = 0; i < nTroops; i++)
            {
                Move   bestMove = null;
                double maxScore = 0;
                foreach (Country c in OwnedCountries)
                {
                    Move m = new Move(null, c, 1);
                    currentSate = movingState;
                    FeaturesState tmpState = currentSate.Excecute(m);
                    if (NeuralNetwork.Score(tmpState) > maxScore)
                    {
                        maxScore = NeuralNetwork.Score(tmpState);
                        bestMove = m;
                    }
                }
                Moves.Add(bestMove);
                movingState.Excecute(bestMove);
            }
            return(Moves);
        }
Exemplo n.º 2
0
 public double Variation(FeaturesState s0, FeaturesState s1)
 {
     if (s1.isFinalState)
     {
         return((s1.Reward) - Score(s0));
     }
     if (s0.isFinalState)
     {
         throw new Exception("Not expected: *");
     }
     return(Score(s1) - Score(s0));
 }
Exemplo n.º 3
0
        public List <Move> AIStage23(FeaturesState s0, int stage)
        {
            // These come in some way
            List <Country> ownedCountries = new List <Country>();

            FeaturesState currentState = s0;
            FeaturesState movingState  = s0;

            bool        changed  = false;
            List <Move> Moves    = new List <Move>();
            double      maxScore = NeuralNetwork.Score(s0);

            do
            {
                Move bestMove = null;
                changed = false;
                foreach (Country c in ownedCountries)
                {
                    foreach (Country n in c.Vecinos)
                    {
                        bool condition = (stage == 2) ? (c.Owner != n.Owner) : (c.Owner == n.Owner);
                        if (condition)
                        {
                            for (int i = 1; i < c.Troops; i++)
                            {
                                Move m = new Move(c, n, i);
                                currentState = movingState;
                                FeaturesState tmpStat = currentState.Excecute(m);
                                if (NeuralNetwork.Score(tmpStat) > maxScore)
                                {
                                    maxScore = NeuralNetwork.Score(tmpStat);
                                    bestMove = m;
                                    changed  = true;
                                }
                            }
                        }
                    }
                }
                if (changed)
                {
                    if (bestMove != null)
                    {
                        Moves.Add(bestMove);
                        movingState.Excecute(bestMove);
                    }
                }
            } while (changed);

            return(Moves);
        }
Exemplo n.º 4
0
        public FeaturesState NextMove(FeaturesState state)
        {
            List <Country> OwnedCountries = new List <Country>(); // It comes from the call
            double         CurrentScore   = NeuralNetwork.Score(state);

            for (int i = 0; i < OwnedCountries.Count; i++)
            {
                for (int j = 0; j < OwnedCountries[i].Vecinos.Count; j++)
                {
                }
            }

            return(null);
        }
Exemplo n.º 5
0
 private double Variation(FeaturesState state, int v)
 {
     return(1 - Score(state));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Score given a set of weights x and a set containing game features
 /// </summary>
 /// <returns> Value between 0 and 1 </returns>
 public double Score(FeaturesState s)
 {
     return(MathUtilities.SigmoidFnc(MathUtilities.DotProduct(s.GetVector(), weights)));
 }
Exemplo n.º 7
0
        public FeaturesState[] LoadStates(string filePath)
        {
            List <FeaturesState> result = new List <FeaturesState>();

            string[] fileLines = File.ReadAllLines(filePath);
            for (int i = 1; i < fileLines.Length; i++)
            {
                string        currentLine = fileLines[i];
                string[]      fields      = currentLine.Split(',');
                FeaturesState s           = new FeaturesState(
                    double.Parse(fields[0]),    // New armies
                    double.Parse(fields[1]),    // Enemy new armies
                    double.Parse(fields[2]),    // Troops
                    double.Parse(fields[3]),    // Enemy troops
                    double.Parse(fields[4]),    // Clusters
                    double.Parse(fields[5]),    // Enemy clusters
                    double.Parse(fields[6]),    // Countries
                    double.Parse(fields[7]),    // Enemy Countries
                    double.Parse(fields[8]),    // Free countries
                    double.Parse(fields[9]),    // Bordering Countries
                    double.Parse(fields[10]),   // Nearby Enemies
                    double.Parse(fields[11]),   // Free Nearby Countries
                    double.Parse(fields[12]),   // Largest Cluster Troops
                    double.Parse(fields[13]),   // Largest Enemy Cluster Troops
                    double.Parse(fields[13]),   // Largest Cluster Countries
                    double.Parse(fields[14]),   // Largest Enemy Cluster Countries
                    double.Parse(fields[15]),   // Nearby-Actual1
                    double.Parse(fields[16]),   // Nearby-Actual2
                    double.Parse(fields[17]),   // Nearby-Actual3
                    double.Parse(fields[18]),   // Nearby-Acutal4
                    double.Parse(fields[19]),   // Nearby-Actual5
                    double.Parse(fields[20]),   // Nearby-Actual6
                    double.Parse(fields[21]),   // Nearby-Actual7
                    double.Parse(fields[22]),   // Nearby-Actual8
                    double.Parse(fields[23]),   // Nearby-Actual9
                    double.Parse(fields[24]),   // Nearby-Actual10
                    double.Parse(fields[25]),   // Nearby-Actual11
                    double.Parse(fields[26]),   // Nearby-Actual12
                    double.Parse(fields[27]),   // Nearby-Actual13
                    double.Parse(fields[28]),   // Nearby-Actual14
                    double.Parse(fields[29]),   // Nearby-Actual15
                    double.Parse(fields[30]),   // Nearby-Actual16
                    double.Parse(fields[31]),   // Nearby-Actual17
                    double.Parse(fields[32]),   // Nearby-Actual18
                    double.Parse(fields[33]),   // Nearby-Actual19
                    double.Parse(fields[34]),   // Nearby-Actual20
                    double.Parse(fields[35]),   // Nearby-Actual21
                    double.Parse(fields[36]),   // Nearby-Actual22
                    double.Parse(fields[37]),   // Nearby-Actual23
                    double.Parse(fields[38]),   // Nearby-Actual24
                    double.Parse(fields[39]),   // Nearby-Actual25
                    double.Parse(fields[40]),   // Nearby-Actual26
                    double.Parse(fields[41]),   // Nearby-Actual27
                    double.Parse(fields[42]),   // Nearby-Actual28
                    double.Parse(fields[43]),   // Nearby-Actual29
                    double.Parse(fields[44]),   // Nearby-Actual30
                    double.Parse(fields[45]),   // Nearby-Actual31
                    double.Parse(fields[46]),   // Nearby-Actual32
                    double.Parse(fields[47]),   // Nearby-Actual33
                    double.Parse(fields[48]),   // Nearby-Actual34
                    double.Parse(fields[49]),   // Nearby-Actual35
                    double.Parse(fields[50]),   // Nearby-Actual36
                    double.Parse(fields[51]),   // Nearby-Actual37
                    double.Parse(fields[52]),   // Nearby-Actual38
                    double.Parse(fields[53]),   // Nearby-Actual39
                    double.Parse(fields[54]),   // Nearby-Actual40
                    double.Parse(fields[55]),   // Nearby-Actual41
                    double.Parse(fields[56])    // Nearby-Actual42
                    );
                result.Add(s);
            }
            FeaturesState s1 = new FeaturesState(int.Parse(fileLines[0]));

            result.Add(s1);
            States = result.ToArray();
            return(result.ToArray());
        }