In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
What the editor wants to share with you this time is how to achieve number guessing Mini Game by linux. The article is rich in content. Interested friends can learn about it. I hope you can get something after reading this article.
Rules of the game:
The game of guessing numbers is usually played by two people, one side gives the number and the other guesses. The person who produces the number should think of four numbers that do not repeat the number, and must not let the guesser know. Those who guess can start to guess. For each guess of a number, the number An and B are given according to the number, where the number in front of A represents the number of numbers in the right position, and the number before B represents the number of numbers that are correct but not in the right position. If the correct answer is 5234, and the guesser guesses 5346, it is 1A2B, where one of 5 is in the right position, marked 1A, while the two numbers 3 and 4 are right, but the position is not right, so it is marked as 2B, which adds up to 1A2B. Then the guesser continues to guess according to the An and B of the author until he guesses correctly (that is, 4A0B).
The person who guesses has eight chances.
For example:
B gives a number, A guess.
An and B
1234 1A0B
5678 2A1B
5674 1A1B
5638 1A1B
2678 2A2B
6278 4A0B (guess)
Source code:
#! / bin/bashclearechoecho "#" echo "# this is a bash-shell game write by lee #" echo "# this game is infinite frequency guess the number #" echo "# version 2.1. 1.20200421 # "echo" # "echo-e"\ n\ n "declare INPUTdeclare PASSWORDdeclare LEN_PWDdeclare Adeclare Bdeclare LOOP#this function is create random numberrandom_number () {PASSWORD=$RANDOM LEN_PWD= `echo $PASSWORD | wc-L` if [ [$LEN_PWD-ne 4]] then random_number else # output standard value Test need Development completed comment out echo $PASSWORD input fi} # this function is accept the input from user's keyboardinput () {read-N4-p "please input a number between 0000-9999:" input# 10x ${input} binary conversion if [[10x ${input}-eq 10x ${PASSWORD}]] then echo-e "\ n" echo "# # # "echo" # conventionalization eq you have tried $LOOP timeship # "echo" # The password is $PASSWORD! # "echo" # "exit elif [[$LOOP-eq 6]] then echo-e"\ n "echo" You have tried $LOOP timesplaying Game over! " Exit else You have tried 0 count_a count_b echo-e "\ n" echo "* *" echo "*" $A "A" $B "B *" echo "* *" echo "You have tried $LOOP times! You left `LOOP` times!" LOOP= `expr $LOOP + 1`expr} # this function is count the variable A's valuecount_a () {for i in `seq 4`expr `expr substr $input $I 1`for j in `seq 4`do VAR_PASSWORD= `expr substr $PASSWORD $j 1`if [[$VAR_INPUT-eq $VAR_PASSWORD]] & & [[$I-eq $j]] then A = `expr $A + 1`fi done done} # this function is count the variable B's valuecount_b () {for i in `expr 4`do VAR_INPUT= `expr substr $input $I 1`for j in `seq 4` do VAR_ PASSWORD= `expr substr $PASSWORD $j 1` if [[$VAR_INPUT-eq $VAR_PASSWORD]] & & [[$I-ne $j]] then B = `expr $B + 1`expr} LOOP=1random_number finish reading this article on how linux implements guessing Mini Game If you think the content of the article is good, you can share it with more people.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.