Morpion solitaire/Unicon: Difference between revisions

Content added Content deleted
m (fix v-space)
(fix for move log offset error, update help, change a default)
Line 35: Line 35:


record morpioncell(symbol,direction,row,col) # a grid cell
record morpioncell(symbol,direction,row,col) # a grid cell
record morpionmove(direction,move,line) # move & line
record morpionmove(direction,move,line,roff,coff) # move & line
record morpiongame(grid,log,history,roff,coff,center,pool,move,count) # all game data
record morpiongame(grid,log,history,roff,coff,center,pool,move,count) # all game data


Line 66: Line 66:
end
end


procedure MorphionMove(MG) #: make a move
procedure MorphionMove(MG) #: make a move
put(MG.history,M := MG.move)
(M := MG.move).roff := MG.roff
log := FormatMoveLog(M,MG.roff,MG.coff)
M.coff := MG.coff
put(MG.history,M)
log := FormatMoveLog(M)
log ||:= sprintf(" - of %i choices.",*MG.pool) # append # choices
log ||:= sprintf(" - of %i choices.",*MG.pool) # append # choices
log ||:= sprintf(" Metric=%i",M_Eval(MG)) # append score (opt)
log ||:= sprintf(" Metric=%i",M_Eval(MG)) # append score (opt)
Line 191: Line 193:


