Morpion solitaire/Unicon: Difference between revisions
Content added Content deleted
m (→Other Interesting Results: ... more trimming) |
m (Fixed syntax highlighting.) |
||
Line 23: | Line 23: | ||
For more see: Morpion -h|-help |
For more see: Morpion -h|-help |
||
== |
===Basic Solution=== |
||
The code need to solve the task requirements is found in this section. Just delete the $define below. The basic code will play a single random game, show an ASCII art grid, and produce a log in Pentasol compatible notation. On any given run your most likely to see a game with scores in the 20's or 60's. |
The code need to solve the task requirements is found in this section. Just delete the $define below. The basic code will play a single random game, show an ASCII art grid, and produce a log in Pentasol compatible notation. On any given run your most likely to see a game with scores in the 20's or 60's. |
||
=== |
===Main and Core Game Play Procedures=== |
||
< |
<syntaxhighlight lang="unicon">link printf,strings,options |
||
$define MORPVER "1.7g" # version |
$define MORPVER "1.7g" # version |
||
Line 215: | Line 215: | ||
/MG.rseed := &random # seed for this game |
/MG.rseed := &random # seed for this game |
||
if MG.move := ?ScanGrid(MG).pool then return MG |
if MG.move := ?ScanGrid(MG).pool then return MG |
||
end</ |
end</syntaxhighlight> |
||
=== |
===Game Logging=== |
||
< |
<syntaxhighlight lang="unicon">procedure WriteMoveLog(MG) #: write move log wrapper |
||
if \M_GameSave then { |
if \M_GameSave then { |
||
savegame := sprintf("Games/%s/%i-L%i",M_GameType,*MG.history,M_Limit) |
savegame := sprintf("Games/%s/%i-L%i",M_GameType,*MG.history,M_Limit) |
||
Line 268: | Line 268: | ||
m.line[m.move,2]-m.coff+MG.coff,m.line[m.move,1]-m.roff+MG.roff, |
m.line[m.move,2]-m.coff+MG.coff,m.line[m.move,1]-m.roff+MG.roff, |
||
m.direction,(d < 0,"-")|(d = 0,"")|"+",abs(d)) |
m.direction,(d < 0,"-")|(d = 0,"")|"+",abs(d)) |
||
end</ |
end</syntaxhighlight> |
||
== |
===Extended Framework=== |
||
None of the code below is needed to satisfy the basic task. It supports the extended framework which includes, command line options, reading and replaying games from a saved file, running mass simulations to glean the best games, and some code for detailed analysis if I ever get around to experimenting with other than random strategy. |
None of the code below is needed to satisfy the basic task. It supports the extended framework which includes, command line options, reading and replaying games from a saved file, running mass simulations to glean the best games, and some code for detailed analysis if I ever get around to experimenting with other than random strategy. |
||
=== |
===Interface, Parameters, Globals=== |
||
< |
<syntaxhighlight lang="unicon">$ifdef EXTENDED |
||
# --- Interface, Parameters, Additional Globals --- |
# --- Interface, Parameters, Additional Globals --- |
||
Line 410: | Line 410: | ||
\t-?|-h|-help\tthis help text") |
\t-?|-h|-help\tthis help text") |
||
stop() |
stop() |
||
end</ |
end</syntaxhighlight> |
||
=== |
===Multigame Simulation and Monitoring Support=== |
||
<syntaxhighlight lang="unicon"> |
|||
<lang Unicon> |
|||
procedure MultiMorphion(N,MG) #: Simulate N games using MG |
procedure MultiMorphion(N,MG) #: Simulate N games using MG |
||
etime := -&time |
etime := -&time |
||
Line 489: | Line 489: | ||
every fprintf(M_Output," %s","-"|&storage) ; fprintf(M_Output,"\n\n") |
every fprintf(M_Output," %s","-"|&storage) ; fprintf(M_Output,"\n\n") |
||
fprintf(M_Output,"Icon/Unicon version %s\n",&version) |
fprintf(M_Output,"Icon/Unicon version %s\n",&version) |
||
end </ |
end </syntaxhighlight> |
||
=== |
===Game Replayer=== |
||
< |
<syntaxhighlight lang="unicon">procedure ReplayMorpion() #: Handle recorded games |
||
Replayer(M := ReadMoveLog(M_ReplayFile)) # read game and save data |
Replayer(M := ReadMoveLog(M_ReplayFile)) # read game and save data |
||
M_Strategy := Replayer |
M_Strategy := Replayer |
||
Line 543: | Line 543: | ||
stop() |
stop() |
||
} |
} |
||
end</ |
end</syntaxhighlight> |
||
=== |
===Game Reader=== |
||
< |
<syntaxhighlight lang="unicon">procedure ReadMoveLog(MG) #: read move log wrapper |
||
fprintf(M_Output,"Reading recorded game from: %s\n",M_ReplayFile) |
fprintf(M_Output,"Reading recorded game from: %s\n",M_ReplayFile) |
||
f := open(M_ReplayFile ,"r") | |
f := open(M_ReplayFile ,"r") | |
||
Line 596: | Line 596: | ||
} |
} |
||
return M |
return M |
||
end</ |
end</syntaxhighlight> |
||
=== |
===Detailed Move Logging (for analysis)=== |
||
< |
<syntaxhighlight lang="unicon">procedure PrintDetails(MG) #: print the log |
||
fprintf(M_Output,"Detailed Move Log\n") |
fprintf(M_Output,"Detailed Move Log\n") |
||
every fprintf(M_Output,"%i : %s\n",i := 1 to *MG.log,MG.log[i]) |
every fprintf(M_Output,"%i : %s\n",i := 1 to *MG.log,MG.log[i]) |
||
Line 619: | Line 619: | ||
log ||:= sprintf(" Metric=%i",M_Eval(MG)) # append score (opt) |
log ||:= sprintf(" Metric=%i",M_Eval(MG)) # append score (opt) |
||
put(MG.log,log) # log the move |
put(MG.log,log) # log the move |
||
end</ |
end</syntaxhighlight> |
||
=== |
===Strategy Support=== |
||
< |
<syntaxhighlight lang="unicon"># No useful examples at this time |
||
procedure Scorefail(MG);end #: dummy M_Eval always fails |
procedure Scorefail(MG);end #: dummy M_Eval always fails |
||
$endif</ |
$endif</syntaxhighlight> |
||
{{libheader|Icon Programming Library}} |
{{libheader|Icon Programming Library}} |