[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-detail-85123-en":3,"doc-seo-85123-105":29,"detail-sidebar-cat-0-en-105":91},{"code":4,"msg":5,"data":6},0,"success",{"doc_id":7,"user_id":8,"nickname":9,"user_avatar":10,"doc_module":4,"category_id":11,"category_name":12,"doc_title":13,"doc_description":14,"doc_content":15,"file_id":16,"file_url":17,"file_type":18,"file_size":19,"view_count":20,"is_deleted":4,"is_public":20,"is_downloadable":20,"audit_status":20,"page_count":21,"language":22,"language_code":23,"site_id":24,"html_lang":23,"table_of_contents":25,"faqs":26,"seo_title":13,"seo_description":14,"update_tm":27,"read_time":28},85123,2336464648746,"Skyler","https://ap-avatar.wpscdn.com/davatar_276721f389ce27ea32af1340a28f341c",6,"Technology","How to Program a Never-Losing Chess Engine","A model based on graph theory represents perfect-information two-player games such as chess and checkers. A backtracking minimax algorithm determines whether a perfect strategy (game resolution) exists, by evaluating positions through terminal sinks with outcomes {win, draw, loss}. A related algorithm proves the weaker property that a strategy exists to never lose by guaranteeing at least a draw. The discussion emphasizes formal provability rather than practical runtime feasibility.","arXiv :2607 .09715v1 [ cs .GT] 24 Jun 2026  \nHow to program a never-losing chess engine  \nFabio Romano  \nJuly 14, 2026  \nAbstract  \nThis article proposes a model, based on graph theory, to represent a variety of two-player games of perfect information, such as chess and checkers. I then provide a backtracking minimax algorithm to find, if it exists, a perfect game strategy (game resolution), and subsequently a variant of that algorithm which is required to determine a weaker condition:  \nthe existence of a strategy to never lose (always reach at least a draw) .  \nOf course, this does not mean that in practice the algorithm can find such a strategy in a short time, but here we are only concerned with formally proving that this is possible, at least theoretically.  \n1 The Shannon’s idea  \nIn 1950, Claude Shannon informally outlined a theoretical procedure for playing a perfect game:  \nWith chess it is possible, in principle, to play a perfect game or construct a machine to do so as follows: One considers in a given position all possible moves, then all moves for the opponent, etc., to the end of the game (in each variation) . The end must occur, by the rules of the games after a finite number of moves (remembering the 50 move drawing rule) . Each of these variations ends in win, loss or draw. By working backward from the end one can determine whether there is a forced win, the position is a draw or is lost.  \n(Claude Shannon)  \nThe above idea is the foundation for Shannon’s work [10] of 1950, which is fundamental, but, theoretically speaking, this article has several issues. First of all, it focuses exclusively on the game of chess, while we would like to design a more general procedure. Second, it relies mostly on heuristics of evaluating functions, lacking of formal proofs for the proposed strategy, while we would like to have a strategy that is provably sound. This is what I intend to do in this article.  \n2 Graph terminology and the game model  \nLet G = ⟨V, E⟩ be a directed graph.  \nDefinition 2.1 (Path) . A path is a sequence of vertices ⟨v1 ,..., vn ⟩ ∈ Vn , with n ≥ 1, such that (vi , vi+1) ∈ E for every i ∈ {1, . . . , n − 1} .  \nDefinition 2.2 (Cycle) . A cycle is a path ⟨v1 ,..., vn ⟩, with n ≥ 2, such that v 1 = vn.  \nDefinition 2.3 (Simple path) . A simple path is a path ⟨v1 ,..., vn ⟩ which does not contain cycles, i.e. ∀i, j ∈ {1,..., n}, i  j : vi  vj .  \nDefinition 2.4 (Sinks) . In this context, we call ”sink” those vertices of G which the only arc they have is a self-loop. Formally:  \nsinks (G) := {v ∈ V | G.Adj (v) = {v}}  \nwhere G.Adj(v) is the set of vertices that are adjacent to v, i. e. G.Adj (v) :={u ∈ V | (v, u) ∈ E} .  \nDefinition 2.5 . Given a set of arcs F ⊆ E , vertices (F) is the set of vertices that compose the arcs in F. Formally:  \nvertices (F) = {v ∈ V | ∃w ∈ V : (v, w) ∈ F ∨ (w, v) ∈ F}  \nDefinition 2.6 (Game graph) . A game graph G := ⟨V, E, v0 , win, turn⟩ is a directed graph in which:  \n• V is the set of positions that can occur during the game;  \n• E ⊆ V 2 is the set of legal moves;  \n• v0 ∈ V \\ sinks(G) is the initial position of the game;  \n• ∀v ∈ V \\ sinks(G): G.Adj (v)  ∅ and v  G.Adj (v) .  \n• win: sinks (G) → {−1, 0 , 1} is a function that returns the winner for every endgame position: 1 if the attacker won, -1 if the defender won, 0 if it is a draw;  \n• turn: V → {1, −1} is defined as follows:  \n– turn (v0 ) ∈ {1, −1};  \n– ∀ (v, u) ∈ E, v  u : turn (v) := −turn(u) .  \n2.1 Evaluation function and depth to winning  \nDefinition 2.7 (eval : V → {−1, 0 , 1}) . The evaluation function eval, which returns the outcome of a position supposing perfect play, is defined by induction as follows:  \nBASE  \n∀v ∈ sinks (G): eval (v) := win(v) .  \nINDUCTION  \n∀v ∈ V \\ sinks(G):  \n• if turn(v) = 1:  \neval (v) := max eval (u)  \nu∈G.Adj(v)  \n• if turn(v) = −1:  \neval (v) := min eval (u)  \nu∈G.Adj(v)  \nAs you can see, this is the classical definition that relies on minimax principle, which comes from game ","cbCailgUGgnRgz8Z","https://ap.wps.com/l/cbCailgUGgnRgz8Z","pdf",279475,1,17,"English","en",105,"# Shannon’s idea\n# Graph terminology and the game model\n## Evaluation function and depth to winning","[{\"question\":\"What problem does the document address for chess-like games?\",\"answer\":\"It studies how to formalize perfect-information two-player games and determine strategies that guarantee outcomes. The focus includes both full resolution (forced win/draw/loss) and the weaker goal of never losing (always at least a draw).\"},{\"question\":\"How is the game represented in the proposed approach?\",\"answer\":\"The game is modeled as a directed game graph where vertices correspond to possible positions and edges correspond to legal moves. Terminal positions are defined as sinks with a self-loop, and the initial position is chosen outside the sinks set.\"},{\"question\":\"What role do minimax evaluation and “depth to winning” play?\",\"answer\":\"An evaluation function is defined by induction using minimax: maximizing for one player and minimizing for the other, starting from sink outcomes. A “depth to winning” function measures how many moves are required to reach a winning terminal under optimal play, and it links finiteness of this depth to the evaluation result.\"}]",1784201240,43,{"code":4,"msg":30,"data":31},"ok",{"site_id":24,"language":23,"slug":32,"title":13,"keywords":33,"description":14,"schema_data":34,"social_meta":86,"head_meta":88,"extra_data":90,"updated_unix":27},"how-to-program-a-never-losing-chess-engine","",{"@graph":35,"@context":85},[36,53,68],{"@type":37,"itemListElement":38},"BreadcrumbList",[39,43,47,50],{"item":40,"name":41,"@type":42,"position":20},"https://docshare.wps.com","Home","ListItem",{"item":44,"name":45,"@type":42,"position":46},"https://docshare.wps.com/document/","Document",2,{"item":48,"name":12,"@type":42,"position":49},"https://docshare.wps.com/document/technology/",3,{"item":51,"name":13,"@type":42,"position":52},"https://docshare.wps.com/document/how-to-program-a-never-losing-chess-engine/85123/",4,{"url":51,"name":13,"@type":54,"author":55,"headline":13,"publisher":57,"fileFormat":60,"inLanguage":23,"description":14,"dateModified":61,"datePublished":62,"encodingFormat":60,"isAccessibleForFree":63,"interactionStatistic":64},"DigitalDocument",{"name":9,"@type":56},"Person",{"url":40,"name":58,"@type":59},"DocShare","Organization","application/pdf","2026-07-17","2026-07-16",true,{"@type":65,"interactionType":66,"userInteractionCount":20},"InteractionCounter",{"@type":67},"ViewAction",{"@type":69,"mainEntity":70},"FAQPage",[71,77,81],{"name":72,"@type":73,"acceptedAnswer":74},"What problem does the document address for chess-like games?","Question",{"text":75,"@type":76},"It studies how to formalize perfect-information two-player games and determine strategies that guarantee outcomes. The focus includes both full resolution (forced win/draw/loss) and the weaker goal of never losing (always at least a draw).","Answer",{"name":78,"@type":73,"acceptedAnswer":79},"How is the game represented in the proposed approach?",{"text":80,"@type":76},"The game is modeled as a directed game graph where vertices correspond to possible positions and edges correspond to legal moves. Terminal positions are defined as sinks with a self-loop, and the initial position is chosen outside the sinks set.",{"name":82,"@type":73,"acceptedAnswer":83},"What role do minimax evaluation and “depth to winning” play?",{"text":84,"@type":76},"An evaluation function is defined by induction using minimax: maximizing for one player and minimizing for the other, starting from sink outcomes. A “depth to winning” function measures how many moves are required to reach a winning terminal under optimal play, and it links finiteness of this depth to the evaluation result.","https://schema.org",{"og:url":51,"og:type":87,"og:title":13,"og:site_name":58,"og:description":14},"article",{"robots":89,"canonical":51},"index,follow",{"doc_id":7,"site_id":24},{"code":4,"msg":5,"data":92},[93,97,101,105,110,113,118,123,128,131,135],{"id":20,"doc_module":4,"doc_module_name":45,"category_name":94,"show_sort_weight":95,"slug":96},"Story & Novel",90,"story-novel",{"id":46,"doc_module":4,"doc_module_name":45,"category_name":98,"show_sort_weight":99,"slug":100},"Literature",80,"literature",{"id":52,"doc_module":4,"doc_module_name":45,"category_name":102,"show_sort_weight":103,"slug":104},"Exam",70,"exam",{"id":106,"doc_module":4,"doc_module_name":45,"category_name":107,"show_sort_weight":108,"slug":109},5,"Comic",60,"comic",{"id":11,"doc_module":4,"doc_module_name":45,"category_name":12,"show_sort_weight":111,"slug":112},50,"technology",{"id":114,"doc_module":4,"doc_module_name":45,"category_name":115,"show_sort_weight":116,"slug":117},7,"Healthcare",40,"healthcare",{"id":119,"doc_module":4,"doc_module_name":45,"category_name":120,"show_sort_weight":121,"slug":122},8,"Research & Report",30,"research-report",{"id":124,"doc_module":4,"doc_module_name":45,"category_name":125,"show_sort_weight":126,"slug":127},9,"Religion & Spirituality",20,"religion-spirituality",{"id":126,"doc_module":4,"doc_module_name":45,"category_name":129,"show_sort_weight":126,"slug":130},"World Cup","world-cup",{"id":132,"doc_module":4,"doc_module_name":45,"category_name":133,"show_sort_weight":132,"slug":134},10,"Lifestyle","lifestyle",{"id":136,"doc_module":4,"doc_module_name":45,"category_name":137,"show_sort_weight":106,"slug":138},19,"General","general"]