procedure FormatMoveLog(M,roff,coff) #: format a log entry
procedure FormatMoveLog(M,roff,coff) #: format a log entry
every /(roff|coff) := 0
/M.roff := \roff | 0
log := sprintf("\"%s\" [%i,%i] : ",
/M.coff := \coff | 0
log := sprintf("\"%s\" [%i,%i] : ",M.direction,
M.direction,M.line[M.move,1]-roff,M.line[M.move,2]-coff)
every x := !M.line do
M.line[M.move,1]-M.roff,M.line[M.move,2]-M.coff)
every x := !M.line do
log ||:= sprintf("[%i,%i] ",x[1]-roff,x[2]-coff)
log ||:= sprintf("[%i,%i] ",x[1]-M.roff,x[2]-M.coff)
return log
return log
end
end
Line 212: Line 215:
Arguments : ")
Arguments : ")
every fprintf(&errout," %s",!M_CommandLine)
every fprintf(&errout," %s",!M_CommandLine)
fprintf(&errout,"_
fprintf(&errout,"_
Morphion [options] Plays the 5T variant of Morphion Solitaire\n_
Morphion [options] Plays the 5T variant of Morphion Solitaire\n_
Where options are:\n_
Where options are:\n_
\t-P|-print<n>\n_
\t-P|-print\tcontrols how much is printed \n_
\t\t\tn=2 shows all boards and a log of all moves (every game)\n_
\t\t\tn=2\tshows all boards and a log of all moves (every game)\n_
\t\t\tn=1 shows a log of the moves and final board (default single game)\n_
\t\t\tn=1\tshows a log of the moves and final board (default single game)\n_
\t\t\tn=0 produces no per game output (default for multigames)\n_
\t\t\tn=0\tproduces no per game output (default for multigames)\n_
\t-A <a> choose player strategy approach (default=random)\n_
\t-A\tchoose player strategy approach (default=random, future)\n_
\t-E\tSpecifiy an position fitness evaluation function (default none, future)\n_
\t-SW <n> Search width (strategy dependent)\n_
\t-SW\tSearch width (strategy dependent, future)\n_
And where these options affect multigame simulations:\n_
\t-SD\tSearch depth (strategy dependent, future)\n_
\t-S <n> runs n games (e.g. -S10) and shows summary of all runs and the board and log for the best result_
\t\tnote for larger n this benefits from larger BLKSIZE, STRSIZE environment variables\n_
\t-UN <n> Give status update notifications every n simulations\n_
\t-B <n> Keep best n games of unique length (default 5)\n_
\t-W <n> Keep worst n games of unique length (default 3)\n_
\t-R|-replay\treplay\n_
\t-R|-replay\treplay\n_
\t-RF\tfile containing game record to be replayed\n_
\t-RF\tfile containing game record to be replayed\n_
\t-RN\tnumber of moves to replay (0=all)\n_
\t-RN\tnumber of moves to replay (0=all)\n_
\t-E\n_
\t-L|-limit\tgames to play (if 0 or less then play until any of 'XxQq' is pressed\n_
\t-L|-limit\tgames to play (if 0 or less then play until any of 'XxQq' is pressed\n_
\t\tnote for larger n this benefits from larger BLKSIZE, STRSIZE environment variables\n_
\t-UN\tGive status update notifications every n simulations\n_
\t-B\tKeep best n games of unique length (default 5)\n_
\t-W\tKeep worst n games of unique length (default 3)\n_
\t-?|-h|-help\tthis help text")
\t-?|-h|-help\tthis help text")
stop()
stop()
Line 261: Line 263:
M_SrchDep := (0 < \opt["SD"]) | 5
M_SrchDep := (0 < \opt["SD"]) | 5
M_Eval := case opt["E"] of {
M_Eval := case opt["E"] of {
"0" : Scorefail
"1" : Score1 # test
default : Score1 # also 1
default : &null # also "0"
}
}
c := sprintf("# --- Morpion Solitaire 5 (v%s) ---\n#\n",MORPVER)
c := sprintf("# --- Morpion Solitaire 5 (v%s) ---\n#\n",MORPVER)
c ||:= "# Command line options :"
c ||:= "# Command line options :"
Line 281: Line 282:
c ||:= sprintf("# - Moves to replay = %i\n",0 ~= \M_ReplayAfter)
c ||:= sprintf("# - Moves to replay = %i\n",0 ~= \M_ReplayAfter)
c ||:= sprintf("# Player Strategy = %i\n",M_Strategy)
c ||:= sprintf("# Player Strategy = %i\n",M_Strategy)
c ||:= sprintf("# - Play Evaluator = %i\n",M_Eval)
c ||:= sprintf("# - Position Fitness Evaluator = %i\n",\M_Eval | "* None *")
c ||:= sprintf("# - Search Width (strategy dependant) = %i\n",M_SrchWid)
c ||:= sprintf("# - Search Width (strategy dependant) = %i\n",M_SrchWid)
c ||:= sprintf("# - Search Depth (strategy dependant) = %i\n",M_SrchDep)
c ||:= sprintf("# - Search Depth (strategy dependant) = %i\n",M_SrchDep)
Line 288: Line 289:
if \opt["Q"] then stop(M_Config,"-Q Stops run after processing options")
if \opt["Q"] then stop(M_Config,"-Q Stops run after processing options")
else write(M_Config)
else write(M_Config)
/M_Eval := Scorefail
end</lang>
end</lang>
== Multigame Simulation and Monitoring Support ==
== Multigame Simulation and Monitoring Support ==
Line 477: Line 479:
if \M_ReplayFile then {
if \M_ReplayFile then {
M_ReplayFile ? (="Games/", savegame ||:= "-RF" || tab(find(".txt")))
M_ReplayFile ? (="Games/", savegame ||:= "-RF" || tab(find(".txt")))
savegame ||:= "-RN" || (0 < M_ReplayAfter)
savegame ||:= "-RN" || (0 < \M_ReplayAfter)
}
}
savegame ||:= sprintf("_%s-%s.txt",deletec(&date,'/'),deletec(&clock,':'))
savegame ||:= sprintf("_%s-%s.txt",deletec(&date,'/'),deletec(&clock,':'))
Line 498: Line 500:
/l := ""
/l := ""
l ||:= sprintf("%i:%i,%i^%i,%i;",
l ||:= sprintf("%i:%i,%i^%i,%i;",
i,m.line[m.move,1],m.line[m.move,2],m.line[e,1],m.line[e,2])
i,m.line[m.move,1]-m.roff,m.line[m.move,2]-m.coff,
m.line[e,1]-m.roff,m.line[e,2]-m.coff)
if *l > 70 then {
if *l > 70 then {
c ||:= l || "\n"
c ||:= l || "\n"