![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-05 22:49 |
48,039 topics / 350,124 posts / today 2 new / 48,251 members |
| DOS批处理 & 脚本技术(批处理室) » Guess the number game [game's over] |
| Printable Version 2,535 / 16 |
| Floor1 dosmania | Posted 2007-09-21 15:25 |
| 初级用户 Posts 54 Credits 172 | |
|
Write a number guessing game. I don't know if anyone has played it. There is this game on the home phone, and I've played it many times. I'm also writing one myself, 7788, not perfected yet. I want to see if everyone has better ideas.
In the forum, those who feel there are no challenging experts can come out and discuss. Thanks. Rules: 1. The game will randomly obtain a four-digit number without repeated digits from 0-9 at the beginning (the first digit can be 0) 2. The player first makes a guess, entering a four-digit number without repeated digits from 0-9 3. Compare the number obtained at the beginning of the game with the number entered by the player: If one digit has the exact same number and position, set flag A1 If one digit has a matching number but wrong position, set flag B1 If the number and position are both mismatched, set flag B0 The exact match of number and position only sets flag A, regardless of B For example: The answer is 4690. If I guess 0679, then the prompt is A1B2 If the prompt is A0B0, it means the guessed number does not appear at all in the answer If the prompt is A0B4, it means the guessed number matches exactly but all positions are wrong A4B0 is the correct answer. 4. Only 10 chances General idea: * Must verify the random answer Verify if the randomly obtained number is four digits, and if each digit has repetition * Must verify the player's input specification Verify if the player's input is pure digits, if there is repetition, if it is 4 digits, otherwise give corresponding prompt and jump back to re-enter * Record historical records What the user entered for the first time, what the prompt was, must be displayed for reference when guessing the second time * Record the number of uses How many times have been guessed, how many times are left, displayed together with the historical records * Must have a chance to play again After the player uses up 10 times and hasn't guessed it, there must be a chance to play again, or if guessed correctly at once, there must be a chance to play again ------------------------------------------------------------------------------------------- The final answer is in posts 7, 9, 11, 16 Close the post! [ Last edited by dosmania on 2007-9-26 at 09:32 PM ] |
|
| Floor2 dosmania | Posted 2007-09-24 15:04 |
| 初级用户 Posts 54 Credits 172 | |
|
I'm in a cold sweat``Why is no one researching it``
|
|
| Floor3 bjsh | Posted 2007-09-24 16:55 |
| 银牌会员 Posts 621 Credits 2,000 | |
|
This is quite interesting;
Just been quite busy these days and haven't had time; During the National Day holiday, I will definitely write it out and post it; |
|
| Floor4 vkill | Posted 2007-09-24 16:57 |
| 金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽 | |
|
There was someone who wrote a number guessing game a long time ago, and it can be modified a bit on that basis.
|
|
| Floor5 HAT | Posted 2007-09-24 21:43 |
| 版主 Posts 5,017 Credits 9,023 | |
|
I wrote a C language version before. I'll convert it to a batch file when I have time.
|
|
| Floor6 dosmania | Posted 2007-09-25 03:37 |
| 初级用户 Posts 54 Credits 172 | |
|
re bjsh:
Looking forward to the moderator's ideas yo```` re vkill: There are people who have written it, but it's completely different, a lot different. That game is quite fake The one I'm talking about is a game that really exists in my home fixed-line phone. Some necessary verifications I mentioned are also distinguished from the one you mentioned. re HAT: Post the code here |
|
| Floor7 qzwqzw | Posted 2007-09-25 11:20 |
| 银牌会员 Posts 636 Credits 2,343 | |
|
The landlord is talking about this game, right?
http://www.cn-dos.net/forum/viewthread.php?tid=32554 |
|
| Floor8 dosmania | Posted 2007-09-25 14:15 |
| 初级用户 Posts 54 Credits 172 | |
|
re qzwqzw:
Read your post. "The anti-guessing is too slow, waited for a long time." In fact, the actual existing number guessing game has 10 guesses, not 8. I tested your release 1 version, and the problems I encountered are also posted in your post. Go check it yourself. It feels like your code is quite a lot... |
|
| Floor9 s11ss | Posted 2007-09-25 14:37 |
| 银牌会员 Posts 566 Credits 2,098 | |
|
```batch
@echo off setlocal enabledelayedexpansion ::::::::::::::::::::::::::: Guess the Number Game ::::::::::::::::::::::::::: :::::::::::::::::::::::::::{s11ss 2007-9-25}::::::::::::::::::::::::::: :Begin set/a counter=1 :GetStr echo Please enter a four-digit number : set/p str= if "%str%"=="" goto :GetStr call set one=%%str:~3,1%% if "%one%" equ "" (echo The number must be four digits!& goto :GetStr) call set one=%%str:~4,1%% if not "%one%" equ "" (echo The number must be four digits!& goto :GetStr) set/a len=0 :IsAllNum call set word=%%str:~%len%,1%% if not "%word%"=="" ( set isnum=False for /l %%a in (0,1,9) do ( if "%word%"=="%%a" ( set/a len+=1 set isnum=True goto :IsAllNum ) ) ) if "%isnum%"=="False" (echo How can there be non-numeric characters? & goto :GetStr) set state=chkinput call :CheckSameNum n %str% if not !counter! equ 1 goto :CheckAnswer goto :CreateRandom :CheckSameNum set s=%2 for /l %%a in (0,1,3) do call set %1%%a=%%s:~%%a,1%% set/a i=0 :ci set/a j=!i!+1 :cj if !%1%j%! equ !%1%i%! ( if !state! equ chkinput ( echo All digits must be different!& goto :GetStr ) else (goto :CreateRandom) ) set/a j+=1 if not !j! gtr 3 goto :cj set/a i+=1 if not !i! gtr 2 goto :ci goto :eof :CreateRandom set/a answer=%random% call set one=%%answer:~3,1%% if "%one%" equ "" (goto :CreateRandom) call set one=%%answer:~4,1%% if not "%one%" equ "" (goto :CreateRandom) set state=chkrandom call :CheckSameNum y %answer% ::The next line can display the answer: ::echo %answer% :CheckAnswer set/a aa=0,bb=0 if not !counter! equ 11 ( for /l %%a in (0,1,3) do ( for /l %%i in (0,1,3) do ( if !n%%i! equ !y%%a! ( if %%i equ %%a ( set/a aa+=1 ) else (set/a bb+=1) ) ) ) set r%counter%=A!aa!B!bb! set str%counter%=!str! for /l %%a in (1,1,!counter!) do echo Guess %%a:!str%%a!,Result:!r%%a! set/a remain=10-!counter! echo Guessed !counter! times, remaining !remain! times. set/a counter+=1 if not !aa! equ 4 ( goto :GetStr ) else ( echo Got it, the answer is !str%counter%!,Happy Mid-Autumn Festival! goto :Replay ) ) echo Have guessed 10 times! :Replay set/p q=Do you want to play again?(y/n) if not "%q%" equ "y" ( if not "%q%" equ "Y" ( echo Press any key to exit... pause>nul goto :eof ) ) goto :Begin ``` [ Last edited by s11ss on 2007-9-25 at 02:44 PM ] |
|
| Floor10 qzwqzw | Posted 2007-09-25 14:50 |
| 银牌会员 Posts 636 Credits 2,343 | |
|
dosmania:
I admit that the guessing algorithm was indeed a bit shoddy After all, it was just an R1 in my spare time Unfortunately, no one was interested in it at that time No discussion atmosphere was formed Later, I also lost interest in this aspect If you have a new algorithm, just post it out Maybe it will rekindle my interest ------------------------------------------------------ As for the issue of guessing 8 times or 10 times I don't think it's a problem I originally set it to 10 times Later, it was changed to 8 times because of the display layout and log reasons To be honest Among the games of this kind I have come into contact with Those for game consoles and TVs have no limit on the number of times For video recorders, it's limited to 8 times, and it doesn't use numbers 9 and 0 There are many varieties for computers An excellent guessing algorithm The exhaustive algorithm should be the one with the least number of times But it's not the most efficient The average number of guessing times should be less than 6 times Setting 8 times can also be considered medium difficulty ------------------------------------------------------ "Feels like you have a lot of code``` " I don't understand, can you explain it? [ Last edited by qzwqzw on 2007-9-25 at 03:05 PM ] |
|
| Floor11 jmz573515 | Posted 2007-09-25 15:56 |
| 银牌会员 Posts 464 Credits 1,212 | |
|
I can't write batch processing, send a VBS one
[ Last edited by jmz573515 on 2007-9-25 at 04:09 PM ] |
|
| Floor12 dosmania | Posted 2007-09-26 14:31 |
| 初级用户 Posts 54 Credits 172 | |
|
Hehe``jmz573515 is amazing, VBS interactivity is N good
if len(n)<>4 Oh``simply can't compare嘛```VBS this one solves the digit problem`` I wonder if jmz573515 has considered the repetition possibility of s1 s2 s3 s4```? |
|
| Floor13 dosmania | Posted 2007-09-26 14:53 |
| 初级用户 Posts 54 Credits 172 | |
|
re s11ss:
Your code also fully meets the requirements```I don't know which ones you verified for random number repetition`` |
|
| Floor14 jmz573515 | Posted 2007-09-26 15:31 |
| 银牌会员 Posts 464 Credits 1,212 | |
|
dosmania:
if len(n)<>4 靠``根本不能比嘛```VBS这个就搞定了位数`` I don't know what you mean by "can't compare", I think it can be limited to 4 digits?? I don't know if jmz573515 has considered the possibility of repetition of s1 s2 s3 s4...? What do you mean by the possibility of repetition? (Do you mean how likely it is? Or whether it is possible to repeat?) Here I only considered the possibility of repetition, so I made a judgment. If there is repetition, I generate a random number again. I didn't consider how likely it is, maybe it's not efficient...) |
|
| Floor15 s11ss | Posted 2007-09-26 16:52 |
| 银牌会员 Posts 566 Credits 2,098 | |
Originally posted by dosmania at 2007-9-26 02:53 PM: Random number repetition? I don't understand your specific meaning. Anyway, my code is to make the 4-digit numbers of the random number not repeat. As for whether the random numbers repeat among themselves, I didn't control it, but there doesn't seem to be a requirement in the question, right? |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |