<s> from __future__ import print_function <EOL> import textwrap <EOL> from collections import defaultdict <EOL> import argparse <EOL> from csv import DictReader <EOL> from time import sleep <EOL> from string import lower <EOL> from random import shuffle <EOL> import sys <EOL> import os <EOL> from buzzer import kSHOW_RIGHT , kPAUSE , kBIGNUMBERS <EOL> from buzzer import clear_screen , PowerPositions , show_score <EOL> from buzzer import Guess , Buzzes , Questions , format_display <EOL> from buzzer import load_finals , interpret_keypress , answer <EOL> kPADDING = "<STR_LIT>" <EOL> kPAD_LEN = <NUM_LIT:5> <EOL> class Score : <EOL> def __init__ ( self , even = <NUM_LIT:0> , odd = <NUM_LIT:0> , human = <NUM_LIT:0> , computer = <NUM_LIT:0> ) : <EOL> self . even = even <EOL> self . odd = odd <EOL> self . human = human <EOL> self . computer = computer <EOL> def add ( self , score ) : <EOL> return Score ( self . even + score . even , <EOL> self . odd + score . odd , <EOL> self . human + score . human , <EOL> self . computer + score . computer ) <EOL> def present_question ( display_num , question_id , question_text , buzzes , final , <EOL> correct , score , power = "<STR_LIT>" ) : <EOL> even_delta = <NUM_LIT:0> <EOL> odd_delta = <NUM_LIT:0> <EOL> question_value = <NUM_LIT:15> <EOL> computer_position = ( max ( question_text ) + <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> for ss in sorted ( question_text ) : <EOL> words = question_text [ ss ] . split ( ) <EOL> for ii , ww in enumerate ( words ) : <EOL> current_guesses = buzzes . current_guesses ( question_id , ss , ii ) <EOL> buzz_now = [ x for x in current_guesses . values ( ) if x . final ] <EOL> if len ( buzz_now ) == <NUM_LIT:1> : <EOL> computer_position = ss , ii <EOL> computer_guess = buzz_now [ <NUM_LIT:0> ] . page <EOL> break <EOL> question_text [ ss ] += "<STR_LIT>" % "<STR_LIT:U+0020>" . join ( [ kPADDING ] * <NUM_LIT:5> ) <EOL> question_done = False <EOL> human_delta = <NUM_LIT:0> <EOL> computer_delta = <NUM_LIT:0> <EOL> human_answers = <NUM_LIT:0> <EOL> computer_answers = <NUM_LIT:0> <EOL> for ss in sorted ( question_text ) : <EOL> words = question_text [ ss ] . split ( ) <EOL> for ii , ww in enumerate ( words ) : <EOL> if question_done or human_answers == <NUM_LIT:2> : <EOL> break <EOL> if computer_position [ <NUM_LIT:0> ] == ss and computer_position [ <NUM_LIT:1> ] == ii : <EOL> if human_delta <= <NUM_LIT:0> : <EOL> if computer_guess == correct : <EOL> if human_answers == <NUM_LIT:2> : <EOL> answer ( computer_guess . split ( "<STR_LIT:(>" ) [ <NUM_LIT:0> ] ) <EOL> computer_answers += <NUM_LIT:1> <EOL> question_done = True <EOL> os . system ( "<STR_LIT>" ) <EOL> if human_delta <= <NUM_LIT:0> : <EOL> computer_delta = question_value <EOL> else : <EOL> answer ( computer_guess . split ( "<STR_LIT:(>" ) [ <NUM_LIT:0> ] ) <EOL> computer_answers += <NUM_LIT:1> <EOL> os . system ( "<STR_LIT>" ) <EOL> if human_delta == <NUM_LIT:0> : <EOL> computer_delta = - <NUM_LIT:5> <EOL> else : <EOL> answer ( computer_guess . split ( "<STR_LIT:(>" ) [ <NUM_LIT:0> ] ) <EOL> computer_answers += <NUM_LIT:1> <EOL> question_done = True <EOL> computer_delta = <NUM_LIT:0> <EOL> current_guesses = buzzes . current_guesses ( question_id , ss , ii ) <EOL> if lower ( ww ) . startswith ( lower ( power ) ) : <EOL> question_value = <NUM_LIT:10> <EOL> press = interpret_keypress ( ) <EOL> if isinstance ( press , int ) : <EOL> if human_delta > <NUM_LIT:0> : <EOL> continue <EOL> if even_delta != <NUM_LIT:0> and press % <NUM_LIT:2> == <NUM_LIT:0> : <EOL> continue <EOL> if odd_delta != <NUM_LIT:0> and press % <NUM_LIT:2> != <NUM_LIT:0> : <EOL> continue <EOL> human_answers += <NUM_LIT:1> <EOL> os . system ( "<STR_LIT>" ) <EOL> response = None <EOL> while response is None : <EOL> response = raw_input ( "<STR_LIT>" <EOL> % press ) <EOL> if '<STR_LIT:+>' in response : <EOL> if press % <NUM_LIT:2> == <NUM_LIT:0> : <EOL> even_delta = question_value <EOL> else : <EOL> odd_delta = question_value <EOL> if computer_delta < <NUM_LIT:0> and human_delta == <NUM_LIT:0> : <EOL> human_delta = question_value <EOL> question_done = True <EOL> elif computer_delta == <NUM_LIT:0> and human_delta == <NUM_LIT:0> : <EOL> human_delta = question_value <EOL> elif '<STR_LIT:->' in response : <EOL> if even_delta == <NUM_LIT:0> and press % <NUM_LIT:2> != <NUM_LIT:0> and ww != kPADDING : <EOL> odd_delta = - <NUM_LIT:5> <EOL> if odd_delta == <NUM_LIT:0> and press % <NUM_LIT:2> == <NUM_LIT:0> and ww != kPADDING : <EOL> even_delta = - <NUM_LIT:5> <EOL> if computer_delta == <NUM_LIT:0> : <EOL> human_delta = - <NUM_LIT:5> <EOL> if even_delta != <NUM_LIT:0> and press % <NUM_LIT:2> != <NUM_LIT:0> : <EOL> question_done = True <EOL> if odd_delta != <NUM_LIT:0> and press % <NUM_LIT:2> == <NUM_LIT:0> : <EOL> question_done = True <EOL> else : <EOL> response = None <EOL> else : <EOL> show_score ( score . even + even_delta , <EOL> score . odd + odd_delta , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> left_color = "<STR_LIT>" , <EOL> right_color = "<STR_LIT>" ) <EOL> show_score ( score . human + human_delta , <EOL> score . computer + computer_delta , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> flush = False ) <EOL> print ( format_display ( display_num , question_text , ss , ii + <NUM_LIT:1> , <EOL> current_guesses , answer = correct , <EOL> points = question_value ) ) <EOL> if computer_delta == <NUM_LIT:0> and human_delta <= <NUM_LIT:0> and computer_answers == <NUM_LIT:0> : <EOL> show_score ( score . even + even_delta , <EOL> score . odd + odd_delta , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> left_color = "<STR_LIT>" , <EOL> right_color = "<STR_LIT>" ) <EOL> show_score ( score . human + human_delta , <EOL> score . computer + computer_delta , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> flush = False ) <EOL> print ( format_display ( display_num , question_text , max ( question_text ) - <NUM_LIT:1> , <EOL> <NUM_LIT:1000> , current_guesses , answer = correct , <EOL> points = computer_delta ) ) <EOL> answer ( final . split ( '<STR_LIT:(>' ) [ <NUM_LIT:0> ] ) <EOL> if final == correct : <EOL> computer_delta = <NUM_LIT:10> <EOL> else : <EOL> print ( "<STR_LIT>" % final ) <EOL> elif computer_delta > <NUM_LIT:0> and computer_answers == <NUM_LIT:0> : <EOL> format_display ( display_num , question_text , computer_position [ <NUM_LIT:0> ] , <EOL> computer_position [ <NUM_LIT:1> ] , current_guesses , answer = correct , <EOL> points = computer_delta ) <EOL> answer ( computer_guess ) <EOL> return score . add ( Score ( even_delta , odd_delta , human_delta , computer_delta ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> parser = argparse . ArgumentParser ( description = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , type = str , default = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , type = str , default = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT>' , type = str , default = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT>' , type = str , default = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT>' , type = str , default = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT>' , type = int , default = <NUM_LIT:0> ) <EOL> parser . add_argument ( '<STR_LIT>' , type = int , default = <NUM_LIT:20> ) <EOL> parser . add_argument ( '<STR_LIT>' , type = str , default = "<STR_LIT>" ) <EOL> flags = parser . parse_args ( ) <EOL> questions = Questions ( flags . questions ) <EOL> buzzes = Buzzes ( flags . buzzes ) <EOL> finals = load_finals ( flags . finals ) <EOL> power = PowerPositions ( flags . power ) <EOL> print ( "<STR_LIT>" ) <EOL> clear_screen ( ) <EOL> current_players = set ( ) <EOL> if False : <EOL> print ( "<STR_LIT>" ) <EOL> players_needed = [ <NUM_LIT:1> ] <EOL> while len ( current_players ) < len ( players_needed ) : <EOL> print ( "<STR_LIT>" % min ( x for x in players_needed if x not in current_players ) ) <EOL> press = interpret_keypress ( ) <EOL> if press in players_needed : <EOL> os . system ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" % press ) <EOL> current_players . add ( press ) <EOL> sleep ( <NUM_LIT> ) <EOL> answer ( "<STR_LIT>" ) <EOL> score = Score ( ) <EOL> question_ids = sorted ( questions . _questions . keys ( ) , key = lambda x : x % <NUM_LIT:11> ) <EOL> if flags . readable != "<STR_LIT>" : <EOL> question_num = <NUM_LIT:0> <EOL> o = open ( flags . readable , '<STR_LIT:w>' ) <EOL> for ii in question_ids : <EOL> question_num += <NUM_LIT:1> <EOL> o . write ( "<STR_LIT>" % question_num ) <EOL> for jj in questions [ ii ] : <EOL> o . write ( "<STR_LIT>" % questions [ ii ] [ jj ] ) <EOL> o . write ( "<STR_LIT>" % questions . answer ( ii ) ) <EOL> question_num = <NUM_LIT:0> <EOL> question_ids = list ( question_ids ) [ flags . skip : ] <EOL> for ii in question_ids : <EOL> question_num += <NUM_LIT:1> <EOL> power_mark = power ( ii ) <EOL> score = present_question ( question_num , ii , questions [ ii ] , <EOL> buzzes , finals [ ii ] , <EOL> questions . answer ( ii ) , <EOL> score = score , <EOL> power = power ( ii ) ) <EOL> print ( "<STR_LIT>" % ( question_num , <EOL> questions . answer ( ii ) ) ) <EOL> sleep ( kPAUSE ) <EOL> if question_num > flags . max_questions - <NUM_LIT:1> : <EOL> break <EOL> show_score ( score . even , <EOL> score . odd , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> left_color = "<STR_LIT>" , <EOL> right_color = "<STR_LIT>" ) <EOL> show_score ( score . human , score . computer ) </s>
