Since the first version, the following facilities have been added to the game:
- a startup screen with option choices
- initial placement of armies at random or by the human player (classic)
- possibility to save the actual game and resume it later on
- in-game helpfile in a scrolling window
- some internal refinements and removal of some flaws
As the helpfile has been modified, two files must be copied, the code file and a data file.
The data file is named "risk_data" and must reside in the same directory as the program.
The code file:
Code: Select all
' Game of Risk version 11-06-2018
' by Henko
init_risk()
do
init_round()
for cp.nr=st_pl to 6
init_player()
if cp.play(1)=0 then continue
if cp.nr=human then human_play(human) else ai_play()
exit_player()
next cp.nr
exit_round()
until stop
end
'y'
' defining the attacking characteristics of the AI players
' ai(-,1) : the max. number of attacked states during one turn
' ai(-,2) : the minumum odds level needed for an attack decision
' ai(-,3) : the number of remaining armies where to stop an attack
'
def AI_values()
for i=1 to 6
.ai(i,1)=2+rnd(4) ! .ai(i,2)=.4+0.3*rnd(1) ! .ai(i,3)=3+rnd(3)
next i
end def
''
def init_round()
if .sflag then k=4 else k=3
for i=1 to .ns
.state(i,3)+=.state(i,1)
button i text floor(.state(i,k))
next i
end def
def init_player()
p=cp.nr ! cp.ncp=state_count()
cp.draft=1+cont_count()
field "play" back color .col(p,1),.col(p,2),.col(p,3)
button "cards" show ! bc(p)
do
if .cards(p)>4 then
cp.draft+=10 ! .cards(p)=max(0,.cards(p)-3) ! bc(p)
end if
until .cards(p)<5
end def
def exit_player()
end def
def exit_round()
.st_pl=1
for i=1 to .ns ! .state(i,4)=.9*.state(i,4)+1 ! next i
if bp("strength") then disp_strength()
end def
def attack(na,nd,f)
f=2-cos(0.3142*f) ! nd*=f
q=na/(na+nd) ! q=min(.8,q) ! q=max(.2,q)
if rnd(1)<q then return 1 else return -1
end def
def check_dead(r)
dead=1
for i=1 to .ns
if .state(i,2)=r then ! dead=0 ! break ! end if
next i
if dead then return .cards(r) else return 0
end def
def f_fld(ff$,c$)
if c$="g" then ! field ff$ back color 0,1,0
else ! field ff$ back color 1,0,0
end if
field ff$ font name "MarkerFelt-Thin"
field ff$ font size 30
end def
def sign_state(s,c)
'for i=1 to 5
draw_state(s,7) ! pause .1
draw_state(s,c) ! pause .1
' next i
button s text max(1,int(.state(s,3)))
end def
def sign_fight(i,ind)
if ind>0 then
if ind=1 then t$=chr$(9732) else t$=chr$(57629)
button i text t$
else ! button i text floor(.state(i,3))
end if
end def
def bc(p) ' update cards button
button "cards" text .cards(p)
pause .5
end def
def close_risk()
f$= "risk_save"
if file_exists(f$) then file f$ delete
file f$ print .human,.diff_level
for i=1 to .ns ! for j=1 to 4
file f$ print .state(i,j)
next j ! next i
for i=1 to 6 ! for j=1 to 3
file f$ print .ai(i,j)
next j ! next i
for i=1 to 6 ! file f$ print .cards(i) ! next i
stop
end def
def bp(a$) = button_pressed(a$)
def cp() ! end def
' {risk_lib}
def human_play(p)
'
'***** draft phase
'
if cp.draft then drafty(p)
'
'***** attack phase
'
field "attack" show ! group3(1)
lna=0 ! lnd=0 ! sp_flag=0 ! s_flag=0 ! c_flag=0
state_count()
do slowdown
if bp("rhelp") then fhelp()
if lna>0 then ! button "att" text floor(.state(lna,3))
else ! button "att" text ""
end if
if lnd>0 then ! button "def" text floor(.state(lnd,3))
else ! button "def" text ""
end if
if bp("strength") then disp_strength()
k=0
for i=1 to .ns ' check state buttons
if bp(str$(i)) then ! k=i ! break! end if
next i
if k then ' check self or foreign
e=0
for i=2 to cp.play(1)+1
if k=cp.play(i) then ! e=1 ! break ! end if
next i
if lna=0 and lnd=0 and e=1 then
lna=k ! sign_fight(lna,1) ! goto done
end if
if lna>0 then
nb=0 ' check neighbour state or not
for j=1 to 6
if .link(lna,j)=k then nb=1
next j
if k=lnd then
sign_fight(lnd,-2) ! lnd=0 ! goto done
end if
if k=lna then
if lnd>0 then ! sign_fight(lnd,-2) ! lnd=0 ! end if
lna=0 ! sign_fight(k,-1) ! goto done
end if
if e=1 and k<>lna then
sign_fight(lna,-1) ! lna=k ! sign_fight(lna,1)
if lnd>0 then ! sign_fight(lnd,-2) ! lnd=0 ! end if
goto done
end if
if nb=1 and e=0 then
if lnd>0 then sign_fight(lnd,-2)
lnd=k ! sign_fight(lnd,2)
end if
end if
end if
done:
if lnd=0 then nxt else quit=0
do ' start attack cycles on this combi
if bp("stop") then
if s_flag=0 then
s_flag=1 ! quit=0 ! button "stop" text "Stop"
else
quit=1 ! button "stop" text "Start" ! continue
end if
end if
if s_flag=0 then ! slowdown ! continue ! end if
if bp("speed") then
sp_flag=1-sp_flag
if sp_flag then ! button ("speed") text "Fast"
else ! button ("speed") text "Slow"
end if
end if
if sp_flag=0 then pause 1 else pause .3
if bp("pause") then
button ("pause") text "Go on"
do ! slowdown ! until bp("pause")
button ("pause") text "Pause"
end if
r=attack(.state(lna,3), .state(lnd,3),.state(lnd,4))
if r=1 then
.state(lnd,3)-=1 ! button "def" text floor(.state(lnd,3))
button "ddef" text "-1" ! button "datt" text ""
button lnd text floor(.state(lnd,3))
else
.state(lna,3)-=1 ! button "att" text floor(.state(lna,3))
button "datt" text "-1" ! button "ddef" text ""
button lna text max(1,floor(.state(lna,3)))
end if
if floor(.state(lnd,3))=0 then ' victory
da=max(1,floor(.state(lna,3)/3)) ! beep
.state(lnd,3)=da ! .state(lna,3)-=da
defen=.state(lnd,2) ! .state(lnd,2)=p
draw_state(lnd,p) ! .state(lnd,4)=0 ! state_count()
dc=check_dead(defen)
if dc then ! .cards(p)+=dc ! bc(p) ! end if
c_flag=1 ! quit=1
end if
if floor(.state(lna,3))=1 then quit=1 ' end of fight
until quit
button "att" text "" ! button "datt" text ""
button "def" text "" ! button "ddef" text ""
button lna text max(1,floor(.state(lna,3)))
button lnd text max(1,floor(.state(lnd,3)))
button "stop" text "Start" ! button "speed" text "Slow"
lna=0 ! lnd=0 ! s_flag=0 ! sp_flag=0
nxt:
until bp("cont")
if c_flag=1 then
.cards(p)+=1 ! bc(p) ! c_flag=0
end if
'
'*****. Move phase
'
group3(0) ! group2(1) ! maxmove=0 ! button "close" show
for i=1 to .ns
if .state(i,2)=p then maxmove+=.state(i,1)
next i
maxmove=int(2*maxmove) ! button "maxtr" text maxmove
field "attack" hide ! field "move" show
lna=0 ! lnb=0 ! ntr=0 ! button "troops" text "0"
do slowdown
if bp("close") then close_risk()
if bp("rhelp") then fhelp()
if bp("strength") then disp_strength()
k=0
for i=1 to .ns ' check state buttons
if bp(str$(i)) then ! k=i ! break! end if
next i
if k=0 then m_label1
e=0
for i=2 to cp.play(1)+1
if k=cp.play(i) then ! e=1 ! break ! end if
next i
if e=0 then continue
if k=lna then
sign_fight(lna,-1) ! lna=0
if lnb>0 then ! sign_fight(lnb,-2) ! lnb=0 ! end if
continue
end if
if k=lnb then ! sign_fight(lnb,-2) ! lnb=0 ! continue ! end if
if lna=0 then ! lna=k ! sign_fight(lna,1) ! continue ! end if
if lnb=0 then
nb=0 ' check neighbour state or not
for j=1 to 6 ! if .link(lna,j)=k then nb=1 ! next j
if nb=0 then continue
lnb=k ! sign_fight(lnb,2)
end if
m_label1:
if lna=0 or lnb=0 then nxt1
lnr=floor(.state(lna,3)) ! if lnr<2 then continue
if bp("less") then
if ntr=0 then ntr=min(lnr-1,maxmove) else ntr-=1
button "troops" text ntr
end if
if bp("more") then
if ntr=maxmove then ntr=0 else ntr=min(lnr-1,ntr+1)
button "troops" text ntr
end if
if bp("okee") then
.state(lna,3)-=ntr ! button lna text floor(.state(lna,3))
.state(lnb,3)+=ntr ! button lnb text floor(.state(lnb,3))
maxmove-=ntr ! ntr=0 ! lna=0 ! lnb=0
button "troops" text "0" ! button "maxtr" text maxmove
end if
nxt1:
until bp("cont")
field "move" hide ! button "close" hide
end def
def drafty(p)
button "cont" show ! group2(1)
button "strength" show ! field "draft" show
button "troops" text "0" ! button "maxtr" text cp.draft
lnr=0 ! ntr=0
do slowdown
if bp("rhelp") then fhelp()
if bp("strength") then disp_strength()
if bp("less") and lnr>0 then
if ntr=0 then ntr=cp.draft else ntr-=1
button "troops" text ntr
end if
if bp("more") and lnr>0 then
if ntr=cp.draft then ntr=0 else ntr+=1
button "troops" text ntr
end if
if bp("okee") and lnr>0 then
.state(lnr,3)+=ntr ! cp.draft-=ntr ! ntr=0
button lnr text floor(.state(lnr,3))
button "troops" text "0" ! button "maxtr" text cp.draft
end if
for i=1 to .ns
if bp(str$(i)) and .state(i,2)=p then
if i=lnr then lnr=0 else lnr=i
end if
next i
until bp("cont") and cp.draft=0
group2(0) ! field "draft" hide
end def
def ai_play()
'
'***** draft phase
p=cp.nr ! field "draft" show
nc=.cards(p) ! ns=cp.play(1)
button "cards" show ! button "cards" text nc ! pause .3
if nc>=3 then
cp.draft+=2*nc+floor(nc/5)-1
.cards(p)-=3
end if
if cp.draft >=1 then
for i=1 to cp.draft
k=(i-1)%ns+2 ! st=cp.play(k) ! .state(st,3)+=1
button st text int(.state(st,3))
next i
cp.draft=0
end if
pause .5 ! field "draft" hide
'
'****** attack phase
dim tab_in(99,3),tab(99,3)
max_attacks=.ai(p,1) ! field "attack" show
start_odds=.ai(p,2) ! stop_odds=.ai(p,3)
won_flag=0 ! ntab=0
for i=2 to ns+1
lnr=cp.play(i) ! n_att=.state(lnr,3)
for j=1 to 6
buur=.link(lnr,j)
if buur=0 or .state(buur,2)=p then continue
n_def=.state(buur,3)
ntab+=1 ! tab_in(ntab,1)=lnr ! tab_in(ntab,2)=buur
tab_in(ntab,3)=n_att/max(n_def,1)
next j
next i
tablesort(ntab,3,tab_in,tab,3)
for i=1 to min(max_attacks,ntab)
if touch_x(0)>-1 then stop
nla=tab(i,1) ! nld=tab(i,2)
d=.state(nld,2) ! if d=p then continue
do
n_att=.state(nla,3) ! n_def=.state(nld,3)
odds=n_att/max(n_def,1)
if odds<start_odds or n_att<=stop_odds then break
v=attack(n_att,n_def,.state(nld,4))
if v=1 then ! won_flag=1 ! .state(nld,3)-=1
else ! .state(nla,3)-=1
end if
sign_state(nla,p) ! sign_state(nld,d)
if .state(nld,3)<1 then
.state(nld,2)=p ! .state(nld,4)=0
dl=max(1,floor(.state(nla,3)/3))
.state(nla,3)-=dl ! .state(nld,3)=dl
sign_state(nla,p) ! sign_state(nld,p)
.cards(p)+=check_dead(d)
break
end if
until forever
next i
if won_flag then
.cards(p)+=1 ! button "cards" text .cards(p) ! pause .3
end if
field "attack" hide
'
'***** move phase
ns=state_count() ! field "move" show
for i=2 to ns+1
dim buren(6)
buur_flag=0 ! bsum=0 ! k=0
lnr=cp.play(i) ! n_c=.state(lnr,3)
for j=1 to 6
b=.link(lnr,j)
if b=0 then break
if .state(b,2)<>p then ! buur_flag=1
else ! k+=1 ! buren(k)=b ! bsum+=.state(b,3)
end if
next j
if k=0 then continue
nb=k ! mu=(n_c+bsum)/(nb+1)
if buur_flag=0 then ! pot=n_c-1
else
if n_c>mu then pot=n_c-mu else pot=0
end if
if pot>0 then ! .state(lnr,3)-=pot ! dp=pot/nb ! end if
for j=1 to nb ! .state(buren(j),3)+=dp ! next j
next i
for i=1 to .ns ! button i text floor(.state(i,3)) ! next i
pause .5 ! field "move" hide
end def
def assign1()
dim t(42)
for i=1 to 42 ! t(i)=i ! .state(i,3)=1 ! next i
for i=1 to 7 ! for s=1 to 6
do ! r=1+rnd(42) ! k=t(r) ! until k
.state(k,2)=s ! t(r)=0 ! draw_state(k,s)
next s ! next i
for cp.nr=1 to .npl
state_count()
if .classic and cp.nr=.human then
cp.draft=13 ! p=.human ! init_round()
field "play" back color .col(p,1),.col(p,2),.col(p,3)
drafty(p)
else
for j=1 to 13
k=2+rnd(7) ! .state(cp.play(k),3)+=1
next j
end if
next cp.nr
for i=1 to 42 ! button i text .state(i,3) ! next i
end def
def assign2()
for k=1 to 42
draw_state(k,.state(k,2))
button k text .state(k,3)
next k
end def
def draw_state(k,c)
dim x(11),y(11)
n=.surf(k,1)
fill color .col(c,1),.col(c,2),.col(c,3)
for i=1 to n
p=.surf(k,i+1)
x(i)=.node(p,1) ! y(i)=.node(p,2)
next i
fill poly x,y count n ! draw poly x,y count n
end def
def state_count()
p=cp.nr ! k=1 ! cp.na=0
for i=1 to .ns
if .state(i,2)<>p then continue
k+=1 ! cp.play(k)=i ! cp.na+=.state(i,3)
next i
cp.play(1)=k-1 ! return k-1
end def
def cont_count()
dim check(6) ! bonus=0
for i=2 to cp.ncp+1
for k=1 to 6
if cp.play(i)<=.cont(k,2) then
check(k)+=1 ! break
end if
next k
next i
for i=1 to 6
if check(i)=.cont(i,4) then bonus+=.cont(i,3)
next i
return bonus
end def
def disp_strength()
.sflag=1-.sflag
if .sflag then ! k=4 ! n$="Strength"
else ! k=3 ! n$="Armies"
end if
button("strength") text n$
for i=1 to .ns ! button i text floor(.state(i,k)) ! next i
a=human_play.lna ! if a and k=3 then sign_fight(a,1)
d=human_play.lnd ! if d and k=3 then sign_fight(d,2)
end def
def fhelp()
page "help" alpha 0 ! page "help" show
for i=0 to 1 step .05
page "help" alpha i ! pause .05
next i
do slowdown ! until bp("hback") or bp("rhelp")
for i=1 to 0 step -.05
page "help" alpha i ! pause .05
next i
page "help" hide
end def
def group1(on)
if on then
field "draft" show ! field "attack" show ! field "move" show
else
field "draft" hide ! field "attack" hide ! field "move" hide
end if
end def
def group2(on)
if on then
button "less" show ! button "more" show ! button "okee" show
button "troops" show ! button "maxtr" show
else
button "less" hide ! button "more" hide ! button "okee" hide
button "troops" hide ! button "maxtr" hide
end if
end def
def group3(on)
if on then
button "datt" show ! button "att" show
button "ddef" show ! button "def" show
button "speed" show ! button "pause" show ! button "stop" show
else
button "datt" hide ! button "att" hide
button "ddef" hide ! button "def" hide
button "speed" hide ! button "pause" hide ! button "stop" hide
end if
end def
def win_welcome(hn$,xo,yo,w,h,t)
p=.human
draw size t
draw color 0,0,0 ! fill color .8,.8,.8
fill rect xo,yo to xo+w,yo+h ! draw rect xo,yo to xo+w,yo+h
draw line xo,yo+50 to xo+w,yo+50
t$="Resume game or start a new game : new"
field "w0" text t$ at xo+20,yo+70 size 660,50 RO! wf("w0")
switch "w9" state 1 at xo+550,yo+80
if p=1 then b$=p&"st" ! if p=2 then b$=p&"nd" ! if p>2 then b$=p&"th"
t$="You are the "&b$&" player, color :"
field "w1" text t$ at xo+20,yo+150 size 470,50 RO ! wf("w1")
field "w2" text "" at xo+530,yo+160 size 80,30 RO
field "w2" back color .col(p,1),.col(p,2),.col(p,3)
t$="Choose difficulty level : (set to easy for now)"
field "w3" text t$ at xo+20,yo+250 size 680,50 RO ! wf("w3")
t$="Random army placement or by player: player"
field "w7" text t$ at xo+20,yo+350 size 700,50 RO ! wf("w7")
switch "w8" state 0 at xo+550,yo+360
field "wtitle" text "The game of Risk" at xo+180,yo+10 size 320,33 RO
field "wtitle" back color .8,.8,.8
field "wtitle" font color 0,0,0
field "wtitle" font name "Courier-Bold"
field "wtitle" font size 30
fill color .7,.7,1
button "wback" text "Start" at xo+w-100,yo+10 size 92,33
fill color .8,.8,.8
.resume=0 ! .classic=0 ! .diff_level=1
end def
def init_risk()
set toolbar off ! option base 1 ! randomize
set orientation landscape
graphics ! graphics clear .7,.7,.7 ! draw color 0,0,0
file "risk_data" input .np,.ns,.nc ! .npl=6
dim .node(.np,2),.surf(.ns,12),.cont(.nc,4),.state(.ns,4)
dim .col(7,3),.cent(.ns,2),lines(4),.link(.ns,6),cp.play(44)
dim .cards(.npl),.ai(6,3)
.human=1+rnd(6) ! .st_pl=1
for i=1 to 6 ! for j=1 to 3 ! read .col(i,j) ! next j ! next i
data 1,0,0, 0,1,0, 0,0,1, 1,1,0, 1,0,1, 0,1,1
win_welcome("come",130,140,750,450,3)
do slowdown
if switch_changed("w9") then
if switch_state("w9")=0 then
if file_exists("risk_save")=0 then
switch "w9" state 1 ! continue
end if
read_save() ! .st_pl=1+.human%6
else ! .human=1+rnd(6) ! .st_pl=1
end if
p=.human
if p=1 then b$=p&"st" ! if p=2 then b$=p&"nd" ! if p>2 then b$=p&"th"
field "w1" text "You are the "&b$&" player, color :"
field "w2" text "" at 660,300 size 80,30 RO
field "w2" back color .col(p,1),.col(p,2),.col(p,3)
end if
until bp("wback")
graphics clear .7,.7,.7
.resume=1-switch_state("w9")
.classic=switch_state("w8") ! .diff_level=1
button "wback" delete ! field "wtitle" delete
field "w0" delete
field "w1" delete ! field "w2" delete ! field "w3" delete
field "w7" delete ! switch "w8" delete ! switch "w9" delete
read_data()
if .resume=0 then AI_values()
set buttons font size 70
button "cont" text chr$(10145) at 830,685 size 70,70
draw size 3 ! draw rect 695,605 to 805,755
field "draft" text " Draft" at 700,610 size 100,40 RO
f_fld("draft","g") ! 'field "draft" hide
field "attack" text " Attack" at 700,660 size 100,40 RO
f_fld("attack","r") ! 'field "attack" hide
field "move" text " Move" at 700,710 size 100,40 RO
f_fld("move","g") ! 'field "move" hide
field "play" text "Player" at 40,450 size 100,80
field "play" font name "MarkerFelt-Thin"
field "play" font size 30
sx=320 ! sy=645 ! sz=50
set buttons custom ! set buttons font size sz
button "close" text chr$(10060) at 960,10 size sz,sz
button "less" text chr$(57915) at sx,sy size sz,sz
button "more" text chr$(57914) at sx+2.5*sz+20,sy size sz,sz
button "okee" text chr$(9989) at sx+2.5*sz+20,sy+sz+10 size sz,sz
set buttons font name "Georgia-Bold" ! set buttons font size 30
fill color .7,.7,1
button "troops" text "" at sx+sz+10,sy size 1.5*sz,sz
button "maxtr" text "" at sx+sz+10,sy+sz+10 size 1.5*sz,sz
button "cards" text "" at 580,705 size sz,sz
button "rhelp" text "Help" at 920,705 size 90,50
sx=10 ! sy=705 ! bw=75 ! bh=50
set buttons font name "MarkerFelt-Thin"
fill color .5,.5,.5
button "speed" text "Slow" at sx,sy size bw,bh
button "pause" text "Pause" at sx+bw+10,sy size bw,bh
button "stop" text "Start" at sx+2*bw+20,sy size bw,bh
button "strength" text "Armies" at 360,570 size 120,50
sx=10 ! sy=585
fill color .7,.7,1
set buttons font name "Georgia-Bold"
button "att" text "" at sx,sy+bh+10 size bw,bh
button "datt" text "" at sx,sy size bw,bh
button "def" text "" at sx+bw+10,sy+bh+10 size bw,bh
button "ddef" text "" at sx+bw+10,sy size bw,bh
draw font size 20 ! draw text "Cards" at 575,685
button "cont" hide ! button "cards" hide
button "strength" hide ! button "close" hide
group1(0) ! group2(0) ! group3(0)
win_help("help",240,50,680,650,3)
if .resume=0 then assign1() else assign2()
end def
def read_data()
f$="risk_data"
for i=1 to 6 ! for j=1 to 3
file f$ input .col(i,j)
next j ! next i
for j=1 to 3 ! .col(7,j)=1 ! next j
for i=1 to .np
file f$ input .node(i,1),.node(i,2)
next i
for i=1 to .ns
file f$ input .surf(i,1)
for j=2 to .surf(i,1)+1
file f$ input .surf(i,j)
next j
file f$ input .cent(i,1),.cent(i,2)
button i text i at .cent(i,1),.cent(i,2) size 28,28
next i
for i=1 to 6
for j=1 to 3 ! file f$ input .cont(i,j) ! next j
.cont(i,4)=.cont(i,2)-.cont(i,1)+1
next i
draw dash 2
for i=1 to 26
file f$ input k,lines(1),lines(2),lines(3),lines(4)
draw line lines(1),lines(2) to lines(3),lines(4)
next i
draw dash 0
for i=1 to .ns
for j=1 to 6 ! file f$ input .link(i,j) ! next j
next i
if .resume=0 then
for i=1 to .ns
file f$ input .state(i,1) ! .state(i,1)/=10
.state(i,4)=0
next i
end if
file f$ input nhelp
dim .ah$(nhelp)
for i=1 to nhelp ! file f$ input .ah$(i) ! next i
end def
def win_help(hn$,xo,yo,w,h,t)
t2=2*t ! t4=4*t
page hn$ set
page hn$ frame xo,yo, w,h
page hn$ color .8,.8,.8,1
set buttons custom ! set buttons font size 22
draw color 0,0,0 ! fill color .8,.8,.8
button "h1" text "" at -t2,0 size w+t4,3
button "h2" text "" at 0,-t2 size t,h+t4
button "h3" text "" at -t2,h-t size w+t4,t
button "h4" text "" at w-t,-t2 size t,h+t4
button "h5" text "" at -t2,48 size w+t4,t
field "htitle" text "Game of Risk help" at 90,10 size 320,33 RO
field "htitle" back color .8,.8,.8
field "htitle" font color 0,0,0
field "htitle" font name "Courier-Bold"
field "htitle" font size 30
button "hback" text "Return" at w-100,10 size 92,33
set lists custom
set lists font size 20 ! draw color 0,0,1
list hn$ text .ah$ at 7,52 size w-10,h-56
draw color 0,0,0
page hn$ hide
end def
def read_save()
f$= "risk_save" ! file f$ reset
file f$ input .human,.diff_level
for i=1 to .ns ! for j=1 to 4
file f$ input .state(i,j)
next j ! next i
for i=1 to 6 ! for j=1 to 3
file f$ input .ai(i,j)
next j ! next i
for i=1 to 6 ! file f$ input .cards(i) ! next i
end def
def wf(fn$)
field fn$ back color .8,.8,.8
field fn$ font color 0,0,1
field fn$ font name "Courier-Bold"
field fn$ font size 24
end def
' table sorting function (option base 1 assumed)
' r = number of rows
' c = number of columns
' in(,) = table to be sorted
' out(,) = sorted table
' onc = column to be used for sorting
'
def tablesort (r,c,in(,),out(,),onc)
option sort descending
dim sortcol(r),index(r)
for i=1 to r ! sortcol(i)=in(i,onc) ! next i
sort sortcol as index
for i=1 to r ! for j=1 to c
out(i,j)=in(index(i),j)
next j ! next i
return
end def
Code: Select all
172 42 6
1
0
0
0
1
0
0
0
1
1
1
0
1
0
1
0
1
1
52 100
46 179
77 163
102 164
124 197
126 158
110 100
170 101
211 124
247 87
279 114
240 160
209 158
270 198
300 156
343 206
315 248
268 239
230 225
203 224
141 225
133 301
187 311
204 334
247 323
258 345
273 341
233 390
287 391
329 415
254 447
228 415
216 430
206 462
254 504
249 630
274 676
293 677
287 633
336 554
316 537
398 458
356 43
415 60
413 121
368 149
354 186
323 114
305 90
451 132
475 166
452 189
427 179
421 159
419 193
405 197
388 272
414 269
416 288
460 270
406 368
441 381
460 345
416 330
442 329
428 300
467 280
486 297
485 331
499 364
515 333
537 369
558 358
572 314
557 279
543 226
499 229
532 214
537 176
557 189
573 118
537 108
481 190
677 114
685 232
635 247
647 329
600 346
593 377
592 400
521 395
495 380
439 397
420 455
451 506
509 517
557 487
559 449
507 425
599 440
657 501
615 576
596 525
583 568
525 558
546 680
591 661
630 648
646 658
679 594
665 581
635 606
655 475
689 432
660 411
699 403
689 350
729 331
801 381
787 404
750 487
820 466
852 407
881 365
867 314
795 302
784 241
759 246
742 279
704 103
760 63
820 71
812 160
849 159
902 88
992 116
950 166
942 204
922 167
898 177
881 231
899 265
935 227
958 223
970 289
918 337
897 319
934 279
780 497
821 520
846 484
856 519
879 515
853 565
813 566
769 508
888 471
943 487
960 529
912 525
879 485
960 550
989 617
967 675
934 677
936 613
900 613
898 555
833 595
841 668
903 646
850 455
7
1
2
3
4
5
6
7
72 120
8
6
7
8
9
10
11
12
13
154 116
7
43
44
45
46
47
48
49
355 82
5
5
6
13
20
21
158 176
6
12
13
20
19
18
14
224 181
5
14
15
16
17
18
295 189
5
19
20
21
22
23
162 244
8
17
18
19
23
24
25
26
27
238 266
5
22
23
24
28
32
176 330
6
28
29
30
31
33
32
254 403
5
31
33
34
35
41
229 452
5
30
31
41
40
42
320 457
7
35
36
37
38
39
40
41
276 565
5
50
51
52
53
54
433 148
6
55
56
57
58
59
60
406 229
9
61
62
63
69
68
67
66
65
64
420 338
8
68
69
70
71
72
73
74
75
529 303
5
67
68
75
76
77
508 248
6
78
79
80
81
82
83
532 136
10
74
75
76
80
81
84
85
86
87
88
607 182
9
91
92
93
94
95
96
97
98
99
468 437
5
90
91
99
98
100
552 407
7
97
98
100
101
102
104
103
602 477
5
97
96
105
104
103
544 515
5
102
104
105
106
107
553 591
5
108
109
110
111
112
636 602
11
73
89
90
113
114
115
116
117
87
88
74
628 368
6
85
86
87
117
118
129
679 275
5
84
85
129
128
130
705 201
6
127
128
130
131
132
133
755 113
4
132
133
134
135
840 96
9
134
135
136
137
138
139
140
142
141
904 116
4
127
133
134
141
822 188
5
125
126
127
141
142
823 255
6
143
144
145
146
147
148
937 269
9
118
119
123
124
125
126
127
128
129
811 332
6
116
117
118
119
120
121
732 378
5
119
120
122
172
123
812 407
8
149
150
151
152
153
154
155
156
819 525
5
157
158
159
160
161
913 490
7
165
166
167
168
169
170
171
858 607
7
162
163
164
165
166
167
168
924 568
1
9
5
10
13
2
14
20
5
21
26
3
27
38
7
39
42
2
1 45 168 15 168
2 951 173 1015 169
3 328 116 276 124
4 326 116 252 176
5 327 119 306 166
6 402 458 422 462
7 396 136 427 157
8 453 197 437 218
9 458 190 490 200
10 434 220 488 201
11 433 221 488 258
12 496 203 485 255
13 441 281 441 299
14 542 375 558 400
15 650 477 660 498
16 626 552 640 606
17 601 620 631 612
18 906 243 935 276
19 884 292 937 277
20 829 463 838 494
21 851 497 895 501
22 858 546 882 564
23 902 507 879 565
24 912 525 911 548
25 442 382 450 400
26 499 364 495 380
2 4 32 0 0 0
1 3 4 5 0 0
2 5 6 14 0 0
1 2 5 7 0 0
2 3 4 6 7 8
3 5 8 0 0 0
4 5 8 9 0 0
5 6 7 9 0 0
7 8 10 0 0 0
9 11 12 0 0 0
10 12 13 0 0 0
10 11 13 21 0 0
11 12 0 0 0 0
3 15 19 0 0 0
14 16 18 19 0 0
15 17 18 21 0 0
16 18 20 21 22 27
15 16 17 19 20 0
14 15 18 20 0 0
17 18 19 27 28 29
12 16 17 22 23 24
17 21 23 27 0 0
21 22 24 25 26 27
21 23 25 0 0 0
23 24 26 0 0 0
23 25 0 0 0 0
17 20 22 23 28 37
20 27 29 36 37 0
20 28 30 36 0 0
29 31 33 36 0 0
30 32 33 0 0 0
1 31 33 34 35 0
30 31 32 34 0 0
32 33 35 36 0 0
32 34 0 0 0 0
28 29 30 34 37 38
27 28 36 38 0 0
36 37 39 0 0 0
38 40 41 0 0 0
39 41 42 0 0 0
39 40 42 0 0 0
40 41 0 0 0 0
3
2
1
5
5
4
9
9
7
4
4
6
6
3
6
6
3
7
3
7
4
5
4
4
9
4
9
5
4
3
3
3
3
4
9
8
5
4
5
2
6
7
201
"The game of Risk
"
"
"
"I play the game of Risk on the iPad quite a lot. Currently "
"there are many Risk like games in the App store. I have a "
"nice version from EA (Electronic Arts), but it is "
"discontinued and does not run under iOS 12 on my new iPad. "
"Hence i programmed my own version now in SB. That also gives "
"the possibility to improve some mechanisms that i considered "
"to be less favourable.
"
"
"
"In this little document, the characteristics of the game are "
"described only as far as they differ from the generally used "
"gamerules. If you never played Risk and want to give this "
"one a try, you are advised to first learn about the game in "
"Wikipedia.
"
"
"
"What's different, compared to the usual game rules.
"
"
"
"The battle order.
"
"This version does not use dices to establish a battle "
"result.
"
"A battle consists of a number of turns. Each turn one army "
"is wasted, be it from the attacker or from the defender. The "
"result is based on a random selection, with the odds "
"calculated as the quotient between the atackers strength and "
"the defenders strenght. The attackers strength is simply the "
"total number of armies in his state. The defenders strength "
"is a virtual number of armies, calculated as the product of "
"the actual number of armies and a defence strength factor.
"
"It is assumed that a state builds defence infrastructure "
"during each year that it is owned by the same player. This "
"results in a defence multiplier that starts with value 1, "
"grows slow in the early years, and stabilizes at a maximum "
"value of 3.
"
"Army losses at the defenders side are deducted from the real "
"number of armies.
"
"After each battle turn, the odds are calculated again for "
"the next turn.
"
"If the last army of the defender is lost, the state is taken "
"over by the new owner. All defence infrastructure is assumed "
"to be destroyed in the battle, hence the defence strength is "
"set back to a value of 1.
"
"One other difference is that only 1/3 of the remaining "
"attacking armies are automatically moved into the taken "
"state. Attacking other states with this occupation force is "
"allowed, but taking many states like 10 or more in one turn "
"by the same army is no longer possible.
"
"
"
"Economic strength.
"
"Each state has an economic strength factor which reflects "
"the importance of the region in the real world. The strength "
"factors range from 0.1 (for Greenland) to 0,9 (west- and "
"east US, for instance).
"
"At the start of each game turn, each state produces an "
"amount of new armies equal to it's economical strenght. "
"Those newly enlisted armies cannot be placed at will by the "
"player, but start off in the state where they are produced. "
"The player gets bonus armies for continents and for victory "
"cards with a minimum of one army. Thos armies can be placed "
"freely.
"
"The total economic strength of all states of a player is "
"also used to calculate the maximum number of move units "
"during the fortify phase. One move unit is a move of one "
"army from one state to a neighbour state.
"
"
"
"Victory cards.
"
"Like in most Risk games, the player gets a card when his "
"attack phase is concluded with at least one state takeover. "
"In this version of Risk, all cards are the same. If at the "
"start of the draft phase the number of cards is 5 or more, "
"sets of 3 cards are converted into 10 armies until the "
"number of cards is less than 5. As usual, when a player "
"looses his last state, his cards are transferred to the "
"player who took that last state.
"
"
"
"Playing the game.
"
"
"
"Startup screen.
"
"The game starts displaying a startup screen. The upper "
"switch is in the position 'new game'. If a saved game exist, "
"it can be resumed by switching the switch. In both cases the "
"second line on the screen tells the human player his number "
"and color in the game. There is one human player and 5 AI "
"(Artificial Intelligence) players at the start of the game, "
"hence 6 in total, every player having his own color.
"
"The third line is for future use and is meant to choose a "
"difficulty level. The actual level of the AI players is "
"about medium.
"
"The fourth line has a switch wich can be used to select the "
"method of initial placement of 13 armies. The classic way "
"leaves the placement to the player, the alternative is to "
"let it be done at random by the game. Choosing to place the "
"armies yourself means a serious decrease in difficulty "
"level, as you probably can secure a 'strong point' "
"(continent) from which to expand further.
"
"After hitting the 'start' button the game starts.
"
"
"
"A game round.
"
"Unless you have player number 1 (with color red), the AI "
"players take their rounds, placing an army somewhere, "
"attacking other players, and moving armies in the fortify "
"phase of their turn. At some point, the animations stop and "
"the 'Play' button shows your color. It's your turn.
"
"
"
"Draft phase:
"
"You get at least 1 army per turn, augmented with additional "
"armies if you occupy one or more entire continents, or if "
"victory cards are converted into armies. Those extra armies "
"may be assigned freely to your states.
"
"To assign one or more armies to one of your states, first "
"select a state by touching the button in the state, then use "
"the arrow buttons in the middle of the screen to augment or "
"to decrease the shown amount of armies. The counter is a "
"closed loop: decreasing under zero produces the maximum "
"number available, augmenting a maximum gives zero on the "
"counter. When satisfied, touch the ok button. If nothing "
"happens, you might not have made a proper selection. When a "
"selected state is selected again, it is deselected.
"
"You may select states and assign armies to them as long as "
"the available number is non-zero. You must touch the "
"progress button at the right side to switch to the attack "
"phase.
"
"The AI players follow the same rules and have the same "
"quantity rights as the human player, but they assign the "
"additional armies in a dumb way. They don't look at the "
"situation of enemy neighbour states.
"
"
"
"Attack phase:
"
"When attacking a state, all available armies in both states "
"are participating in the battle. As told before, for the "
"calculation of the odds, the amount of defensive armies is "
"augmented by a multiplier, which can be as high as 3.
"
"Based on the calculated odds, a series of successive rounds "
"is performed, each round causing the loss of one army, "
"either from the attacker, or from the defender. The "
"attacker, be it human or AI can follow the battle progress "
"and can abort the battle if the result so far is not looking "
"good. Before attacking you see the number of armies in each "
"state. With a toggle button 'Strength' you may have a peek "
"at the defence strength of each state; the multiplier factor "
"has a value of 1/3 or less of the shown values.
"
"If you decide to attack a state (which must be a neighbour "
"state), first select your state with wich to attack, then "
"select the ennemy state to be attacked. The selection can be "
"undone or changed by selecting already selected states "
"again.
"
"When done, touch the start button.
"
"You can follow the result of each attack and the number of "
"remaining armies for atacker and the defender. The speed of "
"the battle can be set to slow or fast with the 'slow/fast' "
"toggle button (default is 'slow'). Only the attacker can "
"decide to abort the battle using the start/stop toggle "
"button.
"
"If the battle results in defeat of the attacked state, the "
"state turns to the new owner, and 1/3 of the remaining "
"attacking armies flow into the taken state. The attacker "
"gets a victory card for the current turn if he had not so "
"far. The defence strength of the taken state is set to 0 "
"(which generates a multiplier value of 1).
"
"If the attacker takes the last state of another player, all "
"victory cards of the defeated player are transferred to the "
"victorious player.
"
"You can terminate this phase by touching the button on the "
"right side to switch to the fortify phase.
"
"AI players first will construct a table containing all their "
"states and the quotient of the number of attacking armies "
"and the number of defending armies of each of the neighbour "
"states. They ignore the defence strength of the defending "
"states (otherwise they become too intelligent for this fixed "
"AI level). Then the list with attacking options is sorted in "
"order of decreasing odds. They then perform a number of "
"battles of the top of the list.
"
"At initialization time, each of the AI players have been "
"assigned random values of the number of states they are "
"allowed to attack per turn, the level of odds needed to "
"start an attack, and a criterion when a battle will be "
"aborted. In this way, very different characters of AI "
"players may occur. This initialization is done within a "
"specific function for that purpose, displayed in yellow in "
"the beginning of the code. You can play with that to create "
"your own AI players.
"
"
"
"Fortify phase:
"
"In this phase, armies may be moved from states to neighbour "
"states. You get a maximum number of army movements allotted, "
"depending on the number and economic strength of your "
"states. Within this maximum you can make many moves.
"
"The proces of moving is the same as that of attacking, be it "
"that the secondly selected state is now one of your own "
"(neighbour) states. The plus and minus buttons work the "
"same, and the remaining quantity of allowable army movements "
"is visible. A selected move is effectuated by touching the "
"ok button.
"
"AI players have no limitation on army moves. They don't take "
"the situation of other player's armies in consideration. "
"They try to balance the amount of armies over their states, "
"with one exception: they will radiate out armies from states "
"that are surrounded solely by friendly states.
"
"In the fortify phase, the game may be quitted using the red "
"'X' button in the right upper corner. The game is then saved "
"and may be resumed at a later time."