Data processing method, system, device and medium for 2048 game based on PHP
By using PHP language to write algorithm logic in the 2048 game and deploying it in the back-end server, the 2048 game written in the front-end language is solved, and the fairness of the game and the authenticity of the data are achieved.
Patent Information
- Application Number
- CN202210068005.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-20
- Publication Date
- 2025-02-28
- Estimated Expiration
- 2042-01-20
AI Technical Summary
Due to the front-end language writing of the existing 2048 games, data forgery and data tampering are prone to problems, affecting the fairness of the game.
The 2048 algorithm logic is written in PHP language and deployed in the backend server. The game interaction data is generated through the front end and sent to the backend server. The backend executes the algorithm logic to generate response data and returns it to the front end.
It effectively prevents malicious data forgery requests, tamper with real data, and ensures the fairness of the game.
Smart Images

Figure CN114602185B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of game technology, and in particular to a data processing method, system, device and medium for a PHP-based 2048 game. Background Art
[0002] With the continuous development of Internet technology, the emergence and iterative updates of front-end languages have made game development more convenient and faster.
[0003] Most existing 2048 games are written in front-end languages, and the algorithms are relatively simple. In addition, during the interaction between the front-end and back-end, it is easy for users to skip the front-end algorithm and make malicious data forgery requests, tampering with real data and affecting the authenticity of the data, which has a great impact on the fairness of the game.
[0004] Currently, the 2048 game written in the front-end language in the related technology is prone to problems of data forgery and data tampering, and no effective solution has been proposed yet. Summary of the invention
[0005] The embodiments of the present application provide a data processing method, system, device and medium for a 2048 game based on PHP, so as to at least solve the problem that data forgery and data tampering are prone to occur in the 2048 game written in the front-end language in the related art.
[0006] In a first aspect, an embodiment of the present application provides a data processing method for a 2048 game based on PHP, the method comprising:
[0007] The 2048 algorithm logic is written in PHP language, and the program of the 2048 algorithm logic is deployed in the back-end server;
[0008] Generate game interaction data through the front end, and send the game interaction data to the back end server, wherein the game interaction data includes an upward movement instruction, a downward movement instruction, a left movement instruction, and a right movement instruction;
[0009] According to the game interaction data, the 2048 algorithm logic is executed by the back-end server to generate response data, and the response data is returned to the front end.
[0010] In some embodiments, executing the 2048 algorithm logic by the backend server according to the game interaction data includes:
[0011] Generate a two-dimensional array chessboard of a preset size through the back-end server, and generate data values of a preset level in the two-dimensional array chessboard;
[0012] Traversing the two-dimensional array board row by row according to the game interaction data, and if a data value exists, recording the data value as a cell;
[0013] Find the farthest empty position that the cell can move to in the moving direction and record it as farthest, and determine whether the adjacent position pointed to by farthest in the moving direction exists;
[0014] If it exists, determine whether the data value of the adjacent position is the same level as the cell. If they are the same, merge the data value and the cell to generate a data value of the next level and move it to the adjacent position. If they are not the same, directly move the cell to the farthest position.
[0015] If it does not exist, the cell is directly moved to the farthest.
[0016] In some embodiments, the method further comprises:
[0017] Generate a two-dimensional array chessboard of a preset size through the back-end server, and generate data values of a preset level in the two-dimensional array chessboard;
[0018] According to the game interaction data, the two-dimensional array chessboard is rotated by matrix rotation to simplify the game interaction data into a single direction movement instruction;
[0019] According to the single direction movement instruction, the rotated two-dimensional array chessboard is traversed row by row, and if there is a data value, the data value is recorded as a cell;
[0020] Find the farthest empty position that the cell can move to in the single direction and record it as farthest, and determine whether there is an adjacent position pointed to by farthest in the single direction;
[0021] If it exists, determine whether the data value of the adjacent position is the same level as the cell. If they are the same, merge the data value and the cell to generate a data value of the next level and move it to the adjacent position. If they are not the same, directly move the cell to the farthest position.
[0022] If it does not exist, directly move the cell to the farthest;
[0023] The two-dimensional array chessboard is then reversely rotated by matrix rotation.
[0024] In some embodiments, the 2048 algorithm logic is written in PHP language including:
[0025] The algorithm logic of chessboard initialization, chessboard reset, chessboard position generation of random numbers, matrix rotation, number movement and number merging is written in PHP language. The matrix rotation is used to rotate the two-dimensional array chessboard, simplifying the game interaction data into a single direction movement instruction.
[0026] In a second aspect, an embodiment of the present application provides a data processing system for a 2048 game based on PHP, the system comprising an algorithm deployment module, an instruction transmission module and an algorithm execution module;
[0027] The algorithm deployment module uses PHP language to write the 2048 algorithm logic and deploys the program of the 2048 algorithm logic in the back-end server;
[0028] The instruction transmission module generates game interaction data through the front end, and sends the game interaction data to the back end server, wherein the game interaction data includes an upward movement instruction, a downward movement instruction, a left movement instruction, and a right movement instruction;
[0029] The algorithm execution module generates response data by executing the 2048 algorithm logic through the back-end server according to the game interaction data, and returns the response data to the front end.
[0030] In some embodiments, the algorithm execution module executes the 2048 algorithm logic through the backend server according to the game interaction data, including:
[0031] The algorithm execution module generates a two-dimensional array chessboard of a preset size through the back-end server, and generates data values of a preset level in the two-dimensional array chessboard;
[0032] The algorithm execution module traverses the two-dimensional array board row by row according to the game interaction data, and if a data value exists, the data value is recorded as a cell;
[0033] The algorithm execution module searches for the farthest empty position that the cell can move to in the moving direction and records it as farthest, and determines whether the farthest is at an adjacent position pointed to in the moving direction;
[0034] If it exists, determine whether the data value of the adjacent position is the same level as the cell. If they are the same, merge the data value and the cell to generate a data value of the next level and move it to the adjacent position. If they are not the same, directly move the cell to the farthest position.
[0035] If it does not exist, the cell is directly moved to the farthest.
[0036] In some embodiments, the system further comprises:
[0037] The algorithm execution module generates a two-dimensional array chessboard of a preset size through the back-end server, and generates data values of a preset level in the two-dimensional array chessboard;
[0038] The algorithm execution module rotates the two-dimensional array chessboard through matrix rotation according to the game interaction data, and simplifies the game interaction data into a single direction movement instruction;
[0039] The algorithm execution module traverses the rotated two-dimensional array chessboard row by row according to the single-direction movement instruction, and if a data value exists, the data value is recorded as a cell;
[0040] The algorithm execution module searches for the farthest empty position that the cell can move to in the single direction and records it as farthest, and determines whether there is an adjacent position pointed to by farthest in the single direction;
[0041] If it exists, determine whether the data value of the adjacent position is the same level as the cell. If they are the same, merge the data value and the cell to generate a data value of the next level and move it to the adjacent position. If they are not the same, directly move the cell to the farthest position.
[0042] If it does not exist, directly move the cell to the farthest;
[0043] The two-dimensional array chessboard is then reversely rotated by matrix rotation.
[0044] In some embodiments, the algorithm deployment module uses PHP language to write the 2048 algorithm logic including:
[0045] The algorithm deployment module uses PHP language to write the algorithm logic of chessboard initialization, chessboard reset, chessboard position generation of random numbers, matrix rotation, number movement and number merging, among which the matrix rotation is used to rotate the two-dimensional array chessboard to simplify the game interaction data into a single direction movement instruction.
[0046] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method described in the first aspect when executing the computer program.
[0047] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in the first aspect above.
[0048] Compared with the related art, the data processing method, system, device and medium of a 2048 game based on PHP provided in the embodiment of the present application adopts PHP language to write 2048 algorithm logic, and deploys the program of 2048 algorithm logic in the back-end server; generates game interaction data through the front end, and sends the game interaction data to the back-end server, wherein the game interaction data includes upward movement instruction, downward movement instruction, left movement instruction and right movement instruction; according to the game interaction data, generates response data through the back-end server executing 2048 algorithm logic, and returns the response data to the front end. The problem that the 2048 game written in the front-end language is prone to data forgery and data tampering is solved, and the back-end data processing of the 2048 game based on PHP is realized, which effectively prevents malicious data forgery requests and tampering of real data, and ensures the fairness of the game. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0050] Figure 1 It is a flowchart of the steps of the data processing method of the 2048 game based on PHP according to an embodiment of the present application;
[0051] Figure 2 It is a structural block diagram of a data processing system for a 2048 game based on PHP according to an embodiment of the present application;
[0052] Figure 3 It is a schematic diagram of the internal structure of an electronic device according to an embodiment of the present application.
[0053] Description of the accompanying drawings: 21. Algorithm deployment module; 22. Instruction transmission module; 23. Algorithm execution module. DETAILED DESCRIPTION
[0054] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application is described and illustrated below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. Based on the embodiments provided in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application.
[0055] Obviously, the drawings described below are only some examples or embodiments of the present application. For ordinary technicians in this field, the present application can also be applied to other similar scenarios based on these drawings without creative work. In addition, it can also be understood that although the efforts made in this development process may be complicated and lengthy, for ordinary technicians in this field related to the content disclosed in this application, some changes in design, manufacturing or production based on the technical content disclosed in this application are just conventional technical means, and should not be understood as insufficient content disclosed in this application.
[0056] Reference to "embodiments" in this application means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those of ordinary skill in the art that the embodiments described in this application may be combined with other embodiments without conflict.
[0057] Unless otherwise defined, the technical terms or scientific terms involved in this application should be understood by people with ordinary skills in the technical field to which this application belongs. The words "one", "a", "a", "the" and the like involved in this application do not indicate a quantitative limitation, and may represent the singular or plural. The terms "include", "comprise", "have" and any of their variations involved in this application are intended to cover non-exclusive inclusions; for example, a process, method, system, product or device that includes a series of steps or modules (units) is not limited to the listed steps or units, but may also include steps or units that are not listed, or may also include other steps or units inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "multiple" involved in this application refers to two or more. "And / or" describes the association relationship of associated objects, indicating that there may be three relationships, for example, "A and / or B" can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the objects before and after are in an "or" relationship. The terms "first", "second", "third", etc. involved in this application are only used to distinguish similar objects and do not represent a specific ordering of the objects.
[0058] The present application embodiment provides a data processing method for a 2048 game based on PHP. Figure 1 is a flowchart of the data processing method of the 2048 game based on PHP according to an embodiment of the present application, such as Figure 1 As shown, the method comprises the following steps:
[0059] Step S102, using PHP language to write the 2048 algorithm logic, and deploying the 2048 algorithm logic program in the back-end server;
[0060] Specifically, the PHP language is used to write the algorithm logic for chessboard initialization, chessboard reset, random number generation for chessboard positions, matrix rotation, number movement and number merging. Among them, matrix rotation is used to rotate the two-dimensional array chessboard, simplifying the game interaction data into a single direction movement instruction.
[0061] Step S104, generating game interaction data through the front end, and sending the game interaction data to the back end server, wherein the game interaction data includes an upward movement instruction, a downward movement instruction, a left movement instruction, and a right movement instruction;
[0062] Step S106, based on the game interaction data, the back-end server executes the 2048 algorithm logic to generate response data, and returns the response data to the front end.
[0063] Through steps S102 to S106 in the embodiment of the present application, the problem that the 2048 game written in the front-end language is prone to data forgery and data tampering is solved, and the back-end data processing of the 2048 game based on PHP is realized, which effectively prevents malicious data forgery requests and tampering of real data, thereby ensuring the fairness of the game.
[0064] In some embodiments, step S106, executing the 2048 algorithm logic by the backend server according to the game interaction data includes:
[0065] 1. Chessboard initialization, chessboard reset and chessboard position generation of random numbers.
[0066] A two-dimensional array chessboard of a preset size is generated through a backend server, and data values of a preset level are generated in the two-dimensional array chessboard.
[0067] Specifically, a 4*4 two-dimensional array chessboard is generated by a backend server, and four level-one data values are generated in fixed positions of the two-dimensional array chessboard.
[0068] 2. Digital mobility and digital merger.
[0069] According to the game interaction data, the two-dimensional array board is traversed row by row. If there is a data value, the data value is recorded as a cell.
[0070] Specifically, the game interaction data includes movement instructions in four directions: upward, downward, left, and right. If it is an upward movement instruction, it will start from the top of the two-dimensional array chessboard and traverse row by row. Similarly, the downward instruction will start from the bottom, and so on. If the traversal finds a data value, the data value will be recorded as a cell.
[0071] Find the farthest empty position that the cell can move to in the moving direction and record it as farthest, and determine whether the adjacent position (farthest-1) pointed to by farthest in the moving direction exists.
[0072] If it exists, determine whether the data value at the adjacent position is the same as the level of the cell. If they are the same, merge the data value and the cell to generate the data value of the next level and move it to the adjacent position. If they are not the same, move the cell directly to the farthest.
[0073] If it does not exist, the cell is moved directly to the farthest.
[0074] Specifically, some codes for number movement and number merging are as follows:
[0075]
[0076]
[0077] Preferably, because the direction of the traversal of the two-dimensional array chessboard in digital movement and digital merging depends on the direction of the game interaction data (upward, downward, left and right), therefore, the algorithm logic of matrix rotation is written to rotate the two-dimensional array chessboard and simplify the game interaction data into a single direction movement instruction.
[0078] 3. Matrix rotation.
[0079] According to the game interaction data, the two-dimensional array chessboard is rotated through matrix rotation to simplify the game interaction data into a single direction movement instruction. For example, if all game interaction instructions are converted into left movement instructions, when the user enters an upward movement instruction, the two-dimensional array chessboard needs to be rotated counterclockwise once through matrix rotation, that is, the upward movement instruction is equivalent to the left movement instruction, and the two-dimensional array chessboard is traversed from the left to perform digital movement and merging. After completion, the two-dimensional array chessboard is reversely rotated through matrix rotation (rotate clockwise once or counterclockwise 3 times).
[0080] It can be seen that the result of merging the numbers up before the two-dimensional array chessboard transformation is the same as the result of merging the numbers left after two transformations of the two-dimensional array chessboard. Similarly, movements in all directions can be simplified to movements to the left, avoiding the need to write the algorithm logic for four digital movements (in four directions) and reducing duplicate code.
[0081] Part of the code for matrix rotation is as follows:
[0082] $arr is a 4*4 two-dimensional array of chessboard, and $n is the number of times to rotate.
[0083]
[0084]
[0085] It should be noted that the steps shown in the above process or the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0086] The embodiment of the present application provides a data processing system for a 2048 game based on PHP. Figure 2 2 is a block diagram of a data processing system for a PHP-based 2048 game according to an embodiment of the present application. Figure 2 As shown, the system includes an algorithm deployment module 21, an instruction transmission module 22 and an algorithm execution module 23;
[0087] The algorithm deployment module 21 uses PHP language to write the 2048 algorithm logic and deploys the 2048 algorithm logic program in the back-end server;
[0088] The instruction transmission module 22 generates game interaction data through the front end and sends the game interaction data to the back end server, wherein the game interaction data includes an upward movement instruction, a downward movement instruction, a left movement instruction and a right movement instruction;
[0089] The algorithm execution module 23 generates response data by executing the 2048 algorithm logic through the back-end server according to the game interaction data, and returns the response data to the front end.
[0090] Through the algorithm deployment module 21, instruction transmission module 22 and algorithm execution module 23 in the embodiment of the present application, the problem of data forgery and data tampering that are prone to occur in the 2048 game written in the front-end language is solved, and the back-end data processing of the 2048 game based on PHP is realized, which effectively prevents malicious data forgery requests and tampering of real data, thereby ensuring the fairness of the game.
[0091] In some embodiments, the algorithm execution module 23 executes the 2048 algorithm logic through the backend server according to the game interaction data, including:
[0092] The algorithm execution module 23 generates a two-dimensional array chessboard of a preset size through a backend server, and generates data values of a preset level in the two-dimensional array chessboard;
[0093] The algorithm execution module 23 traverses the two-dimensional array board row by row according to the game interaction data, and if there is a data value, the data value is recorded as a cell;
[0094] The algorithm execution module 23 finds the farthest empty position that the cell can move to in the moving direction and records it as farthest, and determines whether there is an adjacent position pointed to by farthest in the moving direction;
[0095] If it exists, determine whether the data value at the adjacent position is the same level as the cell. If so, merge the data value and the cell to generate the data value of the next level and move it to the adjacent position. If not, move the cell directly to the farthest position.
[0096] If it does not exist, the cell is moved directly to the farthest.
[0097] In some embodiments, the system further comprises:
[0098] The algorithm execution module 23 generates a two-dimensional array chessboard of a preset size through a backend server, and generates data values of a preset level in the two-dimensional array chessboard;
[0099] The algorithm execution module 23 rotates the two-dimensional array chessboard through matrix rotation according to the game interaction data, and simplifies the game interaction data into a single direction movement instruction;
[0100] The algorithm execution module 23 traverses the rotated two-dimensional array chessboard row by row according to the single-direction movement instruction, and if there is a data value, the data value is recorded as a cell;
[0101] The algorithm execution module 23 finds the farthest empty position to which the cell can move in a single direction and records it as farthest, and determines whether an adjacent position pointed to by farthest in a single direction exists;
[0102] If it exists, determine whether the data value at the adjacent position is the same level as the cell. If so, merge the data value and the cell to generate the data value of the next level and move it to the adjacent position. If not, move the cell directly to the farthest position.
[0103] If it does not exist, move the cell directly to the farthest;
[0104] Then the two-dimensional array chessboard is reversely rotated through matrix rotation.
[0105] In some embodiments, the algorithm deployment module 21 uses PHP language to write the 2048 algorithm logic including:
[0106] The algorithm deployment module 21 uses PHP language to write the algorithm logic of chessboard initialization, chessboard reset, chessboard position generation of random numbers, matrix rotation, number movement and number merging. Among them, matrix rotation is used to rotate the two-dimensional array chessboard, simplifying the game interaction data into a single direction movement instruction.
[0107] It should be noted that the above modules can be functional modules or program modules, and can be implemented by software or hardware. For modules implemented by hardware, the above modules can be located in the same processor; or the above modules can be located in different processors in any combination.
[0108] This embodiment further provides an electronic device, including 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 any one of the above method embodiments.
[0109] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0110] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.
[0111] In addition, in combination with the data processing method of the 2048 game based on PHP in the above embodiment, the embodiment of the present application can provide a storage medium for implementation. The storage medium stores a computer program; when the computer program is executed by the processor, any one of the data processing methods of the 2048 game based on PHP in the above embodiment is implemented.
[0112] In one embodiment, a computer device is provided, which may be a terminal. The computer device includes a processor, a memory, a network interface, a display screen, and an input device connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a data processing method for a 2048 game based on PHP is implemented. The display screen of the computer device may be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device may be a touch layer covered on the display screen, or a key, trackball, or touchpad provided on the housing of the computer device, or an external keyboard, touchpad, or mouse, etc.
[0113] In one embodiment, Figure 3 is a schematic diagram of the internal structure of an electronic device according to an embodiment of the present application, such as Figure 3 As shown, an electronic device is provided, which may be a server, and its internal structure diagram may be as shown in Figure 3 As shown. The electronic device includes a processor, a network interface, an internal memory and a non-volatile memory connected through an internal bus, wherein the non-volatile memory stores an operating system, a computer program and a database. The processor is used to provide computing and control capabilities, the network interface is used to communicate with an external terminal through a network connection, the internal memory is used to provide an environment for the operation of the operating system and the computer program, the computer program is executed by the processor to implement a data processing method for a 2048 game based on PHP, and the database is used to store data.
[0114] Those skilled in the art will understand that Figure 3 The structure shown in the figure is merely a block diagram of a partial structure related to the scheme of the present application, and does not constitute a limitation on the electronic device to which the scheme of the present application is applied. The specific electronic device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.
[0115] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0116] Those skilled in the art should understand that the technical features of the above-described embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above-described embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0117] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A data processing method for a 2048 game based on PHP, characterized in that: The method comprises: The 2048 algorithm logic is written in PHP language, and the program of the 2048 algorithm logic is deployed in the back-end server; Generate game interaction data through the front end, and send the game interaction data to the back end server, wherein the game interaction data includes an upward movement instruction, a downward movement instruction, a left movement instruction, and a right movement instruction; According to the game interaction data, the back-end server executes the 2048 algorithm logic to generate response data, and returns the response data to the front end, wherein according to the game interaction data, the back-end server executes the 2048 algorithm logic to generate response data, and returns the response data to the front end, wherein according to the game interaction data, the back-end server executes the 2048 algorithm logic includes: Generate a two-dimensional array chessboard of a preset size through the back-end server, and generate data values of a preset level in the two-dimensional array chessboard; According to the game interaction data, the two-dimensional array chessboard is rotated by matrix rotation to simplify the game interaction data into a single direction movement instruction; According to the single direction movement instruction, the rotated two-dimensional array chessboard is traversed row by row, and if there is a data value, the data value is recorded as a cell; Find the farthest empty position that the cell can move to in the single direction and record it as farthest, and determine whether there is an adjacent position pointed to by farthest in the single direction; If it exists, determine whether the data value of the adjacent position is the same level as the cell. If they are the same, merge the data value and the cell to generate a data value of the next level and move it to the adjacent position. If they are not the same, directly move the cell to the farthest position. If it does not exist, directly move the cell to the farthest; The two-dimensional array chessboard is then reversely rotated by matrix rotation, wherein the reverse rotation is used to restore the direction of the two-dimensional array chessboard after rotation to be consistent with the direction of the two-dimensional array chessboard before rotation.
2. The method according to claim 1, characterized in that The 2048 algorithm logic written in PHP includes: The algorithm logic of chessboard initialization, chessboard reset, chessboard position generation of random numbers, matrix rotation, number movement and number merging is written in PHP language. The matrix rotation is used to rotate the two-dimensional array chessboard, simplifying the game interaction data into a single direction movement instruction.
3. A data processing system for the 2048 game based on PHP, characterized in that: The system includes an algorithm deployment module, an instruction transmission module and an algorithm execution module; The algorithm deployment module uses PHP language to write the 2048 algorithm logic and deploys the program of the 2048 algorithm logic in the back-end server; The instruction transmission module generates game interaction data through the front end, and sends the game interaction data to the back end server, wherein the game interaction data includes an upward movement instruction, a downward movement instruction, a left movement instruction, and a right movement instruction; The algorithm execution module executes the 2048 algorithm logic through the back-end server according to the game interaction data to generate response data, and returns the response data to the front end, wherein the algorithm execution module executes the 2048 algorithm logic through the back-end server according to the game interaction data, including: The algorithm execution module generates a two-dimensional array chessboard of a preset size through the back-end server, and generates data values of a preset level in the two-dimensional array chessboard; The algorithm execution module rotates the two-dimensional array chessboard through matrix rotation according to the game interaction data, and simplifies the game interaction data into a single direction movement instruction; The algorithm execution module traverses the rotated two-dimensional array chessboard row by row according to the single-direction movement instruction, and if a data value exists, the data value is recorded as a cell; The algorithm execution module searches for the farthest empty position that the cell can move to in the single direction and records it as farthest, and determines whether there is an adjacent position pointed to by farthest in the single direction; If it exists, determine whether the data value of the adjacent position is the same level as the cell. If they are the same, merge the data value and the cell to generate a data value of the next level and move it to the adjacent position. If they are not the same, directly move the cell to the farthest position. If it does not exist, directly move the cell to the farthest; The two-dimensional array chessboard is then reversely rotated by matrix rotation, wherein the reverse rotation is used to restore the direction of the two-dimensional array chessboard after rotation to be consistent with the direction of the two-dimensional array chessboard before rotation.
4. The system according to claim 3, characterized in that The algorithm deployment module uses PHP language to write the 2048 algorithm logic, including: The algorithm deployment module uses PHP language to write the algorithm logic of chessboard initialization, chessboard reset, chessboard position generation of random numbers, matrix rotation, number movement and number merging, among which the matrix rotation is used to rotate the two-dimensional array chessboard to simplify the game interaction data into a single direction movement instruction.
5. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to perform the method according to any one of claims 1 to 2.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 2 is implemented.
Citation Information
Patent Citations
Game data management system, management method and storage medium
CN110960856A