Chess moving path planning method based on chess display platform
By combining path planning methods with image processing and search algorithm optimization, the adaptability and accuracy issues of path planning in chess scenarios are solved, achieving intuitive and efficient display of chess piece movement paths, which is suitable for chess teaching, online competitions, and intelligent robot interaction.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-21
- Publication Date
- 2026-03-10
AI Technical Summary
Existing chess path planning algorithms suffer from insufficient adaptability, accuracy, and efficiency in chess scenarios. Traditional algorithms fail to effectively integrate chess move logic, visual processing is easily affected by lighting and grid lines, and obstacle handling is rigid, resulting in unintuitive and inefficient path planning.
A path planning method based on a chess display platform is adopted. Through image acquisition, preprocessing, grid model construction and search algorithm optimization, combined with Canny edge detection, double convolutional kernel filtering and CNN model to identify chess pieces, a grid model with 9 columns and 10 rows is constructed. The path planning is performed using the evaluation function f(n)=g(n)+h(n)+αt(n)+βb(n) and the results are visualized.
It improves the scenario adaptability and user experience of path planning, ensures the positioning accuracy of chess pieces, flexibly handles obstacles, and generates intuitive chess piece movement paths, making it suitable for chess teaching, online tournament live streaming, and intelligent robot interaction.
Smart Images

