Exemple #1
0
        private static GlobalState BT(GlobalState s, int[] a, List <GlobalState> gstates)
        {
            State[] localstates = new AState[n];
            for (int i = 0; i < n; i++)
            {
                AState aS     = (AState)(s.getLocalStates()[i]);
                int    label  = aS.getLabel();
                int    l      = aS.getL();
                int[]  c      = aS.getC();
                int[]  aSData = new int[n + 2];
                if (label != 2)
                {
                    int shootcount = 0;

                    for (int j = 0; j < n; j++)
                    {
                        if (j != i && a[j] == (i + 1))//convert zero based index of players to one based index for shooting
                        {
                            shootcount++;
                            if (c[j] > 0)//lose confidence with shootings
                            {
                                c[j]--;
                            }
                        }
                        aSData[j] = c[j];
                    }
                    l             = Math.Max(0, l - shootcount);
                    label         = (label + 1) % 3;
                    aSData[n]     = l;
                    aSData[n + 1] = label;
                }
                else
                {
                    for (int j = 0; j < n; j++)
                    {
                        if (j != (i))//update confidence
                        {
                            c[j] = Math.Min(2, c[j] + 1);
                        }
                        aSData[j] = c[j];
                    }
                    l             = 2;//restore life
                    label         = (label + 1) % 3;
                    aSData[n]     = l;
                    aSData[n + 1] = label;
                }
                localstates[i] = new AState(i, aSData);
            }

            return(gstates[getGlobalStateIndex(localstates)]);
        }
Exemple #2
0
        private static double Pr(int i, GlobalState s, int[] a)
        {
            AState aS = (AState)(s.getLocalStates()[i]); //retrive the state of player i

            int[]  c          = aS.getC();               //retrive confidence list of player i
            double normal_sum = 0;
            double maxcij     = 0;

            for (int j = 0; j < n; j++)
            {
                AState aSj = (AState)(s.getLocalStates()[j]);
                if (j != i)
                {
                    if (aSj.getL() > 0)    //only the living ones are considered for shooting
                    {
                        if (c[j] > maxcij) //find max confidence value
                        {
                            maxcij = c[j];
                        }
                        normal_sum += c[j];
                    }
                }
            }
            if (normal_sum > 0)//if some other player is alive
            {
                if (a[i] == 0)
                {
                    return(1 - maxcij / (normal_sum));
                }
                else
                {
                    for (int j = 1; j <= n; j++)
                    {
                        if (a[i] == j)
                        {
                            AState aSj = (AState)(s.getLocalStates()[j - 1]);//shift the index of j
                            int    lj  = aSj.getL();
                            if (lj == 0)
                            {
                                return(0);
                            }
                            else
                            {
                                return((maxcij * c[j - 1]) / normal_sum);//shifting the index to zero based
                            }
                        }
                    }
                }
            }
            else //if no other player is alive
            {
                if (a[i] == 0)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }


            return(0);
        }