Challenge your brain - play the Linux numbers game
Number games have always been a favorite of many people, and in the Linux system, there are also many fun digital games that allow us to try to challenge our brains. These games not only help us relax but also improve our logical thinking and calculation skills. This article will introduce some interesting Linux digital games, allowing you to experience different game fun while learning the Linux system.

A simple linux number guessing game source code
game rules:
Guessing number games are usually played by two people, one party gives the number and the other party guesses it. The person who guesses the numbers must think of 4 numbers without repeating numbers, and cannot let the guesser know. Anyone who guesses can start guessing. Every time a number is guessed, the person who guesses the number must give out how many A and how many B according to this number. The number before A indicates the number of numbers in the correct position, and the number before B indicates the number of numbers with correct numbers but in the wrong position. . For example, the correct answer is 5234, and the guesser guesses 5346, which is 1A2B. There is a 5 in the correct position, which is recorded as 1A, and the two numbers 3 and 4 are correct, but the positions are incorrect, so they are recorded as 2B. , together they are 1A2B. The guesser then continues to guess based on the questioner's number of A's and B's until the guess is correct (i.e. 4A0B).
The person who guesses has 8 chances.
For example:
B puts out a number and A guesses.
A B
1234 1A0B
5678 2A1B
5674 1A1B
5638 1A1B
2678 2A2B
6278 4A0B(guess correctly)
Source code:
#!/bin/bash clear echo echo "###################################################################" echo "# this is a bash-shell game write by lee #" echo "# this game is infinite frequency 猜数字 #" echo "# version 2.1.1.20200421 #" echo "###################################################################" echo -e "\n\n" declare INPUT declare PASSWORD declare LEN_PWD declare A declare B declare LOOP #this function is create random number random_number() { PASSWORD=$RANDOM LEN_PWD=`echo $PASSWORD | wc -L` if [[ $LEN_PWD -ne 4 ]] then random_number else #输出标准值,测试需要,开发完成注释掉 echo $PASSWORD input fi } #this function is accept the input from user's keyboard input() { read -n4 -p "please input a number between 0000-9999:" input # 10#${input} 进制转换 if [[ 10#${input} -eq 10#${PASSWORD} ]] then echo -e "\n" echo "#############################################" echo "#congratulations!You have tried $LOOP times!#" echo "# The password is $PASSWORD ! #" echo "#############################################" exit elif [[ $LOOP -eq 6 ]] then echo -e "\n" echo "You have tried $LOOP times!Game over!" exit else A=0 B=0 count_a count_b echo -e "\n" echo "****************************" echo "* "$A"A"$B"B *" echo "****************************" echo "You have tried $LOOP times! You left `expr 6 - $LOOP` times!" LOOP=`expr $LOOP + 1` input fi } #this function is count the variable A's value count_a() { for i in `seq 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 -eq $j ]] then A=`expr $A + 1` fi done done } #this function is count the variable B's value count_b() { for i in `seq 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` fi done done } LOOP=1 random_number
Through this article, we learned about some interesting Linux digital games, including Sudoku, Minesweeper, 2048, and more. These games are not only entertaining, but also very helpful for our intellectual development. In the Linux system, playing digital games can not only exercise your brain, but also deepen your understanding of Linux commands and operations. I hope readers can try these games, challenge themselves, learn in games, and have fun while learning!
The above is the detailed content of Challenge your brain - play the Linux numbers game. For more information, please follow other related articles on the PHP Chinese website!

Windowsispreferredfordesktopcomputingandgamingdueto:1)itsvastsoftwareandgamelibrary,2)user-friendlyandcustomizableinterface,3)extensivehardwarecompatibility,and4)performanceoptimizationcapabilities,despitesomeresource-heavyandupdate-relatedissues.


For years, Linux software distribution relied on native formats like DEB and RPM, deeply ingrained in each distribution's ecosystem. However, Flatpak and Snap have emerged, promising a universal approach to application packaging. This article exami

The differences between Linux and Windows in handling device drivers are mainly reflected in the flexibility of driver management and the development environment. 1. Linux adopts a modular design, and the driver can be loaded and uninstalled dynamically. Developers need to have an in-depth understanding of the kernel mechanism. 2. Windows relies on the Microsoft ecosystem, and the driver needs to be developed through WDK and signed and certified. The development is relatively complex but ensures the stability and security of the system.

The security models of Linux and Windows each have their own advantages. Linux provides flexibility and customizability, enabling security through user permissions, file system permissions, and SELinux/AppArmor. Windows focuses on user-friendliness and relies on WindowsDefender, UAC, firewall and BitLocker to ensure security.

Linux and Windows differ in hardware compatibility: Windows has extensive driver support, and Linux depends on the community and vendors. To solve Linux compatibility problems, you can manually compile drivers, such as cloning RTL8188EU driver repository, compiling and installing; Windows users need to manage drivers to optimize performance.

The main differences between Linux and Windows in virtualization support are: 1) Linux provides KVM and Xen, with outstanding performance and flexibility, suitable for high customization environments; 2) Windows supports virtualization through Hyper-V, with a friendly interface, and is closely integrated with the Microsoft ecosystem, suitable for enterprises that rely on Microsoft software.

The main tasks of Linux system administrators include system monitoring and performance tuning, user management, software package management, security management and backup, troubleshooting and resolution, performance optimization and best practices. 1. Use top, htop and other tools to monitor system performance and tune it. 2. Manage user accounts and permissions through useradd commands and other commands. 3. Use apt and yum to manage software packages to ensure system updates and security. 4. Configure a firewall, monitor logs, and perform data backup to ensure system security. 5. Troubleshoot and resolve through log analysis and tool use. 6. Optimize kernel parameters and application configuration, and follow best practices to improve system performance and stability.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver Mac version
Visual web development tools