Figure CN121640142A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of chess movement path planning technology, and in particular to a chess movement path planning method based on a chess display platform. Background Technology
[0002] In scenarios such as chess teaching, online tournament live streaming, and intelligent chess robot interaction, chess display platforms often need to achieve automatic planning and visualization of chess piece movement paths to improve user experience or assist in functional implementation. Currently, mainstream path planning largely relies on traditional methods. The algorithm, specifically evaluating the function f(n) = g(n) + h(n), has significant limitations in its suitability for chess scenarios: on the one hand, The algorithm only focuses on "shortest distance" as its core objective and does not optimize for the chess move logic of "moving along straight lines as much as possible." Therefore, the planned path often contains numerous inflection points, such as... Figure 2 As shown in (b), it does not conform to the user's intuitive understanding; on the other hand, the traditional algorithm's mechanism for handling obstacles (non-target pieces) is rigid. When the path is blocked by obstacles, it either cannot output a feasible path or needs to calculate the number of steps the obstacle moves in a complex way, resulting in low planning efficiency and poor scene adaptability.
[0003] Meanwhile, existing visual processing methods mostly employ simple color recognition technology, which is susceptible to interference from lighting, shadows, and chessboard grid lines. The positioning error of chess pieces often exceeds two grid points, and attribute recognition easily confuses similar pieces such as "General / King" and "Advisor / Guard," leading to incorrect obstacle labeling in subsequent grid model construction and further affecting the accuracy of path planning. Furthermore, most solutions lack customized designs for the fixed 9 columns and 10 rows of a chessboard, resulting in insufficient adaptability of general road network models to the chessboard scenario. This makes it difficult to meet the platform's comprehensive requirements for path planning accuracy, efficiency, and visualization. Therefore, a dedicated method integrating high-precision visual processing and scenario-based path planning is urgently needed. Summary of the Invention
[0004] The purpose of this invention is to propose a chess movement path planning method based on a chess display platform, which can realize the automatic planning and visualization of chess piece movement paths. It is applicable to chess teaching systems, online tournament live streaming platforms, intelligent chess robot interaction systems and other scenarios, and solves the technical problems of adaptability, accuracy and efficiency of traditional path planning algorithms in chess scenarios.
[0005] To achieve this objective, the present invention adopts the following technical solution: A chess move path planning method based on a chess display platform includes the following steps: S1: Image acquisition, obtain the current image containing the complete chessboard and all chess pieces; S2: Image preprocessing and information extraction, the current image is sequentially processed by chessboard area localization, chess piece segmentation, attribute recognition and coordinate mapping to obtain the initial position coordinates and attribute information of each chess piece; S3: Target parameters are determined by obtaining the starting and destination coordinates of the target piece through user interaction commands or system preset rules. S4: Mesh model construction. A two-dimensional mesh model is constructed based on the grid distribution of the chessboard. The mesh model has 9 columns and 10 rows, with column numbers ranging from 1 to 9 and row numbers ranging from 1 to 10. The nodes of the mesh model are classified as follows: the starting position coordinates of the target piece are assigned to the starting node in the mesh model, the destination position coordinates of the target piece are assigned to the ending node in the mesh model, the coordinates of other pieces besides the target piece are labeled as obstacle nodes in the mesh model, and the coordinates of pieces without pieces are labeled as blank nodes in the mesh model. S5: Path planning and display, using... The search algorithm calculates the movement path of the target piece and generates a list of optimal paths. If there are obstacle nodes in the optimal path list, an additional list of obstacle movement paths is generated. The optimal paths are then presented in a visual format.
[0006] Preferably, step S2 includes the following sub-steps: S21: Chessboard area localization. The Canny edge detection algorithm is used to extract the edge contours in the image. Small-sized interference contours are filtered out by the contour perimeter threshold. Polygon approximation is performed on the remaining contours. The chessboard contour is selected based on three features: the number of vertices is 4, the area of the region conforms to the standard chessboard size range, and the angle between adjacent sides is close to 90°. The coordinates of the four corner vertices of the chessboard are accurately located. The tilted chessboard is corrected into an orthophoto image through perspective transformation. S22: Chess piece segmentation and attribute recognition. A dual-convolutional kernel morphological filter is used to process the corrected chessboard image. The dual convolutional kernel includes a horizontal convolutional kernel and a vertical convolutional kernel. The horizontal convolutional kernel size is set to 1×7, and the vertical convolutional kernel size is set to 7×1. Horizontal and vertical grid lines are filtered out. Chess pieces are separated from the background based on grayscale threshold segmentation. The grayscale threshold is adaptively determined using the Otsu algorithm to extract the bounding rectangle region of each chess piece. The chess piece region image is input into a pre-trained CNN model. The CNN model structure is an improved version of LeNet-5, with an input size of 128×128 and an output of 14 categories of chess piece attributes, completing the chess piece attribute classification. S23: Coordinate mapping. Establish an image coordinate system with the bottom left corner of the corrected chessboard image as the origin. The positive x-axis points horizontally to the right, and the positive y-axis points vertically upwards. The x-axis corresponds to the chessboard column number, and the y-axis corresponds to the chessboard row number. Calculate the center coordinates of the bounding rectangle of each piece. Based on the number of chessboard grid points, convert the image coordinate system to a grid coordinate system to obtain the corresponding node coordinates (x, y, ...) of the piece in the grid model. grid y grid ), the node coordinates x grid For column number, y grid The line number.
[0007] Preferably, in step S5 The evaluation function for the search algorithm is: f(n)=g(n)+h(n)+αt(n)+βb(n); Where g(n) is the actual movement cost from the starting node to the current node n, and the movement cost between adjacent nodes is fixed at 1; h(n) is the estimated cost from the current node n to the terminal node, calculated using Manhattan distance, and the formula is h(n) = |x grid -x target |+|y grid -y target |,x grid y is the column number of the grid coordinates of the current node. grid x is the grid coordinate row number of the current node. target y is the column number of the grid coordinates of the terminating node. target The grid coordinate row number of the terminating node; t(n) is the turning cost. When the movement direction of the neighboring node and the current node is different from the movement direction of the current node and its parent node, t(n) is 1, otherwise it is 0. b(n) is the cost of moving obstacles; it is 0 when there are no obstacles to move and 1 when obstacles need to be moved. α is the turning cost weight, and β is the moving obstacle cost weight.
[0008] Preferably, in step S5 The turning cost weight α and the moving obstacle cost weight β in the search algorithm evaluation function can be dynamically adjusted according to path planning requirements: If the shortest path is prioritized and moving obstacles are allowed, set β to a smaller value and α to a relatively larger value. If prioritizing avoiding moving obstacles and accepting path turns, set β to a larger value and α to a relatively smaller value.
[0009] Preferably, in step S5 The execution process of the search algorithm includes the following sub-steps: S51: Algorithm initialization, creating an open list and a closed list. The open list stores nodes to be explored, and the closed list stores nodes whose optimal paths have been determined. Add the starting node to the closed list. Traverse the four neighboring nodes of the starting node. The neighboring nodes are in the directions of up, down, left, and right. The row number of the up neighboring node is incremented by 1, the row number of the down neighboring node is decremented by 1, the column number of the left neighboring node is decremented by 1, and the column number of the right neighboring node is incremented by 1. If a neighboring node exceeds the boundary of the mesh model, skip it directly; Add neighboring nodes to the open list and set the starting node as its parent node. Calculate the f(n) of neighboring nodes based on the evaluation function f(n)=g(n)+h(n)+αt(n)+βb(n). S52: Node selection and target determination. Extract the node with the smallest f(n) value from the open list as the current node. If the coordinates of the current node are the same as the coordinates of the termination node, perform path backtracking. Trace back to the starting node through the parent node pointer of the node. Organize the nodes in the tracing process in the order of "starting node → node → termination node" to generate the optimal path list. If there are nodes of the obstacle type in the optimal path list, generate an additional obstacle movement path list and the algorithm terminates. S53: Neighbor node processing: Move the current node from the open list to the closed list, and traverse the four neighboring nodes of the current node. The direction of the neighboring nodes is up, down, left, and right. The row number of the upper neighboring node is +1, the row number of the lower neighboring node is -1, the column number of the left neighboring node is -1, and the column number of the right neighboring node is +1. If a neighboring node exceeds the boundary of the mesh model, skip it directly; If the neighboring node is already in the closed list, skip it directly; If the neighboring node is not in the open list, calculate f(n) based on the evaluation function f(n)=g(n)+h(n)+αt(n)+βb(n), add the neighboring node to the open list and set the current node as its parent node; If the neighboring node is already in the open list, calculate the f(n) value of reaching the neighboring node through the current node. If this value is less than the current f(n) value of the neighboring node, update the f(n) parameter of the neighboring node and the parent node. S55: Path Output and Display. The optimal path list and obstacle movement path list obtained from the planning are transmitted to the chess display platform. The movement trajectory of the target piece is displayed in the form of "highlighted nodes + arrow lines", and the movement process of the obstacles is displayed simultaneously.
[0010] Preferably, in step S54, the process of generating the obstacle movement path list is as follows: the target node for obstacle movement among the obstacle nodes is selected as a blank node in the mesh model. If there is no blank node, the obstacle node is used as the current node and step S53 is repeated. The node with the smallest f(n) value is selected as the target node for obstacle movement among the obstacle nodes.
[0011] Preferably, the optimal path visualization in step S5 is as follows: the optimal path is marked with a first color, the starting node in the optimal path is marked with a first color and the character "start", the ending node is marked with a second color and the character "end", the inflection point node is marked with a third color, the obstacle node that needs to be moved is marked with a fourth color, and the movement trajectory of the obstacle is displayed as a dashed arrow of a fifth color.
[0012] One of the above technical solutions has the following beneficial effects: (1) Path planning is more in line with the chess scenario, improving the user's intuitive experience compared to traditional methods. The algorithm outputs a multi-inflection path. After incorporating chess move logic into the search algorithm, the planned path is closer to the straight-line movement habits of human chess players, with fewer turning points and clearer logic. Whether it is a step demonstration in chess teaching or a path preview in online tournament live broadcast, it can help users quickly understand the move intention, significantly improving scenario adaptability and user experience.
[0013] (2) Improved visual processing accuracy ensures accurate path planning. Through layered image preprocessing and attribute recognition technology, interference from lighting, shadows and grid lines is effectively avoided. The positioning error of chess pieces is controlled within a single grid point, and the accuracy of similar chess piece recognition is greatly improved. This solves the path planning deviation problem caused by "error in obstacle labeling" from the source. Combined with the chess-specific grid model, the accurate correspondence between physical location and digital model is further ensured, providing a reliable data foundation for path planning.
[0014] (3) More flexible obstacle handling, improving scene adaptability and planning efficiency. For scenarios where the path is blocked, the optimal path of the target piece and the list of obstacle movement paths can be generated simultaneously without complex calculations. This not only solves the dilemma of "no solution" in traditional algorithms, but also reduces the computational complexity of obstacle handling through "minimum number of moves", greatly improving planning efficiency. It is suitable for multiple scenarios such as chess teaching (obstacle movement assistance in explaining rules), intelligent robot interaction (automatic avoidance of pieces), and online competitions (path prediction and display), with stronger scene coverage.
[0015] (4) Customized design enhances the specialization of the solution and meets comprehensive needs. A grid model with a fixed specification of 9 columns and 10 rows for chess is customized to avoid the redundancy of the general road network model and make the path planning more focused on the core needs of the chess scene. At the same time, it realizes the integrated design of "high-precision visual extraction - efficient path planning - visualization display", which not only meets the platform's technical requirements for the accuracy and efficiency of path planning, but also enhances the user interaction experience through visualization, fully meeting the comprehensive needs of the chess display platform. Attached Figure Description
[0016] Figure 1 This is a flowchart illustrating a chess movement path planning method based on a chess display platform according to the present invention. Figure 2 In this invention Search algorithm path planning and traditional Comparison of path planning algorithms in obstacle-free scenarios; Figure 3 In this invention Search algorithm path planning and traditional Comparison of path planning algorithms in scenarios with obstacles; Detailed Implementation Embodiments of the present invention are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.
[0017] A chess move path planning method based on a chess display platform includes the following steps: S1: Image acquisition, obtain the current image containing the complete chessboard and all chess pieces; S2: Image preprocessing and information extraction, the current image is sequentially processed by chessboard area localization, chess piece segmentation, attribute recognition and coordinate mapping to obtain the initial position coordinates and attribute information of each chess piece; S3: Target parameters are determined by obtaining the starting and destination coordinates of the target piece through user interaction commands or system preset rules. S4: Mesh model construction. A two-dimensional mesh model is constructed based on the grid distribution of the chessboard. The mesh model has 9 columns and 10 rows, with column numbers ranging from 1 to 9 and row numbers ranging from 1 to 10. The nodes of the mesh model are classified as follows: the starting position coordinates of the target piece are assigned to the starting node in the mesh model, the destination position coordinates of the target piece are assigned to the ending node in the mesh model, the coordinates of other pieces besides the target piece are labeled as obstacle nodes in the mesh model, and the coordinates of pieces without pieces are labeled as blank nodes in the mesh model. S5: Path planning and display, using... The search algorithm calculates the movement path of the target piece and generates a list of optimal paths. If there are obstacle nodes in the optimal path list, an additional list of obstacle movement paths is generated. The optimal paths are then presented in a visual format.
[0018] like Figure 1 As shown, the technical solution of this invention constructs a complete technical framework for chess move path planning through five core steps: image acquisition, image preprocessing and information extraction, target parameter determination, grid model construction, and path planning and display. The logical connection between each step is as follows: Image Acquisition (S1): Capture an image containing the complete chessboard and all pieces using an image acquisition device (such as a USB high-definition camera or industrial camera) to provide raw data for subsequent visual processing. The core is to ensure that the image does not lack key information (such as chessboard boundaries and piece outlines) to avoid subsequent positioning failures due to image incompleteness.
[0019] Image preprocessing and information extraction (S2): This addresses the problem of traditional color recognition being easily affected by lighting and shadows. Through layered processing of "chessboard area positioning → chess piece segmentation → attribute recognition", it accurately distinguishes the chessboard boundary and chess piece outlines, overcoming the attribute recognition problem of similar chess pieces such as "general / king" and "advisor / guard". Furthermore, through a coordinate mapping mechanism, the positions of chess pieces on the physical chessboard are converted into digital coordinates, providing high-precision data support for subsequent mesh modeling and ensuring that the error between the initial position and attribute information of the chess pieces is controlled within a single grid point.
[0020] Target parameter determination (S3): The "starting node-ending node" coordinates of the target piece are clearly defined through user interaction or system presets, defining the core objective of path planning, and simultaneously verifying the validity of the parameters: The obtained starting position coordinates (x...) are... start y start ) and target location coordinates (x end y end ) Perform validity verification. If the coordinates exceed the range of the mesh model (x grid <1 or x grid >9, y grid <1 or ygrid If the value is greater than 10, the system will prompt "Invalid parameter, please re-enter"; after successful verification, record the grid node (starting node) corresponding to the starting position coordinates and the grid node (ending node) corresponding to the destination position coordinates to avoid invalid planning.
[0021] Mesh Model Construction (S4): The physical chessboard is abstracted into a two-dimensional mesh with 9 columns and 10 rows. The mesh nodes are classified into "starting nodes, ending nodes, obstacle nodes, and blank nodes". Essentially, the chess scene is transformed into a "road network model" that can be recognized by the path planning algorithm. The obstacle nodes correspond to non-target pieces, and the blank nodes are passable areas. This not only adapts to the fixed structure of the chessboard, but also clearly defines the movable area and the blocking area, solving the problem of insufficient adaptability of the general road network model to the chess scene.
[0022] Path planning and visualization (S5): using the optimized version Search algorithms that break through traditional... Overcoming the limitation of algorithms that "only pursue the shortest distance," the algorithm incorporates the chess move logic of "moving along a straight line as much as possible" into the path evaluation function, prioritizing the search for straight lines or paths with low inflection points to make the planning results consistent with the user's intuitive understanding. At the same time, for scenarios with obstacles, a two-layer planning mechanism of "main path + obstacle auxiliary path" is constructed: if there are obstacle nodes in the optimal path, the algorithm will simultaneously calculate the minimum number of moves for the obstacle and a reasonable movement path (such as moving to the nearest empty node), generating a list of obstacle movement paths, avoiding the defects of traditional algorithms that are "unsolvable or computationally complex". Finally, the optimal path (including obstacle movement guidance) is presented intuitively through visualization technology, completing the "planning-display" closed loop.
[0023] To further explain, step S2 includes the following sub-steps: S21: Chessboard area localization. The Canny edge detection algorithm is used to extract the edge contours in the image. Small-sized interference contours are filtered out by the contour perimeter threshold. Polygon approximation is performed on the remaining contours. The chessboard contour is selected based on three features: the number of vertices is 4, the area of the region conforms to the standard chessboard size range, and the angle between adjacent sides is close to 90°. The coordinates of the four corner vertices of the chessboard are accurately located. The tilted chessboard is corrected into an orthophoto image through perspective transformation. S22: Chess piece segmentation and attribute recognition. A dual-convolutional kernel morphological filter is used to process the corrected chessboard image. The dual convolutional kernel includes a horizontal convolutional kernel and a vertical convolutional kernel. The horizontal convolutional kernel size is set to 1×7, and the vertical convolutional kernel size is set to 7×1. Horizontal and vertical grid lines are filtered out. Chess pieces are separated from the background based on grayscale threshold segmentation. The grayscale threshold is adaptively determined using the Otsu algorithm to extract the bounding rectangle region of each chess piece. The chess piece region image is input into a pre-trained CNN model. The CNN model structure is an improved version of LeNet-5, with an input size of 128×128 and an output of 14 categories of chess piece attributes, completing the chess piece attribute classification. S23: Coordinate mapping. Establish an image coordinate system with the bottom left corner of the corrected chessboard image as the origin. The positive x-axis points horizontally to the right, and the positive y-axis points vertically upwards. The x-axis corresponds to the chessboard column number, and the y-axis corresponds to the chessboard row number. Calculate the center coordinates of the bounding rectangle of each piece. Based on the number of chessboard grid points, convert the image coordinate system to a grid coordinate system to obtain the corresponding node coordinates (x, y, ...) of the piece in the grid model. grid y grid ), the node coordinates x grid For column number, y grid The line number.
[0024] Steps S21-S23 refine step S2: image preprocessing and information extraction, achieving high-precision information extraction through step-by-step techniques. Chessboard region localization (S21): First, image edges are extracted using Canny edge detection, and Gaussian filtering is used for noise reduction to reduce background interference (such as desktop texture, lighting and shadows). Then, small-sized interference (such as dust, chess piece reflections) is filtered out using the "contour perimeter threshold". The remaining contours are approximated by polygons to retain contours that are close to rectangles. Finally, the chessboard contour is locked based on three features: "4 vertices, area conforms to a standard chessboard, and the included angle between adjacent sides is close to 90°". The tilted chessboard is corrected to an orthophoto image through perspective transformation to ensure the coordinate accuracy of subsequent chess piece localization.
[0025] Piece Segmentation and Attribute Recognition (S22): A dual-kernel morphological filter with a 1×7 horizontal convolutional kernel and a 7×1 vertical convolutional kernel is used to specifically remove the horizontal and vertical grid lines of the chessboard, avoiding interference from the grid lines in piece contour extraction. The Otsu algorithm is used to adaptively determine the grayscale threshold to achieve binarization segmentation of the pieces (dark) and the background (light), and the bounding rectangle of each piece is extracted. The 128×128 pixel piece image is input into the LeNet-5 improved CNN model. The model extracts the texture features of the pieces through convolutional layers and classifies them through fully connected layers, outputting 14 categories of chess attributes (covering the "General", "Advisor", "Minister", "Horse", "Chariot", "Cannon", "Pawn" in Chinese chess and the corresponding black pieces), thus completing attribute recognition.
[0026] Coordinate Mapping (S23): Establish an image coordinate system with the lower left corner of the corrected chessboard as the origin, with the x-axis corresponding to the chessboard column number and the y-axis corresponding to the row number; calculate the center coordinates of the bounding rectangle of the chess piece, and map the image coordinates to grid coordinates according to the chessboard grid number of "9 columns and 10 rows" (x, y, y). grid For column number, y grid (For row numbers), to achieve the conversion of "image pixel coordinates → path planning grid coordinates".
[0027] To further explain, in step S5 The evaluation function for the search algorithm is: f(n)=g(n)+h(n)+αt(n)+βb(n); Where g(n) is the actual movement cost from the starting node to the current node n, and the movement cost between adjacent nodes is fixed at 1; h(n) is the estimated cost from the current node n to the terminal node, calculated using Manhattan distance, and the formula is h(n) = |x grid -x target |+|y grid -y target |,x grid y is the column number of the grid coordinates of the current node. grid x is the grid coordinate row number of the current node. target y is the column number of the grid coordinates of the terminating node. target The grid coordinate row number of the terminating node; t(n) is the turning cost. When the movement direction of the neighboring node and the current node is different from the movement direction of the current node and its parent node, t(n) is 1, otherwise it is 0. b(n) is the cost of moving obstacles; it is 0 when there are no obstacles to move and 1 when obstacles need to be moved. α is the turning cost weight, and β is the moving obstacle cost weight.
[0028] The evaluation function f(n) = g(n) + h(n) + αt(n) + βb(n) quantifies the comprehensive priority of each node by weighted summation of "actual cost + estimated cost + turning cost + obstacle movement cost". The algorithm prioritizes exploring the node with the smallest f(n) value to ensure the optimal path.
[0029] The calculation logic for each parameter of the evaluation function is as follows: g(n): The actual movement cost from the starting node to the current node n. The cost of moving one step to an adjacent node is fixed at 1. This objectively reflects the cost consumed by the path and ensures that the path length is controllable.
[0030] h(n): The estimated cost from the current node n to the terminal node, calculated using Manhattan distance (h(n) = |x grid- x target |+|y grid -y target The Manhattan distance satisfies the admissibility requirement of "not overestimating the actual cost," guiding the algorithm toward the terminal node and avoiding blind exploration.
[0031] t(n): Turning cost, taking only 0 or 1: When the movement direction from the current node to the neighboring node (e.g., up → down) is different from the movement direction from the current node to its parent node (e.g., left → up), t(n) = 1 (marking a turn), otherwise t(n) = 0. This parameter is used to penalize multi-turning paths and guide the algorithm to choose a smooth path.
[0032] b(n): Cost of moving obstacles, taking only 0 or 1: if the current path does not require moving obstacles, b(n) = 0; if obstacles need to be moved, b(n) = 1. This parameter marks the obstacle movement status, providing a basis for subsequent weight adjustments.
[0033] α and β: These are the weights of the turning cost and the obstacle movement cost, respectively, used to balance the priorities of "path smoothing" and "obstacle avoidance".
[0034] To further explain, in step S5 The turning cost weight α and the moving obstacle cost weight β in the search algorithm evaluation function can be dynamically adjusted according to path planning requirements: If the shortest path is prioritized and moving obstacles are allowed, set β to a smaller value and α to a relatively larger value. If prioritizing avoiding moving obstacles and accepting path turns, set β to a larger value and α to a relatively smaller value.
[0035] Furthermore, The cost weight α and the cost weight β for moving obstacles in the search algorithm's evaluation function can be dynamically adjusted according to path planning requirements, adapting to different scenario needs (such as prioritizing the shortest path in teaching scenarios and prioritizing not moving obstacles in competition scenarios), thus solving the problem of fixed priorities in traditional algorithms. Prioritize the shortest path scenario: If you need to display the shortest path (such as explaining the "shortest checkmate path" in chess teaching), set β to a smaller value (such as 5) and α to a larger value (such as 3). In this case, the algorithm pays more attention to g(n)+h(n) (path length) and t(n) (number of turns), and allows moving obstacles to shorten the path.
[0036] In scenarios prioritizing obstacle avoidance: If avoiding obstacle movement is prioritized and path turns are acceptable (consistent with the logic of regular chess games), β should be set to a value much greater than α. In chess scenarios, extensive experiments have verified that optimal control efficiency can be achieved when α is 1 and β is 20. Since the maximum Manhattan distance in the chess grid coordinates is 19 (e.g., from (1,1) to (9,10), Manhattan distance = |1-9|+|1-10|=19), β=20 ensures that the overall cost of "paths involving obstacle movement (b(n)=1, with an additional cost of 20)" is higher than "the longest path without moving obstacles (h(n)=19)", thus forcing the algorithm to prioritize paths without moving obstacles. At the same time, α=1 can effectively filter out the smooth path with the fewest inflection points through the turning cost of t(n)=1.
[0037] To further explain, in step S5 The execution process of the search algorithm includes the following sub-steps: S51: Algorithm initialization, creating an open list and a closed list. The open list stores nodes to be explored, and the closed list stores nodes whose optimal paths have been determined. Add the starting node to the closed list. Traverse the four neighboring nodes of the starting node. The neighboring nodes are in the directions of up, down, left, and right. The row number of the up neighboring node is incremented by 1, the row number of the down neighboring node is decremented by 1, the column number of the left neighboring node is decremented by 1, and the column number of the right neighboring node is incremented by 1. If a neighboring node exceeds the boundary of the mesh model, skip it directly; Add neighboring nodes to the open list and set the starting node as its parent node. Calculate the f(n) of neighboring nodes based on the evaluation function f(n)=g(n)+h(n)+αt(n)+βb(n). S52: Node selection and target determination. Extract the node with the smallest f(n) value from the open list as the current node. If the coordinates of the current node are the same as the coordinates of the termination node, perform path backtracking. Trace back to the starting node through the parent node pointer of the node. Organize the nodes in the tracing process in the order of "starting node → node → termination node" to generate the optimal path list. If there are nodes of the obstacle type in the optimal path list, generate an additional obstacle movement path list and the algorithm terminates. S53: Neighbor node processing: Move the current node from the open list to the closed list, and traverse the four neighboring nodes of the current node. The direction of the neighboring nodes is up, down, left, and right. The row number of the upper neighboring node is +1, the row number of the lower neighboring node is -1, the column number of the left neighboring node is -1, and the column number of the right neighboring node is +1. If a neighboring node exceeds the boundary of the mesh model, skip it directly; If the neighboring node is already in the closed list, skip it directly; If the neighboring node is not in the open list, calculate f(n) based on the evaluation function f(n)=g(n)+h(n)+αt(n)+βb(n), add the neighboring node to the open list and set the current node as its parent node; If the neighboring node is already in the open list, calculate the f(n) value of reaching the neighboring node through the current node. If this value is less than the current f(n) value of the neighboring node, update the f(n) parameter of the neighboring node and the parent node. S55: Path Output and Display. The optimal path list and obstacle movement path list obtained from the planning are transmitted to the chess display platform. The movement trajectory of the target piece is displayed in the form of "highlighted nodes + arrow lines", and the movement process of the obstacles is displayed simultaneously.
[0038] Steps S51-S55 refine the algorithm execution flow of step S5, path planning, and clarify it. The specific steps of the search algorithm: Algorithm initialization (S51): Create an open list (stores nodes to be explored, implemented using a priority queue, sorted by f(n)) and a closed list (stores nodes with determined optimal paths, implemented using a hash table for fast lookup); add the starting node to the closed list, traverse its four neighboring nodes (up / down / left / right, corresponding to row number ±1, column number ±1), and skip outbound nodes; add valid neighboring nodes to the open list, set the starting node as the parent node, and calculate f(n): g(n)=1 (1 step from the starting node to the neighboring node), h(n) uses Manhattan distance to calculate the estimated cost from the current node n to the terminal node, t(n)=0 (both the starting node and neighboring nodes are without turning), i.e., αt(n)=0, b(n) is sorted by neighboring node category (obstacle = 1, otherwise = 0), βb(n) is the actual calculated value, and the initialization is completed.
[0039] Node selection and target determination (S52): Extract the node with the smallest f(n) from the open list as the current node. If the current node is the termination node, backtrack to the starting node through the parent node pointer and organize the node sequence into an optimal path list. If there are obstacle nodes in the path, trigger obstacle movement path generation, and the algorithm terminates; otherwise, continue exploring. The backtracking mechanism from the starting node to the termination node ensures the generation of a complete path, and obstacle node detection triggers movement path generation, avoiding the traditional... The algorithm overcomes the problem of "failure when the path is blocked," but can still output feasible paths in complex, obstructed scenarios, such as... Figure 3 As shown in (b).
[0040] Neighbor node processing (S53): Move the current node from the open list to the closed list, traverse its 4 neighbor nodes, skipping nodes that are out of bounds and nodes in the closed list; if the neighbor node is not in the open list: calculate g(n) (current node g(n) + 1), h(n) (Manhattan distance), t(n) (direction comparison, 1 if different), b(n) (category determination), f(n), add it to the open list and set the current node as the parent node; if the neighbor node is already in the open list: calculate f(n) that can be reached through the current node, if it is smaller, update f(n) and the parent node to ensure that the optimal path is preserved, solve the problems of "path redundancy" and "repeated exploration" in traditional algorithms, and have high planning efficiency.
[0041] Path Output and Display (S55): Display the optimal path list (e.g.) Figure 3 (a), [(1,9),(1,8),(1,7),(1,6),(1,5),(2,5),(3,5),(4,5),(4,4),(4,3)]) and the list of obstacle movement paths (e.g. Figure 3 The data (a), [(1,7)→(2,7)]) is transmitted to the platform and then displayed through "highlighted nodes + arrow connections". The movement process of the obstacles is displayed synchronously, and users can intuitively observe the movement trajectory of the pieces and the adjustment process of the obstacles. This solves the problem of the traditional static path display being unintuitive, and is especially suitable for chess teaching and live competition broadcasts.
[0042] To further explain, in step S54, the process of generating the obstacle movement path list is as follows: the target node for obstacle movement among the obstacle nodes is selected first as a blank node in the mesh model. If there is no blank node, the obstacle node is used as the current node and step S53 is repeated. The node with the smallest f(n) value is selected first as the target node for obstacle movement among the obstacle nodes.
[0043] The above definition of the logic for generating the obstacle movement path list is a supplement to the "obstacle handling" step S54: Target node priority selection: When generating obstacle movement paths, empty nodes in the mesh model are prioritized as obstacle movement targets because empty nodes have no other pieces and will not generate new obstacles after being moved.
[0044] Handling when there are no blank nodes: If there are no blank nodes in the current scene (such as when the chessboard is densely packed with chess pieces), the obstacle node is used as the current node and step S53 is repeated. The node with the smallest f(n) value is selected from the open list of neighboring nodes as the obstacle movement target to ensure that the overall cost of the new path generated after the obstacle is moved is the lowest.
[0045] To further explain, the specific method of visualizing the optimal path in step S5 is as follows: the optimal path is marked with a first color, the starting node in the optimal path is marked with a first color and the character "start", the ending node is marked with a second color and the character "end", the inflection point node is marked with a third color, the obstacle node that needs to be moved is marked with a fourth color, and the movement trajectory of the obstacle is displayed as a dashed arrow of the fifth color.
[0046] The above defines a visual representation of the optimal path, using multi-color differentiation to improve path identification: Path and node annotation: The optimal path is marked with the first color (such as green) to clearly indicate the path's direction; The starting node is marked with the first color (such as blue) + the "start" character, and the ending node is marked with the second color (such as red) + the "end" character, so as to quickly distinguish the starting and ending nodes of the path; Inflection points (nodes where t(n)=1) are marked with a third color (such as pink) to highlight the turning points in the path; Obstacle nodes that need to be moved are marked with the fourth color (such as indigo), and the obstacle movement trajectory is marked with a dashed arrow of the fifth color (such as cyan) to indicate the direction of obstacle movement.
[0047] Display Logic: By using color contrast (e.g., green path vs. pink inflection points vs. indigo obstacles) and text labeling, the abstract list of paths is transformed into intuitive visual images. This can be combined with dynamic playback (e.g., flowing arrows) to improve the user's understanding of the path. Figure 2 (a) and Figure 3 As shown in (a).
[0048] Furthermore, the functional units in the various embodiments of the present invention can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into a module. The integrated module can be implemented in hardware or as a software functional module. If the integrated module is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium.
[0049] Although embodiments of the present invention have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present invention. Those skilled in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of the present invention.
Claims
1. A chess moving path planning method based on a chess display platform, characterized in that, The method comprises the following steps: S1: image acquisition, acquiring a current image containing a complete chessboard and all chessmen; S2: image preprocessing and information extraction, sequentially performing chessboard region positioning, chessman segmentation, attribute recognition and coordinate mapping on the current image to obtain initial position coordinates and attribute information of each chessman; S3: target parameter determination, obtaining starting position coordinates and destination position coordinates of a target chessman through user interactive instructions or system preset rules; S4: grid model construction, constructing a two-dimensional grid model based on the grid point distribution of the chessboard, the grid model being 9 columns and 10 rows, column numbers ranging from 1 to 9 and row numbers ranging from 1 to 10, and classifying the nodes of the grid model: taking the starting position coordinates of the target chessman as the starting node in the grid model, taking the destination position coordinates of the target chessman as the terminal node in the grid model, taking the coordinates of the chessmen other than the target chessman as obstacle nodes in the grid model, and taking the coordinates without chessmen as blank nodes in the grid model; S5: Path planning and display, using The search algorithm calculates the moving path of the target chess piece, generates an optimal path list, and if the optimal path list contains obstacle nodes, an additional obstacle moving path list is generated. The optimal path is presented in a visual form.
2. The method according to claim 1, wherein, The step S2 comprises the following sub-steps: S21: chessboard region positioning, extracting edge contours in the image by using a Canny edge detection algorithm, screening out small-size interference contours by a contour perimeter threshold, performing polygon approximation on the remaining contours, screening out a chessboard contour according to three characteristics that the number of vertices is 4, the area of the region meets the standard chessboard size range and the adjacent edge angle is close to 90°, and accurately positioning the top corner coordinates of the chessboard, and correcting the inclined chessboard into an orthographic image through perspective transformation; S22: chessman segmentation and attribute recognition, processing the corrected chessboard image by using a double convolution kernel morphological filter, the double convolution kernel comprising a horizontal convolution kernel and a vertical convolution kernel, the size of the horizontal convolution kernel being set as 1×7 and the size of the vertical convolution kernel being set as 7×1, filtering out horizontal and vertical grid lines through the filter; separating the chessmen from the background based on a gray value threshold segmentation, the gray value threshold being adaptively determined by an Otsu algorithm, and extracting the circumscribed rectangular region of each chessman; inputting the chessman region image into a pre-trained CNN model, the CNN model structure being an improved version of LeNet-5, the input size being 128×128, and the output being 14 types of chessman attributes, and completing the chessman attribute classification; S23: Coordinate mapping, taking the lower left corner of the corrected chessboard image as the origin, establishing an image coordinate system, with the horizontal right as the positive direction of the x-axis and the vertical up as the positive direction of the y-axis, the x-axis corresponds to the chessboard column number, and the y-axis corresponds to the chessboard row number; calculate the center coordinates of the outer rectangle of each chess piece, convert the image coordinate system to the grid coordinate system according to the number of chessboard grid points, and obtain the corresponding node coordinates (x grid , y grid ) of the chess piece in the grid model, wherein x grid is the column number and y grid is the row number.
3. The method according to claim 1, wherein, The step S5 The search algorithm evaluation function is: f(n) = g(n) + h(n) + αt(n) + βb(n); wherein g(n) is the actual moving cost from the starting node to the current node n, the moving cost between adjacent nodes is fixed as 1; h(n) is the estimated cost from the current node n to the termination node, calculated by Manhattan distance, the formula is h(n)=|x grid -x target |+|y grid -y target |, x grid is the column number of the grid coordinates of the current node, y grid is the row number of the grid coordinates of the current node, x target is the column number of the grid coordinates of the termination node, y target is the row number of the grid coordinates of the termination node; t(n) is the turning cost, t(n) is 1 when the moving direction of the adjacent node and the current node is different from the moving direction of the current node and its parent node, otherwise t(n) is 0; b(n) is the moving obstacle cost, which is 0 when no obstacle is moved and 1 when an obstacle is moved; α is the turning cost weight, and β is the moving obstacle cost weight.
4. The method according to claim 3, wherein, The step S5 The turning cost weight a and the moving obstacle cost weight β of the search algorithm evaluation function can be dynamically adjusted according to the path planning requirements: If the shortest path is preferred and moving obstacles are allowed, β is set to a small value and α is set to a relatively large value; If moving obstacles are preferred to be avoided and turning is acceptable, β is set to a large value and α is set to a relatively small value.
5. The method according to claim 3, wherein, The step S5 The execution process of the search algorithm comprises the following sub-steps: S51: algorithm initialization, create open list and closed list, open list is used to store the node to be explored, closed list is used to store the node whose optimal path has been determined; add the starting node to the closed list; traverse the 4 adjacent nodes of the starting node, the adjacent node direction is up, down, left and right, the up adjacent node corresponds to the row number +1, the down adjacent node corresponds to the row number -1, the left adjacent node corresponds to the column number -1, and the right adjacent node corresponds to the column number +1; If the adjacent node exceeds the boundary of the grid model, it is directly skipped; Add the adjacent node to the open list and set the starting node as its parent node, and calculate the f(n) of the adjacent node based on the evaluation function f(n)=g(n)+h(n)+αt(n)+βb(n); S52: node screening and target determination, extract the node with the minimum f(n) value from the open list as the current node; if the coordinates of the current node are consistent with the coordinates of the termination node, execute path backtracking, trace back to the starting node through the parent node pointer of the node in turn, arrange the nodes in the backtracking process in the order of "starting node→node→termination node", generate the optimal path list, if the optimal path list contains nodes of obstacle nodes, an additional obstacle movement path list is generated, and the algorithm terminates; S53: adjacent node processing, move the current node from the open list to the closed list, traverse the 4 adjacent nodes of the current node, the adjacent node direction is up, down, left and right, the up adjacent node corresponds to the row number +1, the down adjacent node corresponds to the row number -1, the left adjacent node corresponds to the column number -1, and the right adjacent node corresponds to the column number +1; If the adjacent node exceeds the boundary of the grid model, it is directly skipped; If the adjacent node is in the closed list, it is directly skipped; If the adjacent node is not in the open list, calculate f(n) based on the evaluation function f(n)=g(n)+h(n)+αt(n)+βb(n), add the adjacent node to the open list and set the current node as its parent node; If the adjacent node is in the open list, calculate the f(n) value of the adjacent node reached through the current node, if the value is less than the current f(n) value of the adjacent node, update the f(n) parameter and the parent node of the adjacent node; S55: path output and display, transfer the optimal path list and obstacle movement path list obtained by planning to the chess display platform, display the moving track of the target chess piece in the form of "highlighted node+arrow connection", and display the moving process of the obstacle synchronously.
6. The method according to claim 5, wherein, In the step S54, the generation process of the obstacle movement path list is: preferentially selecting the target node of the obstacle movement in the obstacle node as the blank node in the grid model, if there is no blank node, repeating step S53 with the obstacle node as the current node, preferentially selecting the node with the minimum f(n) value as the target node of the obstacle movement in the obstacle node.
7. The method according to claim 6, wherein, The specific way of the optimal path visualization display in the step S5 is that the optimal path is marked with a first color, the start node in the optimal path is marked with the first color and the character start, the end node is marked with a second color and the character end, the inflection point node is marked with a third color, the obstacle node to be moved is marked with a fourth color, and the moving track of the obstacle is displayed with a fifth color dotted line arrow.
Citation Information
Patent Citations
Chess piece path planning method and system based on improved ant colony algorithm, and electronic equipment
CN120851329A