You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print "Each player takes at least one piece, a pipe | in this version, from one row."
print "In the standard version, called misère, the object is to make the opponent take the last piece."
print "(In non-misère play, the last player to take a piece wins.)"
print "Be warned that Nim is a solved game; even with the advantage of going first, it is extremely difficult to beat the computer."
print """Nim appears in the 1961 Alain Resnais film "Last Year at Marienbad" ("L'Année dernière à Marienbad"), dialogue from which decorates this game."""
print "To play a custom game, use 'custom' (no quotes) as the first argument."
print "The second argument is a misère flag (True/False), and the third is to take the first turn (True/False)."
print "The final argument, which is optional, is a list of row lengths for a custom board."
print "The standard board is 1 3 5 7, but a list of numbers of any length may be used."
print "\r\n"
class Board(object):
def __init__(self,rows):
self.rows = rows
def draw(self):
for e,i in enumerate(self.rows):
print "Row %s:" % str(e+1),bold("| ")*int(i)
def update(self,row,draws):
self.rows[row] -= draws
def nim_sum(self):
nim_sum = 0
for r in self.rows:
nim_sum ^= r
return nim_sum
class Player(object):
def __init__(self,name,dialogue,win_string):
self.name = name
def win(self):
clear()
raw_input(bold(self.win_string))
class User(Player):
def __init__(self):
self.name = "user"
self.win_string = "Congratulations, you have won."
self.walk = False
self.chosen_dialogue = list()
def take_turn(self,board):
row = self.prompt_row(board,"Select a row.")
draws = self.prompt_draw(board,row,"How many do you take from row %s?" % str(int(row)+1))
choose = random.randint(1,100)
if choose>83 and not self.walk:
walk = Speech("italic","And once again I walked on alone,", 2)
walk.display()
walk.dialogue = "And once again I walked on alone,\r\n ** down these same corridors,"
walk.display()
walk.dialogue = "And once again I walked on alone,\r\n ** down these same corridors,\r\n ** through these same empty rooms,"
walk.display()
walk.dialogue = "And once again I walked on alone,\r\n ** down these same corridors,\r\n ** through these same empty rooms,\r\n ** I passed these same colonnades,"
walk.display()
walk.dialogue = "And once again I walked on alone,\r\n ** down these same corridors,\r\n ** through these same empty rooms,\r\n ** I passed these same colonnades,\r\n ** these same windowless galleries."
walk.display()
walk.dialogue = "And once again I walked on alone,\r\n ** down these same corridors,\r\n ** through these same empty rooms,\r\n ** I passed these same colonnades,\r\n ** these same windowless galleries.\r\n ** I crossed these same thresholds,"
walk.display()
walk.dialogue = "And once again I walked on alone,\r\n ** down these same corridors,\r\n ** through these same empty rooms,\r\n ** I passed these same colonnades,\r\n ** these same windowless galleries.\r\n ** I crossed these same thresholds,\r\n ** picking my way as if it at random"
walk.display()
walk.dialogue = "And once again I walked on alone,\r\n ** down these same corridors,\r\n ** through these same empty rooms,\r\n ** I passed these same colonnades,\r\n ** these same windowless galleries.\r\n ** I crossed these same thresholds,\r\n ** picking my way as if it at random\r\n ** through a maze of identical paths."
walk.display()
walk.dialogue = "And once again I walked on alone,\r\n ** down these same corridors,\r\n ** through these same empty rooms,\r\n ** I passed these same colonnades,\r\n ** these same windowless galleries.\r\n ** I crossed these same thresholds,\r\n ** picking my way as if it at random\r\n ** through a maze of identical paths.\r\n\r\n ** And once again,"
walk.display()
walk.dialogue = "And once again I walked on alone,\r\n ** down these same corridors,\r\n ** through these same empty rooms,\r\n ** I passed these same colonnades,\r\n ** these same windowless galleries.\r\n ** I crossed these same thresholds,\r\n ** picking my way as if it at random\r\n ** through a maze of identical paths.\r\n\r\n ** And once again,\r\n ** everything was deserted in this vast hotel."
walk.display()
self.walk = True
elif choose<52:
while True:
choose = random.randint(0,12)
if choose not in self.chosen_dialogue:
self.chosen_dialogue.append(choose)
break
one_lines = ("I think this game's silly.","There must be rules.")
rand_speech = Speech("random", "I remember how Frank used to play this last year . . .",2)
rand_speech.display()
rand_speech = Speech("random", "I remember how Frank used to play this last year . . . }\r\n {Yes, yes he did, I'm sure of it.",2)
rand_speech.display()
else:
rand_speech = Speech("random", "There's a trick you have to know.",2)
rand_speech.display()
tricks = ("What you have to do is take the complement of seven each time.","All you have to do is take an uneven number.","It's the one who goes first who loses.","It's the one who starts who wins.","You have to take an even number.","The lowest whole uneven number.","It's a logarithmic series.","You have to pick a different row each time.","Divided by three.","Seven times seven forty-nine.")