Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Feb 21st, 2014 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Calculate the best moves in King of Tokyo - written in setlX (http://randoom.org/Software/SetlX)
  2.  
  3. score:=cachedProcedure(t){
  4.         s:=0;
  5.         for(i in [1..3]){
  6.                 if(t[i] >= 3) {
  7.                         s+=(t[i]-3)+i;
  8.                 }
  9.         }
  10.         return s;
  11. };
  12. pyramid:=cachedProcedure(v){
  13.         return 3**v[4]*((+/v)!)/(v[1]!*v[2]!*v[3]!*v[4]!);
  14. };
  15. expscore:=cachedProcedure(n, k, oldmove){
  16.         size := 6 - +/k;
  17.         total:=0;
  18.         for(v in {[a,b,c,d]:a in [0..size], b in [0..size],c in [0..size],d in [0..size]|a+b+c+d==size}){
  19.                 newt:=[k[1]+v[1],k[2]+v[2],k[3]+v[3],k[4]+v[4]];
  20.                 [_,bests]:=oldmove[newt];
  21.                 total+=bests*pyramid(v);
  22.         }
  23.         return total*1.0/(6**size);
  24. };
  25. bestmove:=cachedProcedure(n, t,oldmove){
  26.         bests:=score(t);
  27.         bestk:={t};
  28.         if(n > 1){
  29.                 for(k in {[a,b,c,d]:a in [0..t[1]],b in [0..t[2]],c in [0..t[3]], d in [0..t[4]]}){
  30.                         s:=expscore(n, k, oldmove);
  31.                         if(s>bests){
  32.                                 bests:=s;
  33.                                 bestk:={k};
  34.                         } else if (s==bests) {
  35.                                 bestk += {k};
  36.                         }
  37.                 }
  38.         }
  39.         return [bestk,bests];
  40. };
  41.  
  42. tt:={[a,b,c,d]:a in [0..6],b in [0..6],c in [0..6],d in [0..6]|a+b+c+d==6};
  43. m:={[1,{}]};
  44. for(t in tt){
  45.         m[1][t]:=[{t},score(t)];
  46.         print(0+" "+t+" "+m[1][t][1]+" "+m[1][t][2]);
  47. }
  48. for(n in [2..3]){
  49.         m[n]:={};
  50.         for(t in tt){
  51.                 m[n][t]:=bestmove(n,t,m[n-1]);
  52.                 print(n-1+" "+t+" "+m[n][t][1]+" "+m[n][t][2]);
  53.         }
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top