# Variable initialisation file.
# This file is read by wims for new sessions (cmd=new or cmd=renew)

# style maybe vector, generate, hmatrix, vmatrix, system, or random.
!default style=random
!default range_a=5
!default range_x=5
!default x=2
!default y=2
!default f=1
!default rel=0

!if $difficulty!=$empty and $difficulty>0
 difficulty=$[rint($difficulty)]
 !if $difficulty>9
  difficulty=9
 !endif
 x=!word   $difficulty of 2 3 2 3 3 4 3 4 5
 y=!word   $difficulty of 2 2 2 2 3 3 3 3 4
 f=!word   $difficulty of 1 1 1 2 1 2 2 3 3
 rel=!word $difficulty of 0 0 1 1 0 1 1 1 1
!endif

!if $style=random
 istyle=!randitem vector,vector,hmatrix,vmatrix,system,system,generate,generate
!else
 !if , isin $style
  istyle=!randitem $style
 !else
  istyle=$style
 !endif
!endif

!if $y<2
 y=2
!endif

!if $x<$y
 x=$y
!endif

!if $f>$x-1
 f=$[$x-1]
!endif

!if $f<1
 f=1
!endif

reply_cnt=0

r0=w/o
r1=with

wims_module_log=$cmd: $style $(x)x$y, $f vacancies $(r$rel) relation

!for j=1 to $y
 a$j=!randint -$range_a,$range_a-1
 !if $(a$j)>=0
  a$j=$[$(a$j)+1]
 !endif
!next j

!for i=1 to $x
 :rerow
 !for j=1 to $y
  b$j=!randint -$range_x,$range_x
#  !if $(b$j)>=0
#   b$j=$[$(b$j)+1]
#  !endif
 !next j
 row$j=
 t=0
 !for j=1 to $y
  m$i$j=!eval $(a$[1+($j+2*$y-2)%$y])*($(b$j))-($(a$[1+$j%$y]))*($(b$[1+$j%$y]))
  t=$[$t+abs($(m$i$j))]
 !next j
 !if $t<=0
  !goto rerow
 !endif
!next i

t=!shuffle $x
!for i=1 to $f
 s=!randint 1,$y
 k=!item $i of $t
 m$k$s=c$i
 pos$i=$k$s
!next i

matrix=
!for j=1 to $y
 row$j=
 !for i=1 to $x
  row$j=!append item $(m$i$j) to $(row$j)
 !next i
 matrix=!append line $(row$j) to $matrix
!next j

status=waiting
difficulty=
