The game of Risk

Henko
Posts: 882
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

The game of Risk

Post by Henko » Sun Oct 21, 2018 6:59 pm

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 am programming 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 (which may become a help screen in a further version), 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.

I kind of copied the world map from the EA game, using transparant paper and the Apple pen stylus. Acquiring the (about) 250 x,y coordinates was really a matter of minutes. Programming the world map was the easiest part of the game. I guess that other phantasy maps can be realized easily as well. All topological and all other quantitative data are kept in a data file RISK_DATA, which is read by the program.

As in the official games, the current map consists of 42 states in 6 continents.
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 player number for the human player is chosen at random (1 though 6) by the game.

The game starts, showing the AI players attacking each others and possibly your states. When a new color is shown and there is no action, it's your color and your turn.

Risk is a turn based game. Each player turn consists of 3 phases: draft, attack, and fortify. The current phase is shown on the screen. The human player progresses to the next phase by touching the most right button with the big arrow on it.
744BB01B-E801-4556-ADD8-859BE3AEDCF5.png
744BB01B-E801-4556-ADD8-859BE3AEDCF5.png (346.94 KiB) Viewed 1585 times
Draft phase:
Each state produces his own new armies, anywhere from 0.2 to 0.9 new army per turn. Those amounts depend on the economical power of each state, and are kept in the data file. For instance, the state of Alaska has a growth rate of 0.2 army/turn, but west- and east-US have 0.9 each (Rbytes: Alberta/Canada is the 4th country in the game, i say no more). Above this you get at leat 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 produces 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 ennemy neighbour states.
2F3EF25F-CF33-4924-849B-FB6BC681A8C9.png
2F3EF25F-CF33-4924-849B-FB6BC681A8C9.png (344.19 KiB) Viewed 1585 times
Attack phase:
When attacking a state, The odds for victory are dependent on the quotient between the number of attacking armies and the number of defensive armies. All available armies in both states are participating in the battle. However, the amount of defensive armies is augmented by a multiplier, which can be as high as 3.
States that remain occupied by the same player for a longer period, build up defensive strength. Slowly in the first turns after capture, then faster, until the strenth factor reaches a value of 10. When attacked by an ennemy, the strength factor of 1 - 10 is converted into a multiplier factor of 1 - 3. The defensive number of armies is multiplied with this factor, but only for the calculation of the odds.
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. 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 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.

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 quality 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.

Follows the program file and the data file. The data file is named RISK_DATA and must reside in the same directory as the program, unless you add a path in the program.

Code: Select all

init_risk()

do
  init_round()
  for cp.nr=1 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

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 ! button "cards" text .cards(p)
do
  if .cards(p)>4 then
    cp.draft+=10 ! .cards(p)=max(0,.cards(p)-3)
    end if
  until .cards(p)<5
end def

def human_play(p)
'
'*****      draft phase
'
if cp.draft then
  button "cont" show ! button "cards" 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("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")
  group2(0) ! field "draft" hide
  end if
'
'*****      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 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 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
      .state(lnd,2)=p ! draw_state(lnd,p) ! .state(lnd,4)=0
      state_count() ! .cards(p)+=check_dead(.state(lnd,2))
      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 floor(.state(lna,3))
  button lnd text 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 ! button "cards" text .cards(p) ! c_flag=0
  end if
'
'*****.       Move phase
'
group3(0) ! group2(1) ! maxmove=0
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("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
end def

def exit_player()
end def

def exit_round()
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 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 bp(a$) = button_pressed(a$)

def cp() ! end def


' {risk_lib}


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 assign()
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()
  for j=1 to 13
    k=2+rnd(7) ! .state(cp.play(k),3)+=1
    next j
  next cp.nr
for i=1 to 42 ! button i text .state(i,3) ! next i
refresh on
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$="Armies"
  else ! k=3 ! n$="Strength"
  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 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 init_risk()
set toolbar off ! option base 1 ! randomize
set orientation landscape
graphics ! graphics clear .7,.7,.7 ! draw color 0,0,0
f$="risk_data" ! file f$ 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)
refresh off
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
for i=1 to .ns
  file f$ input .state(i,1) ! .state(i,1)/=10
  .state(i,4)=0
  next i
for i=1 to 6
  .ai(i,1)=3+rnd(3) ! .ai(i,2)=.5+0.2*rnd(1) ! .ai(i,3)=1+rnd(4)
  next i
set buttons font size 70
button "cont" text chr$(10145) at 840,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 "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
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 ! 
group1(0) ! group2(0) ! group3(0)
assign()   ' assign states and armies to players
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  0  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  26  27  0 
 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

User avatar
GeorgeMcGinn
Posts: 495
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Location: Venice, FL
Flag: United States of America
Contact:

Re: The game of Risk

Post by GeorgeMcGinn » Mon Oct 22, 2018 12:58 am

I love this game. But question – where is the quit button?
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)
https://www.georgemcginn.com
https://www.cosmologyandspace.blog

Henko
Posts: 882
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: The game of Risk

Post by Henko » Mon Oct 22, 2018 6:48 am

There is no quit button yet. For now i use the Apple home button.
The game needs some "polishing", such as:
- most important: different difficulty levels, for which the mechanisms are already present
- speed control while AI players have their turn
- some visibility aspects
- on board Help info
- and last and of least importance: a quit button :lol:

I will play a lot with this version of Risk first to get clear ideas about those adaptations.

User avatar
GeorgeMcGinn
Posts: 495
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Location: Venice, FL
Flag: United States of America
Contact:

Re: The game of Risk

Post by GeorgeMcGinn » Mon Oct 22, 2018 2:10 pm

I'll try the Apple home button.

I spent most of the night playing just two games, one I won, the other I lost. I quit (restarting SB) because most of the time I went last, and only had two countries left.

I played this game (and Stratego) almost every day growing up, so I'm excited about your game. However, I do have a few suggestions that might help, depending on the coding efforts:

— I forget the number of armies we started with, but before the game started, we placed, depending on what country cards we got, as few or as many armies as we needed. For example, if I got Mexico, that country was a choke point between North or South America. I may want to place 10 armies (or more) there. Same if I got one of the Australian sections. Is there a way to allow us, based on our strategy of play, to load countries of our choice with more armies then the game does?

— I tried to switch from Armies to Strength, but Armies all show up as zeroes. Is this a bug in the code? The way it works is when the game first starts it shows army and numbers in each country. When I press the armies button to see the strength it actually goes from armies two armies and everything shows up as zero. Then went straight shows up I see numbers that look like army numbers, and then when I hit the army to strengthen button again to go back to armies, every country shows a zero.

— if I recall from the regular game, if you hold a continent you got extra armies, I believe that you got an extra army for every country in the continent. I don't recall seeing that happening in this game. Is this one of the items that you need to tinker?

— is there anyway for us to see the cards that we get after we win a battle? I know in a regular game that when I play my cards I get extra armies for every card that has a country that I occupy. Is this the same logic that you are applying behind the scenes?

I think the speed of the AI is actually perfect. I can clearly see the moves that each player is making, and that is an important part of my playing strategy to see what each player is trying to do, such as taking over a continent or to move into one or blocking another player from doing the same.

As I said before, I really love this game, it was one of my favorite games growing up, and although I did not purchase the official version on the App Store, I am very grateful to you for taking the time to create this game for us.

This is a Nother example of the power of smart basic, which in my opinion, I cannot believe that Mr. K would allow this product to just whither and die.

Henko wrote:
Mon Oct 22, 2018 6:48 am
There is no quit button yet. For now i use the Apple home button.
The game needs some "polishing", such as:
- most important: different difficulty levels, for which the mechanisms are already present
- speed control while AI players have their turn
- some visibility aspects
- on board Help info
- and last and of least importance: a quit button :lol:

I will play a lot with this version of Risk first to get clear ideas about those adaptations.
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)
https://www.georgemcginn.com
https://www.cosmologyandspace.blog

User avatar
GeorgeMcGinn
Posts: 495
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Location: Venice, FL
Flag: United States of America
Contact:

Re: The game of Risk

Post by GeorgeMcGinn » Mon Oct 22, 2018 2:29 pm

I had one other thought about the way you have structured the way the game is played.

I understand adding defense of strength overtime when you occupy a country/state for a number of turns is an interesting addition to the game. However, because when I hit the army button and everything turns to zeros, I don't know if that really changes the number of armies or just the strength of each army.

Back to my thought, if I recall, what I read was if I win a battle you move only 1/3 of the armies into the new country or state that I one. In the real game I'm allowed to move as many armies as I wish into the new country. This is so that if I wanted to take over an entire continent my army is large enough to move from state to state until I take it all, providing the number of armies that I have is sufficient to beat everyone in the content.

Is there a way for you to allow a player to move after victory, as many armies into the new country? Just being able to do this alone is a strategy that use when you have enough armies to make a run on a number of states.

Let me know if that something that is possible. I'm not sure how you would apply that to the AI players, but they should be able to have that option as well. Maybe certain states are worth moving in most or all of your armies such as Mexico/central America is one of those chokepoints that everybody Half to get through to move from one continent to the other. So maybe you can assign certain states as being more important than others, and then let the AI do with a player would do it, and that is moved more than 1/3 of their army into that new state.

Thanks again for writing and taking the time to create such a wonderful game. I think this is by far your best work and I know as you make changes as you take ideas and add your own to him that this game will be your own version of Risk with the features that make the game a different game but one that is very playable.
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)
https://www.georgemcginn.com
https://www.cosmologyandspace.blog

Henko
Posts: 882
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: The game of Risk

Post by Henko » Mon Oct 22, 2018 4:53 pm

Hello George,
Good to hear that i have a companion at playing the game of Risk.
Indeed there are some minor flaws in the code. I will fix them asap.
Before i run through your comments/suggestions, i forgot a save/load functionality on my todo list, but it will only be saving the current game.

One win and one loss is a perfect balance for any game ;) . A game may last long, because on defeat, the winning player cannot move as many armies into the defeated state as he likes. Only one third is automatically moved into the concurred state. It is deliberately done that way to avoid the situation that an attacking army of say 20 armies takes 10 states one after another in one turn. The amount of automatically moved armies might be one of the parameters that constutes a future difficulty level in the game.

The states and the distribution of armies is currently randomly done by the program. Indeed the EA version of Risk offers the possibiliry of a manual setup. I have never liked that possiblity, because it can have a big impact on the start of the game. Moreover, it seems a lot of coding to me.

The toggle switch armies <=> strength is wrongly initialized. I will code it in such a way that the button indicates what is actually shown in the state buttons. Initially that will be the number of armies.
The documentation states wrongly that the defence strength factors start at a value of one. This must be zero. That's why all states show a zero defence strength. Each turn, the defence factor of each state is augmented according to the formula:
New value = 0.9 x old value + 1
This means that near zero the defence factor grows about linearly with the number of turns, but the grow rate diminues and stabilizes at 10.
The conversion of this defense factor into the multiplier factor is such that the multiplier makes a S-curve between 1 and 3.
If a state is taken by an attacker, it is assumed that all defensive infrastructure has been destroyed, hence the defense strength factor is reset to zero, and the new ruler can begin to build gradually a new defense infrastructure.

The amount of new armies available at draft fase consists of 3 components, as in the usual Risk versions. However, there are two differences:
- the base amount of 0.5 army per state in possesion, is not available for arbitrary placement. In my version they start their live in the state where they are produced. To soften this pain, the player recieves 1 army as basis for free placement.
- The second amount is the well known bonus for possessing an entire continent. They have the same size as in the other versions, 5,2,5,3,7,2 for NA,SA,EU,AF,AS,AU respectively. May be you did not notice, but the mechanism works ok
- The third component, the cards, work different. The mechanism works ok, now and then you must notice an amount of new armies greater than 10. In my version, there is only one kind of card. As in other games, one card is given if at least one state is taken during a turn. Currently, cards are assebled until 5 cards. Then 3 of them are converted in 10 armies. This works ok. It is possible that the "cards" button is not updated everywhere where is should. I will check that.

