Morpion solitaire/Unicon: Difference between revisions
Content added Content deleted
m (fix up description) |
(removed legacy code) |
||
Line 573: | Line 573: | ||
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</lang> |
|||
== Game Read/Write (alternate legacy notation) == |
|||
<lang Unicon>procedure ReadMoveLogOrig(R) #: Read original style move log |
|||
M := [] |
|||
while b := get(R) do { |
|||
until *b = 0 do { |
|||
x := MorpionGameRecord() # new move |
|||
b ?:= ( x.ref := integer(tab(many(&digits))),=":", # base |
|||
x.row := integer(=!["-","+",""]||tab(many(&digits))),=",", |
|||
x.col := integer(=!["-","+",""]||tab(many(&digits))), |
|||
tab(0)) | |
|||
stop(&output,"Syntax error in line above.") |
|||
if b ?:= ( ="^", tab(0)) then { # disamb |
|||
b ?:= ( x.darow := integer(=!["-","+",""]||tab(many(&digits))),=",", |
|||
x.dacol := integer(=!["-","+",""]||tab(many(&digits))), |
|||
tab(0)) | |
|||
stop(&output,"Syntax error in line above (disamiguation).") |
|||
} |
|||
b ?:= ( =(";"|""), tab(0) ) |
|||
put(M,x) |
|||
} |
|||
} |
|||
return sortf(M,1) |
|||
end |
|||
procedure WriteMoveLogOrig(MG) #: write out a re-readable move log |
|||
c := WriteMoveLogHeader(MG) |
|||
c ||:= sprintf("# Alternate Recorded game format:\n_ |
|||
# 1. whitespace and comments (everything past #) are ignored\n_ |
|||
# 2. moves may be ; or newline separated\n_ |
|||
# 3. moves are formatted (using BNF style variables like <x>):\n_ |
|||
# <movenumber>:<row>,<col>[^<drow>,<dcol>]\n_ |
|||
# The optional drow/dcol values provide an additional point\n_ |
|||
# used to disambiguate moves. The point drow/dcol must be\n_ |
|||
# chosen at one end of the line.\n_ |
|||
# Moves are applied in sorted order.\n_ |
|||
# 4. all row/col coordinates are relative to the 1,1 origin\n_ |
|||
# located at the intersection of the lines containing the\n_ |
|||
# top and left most edges of the cross.\n#\n") |
|||
every m := MG.history[i := 1 to *MG.history] do { |
|||
e := m.move ~= (1|5) |
|||
/l := "" |
|||
l ||:= sprintf("%i:%i,%i^%i,%i;", |
|||
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 { |
|||
c ||:= l || "\n" |
|||
l := &null |
|||
} |
|||
} |
|||
c ||:= \l || "\n" |
|||
return c || "#" |
|||
end</lang> |
end</lang> |
||