private static double H(int i, GlobalState s, int[] a) { double R = 4; int lipos = 0; //if li>0 int aizer = 0; //if ai=0 double ajzercount = 0; AState aS = (AState)s.getLocalStates()[i]; int li = aS.getL(); if (li > 0) { lipos = 1; } if (a[i] == 0) { aizer = 1; } if (lipos * aizer == 1) { for (int j = 0; j < n; j++) { if (a[j] == 0) { ajzercount++; } } return(R / ajzercount); } else { return(0); } //int c = -2, r = 2, w = -1; //// only valid state action pairs are accepted //int z_i = s.getLocalStates()[i].getZ();//get z_i //int y_i = s.getLocalStates()[i].getY();//get y_i //if (z_i == 0 && a[i] == 1) //{ // return c; //} //else if (z_i == 1 && a[i] == 0 && !gamma(i, s))//stay in finished state if the job not completed //{ // return w; //} //else if (z_i == 1 && a[i] == 1 && gamma(i, s))//go to completed state if a job completed //{ // return r; //} //else //{ // return 0; //} return(0); }
public static int getGlobalStateIndex(State[] localstates) { int index = 0; index = localstates[0].getLocalIndex(); for (int j = 1; j < n; j++) { index = index * (AState.getNo_of_States()) + localstates[j].getLocalIndex(); } return(index); }
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)]); }
private static void addstrec(int[] con, int p, List <State> slist, int player_id) { if (p < n + 2) { for (int i = 0; i < 3; i++) { con[p] = i; addstrec(con, p + 1, slist, player_id); } } else { State s = new AState(player_id, con); slist.Add(s); } }
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); }
static void Main(string[] args) { if (_debug) { Console.WriteLine("App start"); } //update players for (int i = 0; i < n; i++) { if (bybool[i]) { byZ.Add(i); } else { Al.Add(i); } }// update byzantine and altruistic lists //update states //spec for (int i = 0; i < n; i++) { //for each player List <State> slist = new List <State>(); //state list(set) for player i AState.AddStates(slist, i); locstatelist[i] = slist;// local state list for player i }// construct local state list /*construct global states*/ List <State> before = new List <State>(); computeGstates(before, 0, gstates, locstatelist);// determine the list of global states int nofstates = gstates.Count; Console.WriteLine("state count =" + nofstates); //update actions for (int i = 0; i < n; i++) { localactionset[i] = new List <int>(); for (int j = 0; j <= n; j++) { (localactionset[i]).Add(j);//0=share, j!=0 implies ai=shootj } } List <int> abefore = new List <int>(); // if(byZ.Count>0) computegActions(abefore, 0, byzAc, byZ.Count); abefore = new List <int>(); computegActions(abefore, 0, AlAc, Al.Count); //action list depends on the size of the set abefore = new List <int>(); computegActions(abefore, 0, AlrAc, Al.Count - 1); //action list when player is rational abefore = new List <int>(); computegActions(abefore, 0, multiAc, 2); //create actions pairs abefore = new List <int>(); if (Al.Count > 2) { computegActions(abefore, 0, AlmrAc, Al.Count - 2);//Al when two players are rational } //actions updated // String result1 = Nashepdelta(vcurrent, vprev, ucurrent, uprev); // Console.WriteLine("first part done"); String result2 = Nashepdeltamul(vcurrent, vprev, ucurrent, uprev, 0, 2); Console.WriteLine(result2); System.Diagnostics.Debug.WriteLine("mul result " + result2); }