Morpion solitaire: Difference between revisions
Content added Content deleted
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: | Line 310: | ||
gS=gS/1 |
gS=gS/1 |
||
if gS<3 then call err "grid size is too small:" gS |
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='fa'x /*the empty grid point symbol. */ |
||
@.=empty /*field (grid) is infinite. */ |
@.=empty /*field (grid) is infinite. */ |
||
gC= /*GreeK cross character or null. */ |
|||
CBLF=player\=='' /*carbon-based lifeform ? */ |
CBLF=player\=='' /*carbon-based lifeform ? */ |
||
if CBLF then oFID=player /*oFID is used for the game log. */ |
if CBLF then oFID=player /*oFID is used for the game log. */ |
||
Line 360: | Line 362: | ||
t: say arg(1); call lineout oFID,arg(1); return |
t: say arg(1); call lineout oFID,arg(1); return |
||
Gshot: Gshots=Gshots arg(1)','arg(2); 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 subroutine────────────*/ |
||
GreekCross: wins=0; loX=1e85; hiX=0; |
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) |
|||
⚫ | |||
select |
select |
||
when y==1 |
when y==1 then do x=1 for LB; call place x+LB-1,y,substr(_bot,x,1); end |
||
when y== |
when y==ht then do x=1 for LB; call place x+LB-1,y,substr(_top,x,1); end |
||
when y |
when y==LB then do x=1 for ht; if x>LB & x<TB then iterate; call place x,y,substr(_lob,x,1); end |
||
when y==TB then do x=1 for ht; if x>LB & x<TB then iterate; call place x,y,substr(_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 /*select*/ |
||
end /*y*/ |
end /*y*/ |
||
Line 385: | Line 394: | ||
return |
return |
||
/*─────────────────────────────────────DISPLAY subroutine───────────────*/ |
/*─────────────────────────────────────DISPLAY subroutine───────────────*/ |
||
display: call t; do y=hiY to loY by -1; |
display: call t; do y=hiY to loY by -1; _=indent /*start at a high Y.*/ |
||
do x=loX to hiX /*build an "X" line.*/ |
do x=loX to hiX /*build an "X" line.*/ |
||
_=_||@.x.y |
|||
end /*x*/ |
end /*x*/ |
||
call t |
call t _ /*...and display it.*/ |
||
end /*y*/ |
end /*y*/ |
||
if wins |
if wins==0 then call t copies('═',79) |
||
else call t right('count of (above) wins =' wins,79,'═') |
|||
call t |
|||
return |
return |
||
/*─────────────────────────────────────PLACE subroutine─────────────────*/ |
/*─────────────────────────────────────PLACE subroutine─────────────────*/ |
||
Line 422: | Line 433: | ||
return 0 |
return 0 |
||
end |
end |
||
call t |
call t "move" turn ' ('xx","yy') with "'pointChar'"' |
||
wins=wins+newWins; @.xx.yy=pointChar; call display; turn=turn+1 |
wins=wins+newWins; @.xx.yy=pointChar; call display; turn=turn+1 |
||
return 1 |
return 1 |
||
Line 466: | Line 477: | ||
do y=yy-1 by -1; x=x+1; if @.x.y==empty then leave; z=z||@.x.y; end |
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> |
return eureka+countAline(z) /*───────count diag wins: up&<, down&> */</lang> |
||
'''output''' when running |
'''output''' when running 500 trials, the highest win was a meager 43 (three games, all different), and |
||
one of them is shown below. |
one of them is shown below. |
||
<pre style="height:95ex;overflow:scroll"> |
<pre style="height:95ex;overflow:scroll"> |
||
··· |
···╔══╗··· |
||
··· |
···║··║··· |
||
··· |
···║··║··· |
||
╔══╝··╚══╗ |
|||
☼☼☼☼··☼☼☼☼ |
|||
║········║ |
|||
║········║ |
|||
╚══╗··╔══╝ |
|||
☼☼☼☼··☼☼☼☼ |
|||
··· |
···║··║··· |
||
··· |
···║··║··· |
||
···╚══╝··· |
|||
═══════════════════════════════════════════════════════════════════════════════ |
|||
⚫ | |||
move 44 9,2 h |
|||
move 1 (3,3) with "0" |
|||
⚫ | |||
... previous 42 moves elided ... above is the initial board (grid) ... |
|||
⚫ | |||
--- 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··· |
|||
⚫ | |||
····╚══╝E···· |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
</pre> |
</pre> |