Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2013
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. # Author: ThymineC
  2. # Date: 23/11/2013
  3. # Python version: 2.7
  4. # Description: Evaluates the behaviour of a miner AI using a greedy algorithm that
  5. #              bases its behaviour at each tick on whatever action maximises
  6. #              value/tick ratio
  7.  
  8. def valMineReturn(t, X, Y, Z):
  9.     assert(t <= Y)
  10.    
  11.     return float(Z) / float(X + Y - t)
  12.  
  13. def valReturnNow(t, X, Y, Z):
  14.     assert(t <= Y)
  15.    
  16.     return (Z / float(Y))*t / float(X)
  17.  
  18. def decision(t, X, Y, Z):
  19.     if valMineReturn(t, X, Y, Z) > valReturnNow(t, X, Y, Z):
  20.         return "Mines and returns"
  21.     else:
  22.         return "Returns now"
  23.  
  24. def main():
  25.     xMax = 2
  26.     yMax = 2
  27.     zMax = 3
  28.  
  29.     print "Travel tick range: [1, %s]" % xMax
  30.     print "Mining tick range: [1, %s]" % yMax
  31.     print "Ore value range: [0, %s]\n\n" % zMax
  32.    
  33.     for X in range(1, xMax+1):
  34.         for Y in range(1, yMax+1):
  35.             for Z in range(0, zMax+1):
  36.                 for t in range(1, 2):
  37.                     print "t: %s" % t
  38.                     print "travelTicks: %s" % X
  39.                     print "mineTicks: %s" % Y
  40.                     print "oreValue: %s" % Z
  41.                     print "V(mine+return): %s" % valMineReturn(t, X, Y, Z)
  42.                     print "V(return now): %s" % valReturnNow(t, X, Y, Z)
  43.                     print "decision: %s\n" % decision(t, X, Y, Z)
  44.    
  45. if __name__ == "__main__":
  46.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement