Morpion solitaire: Difference between revisions

m
→‎{{header|REXX}}: re-coded the REXX program to show a true cross, reformatted the output. -- ~~~~
m (→‎{{header|REXX}}: changed wording in the header section. -- ~~~~)
m (→‎{{header|REXX}}: re-coded the REXX program to show a true cross, reformatted the output. -- ~~~~)
Line 310:
gS=gS/1
if gS<3 then call err "grid size is too small:" gS
sw=linesize()-1
indent=left('',max(0,sw-gS-10)%2) /*indentation used board display.*/
empty='fa'x /*the empty grid point symbol. */
@.=empty /*field (grid) is infinite. */
pointgC='f'x /*characterGreeK usedcross forcharacter Greekor crossnull. */
CBLF=player\=='' /*carbon-based lifeform ? */
if CBLF then oFID=player /*oFID is used for the game log. */
Line 360 ⟶ 362:
t: say arg(1); call lineout oFID,arg(1); return
Gshot: Gshots=Gshots arg(1)','arg(2); return
tranGC: if gC=='' then return arg(1); return translate(arg(1),copies(gC,12),'┌┐└┘│─╔╗╚╝║═')
/*─────────────────────────────────────GREEKCROSS subroutine────────────*/
GreekCross: wins=0; loX=1e85; hiX=0; LB=gS-1 /*Low Bar*/
lintel=LB-2; turn=1; loY=loX; hiY=0; ht=4+3*(LB-2) /*─ ─ */
Gshots=; nook=gS-2; Hnook=ht-nook+1; TB=ht-LB+1 /*Top Bar*/
/*─ ─ */
do y=1 for ht; _top='╔'copies('═',lintel)'╗' ; _top=tranGC(_top)
do y=1 for ht
_bot='╚'copies('═',lintel)'╝' ; _bot=tranGC(_bot)
_hib='╔'copies('═',lintel)'╝'left('',lintel)'╚'copies('═',lintel)'╗' ; _hib=tranGC(_hib)
_lob='╚'copies('═',lintel)'╗'left('',lintel)'╔'copies('═',lintel)'╝' ; _lob=tranGC(_lob)
_sid='║' --- the next line says: 44th move, position=9,2 marked with an "h" ---; _sid=tranGC(_sid)
select
when y==1 |y==ht then do x=1 for LB; call place x+LB-1,y,pointsubstr(_bot,x,1); end
when y==LB|y==TBht then do x=1 for ht; if x>LB & x<TB then iterate; call place x+LB-1,y,pointsubstr(_top,x,1); end
when y>==LB & y<TB then do x=1 byfor ht-1; if forx>LB & x<TB then 2iterate; call place x,y,pointsubstr(_lob,x,1); end
otherwise when y==TB then do x=1 for ht; doif x=>LB by& x<TB-LB forthen 2iterate; call place x,y,pointsubstr(_hib,x,1); end
when y>LB & y<TB then do x=1 by ht-1 for 2; call place x,y,_sid; end
otherwise do x=LB by TB-LB for 2; call place x,y,_sid; end
end /*select*/
end /*y*/
Line 385 ⟶ 394:
return
/*─────────────────────────────────────DISPLAY subroutine───────────────*/
display: call t; do y=hiY to loY by -1; aLine_=indent /*start at a high Y.*/
do x=loX to hiX /*build an "X" line.*/
aLine_=aLine_||@.x.y
end /*x*/
call t aLine_ /*...and display it.*/
end /*y*/
 
if wins\==0 then call t rightcopies('count of (above) wins =' wins,79,'═')
else call t right('count of (above) wins =' wins,79,'═')
call t
return
/*─────────────────────────────────────PLACE subroutine─────────────────*/
Line 422 ⟶ 433:
return 0
end
call t '"move'" turn left' ('',9) xx'",'"yy left('',9) with "'pointChar'"'
wins=wins+newWins; @.xx.yy=pointChar; call display; turn=turn+1
return 1
Line 466 ⟶ 477:
do y=yy-1 by -1; x=x+1; if @.x.y==empty then leave; z=z||@.x.y; end
return eureka+countAline(z) /*───────count diag wins: up&<, down&> */</lang>
'''output''' when running 1,000500 trials, the highest win was a meager 4443 (three games, all different), and
one of them is shown below.
<pre style="height:95ex;overflow:scroll">
···☼☼☼☼╔══╗···
········
········
╔══╝··╚══╗
☼☼☼☼··☼☼☼☼
········
········
╚══╗··╔══╝
☼☼☼☼··☼☼☼☼
········
········
···☼☼☼☼··· ... previous 43 moves elided ... above is the initial board (grid) ...···╚══╝···
═══════════════════════════════════════════════════════════════════════════════
--- the next line says: 44th move, position=9,2 marked with an "h" ---
move 44 9,2 h
 
move 1 (3,3) with "0"
·············
... previous 42 moves elided ... above is the initial board (grid) ...
······X······
--- the next line means: 43rd move, position=2,8 marked with an "g" ---
····☼☼☼☼F····
move 43 (2,8) with "g"
····☼TZ☼I····
 
·C·1☼gR☼3WD··
·············
·☼☼☼☼57☼☼☼☼··
····╔══╗F····
·☼aeAfMBHN☼··
····║S·║·····
·☼·Q8GK9Sb☼··
·Cg1║OK║3·Dc·
·☼☼☼☼46☼☼☼☼O·
·╔══╝57╚══╗W·
···0☼UJ☼2·V··
·║aeAN·BQP║U·
···c☼YL☼·h···
·║f·8HG9IV║T·
····☼☼☼☼E····
·╚══╗46╔══╝Z·
····P··d·····
···0║·M║2RJ··
·············
····║YX║Ld···
═════════════════════════════════════════════════════count of (above) wins = 44
····╚══╝E····
* number of wins = 44
······X·b·····
·············
═════════════════════════════════════════════════════count of (above) wins = 4443
 
* number of wins = 4443
</pre>