Advertisement
harveyy

rep fight in the zone

Jul 1st, 2015
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. #!/usr/bin/env python2
  2.  
  3. from collections import defaultdict
  4. import sys
  5.  
  6. graph = { "g1":["s2"],
  7.         "s2": ["g3a","g3b"],
  8.         "g3a":["s4a"],
  9.         "g3b":["s4b"],
  10.         "s4a":["g5","g1"],
  11.         "s4b":["g5","g1"],
  12.         "g5":["s4a","s4b"] }
  13.  
  14. maxrep = 2
  15. repetitions = defaultdict(lambda:0)
  16.  
  17. WIN=1
  18. LOSE=-1
  19.  
  20. def minimax(pos,depth=0):
  21.     print "  "*depth, pos
  22.     repetitions[pos]+=1
  23.     for nextp in graph[pos]:
  24.         if repetitions[nextp]<maxrep:
  25.             if minimax(nextp,depth+1)==LOSE:
  26.                 repetitions[pos]-=1
  27.                 return WIN
  28.     repetitions[pos]-=1
  29.     return LOSE
  30.  
  31.  
  32. if __name__=="__main__":
  33.     if len(sys.argv)>1:
  34.         maxrep = int(sys.argv[1])
  35.     if minimax("g1")==WIN:
  36.         print "Gold wins"
  37.     else:
  38.         print "Silver wins"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement