Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib2, smtplib
- def send_email(text):
- server = smtplib.SMTP_SSL('smtp.gmail.com')
- server.login("bot.nomic@gmail.com", "tankshot")
- msg = "\n" + text
- server.sendmail("bot.nomic@gmail.com", "benderjacob44@gmail.com", msg)
- def sendMessageToPlayer(player, message): #Should send message to player
- print "*"*50
- print "Message for player %s:" %(player)
- print message
- print "*"*50
- def askPlayer(player, question): #Ask player question and return answer
- print "-"*50
- response=raw_input("%s, %s" %(player,question))
- print "-"*50
- return response
- def askPlayerMultiline(player,question):
- print "/"*50
- print "%s, %s" %(player,question)
- output=""
- line=None
- while True:
- try: line = raw_input("")
- except EOFError: break
- output += line + "\n"
- print "/"*50
- return output
- def initPlayerList(): #Get the initial player list somehow
- try:
- for i in range(int(raw_input("How many players? "))):
- players.append(raw_input("What is the name of player %d? " % (i)))
- emails.append(raw_input("What is their email? "))
- except(ValueError):
- print "Error processing that number of players!"
- initPlayerList()
- #Initial Rule Set goes here
- def broadCast(message):
- for player in players:
- sendMessageToPlayer(player, message.format(player=player))
- Debug = False
- try: ruleSet
- except NameError: ruleSet = 0
- tiebreaker=False #Ties are not broken, but they result in rule proposal failure.
- if ruleSet == 0:
- players = []
- emails = []
- initPlayerList()
- broadCast("Welcome to a game which is called Nomic. The current rules are simple. Get this program to output '{player} wins!'. However, all rules can be changed, including this one! Good luck!")
- #broadCast("The current ruleset is:\n" + open(__file__).read())
- ruleUrl = None
- oldRuleUrl = None
- gameOver=False
- while not gameOver:
- for player in players:
- if ruleUrl:
- sendMessageToPlayer(player, "The current ruleset is found at " + ruleUrl)
- if askPlayer(player, "Would you like to propose a change to the rules?(y/n) ")[0].lower() == 'y':
- oldRuleUrl = ruleUrl
- ruleUrl = askPlayer(player, "Please send the url for the modified ruleset: ")
- try: rule = urllib2.urlopen(ruleUrl).read()
- except Exception, e: sendMessageToPlayer(player, "Error: " + str(e)); ruleUrl = oldRuleUrl; continue
- else:
- continue
- votes=[]
- for p in players:
- send_email(("Player %s has proposed this rule change: " % player) + ruleUrl)
- vote=askPlayer(p, "Do you approve %s's rule change? " % (player)) #Vote on rules
- votes.append(vote)
- total=0.0
- for v in votes:
- res=v.lower()
- if res == "y" or res == "yes" or res== "1":
- total+=1.0
- elif res == "n" or res == "no" or res == "-1":
- total -= 1.0
- elif res == "a" or res == "abstain" or res == "0":
- total += 0.0
- else:
- print "Invalid vote detected. Assuming it is a vote to abstain."
- rulePassed=False
- if not tiebreaker:
- if total > 0:
- rulePassed=True
- else:
- if total >= 0:
- rulePassed=True
- if rulePassed:
- try:
- ruleSet += 1
- exec rule
- gameOver = True
- break
- except Exception, e:
- broadCast("Ruleset %d has crashed! Reverting to ruleset %d." % (ruleSet, ruleSet-1))
- ruleSet -= 1
- ruleUrl = oldRuleUrl
- else:
- ruleUrl = oldRuleUrl
- #aaaaa
Add Comment
Please, Sign In to add comment