Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. #
  3. # wireworld
  4.  
  5. mapfile -t input
  6.  
  7. # 00000000000000000000000000000000000000000
  8. # 00000000000000000000000000000000000000000
  9. # 00000000000321333320000000000000000000000
  10. # 00000000003000000001333330000000000000000
  11. # 00000000000333333330000003000000000000000
  12. # 00000000000000000000000033330000000000000
  13. # 00000000000000000000000030033333000000000
  14. # 00000000000000000000000033330000000000000
  15. # 00000000000321333330000001000000000000000
  16. # 00000000003000000003333320000000000000000
  17. # 00000000000331233330000000000000000000000
  18. # 00000000000000000000000000000000000000000
  19. # 00000000000000000000000000000000000000000
  20.  
  21. declare -A uni cpy
  22.  
  23. # store world
  24. X=${#input[@]}
  25. Y=${#input[0]}
  26.  
  27. for ((i = 0; i < X; i++)) {
  28. for ((j = 0; j < Y; j++)) {
  29. uni[$i $j]=${input[i]:j:1}
  30. }
  31. }
  32.  
  33. # enable sleep builtin
  34. enable -f /usr/lib/bash/sleep sleep
  35.  
  36. # \e[2J : clear screen
  37. # \e[?25l : hide cursor
  38. # \e[?25h : show cursor
  39. printf '\e[2J\e[?25l'
  40. trap $'printf \e[?25h' EXIT
  41.  
  42. for ((;;)) {
  43. out='\e[H'
  44.  
  45. for ((i = 0; i < X; i++)) {
  46. for ((j = 0; j < Y; j++)) {
  47. c=0
  48.  
  49. case ${uni[$i $j]} in
  50. 1) out+='\e[44m \e[m'; cpy[$i $j]=2;;
  51. 2) out+='\e[41m \e[m'; cpy[$i $j]=3;;
  52. 3) out+='\e[43m \e[m'
  53.  
  54. for a in -1 0 1; {
  55. for b in -1 0 1; {
  56. ((a || b)) && {
  57. ((
  58. x = i + a, x = x < 0 ? X - 1 : x % X,
  59. y = j + b, y = y < 0 ? Y - 1 : y % Y
  60. ))
  61.  
  62. ((uni[$x $y] == 1 && c++))
  63. }
  64. }
  65. }
  66.  
  67. ((c && c < 3)) && cpy[$i $j]=1
  68. ;;
  69. 0) out+='\e[40m \e[m'
  70. esac
  71. }
  72.  
  73. out+='\n'
  74. }
  75.  
  76. printf '%b' "$out"
  77.  
  78. for i in "${!cpy[@]}"; {
  79. uni[$i]=${cpy[$i]}
  80. }
  81.  
  82. sleep .2
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement