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); }
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 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); }