Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python2
- from collections import defaultdict
- import sys
- graph = { "g1":["s2"],
- "s2": ["g3a","g3b"],
- "g3a":["s4a"],
- "g3b":["s4b"],
- "s4a":["g5","g1"],
- "s4b":["g5","g1"],
- "g5":["s4a","s4b"] }
- maxrep = 2
- repetitions = defaultdict(lambda:0)
- WIN=1
- LOSE=-1
- def minimax(pos,depth=0):
- print " "*depth, pos
- repetitions[pos]+=1
- for nextp in graph[pos]:
- if repetitions[nextp]<maxrep:
- if minimax(nextp,depth+1)==LOSE:
- repetitions[pos]-=1
- return WIN
- repetitions[pos]-=1
- return LOSE
- if __name__=="__main__":
- if len(sys.argv)>1:
- maxrep = int(sys.argv[1])
- if minimax("g1")==WIN:
- print "Gold wins"
- else:
- print "Silver wins"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement