Body: <p>Say I have a game like tic-tac-toe or chess. Or some other visual logic based problem. </p>
  
  <p>I could express the state of the game as a string. (or perhaps a 2D array)</p>
  
  <p>I want to be able to express the possible moves of the game as rules which change the string. e.g. replacement rules. </p>
  
  <p>I looked into regex as a possibility but this doesn't seem powerful enough. For example, one can't have named patterns which one can use again. (e.g. if I wanted to name a pattern called "numbers_except_for_8". To be used again.</p>
  
  <p>And it also should be able to express things like "repeat if possible".</p>
  
  <p>In other words I need some simple language to express rules of a game that has:</p>
  
  <ul>
  <li>modularity</li>
  <li>simpleness</li>
  <li>can act on other rules (self referential)</li>
  </ul>
  
  <p>There are languages like LISP but these on the other hand seem too complicated. (Perhaps there is no simple language hence why the English language is so complicated).</p>
  
  <p>I did read once about a generalised board game solving software program which had a way to express the rules of a game. But I can't seem to find a reference to it anywhere.</p>
  
  <p>As an example rules for tic tac toe might be:</p>
  
  <p>Players-Turn:
  "Find a blank square"->"Put an X in it"->Oponent's turn</p>
  
  <p>Oponents-Turn:
  "Find a blank square"->"Put an O in it"->Player's turn</p>
  
  <p>So I think the ingredients for rules are: searching for patterns, determining if an object is of a particular type (which might be the same as the first ingredient), and replacing.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-11-01T22:00:03.323Z
Comments.Text: What about the prolog?  Express the rules and moves using a logical expression.
Comments.UserDisplayName: OmG
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-11-02T12:09:57.160Z
Comments.Text: @OmG I think that may be the language that the Stanford Generalised Game Playing program uses. Might be a good idea. The syntax does get a bit complicated beyond simple rules though. But it does seem similar to what I need like this tic-tac-toe game: https://swish.swi-prolog.org/p/Tic-Tac-Toe.swinb
Comments.UserDisplayName: zooby
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-11-02T12:19:06.470Z
Comments.Text: Actually just seen a variant called ProbLog which uses probabilities as well.
Comments.UserDisplayName: zooby
Tags: <programming-languages><meta-rules>
Title: What is a good language for expressing replacement or template rules?
UserDisplayName: zooby
ThreadText: # What is a good language for expressing replacement or template rules?
  
  (Asked by: username_0 on 2019-11-01)
  
  Say I have a game like tic-tac-toe or chess. Or some other visual logic based problem.
  
  I could express the state of the game as a string. (or perhaps a 2D array)
  
  I want to be able to express the possible moves of the game as rules which change the string. e.g. replacement rules.
  
  I looked into regex as a possibility but this doesn't seem powerful enough. For example, one can't have named patterns which one can use again. (e.g. if I wanted to name a pattern called "numbers\_except\_for\_8". To be used again.
  
  And it also should be able to express things like "repeat if possible".
  
  In other words I need some simple language to express rules of a game that has:
  
  * modularity
  * simpleness
  * can act on other rules (self referential)
  
  There are languages like LISP but these on the other hand seem too complicated. (Perhaps there is no simple language hence why the English language is so complicated).
  
  I did read once about a generalised board game solving software program which had a way to express the rules of a game. But I can't seem to find a reference to it anywhere.
  
  As an example rules for tic tac toe might be:
  
  Players-Turn:
  "Find a blank square"->"Put an X in it"->Oponent's turn
  
  Oponents-Turn:
  "Find a blank square"->"Put an O in it"->Player's turn
  
  So I think the ingredients for rules are: searching for patterns, determining if an object is of a particular type (which might be the same as the first ingredient), and replacing.
  
  **Tags:** programming-languages, meta-rules
  > **Comments:**
  > **username_1**: What about the prolog?  Express the rules and moves using a logical expression.  
  > **username_0**: @OmG I think that may be the language that the Stanford Generalised Game Playing program uses. Might be a good idea. The syntax does get a bit complicated beyond simple rules though. But it does seem similar to what I need like this tic-tac-toe game: https://swish.swi-prolog.org/p/Tic-Tac-Toe.swinb  
  > **username_0**: Actually just seen a variant called ProbLog which uses probabilities as well.  
  
  ---
  
  ## 0 answers
  
  