Yes, the power (functionality) and speed of SB is ashtonishing for an interpreter.
Mr. K. has made a masterpiece, and Apple be cursed tenfold for blocking further updates of SB. For me, SB will never die. I bought an extra iPad and will freeze the old one on iOS 10.3.3, retaining SB and the EA version of Risk.

User avatar
GeorgeMcGinn
Posts: 495
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Location: Venice, FL
Flag: United States of America
Contact:

Re: The game of Risk

Post by GeorgeMcGinn » Mon Oct 22, 2018 8:45 pm

Thanks for your explanation on the issues that I haven't had pointed out. But probably will always be in disagreement on the initial placement of armies. I remember as a child playing this game and part of the strategy was to make sure that if you had a good choke point or you had three or four states in a row that forms a wall, you were allowed to build him up with in the army stew for tech them from someone breaking through.

In order for me to keep that from happening, I need to place my arm is there when I get home use for the beginning of my next turn. It takes a little more work but that's the game tonight so that's the rules that I will have to work around.

Also I noticed one thing today as I won my first game that I did not get my "winner winner, chicken dinner!" The game actually continues to play where there is no one left to five (see the image below as it shows my turn, with a number of armies to place, but no one left to fight).

Again, I thank you for your efforts as this version of rest will be a challenge to learn to play and win.

IMG_0565.PNG
IMG_0565.PNG (713.98 KiB) Viewed 1565 times
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)
https://www.georgemcginn.com
https://www.cosmologyandspace.blog

User avatar
rbytes
Posts: 1963
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone X
iPad 4
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: The game of Risk

Post by rbytes » Tue Oct 23, 2018 4:59 am

An impressive creation, Henk. I don't have the same history of playing Risk that you and George have, but I will give it a shot to learn how. I will need to print off a help sheet for now, but look forward to a help page in a future version.
Zzzzz

Henko
Posts: 882
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: The game of Risk

Post by Henko » Tue Oct 23, 2018 6:17 am

I will add the clasic way of initial army placement on my to-do list. I don't like that method, as it gives kind of a false start to the human player. But by using a variable "classic", the user then will have a choice out of the two methods.
But first i will care for the little flaws in the current version.
One of those flaws is that a total victory is not detected and the player is not jubilated at :D :lol:
When playing the EA version of the game, i never end it. As soon as i see that the final victory is 100% sure, i hit the home button.
But you are right, there should be a "normal" end to the game, when it goes public on the forum.



GeorgeMcGinn wrote:
Mon Oct 22, 2018 8:45 pm
Thanks for your explanation on the issues that I haven't had pointed out. But probably will always be in disagreement on the initial placement of armies. I remember as a child playing this game and part of the strategy was to make sure that if you had a good choke point or you had three or four states in a row that forms a wall, you were allowed to build him up with in the army stew for tech them from someone breaking through.

In order for me to keep that from happening, I need to place my arm is there when I get home use for the beginning of my next turn. It takes a little more work but that's the game tonight so that's the rules that I will have to work around.

Also I noticed one thing today as I won my first game that I did not get my "winner winner, chicken dinner!" The game actually continues to play where there is no one left to five (see the image below as it shows my turn, with a number of armies to place, but no one left to fight).

Again, I thank you for your efforts as this version of rest will be a challenge to learn to play and win.


IMG_0565.PNG

User avatar
Dutchman
Posts: 907
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: The game of Risk

Post by Dutchman » Tue Oct 23, 2018 8:22 am

Nice piece of work. :!:
I myself am not a game fan, but as soon as the final version comes into sight I will find out if I may also become addicted. :D
We consider it a refreshing mental exercise to figure out ways to circumvent foolishness (Quote from Richard)

Post Reply