Morpion solitaire/Unicon: Difference between revisions

m
Fixed syntax highlighting.
(→‎Other Interesting Results: added graphs from interesting results)
m (Fixed syntax highlighting.)
 
(2 intermediate revisions by one other user not shown)
Line 23:
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.
=== Main and Core Game Play Procedures ===
<langsyntaxhighlight Uniconlang="unicon">link printf,strings,options
 
$define MORPVER "1.7g" # version
Line 215:
/MG.rseed := &random # seed for this game
if MG.move := ?ScanGrid(MG).pool then return MG
end</langsyntaxhighlight>
 
=== Game Logging ===
<langsyntaxhighlight Uniconlang="unicon">procedure WriteMoveLog(MG) #: write move log wrapper
if \M_GameSave then {
savegame := sprintf("Games/%s/%i-L%i",M_GameType,*MG.history,M_Limit)
Line 268:
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))
end</langsyntaxhighlight>
 
== =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.
=== Interface, Parameters, Globals ===
 
<langsyntaxhighlight Uniconlang="unicon">$ifdef EXTENDED
 
# --- Interface, Parameters, Additional Globals ---
Line 410:
\t-?|-h|-help\tthis help text")
stop()
end</langsyntaxhighlight>
 
=== Multigame Simulation and Monitoring Support ===
<syntaxhighlight lang="unicon">
<lang Unicon>
procedure MultiMorphion(N,MG) #: Simulate N games using MG
etime := -&time
Line 489:
every fprintf(M_Output," %s","-"|&storage) ; fprintf(M_Output,"\n\n")
fprintf(M_Output,"Icon/Unicon version %s\n",&version)
end </langsyntaxhighlight>
 
=== Game Replayer ===
<langsyntaxhighlight Uniconlang="unicon">procedure ReplayMorpion() #: Handle recorded games
Replayer(M := ReadMoveLog(M_ReplayFile)) # read game and save data
M_Strategy := Replayer
Line 543:
stop()
}
end</langsyntaxhighlight>
 
=== Game Reader ===
<langsyntaxhighlight Uniconlang="unicon">procedure ReadMoveLog(MG) #: read move log wrapper
fprintf(M_Output,"Reading recorded game from: %s\n",M_ReplayFile)
f := open(M_ReplayFile ,"r") |
Line 596:
}
return M
end</langsyntaxhighlight>
 
=== Detailed Move Logging (for analysis) ===
<langsyntaxhighlight Uniconlang="unicon">procedure PrintDetails(MG) #: print the log
fprintf(M_Output,"Detailed Move Log\n")
every fprintf(M_Output,"%i : %s\n",i := 1 to *MG.log,MG.log[i])
Line 619:
log ||:= sprintf(" Metric=%i",M_Eval(MG)) # append score (opt)
put(MG.log,log) # log the move
end</langsyntaxhighlight>
 
=== Strategy Support ===
<langsyntaxhighlight Uniconlang="unicon"># No useful examples at this time
 
procedure Scorefail(MG);end #: dummy M_Eval always fails
$endif</langsyntaxhighlight>
 
{{libheader|Icon Programming Library}}
Line 1,031:
 
Summary of Results every '*' = 6761 games
...
0 | ( 0)
5 | ( 0)
10 | ( 0)
15 | ( 0)
20 | ( 0)
25 | ( 0)
30 | ( 0)
35 | ( 0)
40 | ( 0)
45 | ( 0)
50 | ( 0)
55 | ( 0)
60 | ( 0)
65 | ( 0)
70 | ( 0)
75 | ( 0)
80 | ( 0)
85 | ( 0)
90 | ( 0)
95 | ( 0)
100 | ( 0)
105 | ( 0)
110 | ( 0)
115 | ( 0)
120 | (324190) ***********************************************
Line 1,083 ⟶ 1,061:
 
Summary of Results every '*' = 973 games
...
0 | ( 0)
20 | ( 0)
40 | ( 0)
60 | ( 0)
80 | ( 0)
100 | ( 0)
120 | ( 0)
140 | ( 77901) ********************************************************************************
Line 1,108 ⟶ 1,081:
 
Summary of Results every '*' = 5643 games
...
0 | ( 0)
20 | ( 0)
40 | ( 0)
60 | ( 0)
80 | ( 0)
100 | ( 0)
120 | (451482) ********************************************************************************
9,477

edits