Method, device, electronic device and storage medium for processing chess game
By using the preset FEN format to record the chess information in the Jieqi game, the problems of cumbersome notation and analysis in the existing technology are solved, and more efficient chess game recording and dissemination are achieved.
Patent Information
- Application Number
- CN202211058566.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-30
- Publication Date
- 2025-03-21
- Estimated Expiration
- 2042-08-30
AI Technical Summary
In the existing technology, the notation operation of chess and chess games is complicated, which makes it difficult to analyze chess games and is not conducive to the spread of chess games.
The preset FEN format is used to record the chess information of each chess grid position on the chessboard, including the chess position information and the chess type information on the chess grid, simplifying the notation process and improving the analysis efficiency.
It significantly reduces the difficulty of recording chess, improves the analysis and dissemination efficiency of chess games, and provides users with a better experience.
Smart Images

Figure CN115445173B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of computer technology. More specifically, the embodiments of the present invention relate to a method, device, electronic device and storage medium for processing a chess game. Background Art
[0002] The "FEN" notation that already exists on the market is suitable for notating the normal Chinese chess game mode. FEN (Forsyth-Edwards Notation) is a recording standard specifically used to represent chess situations. Under this standard, a situation can be simply represented by a line of "FEN format string" instead of the tedious "Red general is at the fourth bottom line, Black general is at the fifth bottom line...". Since it is in text format (involving only a very limited number of letters, numbers and symbols), it is very convenient to transmit chess games online. Instead of drawing chess pictures on paper or describing them clumsily with complex text, you can use chess editing software to set up the situation, automatically get the FEN format string, and then paste it on network application platforms that can transmit text, such as Web pages, BBS, electronic forums, etc. Summary of the invention
[0003] However, due to the need to save and disseminate chess games, most of the products known in the prior art that support chess games record the chess-playing process into a relatively complex JSON file. The JSON format is suitable for relatively complex object transmission methods, and uses its key-value pair method to transmit information. When using JSON, a lot of redundant data is easily generated, which will bring a lot of inconvenience when parsing and disseminating the chess game, and is not conducive to the preservation and dissemination of the chess game.
[0004] Therefore, in the prior art, the operation of recording chess games is cumbersome, which makes it difficult to analyze the chess games and is not conducive to the dissemination of the chess games. This is a very annoying process.
[0005] Therefore, there is a great need for an improved chess game notation method suitable for the Chinese chess game disclosure mode, which is easy to analyze and spread, so as to make the chess game analysis easier and the chess game dissemination more convenient.
[0006] In this context, embodiments of the present invention are intended to provide a method, device, electronic device and storage medium for processing a chess game.
[0007] In a first aspect of an embodiment of the present invention, a method for processing a chess game is provided, comprising:
[0008] Detecting a chess move operation on a target hidden chess piece on a target chessboard;
[0009] In response to the chess move operation, generating a chess move record of the target hidden chess piece;
[0010] The move records of the target hidden chess pieces are recorded in a preset FEN file, wherein the preset FEN file is used to record the chess square information of each chess square position on the chessboard in the chess game mode in a preset FEN format, and the chess square information includes the chess square position information and the chess piece type information on the chess square.
[0011] In one embodiment of the present invention, in response to the chess move operation, generating a chess move record of the target dark chess piece includes:
[0012] Identify first chess square position information of the target dark chess piece from a first chessboard image corresponding to before the target dark chess piece moves, and identify second chess square position information of the target dark chess piece from a second chessboard image corresponding to after the target dark chess piece moves;
[0013] When a flipping operation of the target hidden chess piece is detected, determining first chess piece type information corresponding to the target hidden chess piece;
[0014] The chess move record is generated according to the first chess square position information, the second chess square position information and the first chess piece type information corresponding to the target dark chess piece.
[0015] In one embodiment of the present invention, the determining the first chess piece type information corresponding to the target dark chess piece includes:
[0016] Acquire a third chessboard image corresponding to the target dark chess piece becoming a bright chess piece;
[0017] Identify first chess piece type information of a chess piece in standard chess corresponding to the target dark chess piece from the third chessboard image, wherein the first chess piece type information is used to characterize the chess piece name of the chess piece in standard chess.
[0018] In one embodiment of the present invention, generating a move record of the target dark chess piece according to the first chess square position information, the second chess square position information and the first chess piece type information corresponding to the target dark chess piece includes:
[0019] sequentially marking the first chess square position information, the second chess square position information and the first chess piece type information with characters to obtain a target character string consisting of a plurality of first characters;
[0020] The target character string is used as the chess move record to be recorded in the preset FEN file.
[0021] In one embodiment of the present invention, before recording the move record of the target dark chess piece into a preset FEN file, the method further includes:
[0022] Acquire an initial chess game image, wherein the initial chess game image includes an initialized chess game based on a chess game mode;
[0023] Sequentially identifying chess square information of each chess square position from the initial chess game image, wherein the chess square information includes second chess piece type information of the chess piece on the chess square, and the second chess piece type information is used to indicate whether the chess piece belongs to an open chess piece or a hidden chess piece of a target party among two players;
[0024] According to the preset FEN format, the chess information of each chess position is marked with characters in turn to obtain a first FEN format string consisting of a plurality of second characters;
[0025] The first FEN format string is recorded into the preset FEN file.
[0026] In one embodiment of the present invention, after detecting a move operation on a target dark chess piece on a target chessboard, the method further includes:
[0027] When it is detected that the chess move operation is the first chess move by the target party of the two players, the target party is marked with a third character, and the start signal of the chess move in the initial situation is marked with a fourth character;
[0028] On the basis of the first FEN format string, sequentially concatenate the third character and the fourth character to obtain a second FEN format string;
[0029] The second FEN format string is recorded into the preset FEN file.
[0030] In one embodiment of the present invention, after recording the move record of the target dark chess piece into a preset FEN file, the method further includes:
[0031] Decompose each character in the preset FEN file;
[0032] Parsing each character according to the preset parsing rule corresponding to the preset FEN file to obtain the chess square information of each chess square on the chessboard;
[0033] Restore the chess game on the board based on the information of each chess square.
[0034] In a second aspect of the embodiments of the present invention, a chess game processing device is provided, the device comprising:
[0035] A detection module, used to detect chess moves targeting target hidden chess pieces on a target chessboard;
[0036] A generating module, for generating a chess move record of the target hidden chess piece in response to the chess move operation;
[0037] The first recording module is used to record the chess moves of the target hidden chess pieces into a preset FEN file, wherein the FEN file is used to record the chess square information of each chess square position on the chessboard in the chess game mode in a preset FEN format, and the chess square information includes the chess square position information and the chess piece type information on the chess square.
[0038] In one embodiment of the present invention, the generating module comprises:
[0039] an identification unit, used to identify first chess square position information of the target dark chess piece from a first chessboard image corresponding to before the target dark chess piece moves, and to identify second chess square position information of the target dark chess piece from a second chessboard image corresponding to after the target dark chess piece moves;
[0040] A determination unit, configured to determine first chess piece type information corresponding to the target dark chess piece when a flipping operation of the target dark chess piece is detected;
[0041] A generating unit is used to generate the chess move record according to the first chess square position information, the second chess square position information and the first chess piece type information corresponding to the target hidden chess piece.
[0042] In one embodiment of the present invention, the determining unit includes:
[0043] A collection subunit, used for collecting a third chessboard image corresponding to the target dark chess piece becoming a bright chess piece;
[0044] The identification subunit is used to identify the first chess piece type information of the chess piece in the standard chess corresponding to the target dark chess piece from the third chessboard image, wherein the first chess piece type information is used to represent the chess piece name of the chess piece in the standard chess.
[0045] In one embodiment of the present invention, the generating unit includes:
[0046] a marking subunit, used to mark the first chess square position information, the second chess square position information and the first chess piece type information with characters in sequence to obtain a target character string consisting of a plurality of first characters;
[0047] The recording subunit is used to record the target character string as the chess move record in the preset FEN file.
[0048] In another embodiment of the present invention, the device further comprises:
[0049] An acquisition module, used for acquiring an initial chess game image before the first recording module records the chess move record of the target hidden chess game into a preset FEN file, wherein the initial chess game image includes an initialized chess game based on a chess game mode;
[0050] an identification module, used to sequentially identify chess square information of each chess square position from the initial chess game image, wherein the chess square information includes second chess piece type information of the chess piece on the chess square, and the second chess piece type information is used to indicate whether the chess piece belongs to an open chess piece or a hidden chess piece of a target party among two players;
[0051] A first marking module is used to mark the chess information of each chess position with characters in turn according to the FEN format to obtain a first FEN format string composed of multiple second characters;
[0052] The second recording module is used to record the first FEN format string into the preset FEN file.
[0053] In another embodiment of the present invention, the device further comprises:
[0054] A second marking module is used for marking the target player with a third character after the detection module detects a move operation on the target dark chess piece on the target chessboard, and marking a start signal of the move operation in the initialization situation with a fourth character when it is detected that the move operation is the first move of the target player among the two players;
[0055] A concatenation module, configured to sequentially concatenate the third character and the fourth character on the basis of the first FEN format string to obtain a second FEN format string;
[0056] The third recording module is used to record the second FEN format string into the preset FEN file.
[0057] In another embodiment of the present invention, the device further comprises:
[0058] A splitting module, used for disassembling each character in the preset FEN file after the first recording module records the move record of the target dark chess piece into the preset FEN file;
[0059] A parsing module, used for parsing each character according to a preset parsing rule corresponding to the preset FEN file to obtain the chess square information of each chess square on the chessboard;
[0060] The restoration module is used to restore the chess game on the chessboard according to the information of each chess square.
[0061] In a third aspect of the embodiments of the present invention, an electronic device is provided, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in the above method embodiment.
[0062] In a fourth aspect of the embodiments of the present invention, a storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the steps in the above-mentioned device embodiment when running.
[0063] According to the chess game processing method, device, electronic device and storage medium of the embodiment of the present invention, by adopting the preset FEN format, the chess moves and the types of chess pieces of the hidden chess are recorded. When the hidden chess pieces are revealed, it is possible to record whether the hidden chess pieces are revealed and the types of chess pieces of the hidden chess. The notation method is simple, thereby significantly reducing the difficulty of recording the revealed chess pieces. In addition, the chess game recorded in the preset FEN format is easy to parse, which is conducive to the dissemination of the chess game and brings a better experience to users. BRIEF DESCRIPTION OF THE DRAWINGS
[0064] The above and other objects, features and advantages of the exemplary embodiments of the present invention will become readily understood by reading the detailed description below with reference to the accompanying drawings. In the accompanying drawings, several embodiments of the present invention are shown in an exemplary and non-limiting manner, in which:
[0065] Figure 1 The application scenario according to the embodiment of the present invention is schematically shown;
[0066] Figure 2 A flowchart of a method for processing a chess game according to an embodiment of the present invention is schematically shown;
[0067] Figure 3 Schematically shows an initial chess game according to yet another embodiment of the present invention;
[0068] Figure 4 A flowchart of a method for processing a chess game according to another embodiment of the present invention is schematically shown;
[0069] Figure 5 A flowchart of a method for processing a chess game according to another embodiment of the present invention is schematically shown;
[0070] Figure 6 Schematically shows a chess game situation according to another embodiment of the present invention;
[0071] Figure 7 Schematically illustrates a chess game processing device according to an exemplary embodiment of the present invention;
[0072] Figure 8 The structure diagram of an electronic device according to another embodiment of the present invention is schematically shown;
[0073] In the drawings, the same or corresponding reference numerals represent the same or corresponding parts. DETAILED DESCRIPTION
[0074] The principles and spirit of the present invention will be described below with reference to several exemplary embodiments. It should be understood that these embodiments are provided only to enable those skilled in the art to better understand and implement the present invention, and are not intended to limit the scope of the present invention in any way. On the contrary, these embodiments are provided to make the present disclosure more thorough and complete, and to fully convey the scope of the present disclosure to those skilled in the art. SUMMARY OF THE INVENTION
[0076] The inventors have found that the "FEN" notation method currently available on the market is suitable for notating the normal Chinese chess game mode, but in the uncovered chess game mode, it is impossible to record whether a certain chess piece has been uncovered. When making a move, if the target chess piece is a dark chess piece, it is also impossible to dynamically specify the type of the chess piece after the dark chess piece is uncovered, which is not conducive to the preservation and dissemination of the uncovered chess game.
[0077] The present invention provides a chess game processing method. When performing a chess game, a chess move operation on a target hidden chess piece on a target chessboard is detected; in response to the detected chess move operation, a chess move record of the target hidden chess piece is generated; and the chess move record of the target hidden chess piece is recorded in a preset FEN file. The preset FEN file uses a preset FEN format to record chess grid position information and chess piece type information of each chess grid on a chessboard in a chess game mode, so as to complete the chess record record of the current chess game.
[0078] The FEN notation method for chess-revealing mode provided by the present invention is a FEN notation method suitable for chess-revealing mode evolved from a standard FEN string. Compared with directly using other methods such as JSON for storage and transmission on the market, the use of pure FEN notation can improve the efficiency of parsing and transmission. Moreover, since the information of the current chess piece is included in the move record, we are allowed to obtain the type of the revealed chess piece from the server, so that the user cannot know the type of the unrevealed chess piece through some means, which is helpful to improve the fairness of the chess-revealing game.
[0079] Application Scenario Overview
[0080] First, refer to Figure 1 , Figure 1 The application scenario according to the embodiment of the present invention is schematically shown. Figure 1 , which illustrates application scenarios in which embodiments of the present invention may be implemented. Figure 1 The scenario shown in the figure includes a terminal 200 and a server 100. The terminal 200 may be a mobile terminal, such as a mobile electronic device such as a mobile phone, a tablet computer, a laptop computer, a personal digital assistant, or a desktop computer. The server 100 may be a software operator server, etc. The terminal 200 and the server 100 may be connected to each other by communication, for example, via the mobile Internet.
[0081] When detecting the move operation of any target hidden chess piece during the game of revealing chess pieces on the target interface, the detection can be performed on the server 100 side, or on the terminal 200 side, and the target interface can be on the terminal 200 side. More specifically, for example, in the interface of the software installed on the terminal 200, the user operates the software interface to generate the move operation of the target hidden chess piece, and the server 100 identifies the move record of the target hidden chess piece according to the move operation of the target hidden chess piece, for example, the move record includes the position of the hidden chess piece before moving, the position after moving, and the name of the corresponding visible chess piece after the hidden chess piece is revealed, and then records the move record into the preset FEN file, thereby realizing the record of the chess record of the game of revealing chess pieces.
[0082] Exemplary Methods
[0083] Combine the following Figure 1 For application scenarios, refer to Figure 2 A method for processing a chess game according to an exemplary embodiment of the present invention is introduced.
[0084] It should be noted that the above application scenarios are only shown to facilitate understanding of the spirit and principle of the present invention, and the embodiments of the present invention are not limited in this respect. On the contrary, the embodiments of the present invention can be applied to any applicable scenario.
[0085] The present invention is mainly used in the scenarios of chess game situation storage and transmission during the Chinese chess game in the chess revelation mode and chess game endgame situation restoration.
[0086] For example, see Figure 2 As shown in FIG. 1 , it is a flow chart of a method for processing a chess game according to an embodiment of the present invention. Figure 2 As shown, the method for processing the chess game may include the following steps:
[0087] Step S202, detecting a move operation on a target hidden chess piece on a target chessboard;
[0088] In this embodiment, the target chessboard is a revealed chessboard. When a revealed chess game is being played, the chess moves of any hidden chess pieces on the electronic chessboard can be monitored in real time. The chess moves include at least chess piece movement, chess piece capture, and chess piece revealing.
[0089] Among them, the game of uncovering chess is based on Chinese chess, and it uses both light and dark pieces to play the game, changing the traditional way of playing. In the game of uncovering chess, the pieces on the chessboard that cannot see the words on the back are called dark pieces, and the pieces that show the words after being uncovered are called light pieces. Figure 3As shown, each player turns over 15 chess pieces and places them on their own side of the chessboard in a random pattern. The "king" or "general" is placed at the origin, and the rest of the chess pieces are hidden. During the game, each player takes turns to move. The player who moves first reveals any of his own chess pieces and makes a move according to the rules of Chinese chess (open chess) based on its position. The player can also capture the opponent's chess pieces if they are within its attack range. The revealed elephants and soldiers can cross the river to attack and kill. Whoever captures the opponent's king first is declared the winner.
[0090] In one example, it is displayed on the user interface that a chess game is being played, and the server 100 detects that a chess game is being played on the user interface of the terminal 200, and a move operation and a flip operation of a target hidden chess piece have occurred.
[0091] Step S204, in response to the chess move operation, generating a chess move record of the target hidden chess piece.
[0092] In one example, the server 100 responds to the detected chess move operation and generates a chess move record of the target hidden chess piece.
[0093] When implementing it, Figure 4 As shown, the above step S204 includes the following steps:
[0094] Step S2041, identifying first chess square position information of the target dark chess piece from the first chessboard image corresponding to the target dark chess piece before it moves, and identifying second chess square position information of the target dark chess piece from the second chessboard image corresponding to the target dark chess piece after it moves;
[0095] In one example, after detecting that the target hidden chess piece has moved, the server 100 collects the chessboard image before and after the hidden chess piece has moved, and identifies the position information of the hidden chess piece through the image. In the process of revealing the chess pieces, before the hidden chess piece is revealed, the chess piece is moved according to the chess piece moving rules in the normal mode Chinese chess according to the starting point of the hidden chess piece (i.e., the first chess square position information, i.e., the coordinate point corresponding to the chess square position in the initial chess game of revealing the chess piece) and after the chess piece is moved, the coordinate point of the target point where the target hidden chess piece is located after moving is recorded (i.e., the second format position).
[0096] For example, Figure 3 The chessboard shown is recorded from the bottom. From left to right, the columns are represented by a, b, c, d, etc. From bottom to top, the rows are represented by natural numbers 0, 1, 2, 3, etc. For example, the fourth row of the first column is marked as a3, and the fourth row of the third column is marked as c3.
[0097] Step S2042, when a flipping operation of a target dark chess piece is detected, determining first chess piece type information corresponding to the target dark chess piece;
[0098] More specifically, the above step S2042 includes: collecting the third chessboard image corresponding to the target dark chess piece after it becomes a visible chess piece; identifying the first chess piece type information of the standard chess piece corresponding to the target dark chess piece from the third chessboard image, wherein the first chess piece type information is used to characterize the chess piece name of the standard chess piece.
[0099] Different from the normal game mode, before the hidden chess pieces are revealed, the two players do not know what type they are. Therefore, the record of the hidden chess moves is not enough with only the coordinates of the starting point and the target point. It is also necessary to know what type of chess piece is revealed at this time.
[0100] In one example, after detecting the flipping operation of the target hidden chess piece, the server 100 collects the chessboard image corresponding to the flipping of the chess piece, and identifies the first chess piece type information of the visible chess piece corresponding to the hidden chess piece after the hidden chess piece is uncovered through the picture. The first chess piece type is used to mark the hidden chess piece as the corresponding chess piece in the normal mode.
[0101] Optionally, the first chess piece type information can be marked with a positive integer. For example, after the dark chess pieces are revealed, the code 11 is used to refer to the red side's bishop, the code 27 is used to mark the black side's elephant, and the code 14 is used to mark the red side's knight.
[0102] Step S2043, generating a chess move record according to the first chess square position information, the second chess square position information and the first chess piece type information corresponding to the target hidden chess piece.
[0103] In specific implementation, the above step S2043 includes: sequentially marking the first chess square position information, the second chess square position information and the first chess piece type information to obtain a target string consisting of multiple first characters; and using the target string as a chess move record to record it in a preset FEN file.
[0104] In this embodiment, after the chess piece is revealed, the chess piece type information corresponding to the hidden chess piece is recorded as the first chess piece type information, and the first chess piece type information indicates that the name of the chess piece of the visible chess piece is known. Use "<chess piece number>" as a mark and place it after the starting point and the target point of the original move record as the chess piece type after the step is revealed, such as: "a3a4 <11> ”.
[0105] Among them, the chess piece numbers are preset values, and all chess piece numbers are as follows:
[0106] Red chess pieces: 8-General, 9-Minister, 10-Minister, 11-Xiang, 12-Xiang, 13-Horse, 14-Horse, 15-Rook, 16-Rook, 17-Cannon, 18-Cannon, 19-23-Soldier; Black chess pieces: 24-General, 25-Minister, 26-Minister, 27-Elephant, 28-Elephant, 29-Horse, 30-Horse, 31-Rook, 32-Rook, 33-Cannon, 34-Cannon, 35-39-Pawn.
[0107] According to the above example, if the dark chess piece moves from the first column and fourth row to the first column and fifth row, and after the chess piece is revealed, it corresponds to the red side's elephant, and the corresponding code of the red side is 11, then the record mark of the dark chess piece's move is a3a4 <11> In this embodiment, the chess move records are marked with preset simple characters, which is simple to operate and easy to analyze.
[0108] Among them, when the user operates on the chessboard, the program terminal obtains the starting and target points of the user's operation to generate coordinates, such as a3, a4, and then generates a chess move record based on the type number of the current chess piece revealed returned by the server, such as 11.
[0109] It should be noted that the type number does not necessarily need to be generated by the server, and the client can also randomly select a chess piece number from the remaining unrevealed chess pieces; this is not limited here.
[0110] Step S206, recording the target hidden chess move record into a preset FEN file, wherein the preset FEN file is used to record the chess square information of each chess square position on the chessboard in a preset FEN format, and the chess square information includes the chess square position information and the chess piece type information on the chess square.
[0111] In this embodiment, the preset FEN file is a folder specifically used to store chess records in the preset FEN format.
[0112] According to the method provided in the embodiment of the present invention, a preset FEN format is used to record the chess moves and the types of chess pieces of the hidden chess. When the hidden chess pieces are revealed, it can be recorded whether the hidden chess pieces are revealed and the types of chess pieces of the hidden chess. The notation method is simple, thereby significantly reducing the difficulty of recording the revealed chess pieces. In addition, the chess game recorded in the preset FEN format is easy to parse, which is conducive to the dissemination of the chess game and brings a better experience to users.
[0113] In an optional embodiment of the present case, as Figure 5 As shown, before the above step S206, the following steps are also included:
[0114] Step S301, obtaining an initial chess game image, wherein the initial chess game image includes an initialized chess game based on a chess game mode;
[0115] In this embodiment, according to the rules of Chinese chess, an initial situation is first initialized, that is, only the general of each player is exposed, and the other chess pieces are shuffled and placed face down as shown in the figure below. The positions of the chess pieces in the initial situation are fixed. Figure 3 shown.
[0116] Step S302, sequentially identifying chess square information of each chess square position from the initial chess game image, wherein the chess square information includes second chess piece type information of the chess piece on the chess square, and the second chess piece type information is used to indicate whether the chess piece belongs to the visible chess piece or the hidden chess piece of the target side of the two players;
[0117] In this embodiment, before the chess piece is revealed, the chess piece type information of the chess piece is recorded as the second chess piece type information, recording whether the chess piece is a black side's hidden chess piece or an exposed chess piece, or a red side's hidden chess piece or an exposed chess piece.
[0118] See also Figure 3 Except for the generals or kings of the two players, which are visible pieces, all other pieces are hidden pieces. The chess piece information of each chess square on the chessboard is identified in turn, such as determining whether a chess square corresponds to the red side or the black side, whether there is a chess piece on the chess square, and if so, further identifying whether it is an visible piece or a hidden piece (i.e., the second chess piece type information mentioned above).
[0119] Step S303: according to the preset FEN format, character marking is performed on the chess square information of each chess square position in turn to obtain a first FEN format string consisting of a plurality of second characters.
[0120] In this embodiment, based on the existing FEN rules, a dark chess piece type is added to clarify whether the dark chess piece is a black chess piece or a red chess piece.
[0121] For example, the black side will use the character "k" (i.e. the first character above) to mark, the red side's general will use the character "K" (i.e. the first character above) to mark, the black side's dark chess will use "x" (i.e. the first character above) to mark, and the red side's dark chess will use "X" (i.e. the first character above) to mark, then Figure 2 The chess record of the initial chess game shown is recorded in the preset FEN format of this scheme as: xxxxkxxxx / 9 / 1x5x1 / x1x1x1x1x / 9 / 9 / X1X1X1X1X / 1X5X1 / 9 / XXXXKXXXX (that is, the first FEN format string mentioned above).
[0122] Step S304: Record the first FEN format string into a preset FEN file.
[0123] According to the above example, on the basis of the standard FEN rule, a mark of the chess piece type is added, that is, the preset FEN rule of this embodiment, so that the chess record of the initial chess game of the chess game is recorded by using the preset FEN rule.
[0124] Furthermore, when it is detected that the chess move operation is the first move by the target party of the two players, the third character is used to mark the target party, and the fourth character is used to mark the start signal of initializing the chess move; on the basis of the first FEN format string, the third character and the fourth character are sequentially spliced to obtain a second FEN format string; the second FEN format string is recorded in a preset FEN file.
[0125] In one example, if the target dark chess piece is the first to be moved after the initial chess game, the server 100 identifies from the user interface whether the dark chess piece belongs to the black side or the red side, and then uses the third character to mark which side starts to move. For example, the black side uses the character "b", and the red side uses the character "w" (i.e., the third character). The start signal of the chess game is marked with a fourth character, such as "moves", and the moves character is followed by the dark chess piece's move record.
[0126] At this time, based on the chess record of the initial chess game, the current chess record (i.e. the second FEN format string mentioned above) is marked as:
[0127] xxxxkxxxx / 9 / 1x5x1 / x1x1x1x1x / 9 / 9 / X1X1X1X1X / 1X5X1 / 9 / XXXXKXXXX w moves.
[0128] Furthermore, if the hidden chess piece is red, and red makes its first move, and moves from the first column, fourth row to the first column, fifth row, and after revealing the chess piece, it corresponds to the red side's elephant. The corresponding code of the red side is 11, then the record of the hidden chess piece is marked as a3a4. <11> , record the chess moves into the preset FEN file, then the current chess record is:
[0129] xxxxkxxxx / 9 / 1x5x1 / x1x1x1x1x / 9 / 9 / X1X1X1X1X / 1X5X1 / 9 / XXXXKXXXX w movesa3a4 <11> .
[0130] In an optional embodiment of the present case, after the above step S206, it also includes: disassembling each character in the preset FEN file; parsing each character according to the preset parsing rules corresponding to the preset FEN file to obtain the chess square information of each chess square on the chessboard; and restoring the chess game on the chessboard according to each chess square information.
[0131] According to the above embodiment, the preset FEN format is used to record the chess game, and the preset FEN format chess record is obtained. After obtaining the preset FEN chess record of the chess game revealing mode, the parsing method of the initial chess game FEN part is roughly the same as the standard FEN, each character in the FEN is disassembled, and then input into the automatic machine recognition type and responds to the processing, the difference is that "x" and "X" are added to mark the unrevealed dark chess mark, and after parsing the chess game information corresponding to the preset FEN chess record, the specific chess game situation can be restored.
[0132] For example, when parsing to a character at a certain position in the FEN string:
[0133] "xX": indicates that there is a chess piece at the current parsed position, and it is a hidden chess piece that has not been revealed. If it is "x", it means it is a black chess piece, and "X" means it is a red chess piece. In this case, a set is used to record the chess piece at the current grid position as a hidden chess piece, and the chess piece is placed according to the preset moves of the preset chess pieces in each grid before it is revealed.
[0134] “ / ”: It means that we have finished parsing the data of a row in the chessboard and are ready to parse the data of the next row. At this time, the current row number marked is increased by 1;
[0135] "1-9": If the parsed character is any number between 1 and 9, it means that there are y (values range from 1 to 9) empty squares starting from the current row and column, and there are no chess pieces on these empty squares; y is equal to the number corresponding to the parsed character;
[0136] "rnbakcp": If the parsed character is one of these characters, it means that there is a black chess piece in the current row and column. According to the preset conversion rules, the position is marked with the type mark of the chess piece; the chess piece type corresponding to each character grid is: r-chariot, n-horse, b-bishop, a-soldier, k-general, c-cannon, p-pawn;
[0137] "RNBAKCP": If the parsed character is one of the characters "RNBAKCP", it means that there is a red chess piece in the current row and column. According to the preset conversion rules, the position is marked with the type mark of the chess piece; where each character grid corresponds to the chess piece type: R-chariot, N-horse, B-bearer, A-official, K-king, C-cannon, P-pawn;
[0138] "" (spaces between double quotes): When a space is parsed, it means that the FEN part of the initial situation has been parsed, and the current move can be parsed. If the character after the space is "b", it means that it is the black side's turn to make a move, otherwise it is the red side's turn to make a move;
[0139] So far, the basic FEN parsing has been completed. Next, we need to parse the move records passed in by the user to restore the historical records of the game.
[0140] FEN uses "moves" as a separator, followed by a list of historical moves. Multiple records are separated by spaces. You can use spaces to split a whole list of moves into multiple moves, such as: "a3a4 <11> a6a5 <28> c3c4 <13> "Split into: "a3a4 <11> ","a6a5 <28> ","c3c4 <13> ", and then extract the chess move coordinates and the starting point chess piece number according to each chess move record, such as "a3a4 <11> " Extract the chess coordinates "a3a4" and the chess piece number "11"; then, according to the chess coordinates, first place the chess piece according to the preset placement rules of the chess piece at the starting coordinate position (for example, the a3 position corresponds to the position of the pawn in the ordinary game mode, so when the chess piece is not revealed, the chess piece must be placed according to the pawn's move); after placing the chess piece, replace the chess piece type with the corresponding open chess piece type according to the parsed chess piece number, such as replacing it with the "Xiang" numbered "11", thus completing the process of a hidden chess move.
[0141] The process of moving the chess pieces is no different from the normal game mode, so I will not go into details.
[0142] In an example, if the obtained preset FEN chess record is: xxxxkxxxx / 9 / 1x5x1 / x1x1x1x1x / 9 / 9 / X1X1X1X1X / 1X5X1 / 9 / XXXXKXXXXw moves a3a4 <11> a6a5 <28> c3c4 <13> c6c5 <34> e3e4 <16> e6e5 <30> g3g4 <10> g6g5 <26> i3i4 <14> i6i5 <27> , then through the above analysis method, we can get Figure 6 The chess game situation shown, Figure 6 FIG. 2 schematically shows a chess game situation according to yet another embodiment of the present invention.
[0143] Through the above steps, by recording the type of hidden chess pieces, i.e., chess operation, on the basis of the standard FEN rules, it is clear whether a certain chess piece is revealed, and the problem that in the existing notation method, if the target chess piece is a hidden chess piece when playing chess, the type of the hidden chess piece after being revealed cannot be dynamically specified; further, for the known products on the market that support revealing chess games, most of them record the information such as the initial situation and the movement of chess pieces during the game, the type of revealed chess pieces, etc. into complex JSON, the present invention uses a more concise and clear FEN format string to record the key information of the chess score, which can avoid a lot of redundant data when using JSON; in addition, the special FEN string in this solution follows the notation standard of the standard FEN string, and only optimizes and upgrades the chess pieces and the records of the moves in the revealing chess scene, therefore, the existing application program that supports parsing the standard FEN only needs to perform adaptive transformation of the performance, and can easily support the parsing of the revealing chess mode FEN, and compared with JSON, the FEN string is more concise, saves more traffic during dissemination and sharing, and is faster and more convenient to transmit.
[0144] Exemplary Devices
[0145] After introducing the method of the exemplary embodiment of the present invention, next, refer to Figure 7 A chess game processing device according to an exemplary embodiment of the present invention is introduced.
[0146] The implementation of the chess game processing device can refer to the implementation of the above method, and the repeated parts will not be repeated. The term "unit" or "module" used below can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware is also possible and conceived.
[0147] Figure 7 A chess game processing device according to another embodiment of the present invention is schematically shown, the device comprising:
[0148] A detection module 70 is used to detect a move operation on a target hidden chess piece on a target chessboard;
[0149] A generating module 72, connected to the detecting module 70, for generating a moving record of a target hidden chess piece in response to a moving operation;
[0150] The first recording module 74 is connected to the above-mentioned generation module 72, and is used to record the target hidden chess moves into a preset FEN file, wherein the FEN file is used to record the chess square information of each chess square position on the chessboard in the chess game mode in a preset FEN format, and the chess square information includes the chess square position information and the chess piece type information on the chess square.
[0151] Optionally, the generating module 72 includes:
[0152] An identification unit, used to identify first chess square position information of the target dark chess piece from a first chessboard image corresponding to the target dark chess piece before it moves, and to identify second chess square position information of the target dark chess piece from a second chessboard image corresponding to the target dark chess piece after it moves;
[0153] A determination unit, configured to determine first chess piece type information corresponding to the target dark chess piece when a flipping operation of the target dark chess piece is detected;
[0154] A generating unit is used to generate a chess move record according to the first chess square position information, the second chess square position information and the first chess piece type information corresponding to the target hidden chess piece.
[0155] Optionally, the determining unit includes:
[0156] A collection subunit, used for collecting a third chessboard image corresponding to the target dark chess piece becoming a bright chess piece;
[0157] The identification subunit is used to identify the first chess piece type information of the chess piece in the standard chess corresponding to the target hidden chess piece from the third chessboard image, wherein the first chess piece type information is used to represent the chess piece name of the chess piece in the standard chess.
[0158] Optionally, the generating unit includes:
[0159] A marking subunit, used to mark the first chess square position information, the second chess square position information and the first chess piece type information with characters in sequence to obtain a target character string consisting of a plurality of first characters;
[0160] The recording subunit is used to record the target string as a move record to a preset FEN file.
[0161] Optionally, the above device further includes:
[0162] An acquisition module, used for acquiring an initial chess game image before the first recording module records the target hidden chess move into a preset FEN file, wherein the initial chess game image includes an initialized chess game based on a chess game mode;
[0163] An identification module is used to sequentially identify chess square information of each chess square position from the initial chess game image, wherein the chess square information includes second chess piece type information of the chess piece on the chess square, and the second chess piece type information is used to indicate whether the chess piece belongs to an open chess piece or a hidden chess piece of a target side of two players;
[0164] A first marking module is used to mark the chess information of each chess position with characters in turn according to the FEN format to obtain a first FEN format string composed of multiple second characters;
[0165] The second recording module is used to record the first FEN format string into a preset FEN file.
[0166] Optionally, the above device further includes:
[0167] A second marking module is used for marking the target side with a third character and marking a start signal of initializing the chess position with a fourth character after the detection module detects a chess move operation on the target dark chess piece on the target chess board, when it is detected that the chess move operation is the first chess move by the target side of the two players;
[0168] A concatenation module, used for concatenating the third character and the fourth character in sequence on the basis of the first FEN format string to obtain a second FEN format string;
[0169] The third recording module is used to record the second FEN format string into a preset FEN file.
[0170] Optionally, the above device further includes:
[0171] A splitting module is used to split each character in the preset FEN file after the first recording module records the chess operation of the target dark chess piece into the preset FEN file;
[0172] A parsing module, used for parsing each character according to a preset parsing rule corresponding to a preset FEN file, to obtain the chess square information of each chess square on the chessboard;
[0173] The restoration module is used to restore the chess game on the chessboard according to the information of each chess square. It should be noted that the above modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited to this: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.
[0174] An embodiment of the present invention further provides a storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.
[0175] Optionally, in this embodiment, the storage medium may be configured to store a computer program for performing the following steps:
[0176] S1, detecting a move operation on a target dark chess piece on a target chessboard;
[0177] S2, in response to the chess move operation, generating a chess move record of the target hidden chess piece;
[0178] S3, recording the target hidden chess move record into a preset FEN file, wherein the preset FEN file is used to record the chess square information of each chess square position on the chessboard in the chess game mode in a preset FEN format, and the chess square information includes the chess square position information and the chess piece type information on the chess square.
[0179] Optionally, in this embodiment, the above-mentioned storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store computer programs.
[0180] Based on the above Figure 2 The method shown and Figure 7 In order to achieve the above-mentioned purpose, the embodiment of the present invention also provides an electronic device, such as Figure 8 As shown, the system includes a memory 52 and a processor 51, wherein the memory 52 and the processor 51 are both arranged on a bus 53. The memory 52 stores a computer program, and the processor 51 executes the computer program to realize Figure 2 The method of handling the chess game shown.
[0181] Based on this understanding, the technical solution of the present invention can be embodied in the form of a software product, which can be stored in a memory (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.), and includes a number of instructions for enabling an electronic device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in various implementation scenarios of the present invention.
[0182] Optionally, the device may also be connected to a user interface, a network interface, a camera, a radio frequency (RF) circuit, a sensor, an audio circuit, a WI-FI module, etc. The user interface may include a display, an input unit such as a keyboard, etc., and the optional user interface may also include a USB interface, a card reader interface, etc. The network interface may optionally include a standard wired interface, a wireless interface (such as a Bluetooth interface, a WI-FI interface), etc.
[0183] Those skilled in the art will appreciate that the structure of an electronic device provided in this embodiment does not limit the physical device, and may include more or fewer components, or a combination of certain components, or different component arrangements.
[0184] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.
[0185] In addition, although the operations of the method of the present invention are described in a specific order in the accompanying drawings, this does not require or imply that the operations must be performed in this specific order, or that all the operations shown must be performed to achieve the desired results. On the contrary, the steps depicted in the flow chart can be performed in a different order. Additionally or alternatively, some steps can be omitted, multiple steps can be combined into one step, and / or one step can be decomposed into multiple steps.
[0186] It should be understood that each box in the flowchart and / or block diagram and the combination of boxes in the flowchart and / or block diagram can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer or other programmable data processing device to produce a machine, and these computer program instructions are executed by a computer or other programmable data processing device to produce a device that implements the functions / operations specified in the boxes in the flowchart and / or block diagram.
[0187] These computer program instructions may also be stored in a computer-readable medium that enables a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable medium produce a product that includes an instruction device that implements the functions / operations specified in the blocks in the flowchart and / or block diagram.
[0188] Computer program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operational steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby enabling the instructions executed on the computer or other programmable device to provide a process for implementing the functions / operations specified in the blocks in the flowchart and / or block diagram.
[0189] The use of the verbs "comprise", "include" and their conjugations mentioned in the application documents does not exclude the presence of elements or steps other than those recorded in the application documents. The article "a" or "an" before an element does not exclude the presence of a plurality of such elements.
[0190] Although the spirit and principle of the present invention have been described with reference to several specific embodiments, it should be understood that the present invention is not limited to the disclosed specific embodiments, and the division of various aspects does not mean that the features in these aspects cannot be combined to benefit, and this division is only for the convenience of expression. The present invention is intended to cover various modifications and equivalent arrangements included in the spirit and scope of the attached claims. The scope of the attached claims conforms to the broadest interpretation, thereby including all such modifications and equivalent structures and functions.
Claims
1. A method for processing a chess game, characterized in that: The method comprises: Detecting a chess move operation on a target hidden chess piece on a target chessboard; In response to the chess move operation, a chess move record of the target dark chess is generated, including: identifying first chess square position information of the target dark chess from a first chessboard image corresponding to before the target dark chess moves, and identifying second chess square position information of the target dark chess from a second chessboard image corresponding to after the target dark chess moves; when a chess flip operation of the target dark chess is detected, determining first chess piece type information corresponding to the target dark chess; sequentially marking the first chess square position information, the second chess square position information and the first chess piece type information with characters to obtain a target character string composed of a plurality of first characters; and using the target character string as the chess move record; The move records of the target hidden chess pieces are recorded in a preset FEN file, wherein the preset FEN file is used to record the chess square information of each chess square position on the chessboard in the chess game mode in a preset FEN format, and the chess square information includes the chess square position information and the chess piece type information on the chess square.
2. The method according to claim 1, characterized in that The determining of the first chess piece type information corresponding to the target dark chess piece includes: Collecting a third chessboard image corresponding to the target dark chess piece becoming a bright chess piece; Identify first chess piece type information of a chess piece in standard chess corresponding to the target dark chess piece from the third chessboard image, wherein the first chess piece type information is used to characterize the chess piece name of the chess piece in standard chess.
3. The method according to claim 1, characterized in that Before recording the move record of the target dark chess piece into a preset FEN file, the method further includes: Acquire an initial chess game image, wherein the initial chess game image includes an initialized chess game based on a chess game mode; Sequentially identifying chess square information of each chess square position from the initial chess game image, wherein the chess square information includes second chess piece type information of the chess piece on the chess square, and the second chess piece type information is used to indicate whether the chess piece belongs to an open chess piece or a hidden chess piece of a target party among two players; According to the preset FEN format, the chess information of each chess position is marked with characters in turn to obtain a first FEN format string consisting of a plurality of second characters; The first FEN format string is recorded into the preset FEN file.
4. The method according to claim 3, characterized in that: After detecting a move operation on a target dark chess piece on a target chessboard, the method further includes: When it is detected that the chess move operation is the first chess move by the target party of the two players, the target party is marked with a third character, and a start signal for initializing the chess move is marked with a fourth character; On the basis of the first FEN format string, sequentially concatenate the third character and the fourth character to obtain a second FEN format string; The second FEN format string is recorded into the preset FEN file.
5. The method according to any one of claims 1 to 4, characterized in that After recording the move record of the target dark chess piece into a preset FEN file, the method further includes: Decompose each character in the preset FEN file; Parsing each character according to the preset parsing rule corresponding to the preset FEN file to obtain the chess square information of each chess square on the chessboard; Restore the chess game on the board based on the information of each chess square.
6. A chess game processing device, characterized in that: The device comprises: A detection module, used to detect a chess move operation on a target hidden chess piece on a target chessboard; A generating module, for generating a chess move record of the target dark chess piece in response to the chess move operation, comprising: identifying first chess square position information of the target dark chess piece from a first chessboard image corresponding to before the target dark chess piece moves, and identifying second chess square position information of the target dark chess piece from a second chessboard image corresponding to after the target dark chess piece moves; when a chess flip operation of the target dark chess piece is detected, determining first chess piece type information corresponding to the target dark chess piece; sequentially marking the first chess square position information, the second chess square position information and the first chess piece type information with characters to obtain a target character string composed of a plurality of first characters; and using the target character string as the chess move record; The first recording module is used to record the chess moves of the target hidden chess pieces into a preset FEN file, wherein the FEN file is used to record the chess square information of each chess square position on the chessboard in the chess game mode in a preset FEN format, and the chess square information includes the chess square position information and the chess piece type information on the chess square.
7. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.
8. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Chinese chess game learning method based on deep reinforcement learning method and system thereof
CN113599798A
Chess game control method and device, storage medium and electronic equipment
CN113856209A