@@ -36,13 +36,14 @@ def __init__(self, program):
3636
3737 self .flag_auto = True
3838 self .flag_show = False
39+ self .score_limit = 0
3940
4041 self .colorize = str .maketrans (
4142 {
42- "W" : "\033 [93m" "█" " \033 [0m" ,
43- "x" : "\033 [92m" "☁︎" " \033 [0m" ,
44- "o" : "\033 [91m" "✿" " \033 [0m" ,
45- "=" : "\033 [96m" "▄" " \033 [0m" ,
43+ "W" : "\033 [93m█ \033 [0m" ,
44+ "x" : "\033 [92mx \033 [0m" , # "x": "\033[92m☁︎ \033[0m",
45+ "o" : "\033 [91mo \033 [0m" , # "o": "\033[91m✿ \033[0m",
46+ "=" : "\033 [96m▄ \033 [0m" ,
4647 }
4748 )
4849
@@ -101,6 +102,10 @@ def play(self):
101102 self .show ()
102103 time .sleep (0.01 )
103104
105+ # to limit the screencast
106+ if self .score_limit and self .score >= self .score_limit :
107+ return
108+
104109 self .computer .input .append (self .joystick ())
105110
106111 def joystick (self ):
@@ -122,9 +127,9 @@ def joystick(self):
122127
123128
124129def main ():
125-
126130 parser = argparse .ArgumentParser ()
127131 parser .add_argument ("-v" , "--verbose" , action = "store_true" )
132+ parser .add_argument ("--limit" , type = int )
128133 parser .add_argument ("--elapsed" , action = "store_true" )
129134 parser .add_argument ("-p" , "--play" , action = "store_true" , help = "play the game" )
130135 parser .add_argument ("input" , nargs = "?" , default = "input.txt" )
@@ -140,12 +145,16 @@ def main():
140145
141146 if args .verbose :
142147 game .flag_show = True
148+ game .score_limit = args .limit
143149 if args .play :
144150 game .flag_show = True
145151 game .flag_auto = False
146152
147- print (game .part1 ())
148- print (game .part2 ())
153+ try :
154+ print (game .part1 ())
155+ print (game .part2 ())
156+ except KeyboardInterrupt :
157+ pass
149158
150159
151160if __name__ == "__main__" :
0 commit comments