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


