Operating Method of Chinese Chess Engine and Related Devices
By identifying and transforming the types of initial Chinese chess moves, various problems of inconsistent moves in the existing technology are solved, and the unified transformation of digital moves and the isolation between the logic layer and the UI rendering layer are realized, which improves the convenience of developers and the portability of the engine.
Patent Information
- Application Number
- CN202210605270.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-30
- Publication Date
- 2025-07-11
- Estimated Expiration
- 2042-05-30
AI Technical Summary
In the existing Chinese chess applications, various moves are not unified, which leads to developers need to manually convert or rely on a single move during the development process, which increases the difficulty of development and lacks a unified message notification mechanism and the binding problem between the logic layer and the UI rendering layer.
It provides a running method of the Chinese chess engine. By identifying the type of initial move, determining the starting position and target position of the target piece, and converting it into digital moves, realizing the unity of various moves, and supporting multiple UI rendering applications through the isolation settings between the logic layer and the UI rendering layer.
The unified transformation of various Chinese chess moves has been achieved, which reduces the difficulty of manual transformation, provides a convenient message notification mechanism, and improves the portability and development efficiency of the engine.
Smart Images

Figure CN114968239B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of Chinese chess engines, and in particular, to a method for operating a Chinese chess engine and related devices. Background Art
[0002] This section aims to provide background or context for the embodiments of the present application described in the claims. The descriptions herein are not admitted to be prior art merely because they are included in this section.
[0003] Currently, there are an endless number of chess applications derived from Chinese chess engines. Whether it is a PC client, a mobile device, or a web application, various Chinese chess applications have emerged. However, most of the existing Chinese chess applications currently only stay on the surface, with weak support for general FEN positions and PGN chess scores. Coupled with the outdated technology stacks implemented in current Chinese chess applications in the front-end field, and the entanglement of the core chess-playing functions with UI rendering, it is rather troublesome to migrate. In addition, the current Chinese chess engines do not have a perfect message notification mechanism, and it is impossible to timely notify developers for unified processing of various operations and changes on the chessboard. At the same time, the moves supported by most current Chinese chess applications are different and not unified, and the conversion of various moves during chess-playing gives developers a huge headache. Summary of the Invention
[0004] In view of the above technical problems, there is an urgent need for a method for operating a Chinese chess engine that can unify various moves.
[0005] Based on the above objectives, the present application provides a method for operating a Chinese chess engine, including:
[0006] Determining the type of the initial move based on the characteristics of the initial move of Chinese chess input;
[0007] Determining the starting position and the target position of the target piece in the initial move based on the type of the initial move;
[0008] Converting the initial move into a digital move based on the starting position and the target position.
[0009] In some exemplary embodiments, converting the initial move into a digital move based on the starting position and the target position includes:
[0010] Determining a first digital number corresponding to the starting position and a second digital number corresponding to the target position based on a preset list of piece position numbers;
[0011] Numerically expand the first digital number based on a preset algorithm, and convert the initial move into a digital move based on the expanded first digital number and the second digital number; or, numerically expand the second digital number based on a preset algorithm, and convert the initial move into a digital move based on the expanded second digital number and the first digital number.
[0012] In some exemplary embodiments, the types of the initial moves include Chinese vertical line moves, digital vertical line moves, UCCI coordinate moves, and grid serial number methods; determining the starting position and the target position of the target piece in the initial move based on the type of the initial move includes:
[0013] In response to determining that the type of the initial move is a digital vertical line move, determine the starting position based on the part of the initial move before the preset moving character, and determine the target position based on the starting position, the preset moving character, and the part of the initial move after the preset moving character;
[0014] In response to determining that the type of the initial move is a Chinese vertical line move, convert the initial move into a digital vertical line move, and determine the starting position and the target position based on the initial move converted into a digital vertical line move;
[0015] In response to determining that the type of the initial move is a UCCI coordinate move, determine the starting position based on the first two characters of the initial move, and determine the target position based on the last two characters of the initial move;
[0016] In response to determining that the type of the initial move is a grid serial number method, determine the starting position based on the number before the arrow character in the initial move, and determine the target position based on the number after the arrow character in the initial move.
[0017] In some exemplary embodiments, the method further includes:
[0018] Determine the legality of each move based on the starting position and the target position of the piece to be moved in each move;
[0019] In response to collecting an illegal move record, send the illegal move record to the third-party developer so that the third-party developer configures the corresponding UI rendering special effects.
[0020] In some exemplary embodiments, the method further includes:
[0021] In response to determining that a checkmate situation appears in the current chess game, send the checkmate situation to the third-party developer so that the third-party developer configures the corresponding UI rendering special effects.
[0022] In response to determining that a checkmate situation appears in the current chess game, send the checkmate situation to the third-party developer so that the third-party developer can configure corresponding UI rendering special effects.
[0023] In some exemplary embodiments, the logic layer of the Chinese chess engine is isolated from the UI rendering layer so that the logic layer can access different UI rendering applications.
[0024] In some exemplary embodiments, after determining the type of the initial move of the Chinese chess based on the characteristics of the input initial move of the Chinese chess, the method further includes:
[0025] In response to determining that the type of the initial move is a numerical move, no longer convert the initial move.
[0026] Based on the same inventive concept, an exemplary embodiment of the present application further provides a Chinese chess engine, including:
[0027] In some exemplary embodiments, the conversion module is specifically configured to:
[0028] Determine a first numerical number corresponding to the starting position and a second numerical number corresponding to the target position based on a preset list of piece position numbers;
[0029] Numerically expand the first numerical number based on a preset algorithm, and convert the initial move into a numerical move based on the expanded first numerical number and the second numerical number; or, numerically expand the second numerical number based on a preset algorithm, and convert the initial move into a numerical move based on the expanded second numerical number and the first numerical number.
[0030] In some exemplary embodiments, the types of the initial move include Chinese vertical line move, numerical vertical line move, UCCI coordinate move, and grid serial number method; the second determination module is specifically configured to:
[0031] In response to determining that the type of the initial move is a numerical vertical line move, determine the starting position based on the part of the initial move before the preset move character, and determine the target position based on the starting position, the preset move character, and the part of the initial move after the preset move character;
[0032] In response to determining that the type of the initial move is a Chinese vertical line move, convert the initial move into a numerical vertical line move, and determine the starting position and the target position based on the initial move converted into a numerical vertical line move;
[0033] In response to determining that the type of the initial move is the UCCI coordinate move, determine the starting position based on the first two characters of the initial move, and determine the target position based on the last two characters of the initial move;
[0034] In response to determining that the type of the initial move is the grid serial number method, determine the starting position based on the number before the arrow character in the initial move, and determine the target position based on the number after the arrow character in the initial move.
[0035] In some exemplary embodiments, the engine further includes a first notification module, and the first notification module is configured to:
[0036] Determine the legality of each move based on the starting position and the target position of the piece to be moved in each move;
[0037] In response to collecting an illegal move record, send the illegal move record to the third-party developer so that the third-party developer configures the corresponding UI rendering special effects.
[0038] In some exemplary embodiments, the engine further includes a second notification module, and the second notification module is configured to:
[0039] In response to determining that a check situation appears in the current chess game, send the check situation to the third-party developer so that the third-party developer configures the corresponding UI rendering special effects.
[0040] In response to determining that a checkmate situation appears in the current chess game, send the checkmate situation to the third-party developer so that the third-party developer configures the corresponding UI rendering special effects.
[0041] In some exemplary embodiments, the engine further includes a third determination module, and the third determination module is configured to:
[0042] In response to determining that the type of the initial move is the numerical move, no longer convert the initial move.
[0043] Based on the same inventive concept, the exemplary embodiments of the present application further provide an electronic device, including a memory, a processor, and a computer program stored on the memory and executable by the processor. When the processor executes the program, the running method of the Chinese chess engine as described above is implemented.
[0044] Based on the same inventive concept, the exemplary embodiments of the present application further provide a non-transitory computer-readable storage medium. The non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to cause a computer to execute the running method of the Chinese chess engine as described above.
[0045] As can be seen from the above, for the method, device, electronic device, and storage medium for operating a Chinese chess engine provided in this application, first, the type of the initial move of Chinese chess is determined according to the characteristics of the input initial move of Chinese chess; then, the starting position and the target position of the target piece in the initial move are determined according to the type of the initial move; finally, the initial move is converted into a digital move according to the starting position and the target position, so as to unify various input Chinese chess moves into digital moves, avoid various difficulties encountered in manual move conversion, and enable the Chinese chess engine of this application to be applicable to various Chinese chess moves, providing convenience for third-party developers. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the technical solutions in this application or related technologies, the following will briefly introduce the drawings required for use in exemplary embodiments or related technology descriptions. Obviously, the drawings in the following description are only exemplary embodiments of this application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0047] Figure 1 It is a schematic diagram of the application scenario of an exemplary embodiment of this application;
[0048] Figure 2 It is a schematic flowchart of a method for operating a Chinese chess engine according to an exemplary embodiment of this application;
[0049] Figure 3 It is a schematic diagram of a preset piece position number list of a Chinese chess according to an exemplary embodiment of this application;
[0050] Figure 4 It is a schematic diagram of the structure of a Chinese chess engine according to an exemplary embodiment of this application;
[0051] Figure 5 It is a schematic diagram of the structure of a specific electronic device according to an exemplary embodiment of this application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0052] The following will describe the principles and spirit of this application with reference to several exemplary embodiments. It should be understood that these embodiments are only provided to enable those skilled in the art to better understand and then implement this application, rather than limiting the scope of this application in any way. On the contrary, these embodiments are provided to make this application more thorough and complete, and to be able to convey the scope of this application to those skilled in the art completely.
[0053] According to the embodiments of this application, a method, device, electronic device, and storage medium for operating a Chinese chess engine are provided.
[0054] In this text, it should be understood that any number of elements in the drawings is for illustration rather than limitation, and any naming is only for distinction and does not have any limiting meaning.
[0055] The principles and spirit of the present application will be elaborated in detail below with reference to several representative embodiments of the present application. Summary of the Invention
[0057] In the current related technologies, the moves supported by most Chinese chess application programs are different and not unified. These moves include vertical line moves in Chinese, digital vertical line moves, UCCI coordinate moves, chessboard grid moves, and other types of moves. These moves are not interchangeable. When third-party developers develop Chinese chess application programs through a chess engine, they often need to manually convert various moves, or can only develop based on a single move provided by the development engine, which brings inconvenience to program development.
[0058] To solve the above problems, the present application provides a method for running a Chinese chess engine, specifically including:
[0059] First, determine the type of the initial move of Chinese chess according to the characteristics of the input initial move of Chinese chess; then determine the starting position and the target position of the target chess piece in the initial move according to the type of the initial move; finally, convert the initial move into a digital move according to the starting position and the target position, so as to unify the various input Chinese chess moves into digital moves, avoid various difficulties encountered in manual move conversion, and enable the Chinese chess engine of the present application to be applicable to various Chinese chess moves, providing convenience for third-party developers.
[0060] After introducing the basic principles of the present application, various non-limiting embodiments of the present application will be specifically introduced below.
[0061] Overview of Application Scenarios
[0062] Refer to Figure 1, which is a schematic diagram of the application scenario of the operation method of the Chinese chess engine provided by an exemplary embodiment of the present application. This application scenario includes a terminal device 101, a server 102, and a data storage system 103. Among them, the terminal device 101, the server 102, and the data storage system 103 can all be connected through a wired or wireless communication network. The terminal device 101 includes, but is not limited to, a desktop computer, a mobile phone, a mobile computer, a tablet computer, a media player, a smart wearable device, a personal digital assistant (PDA), or other electronic devices capable of implementing the above functions. The server 102 and the data storage system 103 can both be independent physical servers, or a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms.
[0063] The server 102 is used to provide the operation service of the Chinese chess engine to the users of the terminal device 101. A client communicating with the server 102 is installed in the terminal device 101, and the user can obtain data in the Chinese chess engine through this client. During the operation of the Chinese chess engine, the client inputs the initial move of Chinese chess by calling the input components (such as a touch screen, a keyboard, a camera, etc.) of the terminal device 101; the client sends the initial move of Chinese chess to the server 102. The server 102 can convert the input initial move into a digital move through the Chinese chess engine, so that the user can directly play chess through the input initial move. Optionally, after the initial move of Chinese chess is input to the client, the client can also convert the input initial move into a digital move through the Chinese chess engine.
[0064] Various data related to move conversion are stored in the data storage system 103. The server 102 can randomly retrieve various data related to move conversion from the data storage system 103.
[0065] Next, in combination with Figure 1 the application scenario, the operation method of the Chinese chess engine according to an exemplary embodiment of the present application will be described. It should be noted that the above application scenario is only shown for the convenience of understanding the spirit and principle of the present application, and the embodiments of the present application are not limited in this regard. On the contrary, the embodiments of the present application can be applied to any applicable scenario.
[0066] Exemplary Method
[0067] Refer to Figure 2, an exemplary embodiment of the present application provides a method for running a Chinese chess engine, and the method includes the following steps:
[0068] S101, determining the type of the initial move based on the characteristics of the initial move of Chinese chess input.
[0069] Specifically, when the initial move input to the Chinese chess engine is obtained, the type of the initial move can be determined according to the characteristics of the initial move. The characteristics of the initial move can be notation characteristics, that is, each type of move corresponds to a notation characteristic. For example, those containing Chinese belong to the Chinese vertical line method, the grid serial number move contains arrow characters, and the UCCI coordinate move is generally represented by a combination of two pairs of letters and numbers as the starting point grid coordinate and the target point grid coordinate. Optionally, a neural network model can also be trained to identify the type of the initial move.
[0070] It should be noted that the engines referred to in the present application are all engines in the computer field, and the moves of Chinese chess represent the positions where a certain piece in Chinese chess moves from and to.
[0071] S102, determining the starting position and the target position of the target piece in the initial move based on the type of the initial move.
[0072] Specifically, after determining the type of the initial move, according to the type of the initial move, the starting position and the target position of the target piece in the initial move are determined. Among them, the starting position is the current position of the target piece, and the target position is the position where the target piece will reach.
[0073] In some embodiments, the types of the initial move include the Chinese vertical line move, the digital vertical line move, the UCCI coordinate move, and the grid serial number method; determining the starting position and the target position of the target piece in the initial move based on the type of the initial move includes:
[0074] In response to determining that the type of the initial move is the digital vertical line move, determining the starting position based on the part before the preset move character in the initial move, and determining the target position based on the starting position, the preset move character, and the part after the preset move character in the initial move;
[0075] In response to determining that the type of the initial move is the Chinese vertical line move, converting the initial move into a digital vertical line move, and determining the starting position and the target position based on the initial move converted into the digital vertical line move;
[0076] In response to determining that the type of the initial move is the UCCI coordinate move, determine the starting position based on the first two characters of the initial move, and determine the target position based on the last two characters of the initial move;
[0077] In response to determining that the type of the initial move is the grid serial number method, determine the starting position based on the number before the arrow character in the initial move, and determine the target position based on the number after the arrow character in the initial move.
[0078] In specific implementation, when determining that the type of the initial move is the digital vertical line move, first determine the preset movement character in the initial move. The preset movement character mainly refers to the character indicating movement. For example, the movement character "." represents translation, the movement character "+" represents forward movement, and the movement character "-" represents backward movement. It should be noted that to avoid confusion with the characters indicating directions, the preset movement character is the movement character after the letter. For example, in "+C+2", "+C" represents the front cannon (the cannon in the front), and "+C+2" represents the front cannon moving forward two grids. After determining the preset movement character, the starting position can be determined according to the part before the preset movement character in the initial move, and the target position can be determined according to the starting position, the preset movement character, and the part after the preset movement character in the initial move. Optionally, the starting position can be determined according to the current Chinese chess situation in the Chinese chess engine and the meaning of the part before the preset movement character, and then the target position can be determined according to the current Chinese chess situation, the starting position, the preset movement character, and the meaning of the part after the preset movement character in the initial move. It should be noted that the situation in this application is for the Chinese chess field and is used to describe the distribution of the pieces of the two players currently playing chess.
[0079] When determining that the type of the initial move is the Chinese vertical line move, since this move is not easy to process by the program, therefore, we convert the Chinese vertical line move into the digital vertical line move according to the relevant Chinese mapping table and characteristic mapping rules (part of the mapping table includes the mapping of piece types, such as converting the cannon to C, the mapping of converting Chinese numbers to Arabic numbers, such as converting two to 2, and the mapping of converting the movement type to a symbol, such as converting horizontal movement to "."). For example, convert "cannon two horizontal five" to: "C2.5", and then continue to process through the processing method of the digital vertical line move as described above, and determine the starting position and the target position according to the initial move converted into the digital vertical line move.
[0080] When it is determined that the type of the initial move is the UCCI coordinate move, the starting position is determined according to the first two characters of the initial move, and the target position is determined according to the last two characters of the initial move. For example, in "h2e2", the starting position can be determined according to "h2", and the target position can be determined according to "e2". Among them, h and 2 in "h2" respectively represent the abscissa and ordinate in the preset chessboard.
[0081] When it is determined that the type of the initial move is the grid serial number move, the starting position can be determined according to the number before the arrow character in the initial move, and the target position can be determined according to the number after the arrow character in the initial move. For example, in "170—>167", "—>" is the arrow character, 170 represents the position numbered 170 in the preset chessboard, and 167 represents the position numbered 167 in the preset chessboard.
[0082] In some embodiments, after determining the type of the initial move of Chinese chess based on the characteristics of the input initial move, the method further includes:
[0083] In response to determining that the type of the initial move is the digital move, the initial move is not transformed.
[0084] Specifically, when it is determined that the type of the initial move is the digital move, the initial move does not need to be transformed.
[0085] S103, transform the initial move into a digital move based on the starting position and the target position.
[0086] Specifically, after determining the starting position and the target position of the initial move, the initial move is transformed into a digital move according to the starting position and the target position.
[0087] In some embodiments, transforming the initial move into a digital move based on the starting position and the target position includes:
[0088] Determine the first digital number corresponding to the starting position and the second digital number corresponding to the target position based on the preset list of piece position numbers;
[0089] Perform numerical expansion on the first digital number based on a preset algorithm, and transform the initial move into a digital move based on the expanded first digital number and the second digital number; or, perform numerical expansion on the second digital number based on a preset algorithm, and transform the initial move into a digital move based on the expanded second digital number and the first digital number.
[0090] Specifically, refer to Figure 3, where in the preset list of piece position numbers, each position on the chessboard corresponds to a numerical number. For example, Figure 3 the numerical number corresponding to the position of the black rook in Figure 3 is 051. Optionally, the specific value of the numerical number can be set as needed and is not limited herein. After determining the starting position and the target position of the target piece in the initial move, the first numerical number corresponding to the starting position and the second numerical number corresponding to the target position can be determined according to the preset list of piece position numbers. The numerical move in this application mainly represents a move by a single number. For example, the simplest numerical move can be the direct addition of the first numerical number and the second numerical number. For example, if the first numerical number corresponding to the starting position of a certain move is 40 and the second numerical number corresponding to the target position is 60, then 100 can be used to represent the numerical move corresponding to this move. However, if the numerical move is directly determined by the first numerical number and the second numerical number, it will lead to the inability to distinguish two different moves in some cases. For example, if the first numerical number corresponding to the starting position of a certain move is 30 and the second numerical number corresponding to the target position is 70, and the two are directly added, then the numerical move for this time is also 100, but this move is significantly different from the first move with the same numerical move of 100. To avoid this situation, it is necessary to numerically expand the first numerical number or the second numerical number through a preset algorithm, and then determine the current numerical move based on the expanded numerical number. The preset algorithm can be set as needed and is not limited herein. For example, if the first numerical number corresponding to the starting position of a certain move is 40 and the second numerical number corresponding to the target position is 60, and the preset algorithm is to expand the first numerical number by 8 times, then the numerical move at this time is: 40 * 8 + 60 = 3260. When the first numerical number is 30 and the second numerical number is 70 at this time, the corresponding numerical move is: 30 * 8 + 70 = 2470. Thus, each numerical move has uniqueness.
[0091] In some exemplary embodiments, the method further includes:
[0092] Determining the legality of each move based on the starting position and the target position of the piece to be moved in each move;
[0093] In response to collecting an illegal move record, sending the illegal move record to a third-party developer so that the third-party developer configures the corresponding UI rendering special effects.
[0094] In specific implementation, some preset rules of Chinese chess can be used, and the legality of each chess move can be determined based on the starting position and the target position of the piece to be moved in each chess move. Optionally, it can be checked whether there is a piece at the starting point. If there is no piece, the move is illegal. It can also be checked whether there is a piece of the moving side at the target point. If there is a piece of the moving side blocking the way, the move is illegal. In addition, the legality of each chess move can be judged according to the different types of the target piece. For example, the general can only move in the four directions of up, down, left, and right within the general's tent and can only move one step at a time. After determining the legality of each chess move, when an illegal chess move record is collected, the illegal chess move record is sent to the third-party developer so that the third-party developer can configure the corresponding UI rendering special effects. It should be noted that in this application, the legality of the chess move is actively verified, and when an illegal chess move is monitored, the illegal chess move record is actively sent to the third-party developer. The third-party developer can configure the corresponding UI rendering special effects according to the illegal chess move record, which is convenient for the third-party developer to customize the UI rendering special effects personalizedly.
[0095] In some embodiments, the method further includes:
[0096] In response to determining that a checkmate situation appears in the current chess game, the checkmate situation is sent to the third-party developer so that the third-party developer can configure the corresponding UI rendering special effects.
[0097] In response to determining that a stalemate situation appears in the current chess game, the stalemate situation is sent to the third-party developer so that the third-party developer can configure the corresponding UI rendering special effects.
[0098] In specific implementation, some preset rules of Chinese chess can be used to determine whether a checkmate situation appears in the current chess game. Optionally, taking the perspective of the opponent's general or marshal as a reference, all the opponent's pieces in the entire chessboard array can be traversed. As long as any one piece can reach the position of the opponent's general or marshal within one move, it is considered that there is a checkmate situation at this time. Optionally, some preset rules of Chinese chess can be used to determine whether a stalemate situation appears in the current chess game. Optionally, after a certain side makes a move, first judge whether there is a check situation. If there is no check, it is not a stalemate. If there is a checkmate situation, then traverse all our pieces and use the virtual move (that is, try to make a move and then revoke it. The actual chessboard does not change, but more information can be obtained after trying to make a move) method to let all pieces try to take one step using their respective legal move methods to see if a move that can solve the checkmate situation can be achieved. If all the moves of all pieces cannot solve the situation, then it can be judged that the current situation has reached a stalemate against the opponent. When a checkmate situation or a stalemate situation is monitored, the checkmate situation or the stalemate situation is sent to the third-party developer so that the third-party developer can configure personalized UI rendering special effects.
[0099] In most existing Chinese chess engines, the logic layer for playing chess is more or less bound to the UI rendering layer. When these basic engine libraries were designed, the strong portability of the engine was not considered, and a specific UI framework was used in the development process. This makes it extremely difficult to extract the logic layer of the engine into another UI framework. However, with the continuous development of front-end technologies, browser compatibility issues have been gradually resolved, and the emergence of more and more view-layer UI rendering frameworks has brought more choices to developers, but at the same time, it has also exposed the drawbacks brought by the strong binding to the UI framework to the engine library. To avoid these drawbacks, in some embodiments, the logic layer of the Chinese chess engine is isolated from the UI rendering layer, so that the logic layer can access different UI-rendered applications, thereby making the Chinese chess engine of the present application highly portable.
[0100] In some embodiments, the Chinese chess engine of the present application provides static methods for parsing and generating PGN chess scores. Third-party developers can input existing PGN chess scores in the form of strings, and then the current chess score structure can be parsed, and a quick step-by-step method can be generated to facilitate step-by-step review. Among them, PGN is used to record the norms of Chinese chess games. In addition to containing the moves, it also includes other information and annotations of the chess game. Specifically, when the Chinese chess engine of the present application receives an incoming PGN chess score, it will first perform feature parsing on the chess score, parse and process the two sides of the current chess score, the starting situation, the win-loss situation, the game name, the game time, the specific move records, etc. to form a PGN object. Then, according to the move records in this PGN object, a number is set for each move, and a method that can execute the chess-playing operation several times in a loop according to the number is generated, and a quick method for switching the corresponding move according to the number is passed in. Third-party developers can directly input the target number of moves to update the current chessboard to the state of the target number of moves.
[0101] In some embodiments, the Chinese chess engine of the present application provides a complete cli command-line tool that developers can choose to install and use as needed, supporting various operations such as quickly playing chess and reviewing in the command line to improve efficiency. When playing chess, when the user inputs a certain move, the doMove method of the Chinese chess engine instance is called to play chess, and the command-line tool will display all types of move information of the current move in real time, facilitating developers to quickly obtain different moves for each step. The user can also use the free mode and use keys such as the up, down, left, and right arrow keys and the space bar and enter key to perform more efficient chess-playing operations.
[0102] The operation method of the Chinese chess engine provided by this application first determines the type of the initial move according to the characteristics of the initial move of Chinese chess input; then determines the starting position and the target position of the target chess piece in the initial move according to the type of the initial move; finally, converts the initial move into a digital move according to the starting position and the target position, so as to unify various Chinese chess moves input into digital moves, avoid various difficulties encountered in manual move conversion, and enable the Chinese chess engine of this application to be applicable to various Chinese chess moves, providing convenience for third-party developers. At the same time, through a perfect message notification mechanism, this application can notify the outside world of most details of the user's operation on the chessboard by dispatching subscription messages, facilitating third-party developers to handle various special situations more flexibly. In addition, the logic layer and the UI rendering layer of the Chinese chess engine of this application are isolated, making it more convenient for third-party developers to connect the logic layer to various types of UI rendering libraries.
[0103] Exemplary Device
[0104] Based on the same inventive concept, corresponding to the method of any of the above exemplary embodiments, this application also provides a Chinese chess engine.
[0105] Reference Figure 4 , the Chinese chess engine includes:
[0106] A first determination module 201 that determines the type of the initial move based on the characteristics of the initial move of Chinese chess input;
[0107] A second determination module 202 that determines the starting position and the target position of the target chess piece in the initial move based on the type of the initial move;
[0108] A conversion module 203 that converts the initial move into a digital move based on the starting position and the target position.
[0109] In some exemplary embodiments, the conversion module is specifically configured to:
[0110] Determine a first digital number corresponding to the starting position and a second digital number corresponding to the target position based on a preset chess piece position number list;
[0111] Perform numerical expansion on the first digital number based on a preset algorithm, and convert the initial move into a digital move based on the expanded first digital number and the second digital number; or, perform numerical expansion on the second digital number based on a preset algorithm, and convert the initial move into a digital move based on the expanded second digital number and the first digital number.
[0112] In some exemplary embodiments, the types of the initial moves include Chinese vertical line moves, digital vertical line moves, UCCI coordinate moves, and grid serial number methods; the second determination module is specifically configured to:
[0113] In response to determining that the type of the initial move is a digital vertical line move, determine the starting position based on the part of the initial move before the preset move character, and determine the target position based on the starting position, the preset move character, and the part of the initial move after the preset move character;
[0114] In response to determining that the type of the initial move is a Chinese vertical line move, convert the initial move into a digital vertical line move, and determine the starting position and the target position based on the initial move converted into a digital vertical line move;
[0115] In response to determining that the type of the initial move is a UCCI coordinate move, determine the starting position based on the first two characters of the initial move, and determine the target position based on the last two characters of the initial move;
[0116] In response to determining that the type of the initial move is a grid serial number method, determine the starting position based on the number before the arrow character in the initial move, and determine the target position based on the number after the arrow character in the initial move.
[0117] In some exemplary embodiments, the engine further includes a first notification module, and the first notification module is configured to:
[0118] Determine the legality of each move based on the starting position and the target position of the piece to be moved in each move;
[0119] In response to collecting an illegal move record, send the illegal move record to the third-party developer so that the third-party developer configures the corresponding UI rendering special effects.
[0120] In some exemplary embodiments, the engine further includes a second notification module, and the second notification module is configured to:
[0121] In response to determining that a check situation appears in the current chess game, send the check situation to the third-party developer so that the third-party developer configures the corresponding UI rendering special effects.
[0122] In response to determining that a checkmate situation appears in the current chess game, send the checkmate situation to the third-party developer so that the third-party developer configures the corresponding UI rendering special effects.
[0123] In some exemplary embodiments, the engine further includes a third determination module, which is configured to:
[0124] In response to determining that the type of the initial move is a numeric move, the initial move is not transformed any further.
[0125] For convenience of description, when describing the above device, various modules are described separately according to their functions. Of course, when implementing this application, the functions of each module can be implemented in one or more pieces of software and / or hardware.
[0126] The device of the above exemplary embodiment is used to implement the running method of the corresponding Chinese chess engine in any of the foregoing exemplary embodiments, and has the beneficial effects of the corresponding method exemplary embodiments, which will not be elaborated here.
[0127] Based on the same inventive concept, corresponding to the method of any of the above exemplary embodiments, the present application further provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, it implements the running method of the Chinese chess engine described in any of the above exemplary embodiments.
[0128] Figure 5 FIG. shows a more specific schematic diagram of the hardware structure of the electronic device provided in this exemplary embodiment. The device may include: a processor 301, a memory 302, an input / output interface 303, a communication interface 304, and a bus 305. Among them, the processor 301, the memory 302, the input / output interface 303, and the communication interface 304 are communicatively connected to each other inside the device through the bus 305.
[0129] The processor 301 may be implemented in a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, etc., and is used to execute relevant programs to implement the technical solutions provided in the exemplary embodiments of this specification.
[0130] The memory 302 may be implemented in the form of a ROM (Read Only Memory), a RAM (Random Access Memory), a static storage device, a dynamic storage device, etc. The memory 302 may store an operating system and other application programs. When implementing the technical solutions provided in the exemplary embodiments of this specification through software or firmware, the relevant program codes are stored in the memory 302 and called and executed by the processor 301.
[0131] The input / output interface 303 is used to connect to the input / output module to achieve information input and output. The input / output module can be configured as a component in the device (not shown in the figure), or can be externally connected to the device to provide corresponding functions. Among them, the input device can include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output device can include a display, a speaker, a vibrator, an indicator light, etc.
[0132] The communication interface 304 is used to connect to the communication module (not shown in the figure) to achieve communication and interaction between this device and other devices. Among them, the communication module can achieve communication through a wired method (such as USB, network cable, etc.), or can achieve communication through a wireless method (such as a mobile network, WIFI, Bluetooth, etc.).
[0133] The bus 305 includes a path for transmitting information between various components of the device (such as the processor 301, the memory 302, the input / output interface 303, and the communication interface 304).
[0134] It should be noted that although the above device only shows the processor 301, the memory 302, the input / output interface 303, the communication interface 304, and the bus 305, in the specific implementation process, the device may also include other components necessary for normal operation. In addition, those skilled in the art can understand that the above device may also only include the components necessary to implement the solution of the exemplary embodiment of this specification, and does not necessarily include all the components shown in the figure.
[0135] The electronic device of the above exemplary embodiment is used to implement the running method of the corresponding Chinese chess engine in any of the foregoing exemplary embodiments, and has the beneficial effects of the corresponding method exemplary embodiments, which will not be elaborated here.
[0136] Exemplary Program Product
[0137] Based on the same inventive concept, corresponding to any of the above exemplary embodiment methods, the present application also provides a non-transitory computer-readable storage medium, and the non-transitory computer-readable storage medium stores computer instructions for causing the computer to execute the running method of the Chinese chess engine as described in any of the foregoing exemplary embodiments.
[0138] The computer-readable medium of this exemplary embodiment includes permanent and non-permanent, removable and non-removable media. Information storage can be implemented by any method or technology. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette tapes, magnetic disk storage or other magnetic storage devices, or any other non-transitory medium that can be used to store information that can be accessed by a computing device.
[0139] The computer instructions stored in the storage medium of the above exemplary embodiment are used to cause the computer to execute the operation method of the Chinese chess engine described in any of the above exemplary embodiments, and have the beneficial effects of the corresponding method exemplary embodiments, which will not be elaborated here.
[0140] Those of ordinary skill in the art should understand that: the discussion of any of the above exemplary embodiments is only exemplary and is not intended to imply that the scope of the present application (including the claims) is limited to these examples; under the concept of the present application, the technical features in the above exemplary embodiments or different exemplary embodiments can also be combined, the steps can be implemented in any order, and there are many other variations in different aspects of the exemplary embodiments of the present application as described above, which are not provided in detail for the sake of brevity.
[0141] In addition, for simplicity of description and discussion, and so as not to make the exemplary embodiments of the present application difficult to understand, the well-known power / ground connections to integrated circuit (IC) chips and other components may or may not be shown in the provided drawings. Further, the devices may be shown in block diagram form so as not to make the exemplary embodiments of the present application difficult to understand, and this also takes into account the fact that the details of the implementation of these block diagram devices are highly dependent on the platform on which the exemplary embodiments of the present application are to be implemented (i.e., these details should be entirely within the understanding of those skilled in the art). In cases where specific details (such as circuits) are set forth to describe the exemplary embodiments of the present application, it will be apparent to those skilled in the art that the exemplary embodiments of the present application can be implemented without these specific details or with variations of these specific details. Therefore, these descriptions should be considered illustrative rather than restrictive.
[0142] Although the present application has been described in connection with specific exemplary embodiments thereof, many alternatives, modifications, and variations of these exemplary embodiments will be apparent to those of ordinary skill in the art in light of the foregoing description. For example, other memory architectures (e.g., dynamic RAM (DRAM)) may be used with the exemplary embodiments discussed.
[0143] The exemplary embodiments of the present application are intended to cover all such alternatives, modifications, and variations that fall within the broad scope of the appended claims. Accordingly, any omissions, modifications, equivalent substitutions, improvements, etc., made within the spirit and principle of the exemplary embodiments of the present application shall be included within the protection scope of the present application.
Claims
1. A method for running a Chinese chess engine, characterized in that including: determining the type of the initial move based on the characteristics of the initial move of Chinese chess in the input, where the type of the initial move includes Chinese vertical line move, digital vertical line move, UCCI coordinate move, and grid serial number method; determining the starting position and the target position of the target piece in the initial move based on the type of the initial move; converting the initial move into a digital move based on the starting position and the target position, including: determining a first digital number corresponding to the starting position and a second digital number corresponding to the target position based on a preset list of piece position numbers; numerically expanding the first digital number based on a preset algorithm, and converting the initial move into a digital move based on the expanded first digital number and the second digital number; or, numerically expanding the second digital number based on a preset algorithm, and converting the initial move into a digital move based on the expanded second digital number and the first digital number; the logic layer of the Chinese chess engine is isolated from the UI rendering layer so that the logic layer can access different UI rendering applications.
2. The method according to claim 1, wherein determining the starting position and the target position of the target piece in the initial move based on the type of the initial move, including: in response to determining that the type of the initial move is a digital vertical line move, determining the starting position based on the part of the initial move before a preset move character, and determining the target position based on the starting position, the preset move character, and the part of the initial move after the preset move character; in response to determining that the type of the initial move is a Chinese vertical line move, converting the initial move into a digital vertical line move, and determining the starting position and the target position based on the initial move converted into a digital vertical line move; in response to determining that the type of the initial move is a UCCI coordinate move, determining the starting position based on the first two characters of the initial move, and determining the target position based on the last two characters of the initial move; in response to determining that the type of the initial move is a grid serial number method, determining the starting position based on the number before the arrow character in the initial move, and determining the target position based on the number after the arrow character in the initial move.
3. The method according to claim 1, wherein The method further includes: determining the legality of each move based on the starting position and the target position of the piece to be moved in each move; in response to collecting an illegal move record, sending the illegal move record to a third-party developer so that the third-party developer configures a corresponding UI rendering special effect.
4. The method according to claim 1, characterized in that The method further includes: in response to determining that a check situation appears in the current chess game, sending the check situation to a third-party developer so that the third-party developer configures a corresponding UI rendering special effect; in response to determining that a checkmate situation appears in the current chess game, sending the checkmate situation to the third-party developer so that the third-party developer configures a corresponding UI rendering special effect.
5. The method according to claim 1, characterized in that After determining the type of the initial move based on the characteristics of the initial move of Chinese chess in the input, the method further includes: In response to determining that the type of the initial move is a numeric move, the initial move is no longer transformed.
6. An operating device for a Chinese chess engine, characterized in that, Comprising: A first determination module that determines the type of the initial move based on the characteristics of the initial move of Chinese chess, wherein the type of the initial move includes a Chinese vertical line move, a numeric vertical line move, a UCCI coordinate move, and a grid serial number method; A second determination module that determines the starting position and the target position of the target chess piece in the initial move based on the type of the initial move; A transformation module that transforms the initial move into a numeric move based on the starting position and the target position, including: determining a first numeric number corresponding to the starting position and a second numeric number corresponding to the target position based on a preset chess piece position number list; numerically expanding the first numeric number based on a preset algorithm, and transforming the initial move into a numeric move based on the expanded first numeric number and the second numeric number; or numerically expanding the second numeric number based on a preset algorithm, and transforming the initial move into a numeric move based on the expanded second numeric number and the first numeric number; the logic layer of the Chinese chess engine is isolated from the UI rendering layer so that the logic layer can access different UI rendering application programs.
7. An electronic device, characterized in that, Comprising a memory, a processor, and a computer program stored on the memory and executable by the processor, and when the processor executes the program, the method according to any one of claims 1 to 5 is implemented.
8. A non-transitory computer-readable storage medium, characterized in that, The non-transitory computer-readable storage medium stores computer instructions for causing a computer to execute the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Chinese chess game learning method based on deep reinforcement learning method and system thereof
CN113599798A