# fb7f7bf4324b7c9273750313cc6349967cd217380394a869c4adbbf0746d00e8 Elan 1.2.0 guest default_profile valid

# REDO on basis that the computer player will be added using 'append' with small mods to your code 
main
  variable x1 set to 10
  variable y1 set to 7
  variable dir1 set to "d"
  let grid be new Array2D<of Int>(40, 30, white)
  for i from 1 to 1000 step 1
    call displayBlocks(grid)
    call pause(500)
  end for
end main

procedure move(out x as Int, out y as Int, out dir as String)
  let k be getKey()
  if (k isnt "") and (directions.contains(k)) then
    set dir to k
  end if
  if dir is "d" then
    set x to x + 1
  else if dir is "s" then
    set y to y + 1
  else if dir is "a" then
    set x to x - 1
  else if dir is "w" then
    set y to y - 1
  end if
end procedure

constant directions set to "wasd"

procedure compTurn(out dir as String)
  let i be directions.indexOf(dir)
  let rnd be randomInt(-1, 1)
  let i2 be (i + rnd) mod 4
  set dir to directions[i2]
end procedure

function newDirection(current as String, rnd as Float) returns String
  variable i set to directions.indexOf(current)
  if rnd > 0.5 then
    set i to (i + 1) mod 3
  else
    set i to (i - 1) mod 3
  end if
  return directions[i]
end function

test newDirection

end test
