The second program (program number 2) is the game “Lizards”, in which the computer guesses the name of the animal conceived by the player. In this case, the computer asks questions, and the player answers only "yes" or "no." If the computer was not previously “familiar” with such an animal, then it “asks” to ask him leading questions or “offers” a new name to it.
@echo off : begin set qfile = questions.txt set tfile = questions_tmp.txt set cursor = 1 set prew_cursor = 1 set count = rem ------------------------------------------------- ---------------------- echo Think of an animal and press any key to continue ... pause> nul call: get_current : get_answer set answer = set / p answer =% question% [d] / n: set prew_cursor =% cursor% set prew_answer =% answer% if not "% answer%" == "n" ( set cursor =% yes_id% ) else ( set cursor =% no_id% ) call: get_current if not "% yes_id%" == "0" ( goto: get_answer ) set answer = set / p answer = This is% question%. I guessed? [d] / n: if not "% answer%" == "n" ( echo I thought so. goto: end ) rem ------------------------------------------------- ---------------------- call: get_count set / a new_animal_id =% count% + 1 set / a new_question_id =% count% + 2 call: update_current : get_new_animal set new_animal = set / p new_animal = Hm. Strange. Well, what is it ?: if "% new_animal%" == "" ( goto: get_new_animal ) echo% new_animal%: 0: 0 >>% qfile% : get_new_question set new_question = set / p new_question = Please write a question that characterizes the differences between animals% new_animal% and% question%: if "% new_question%" == "" ( goto: get_new_question ) set right_answer = set / p right_answer = And what is the correct answer for the animal% new_animal% [d] / n: if not "% right_answer%" == "n" ( echo% new_question%:% new_animal_id%:% cursor% >>% qfile% ) else ( echo% new_question%:% cursor%:% new_animal_id% >>% qfile% ) goto: end rem ------------------------------------------------- ---------------------- : get_count for / f "delims =:" %% i in ('findstr / r / n. *% qfile%') do set count = %% i rem Number of lines one less (empty line at the end) rem set / a count =% count% -1 exit / b : get_current for / f "tokens = 1-4 delims =:" %% i in ('findstr / r / n. *% qfile%') do call: get_current_callback %% i "% j" %% k %% l exit / b : get_current_callback if "% ~ 1" == "% cursor%" ( set question =% ~ 2 set yes_id =% ~ 3 set no_id =% ~ 4 ) exit / b : update_current if exist% tfile% ( del% tfile% ) for / f "tokens = 1-4 delims =:" %% i in ('findstr / r / n. *% qfile%') do call: update_current_callback %% i "% j" %% k %% l copy / y% tfile%% qfile%> nul exit / b : update_current_callback if "% ~ 1" == "% prew_cursor%" ( if not "% prew_answer%" == "n" ( echo% ~ 2:% new_question_id%:% ~ 4 >>% tfile% ) else ( echo% ~ 2:% ~ 3:% new_question_id% >>% tfile% ) ) else ( echo% ~ 2:% ~ 3:% ~ 4 >>% tfile% ) exit / b rem ------------------------------------------------- ---------------------- : end set answer = set / p answer = One more time? [d] / n: if not "% answer%" == "n" ( goto: begin )
Source: https://habr.com/ru/post/72832/
All Articles