├── golden.txt ├── map_stat.rb ├── maps ├── world-1.map ├── world-2.map ├── world-classic.map ├── 32x32.map ├── 32x32_empty.map ├── 48x48.map ├── 64x64.map └── 200x200.map ├── local.rb ├── sample.ghc ├── parse_first_map.rb ├── down.rb ├── pack.sh ├── test_sim.sh ├── test.rb ├── Makefile ├── gen_map.rb ├── gen_lman_inst.rb ├── gen_ghost_inst.rb ├── lman.rb ├── README ├── lman_inst.rb ├── ghost.rb ├── solution ├── ghost0.ghc ├── ghost1.ghc ├── ghost2.ghc └── ghost3.ghc ├── akabei.rb ├── dsl.rb ├── ai.rb ├── sim.go └── ld.gcc /golden.txt: -------------------------------------------------------------------------------- 1 | Score: 1360 Lives: 2 Ticks: 20102 2 | Score: 1320 Lives: 3 Ticks: 18992 3 | Score: 2000 Lives: 3 Ticks: 46535 4 | -------------------------------------------------------------------------------- /map_stat.rb: -------------------------------------------------------------------------------- 1 | c = $<.read.gsub("\n", '') 2 | 3 | puts "total: #{c.size}" 4 | puts "wall: #{c.count('#')} #{c.count('#') * 100 / c.size}%" 5 | puts "pill: #{c.count('.')} #{c.count('.') * 100 / c.size}%" 6 | 7 | -------------------------------------------------------------------------------- /maps/world-1.map: -------------------------------------------------------------------------------- 1 | ############## 2 | #o....%......# 3 | #.#.######.#.# 4 | #.#...##...#.# 5 | #.#.#====#.#.# 6 | #...######...# 7 | ###.#..\.#.### 8 | #...#.##.#...# 9 | #.#...##...#.# 10 | #.###.##.###.# 11 | #.....##....o# 12 | ############## 13 | 14 | -------------------------------------------------------------------------------- /local.rb: -------------------------------------------------------------------------------- 1 | require './lman' 2 | 3 | class Lman 4 | def gen 5 | ldc(21) 6 | ldf(:body) 7 | ap(1) 8 | rtn() 9 | label(:body) 10 | ld(0, 0) 11 | ld(0, 0) 12 | add() 13 | rtn() 14 | 15 | emit 16 | end 17 | end 18 | 19 | L.gen 20 | -------------------------------------------------------------------------------- /sample.ghc: -------------------------------------------------------------------------------- 1 | mov a,255 2 | mov b,0 3 | mov c,255 4 | inc c 5 | jgt 7,[c],a 6 | mov a,[c] 7 | mov b,c 8 | jlt 3,c,3 9 | mov a,b 10 | mov d,a 11 | int 0 12 | 13 | int 3 14 | int 6 15 | inc [b] 16 | ;mov e,[0] 17 | ;mov f,[1] 18 | ;mov g,[2] 19 | ;mov h,[3] 20 | ;int 8 21 | hlt 22 | -------------------------------------------------------------------------------- /maps/world-2.map: -------------------------------------------------------------------------------- 1 | ############### 2 | #\...........o# 3 | #.###.###.###.# 4 | #.# #.# #.# #.# 5 | #.###.###.###.# 6 | #.............# 7 | #.###.###.###.# 8 | #.# #.# #.# #.# 9 | #.###.###.###.# 10 | #.............# 11 | #.###.###=###.# 12 | #.# #.# #.# #.# 13 | #.###.###.###.# 14 | #o.....%.....=# 15 | ############### 16 | -------------------------------------------------------------------------------- /parse_first_map.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | $<.each do |line| 4 | if line =~ /^map\[(.*)\]$/ 5 | tot = 0 6 | $1.split.map{|a| 7 | x, y = a.split(':') 8 | [y.to_i, x.to_i] 9 | }.sort.each do |cnt, pc| 10 | tot += cnt 11 | puts "#{pc}: #{cnt}" 12 | end 13 | 14 | p tot 15 | 16 | break 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /down.rb: -------------------------------------------------------------------------------- 1 | require './lman' 2 | 3 | class Lman 4 | def gen 5 | dum(2) 6 | ldc(2) 7 | ldf(:step) 8 | ldf(:init) 9 | rap(2) 10 | rtn() 11 | 12 | label(:init) 13 | ldc(42) 14 | ld(0, 1) 15 | cons() 16 | rtn() 17 | 18 | label(:step) 19 | ld(0, 0) 20 | ldc(1) 21 | add() 22 | ld(1, 0) 23 | cons() 24 | rtn() 25 | 26 | emit 27 | end 28 | end 29 | 30 | L.gen 31 | -------------------------------------------------------------------------------- /pack.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | make 4 | 5 | rm -fr shinh 6 | 7 | mkdir -p shinh/solution 8 | cp lambdaman.gcc shinh/solution 9 | cp akabei.ghc shinh/solution/ghost0.ghc 10 | cp pinky3.ghc shinh/solution/ghost1.ghc 11 | cp pinky2.ghc shinh/solution/ghost2.ghc 12 | cp pinky1.ghc shinh/solution/ghost3.ghc 13 | 14 | cd shinh 15 | svn export $SVN/icfpc/2014 code 16 | chmod 755 code/ai.rb 17 | 18 | cd .. 19 | tar -cvzf shinh-icfpc2014.tgz shinh 20 | sha1sum shinh-icfpc2014.tgz 21 | -------------------------------------------------------------------------------- /test_sim.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | go run sim.go maps/world-1.map ld.gcc sample.ghc > logs/1.log 4 | go run sim.go maps/world-2.map ld.gcc sample.ghc > logs/2.log 5 | go run sim.go maps/world-classic.map ld.gcc sample.ghc > logs/classic.log 6 | 7 | grep Lives logs/1.log | tail -1 > actual.txt 8 | grep Lives logs/2.log | tail -1 >> actual.txt 9 | grep Lives logs/classic.log | tail -1 >> actual.txt 10 | 11 | if diff golden.txt actual.txt; then 12 | echo 'PASS' 13 | else 14 | echo 'FAIL' 15 | fi 16 | -------------------------------------------------------------------------------- /maps/world-classic.map: -------------------------------------------------------------------------------- 1 | ####################### 2 | #..........#..........# 3 | #.###.####.#.####.###.# 4 | #o###.####.#.####.###o# 5 | #.....................# 6 | #.###.#.#######.#.###.# 7 | #.....#....#....#.....# 8 | #####.#### # ####.##### 9 | # #.# = #.# # 10 | #####.# ### ### #.##### 11 | # . # === # . # 12 | #####.# ####### #.##### 13 | # #.# % #.# # 14 | #####.# ####### #.##### 15 | #..........#..........# 16 | #.###.####.#.####.###.# 17 | #o..#......\......#..o# 18 | ###.#.#.#######.#.#.### 19 | #.....#....#....#.....# 20 | #.########.#.########.# 21 | #.....................# 22 | ####################### 23 | 24 | -------------------------------------------------------------------------------- /test.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | system("make") 4 | 5 | ['sample', 'akabei', 'red', 'prod'].each do |g| 6 | #['akabei', 'red', 'prod'].each do |g| 7 | ['world-1', 'world-2', 'world-classic'].each do |m| 8 | if g == 'prod' 9 | ghc = 'akabei.ghc pinky1.ghc pinky2.ghc pinky3.ghc' 10 | elsif g == 'red' 11 | ghc = 'akabei.ghc pinky3.ghc pinky1.ghc akabei.ghc' 12 | else 13 | ghc = "#{g}.ghc" 14 | end 15 | name = "#{m}-#{g}" 16 | log = "logs/#{name}.log" 17 | if !system("go run sim.go maps/#{m}.map lambdaman.gcc #{ghc} > #{log}") 18 | raise 19 | end 20 | 21 | result = `grep Lives #{log} | tail -1` 22 | puts "#{name} #{result}" 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | GHCS := akabei.ghc pinky1.ghc pinky2.ghc pinky3.ghc 2 | 3 | all: lman_inst.rb ghost_inst.rb lambdaman.gcc $(GHCS) 4 | 5 | lambdaman.gcc: ai.rb lman_inst.rb dsl.rb lman.rb 6 | ruby $< > $@.tmp && mv $@.tmp $@ 7 | 8 | akabei.ghc: akabei.rb ghost_inst.rb ghost.rb 9 | ruby $< > $@.tmp && mv $@.tmp $@ 10 | 11 | pinky1.ghc: akabei.rb ghost_inst.rb ghost.rb 12 | ruby $< 1 > $@.tmp && mv $@.tmp $@ 13 | 14 | pinky2.ghc: akabei.rb ghost_inst.rb ghost.rb 15 | ruby $< 2 > $@.tmp && mv $@.tmp $@ 16 | 17 | pinky3.ghc: akabei.rb ghost_inst.rb ghost.rb 18 | ruby $< 3 > $@.tmp && mv $@.tmp $@ 19 | 20 | lman_inst.rb: gen_lman_inst.rb 21 | ruby $< > $@.tmp && mv $@.tmp $@ 22 | 23 | ghost_inst.rb: gen_ghost_inst.rb 24 | ruby $< > $@.tmp && mv $@.tmp $@ 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /gen_map.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | #W = 32 4 | #H = 32 5 | W = 256 6 | H = 256 7 | EMPTY = '.' 8 | 9 | map = [] 10 | 11 | H.times{|y| 12 | r = '' 13 | W.times{|x| 14 | c = '#' 15 | if x == 0 || y == 0 || x == W - 1 || y == H - 1 16 | c = '#' 17 | elsif x % 2 == 1 || y % 2 == 1 18 | c = EMPTY 19 | end 20 | r += c 21 | } 22 | map << r 23 | } 24 | 25 | map[1][1] = '%' 26 | map[W-83][H-83] = '\\' 27 | map[H / 2 - 1][W / 2 - 1] = '=' 28 | map[H / 2 + 1][W / 2 - 1] = '=' 29 | map[H / 2 - 1][W / 2 + 1] = '=' 30 | map[H / 2 + 1][W / 2 + 1] = '=' 31 | 32 | map[W-5][H-5] = '.' 33 | 34 | map = map * "\n" 35 | 36 | while map.count('.') > 10000 37 | r = rand(map.size) 38 | if map[r] == '.' 39 | map[r] = ' ' 40 | end 41 | end 42 | 43 | puts map 44 | -------------------------------------------------------------------------------- /gen_lman_inst.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | puts 'class Lman' 4 | 5 | [[:ldc, :int], 6 | [:ldf, :sym], 7 | [:ap, :int], 8 | [:rtn], 9 | [:ld, :int, :int], 10 | [:st, :int, :int], 11 | [:add], 12 | [:sub], 13 | [:mul], 14 | [:div], 15 | [:ceq], 16 | [:cgt], 17 | [:cgte], 18 | [:cons], 19 | [:car], 20 | [:cdr], 21 | [:atom], 22 | [:brk], 23 | [:dbug], 24 | [:dum, :int], 25 | [:rap, :int], 26 | [:tsel, :sym, :sym], 27 | ].each do |op, *args| 28 | as = args.each_index.map{|i|"a#{i}"} 29 | puts " def #{op}(#{as * ', '})" 30 | args.zip(as).each do |t, a| 31 | case t 32 | when :int 33 | puts %Q( raise if !#{a}.is_a?(Fixnum)) 34 | when :sym 35 | puts %Q( raise if !#{a}.is_a?(Symbol)) 36 | else 37 | raise "#{t}" 38 | end 39 | end 40 | puts " @insts << [#{([":#{op}"] + as) * ', '}]" 41 | puts " end" 42 | puts 43 | end 44 | 45 | puts 'end' 46 | -------------------------------------------------------------------------------- /gen_ghost_inst.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | puts 'class Ghost' 4 | 5 | [[:mov, :rm, :rm], 6 | [:inc, :rm], 7 | [:dec, :rm], 8 | [:add, :rm, :rm], 9 | [:sub, :rm, :rm], 10 | [:mul, :rm, :rm], 11 | [:div, :rm, :rm], 12 | [:and, :rm, :rm], 13 | [:or, :rm, :rm], 14 | [:xor, :rm, :rm], 15 | [:jlt, :sym, :rm, :rm], 16 | [:jeq, :sym, :rm, :rm], 17 | [:jgt, :sym, :rm, :rm], 18 | [:int, :int], 19 | [:hlt], 20 | ].each do |op, *args| 21 | as = args.each_index.map{|i|"a#{i}"} 22 | puts " def #{op}(#{as * ', '})" 23 | args.zip(as).each do |t, a| 24 | case t 25 | when :int 26 | puts %Q( raise if !#{a}.is_a?(Fixnum)) 27 | when :sym 28 | puts %Q( raise if !#{a}.is_a?(Symbol)) 29 | when :rm 30 | puts %Q( raise if !check_rm(#{a})) 31 | else 32 | raise "#{t}" 33 | end 34 | end 35 | puts " @insts << [#{([":#{op}"] + as) * ', '}]" 36 | puts " end" 37 | puts 38 | end 39 | 40 | puts 'end' 41 | -------------------------------------------------------------------------------- /maps/32x32.map: -------------------------------------------------------------------------------- 1 | ################################ 2 | #\.............................# 3 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 4 | #..............................# 5 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 6 | #..............................# 7 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 8 | #..............................# 9 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 10 | #..............................# 11 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 12 | #..............................# 13 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 14 | #..............................# 15 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 16 | #..............=.=.............# 17 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 18 | #..............=.=.............# 19 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 20 | #..............................# 21 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 22 | #..............................# 23 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 24 | #..............................# 25 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 26 | #..............................# 27 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 28 | #..............................# 29 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 30 | #............................%.# 31 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 32 | ################################ 33 | -------------------------------------------------------------------------------- /maps/32x32_empty.map: -------------------------------------------------------------------------------- 1 | ################################ 2 | #\ # 3 | # # # # # # # # # # # # # # # ## 4 | # # 5 | # # # # # # # # # # # # # # # ## 6 | # # 7 | # # # # # # # # # # # # # # # ## 8 | # # 9 | # # # # # # # # # # # # # # # ## 10 | # # 11 | # # # # # # # # # # # # # # # ## 12 | # # 13 | # # # # # # # # # # # # # # # ## 14 | # # 15 | # # # # # # # # # # # # # # # ## 16 | # = = # 17 | # # # # # # # # # # # # # # # ## 18 | # = = # 19 | # # # # # # # # # # # # # # # ## 20 | # # 21 | # # # # # # # # # # # # # # # ## 22 | # # 23 | # # # # # # # # # # # # # # # ## 24 | # # 25 | # # # # # # # # # # # # # # # ## 26 | # # 27 | # # # # # # # # # # # # # # # ## 28 | # . # 29 | # # # # # # # # # # # # # # # ## 30 | # % # 31 | # # # # # # # # # # # # # # # ## 32 | ################################ 33 | -------------------------------------------------------------------------------- /lman.rb: -------------------------------------------------------------------------------- 1 | class Lman 2 | def initialize 3 | @insts = [] 4 | @labels = {} 5 | @rlabels = {} 6 | @anon_num = 0 7 | end 8 | 9 | def label(a) 10 | if !a.is_a?(Symbol) 11 | raise "Not a label: #{a}" 12 | end 13 | @labels[a] = @insts.size 14 | @rlabels[@insts.size] = a 15 | end 16 | 17 | def anon_label 18 | l = "_L#{@anon_num}" 19 | @anon_num += 1 20 | l.to_sym 21 | end 22 | 23 | def emit 24 | ninst = 0 25 | @insts.each do |op, *args| 26 | o = ["#{op}".upcase] 27 | c = [] 28 | 29 | if l = @rlabels[ninst] 30 | c << "@#{l}" 31 | end 32 | 33 | args.each do |a| 34 | if a.is_a?(Symbol) 35 | if !@labels[a] 36 | raise "Undefined label #{a}" 37 | end 38 | o << @labels[a] 39 | c << "#{a}" 40 | else 41 | o << a 42 | end 43 | end 44 | l = o * ' ' 45 | if !c.empty? 46 | l += ' ; ' + c * ' ' 47 | end 48 | puts l 49 | 50 | ninst += 1 51 | end 52 | end 53 | end 54 | 55 | if !system('make lman_inst.rb > make.log') 56 | raise "make failed" 57 | end 58 | 59 | require './lman_inst.rb' 60 | 61 | L = Lman.new 62 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Team name: shinh7 2 | Member: Shinichiro Hamaji 3 | 4 | * ai.rb and dsl.rb 5 | 6 | A Lambda-man DSL, implemented in Ruby. It does: 7 | 8 | - breadth first search for region close to lambdaman 9 | - calculate score for each direction based on the location of pills 10 | - wait ghost next to a power pill 11 | - try not to go in a straight path where a ghost is coming 12 | - try not to be too close to a ghost 13 | - handle extreme maps (too big map, too many pills, etc.) 14 | - prefer fruits 15 | - etc. 16 | 17 | * lman.rb and gen_lman_inst.rb 18 | 19 | The backend assembler of the lambdaman AI. 20 | 21 | * akabei.rb, ghost.rb, and gen_ghost_inst.rb 22 | 23 | The ghost AI and its assembler. "Akabei" is named after blinky. 24 | 25 | - Go to the location of lambdaman (or the location to which lambdaman 26 | is going, if you pass a parameter) 27 | - When frighten or lambdaman is close to a power pill, it will go to 28 | the opposite direction. 29 | - A small randomization. 30 | 31 | * sim.go 32 | 33 | A game simulator written in Go. It was fairly compatible with the 34 | reference implementation until the timing of this was fixed :( 35 | 36 | https://github.com/icfpcontest2014/icfpcontest2014.github.io/commit/12fc72d6082820c2035f1da28dd9dd718fb3db77 37 | 38 | * My environment 39 | 40 | My ruby version is "ruby 2.1.2p95 (2014-05-08) [x86_64-linux-gnu]" 41 | My go version is "go version go1.3 linux/amd64" 42 | -------------------------------------------------------------------------------- /lman_inst.rb: -------------------------------------------------------------------------------- 1 | class Lman 2 | def ldc(a0) 3 | raise if !a0.is_a?(Fixnum) 4 | @insts << [:ldc, a0] 5 | end 6 | 7 | def ldf(a0) 8 | raise if !a0.is_a?(Symbol) 9 | @insts << [:ldf, a0] 10 | end 11 | 12 | def ap(a0) 13 | raise if !a0.is_a?(Fixnum) 14 | @insts << [:ap, a0] 15 | end 16 | 17 | def rtn() 18 | @insts << [:rtn] 19 | end 20 | 21 | def ld(a0, a1) 22 | raise if !a0.is_a?(Fixnum) 23 | raise if !a1.is_a?(Fixnum) 24 | @insts << [:ld, a0, a1] 25 | end 26 | 27 | def st(a0, a1) 28 | raise if !a0.is_a?(Fixnum) 29 | raise if !a1.is_a?(Fixnum) 30 | @insts << [:st, a0, a1] 31 | end 32 | 33 | def add() 34 | @insts << [:add] 35 | end 36 | 37 | def sub() 38 | @insts << [:sub] 39 | end 40 | 41 | def mul() 42 | @insts << [:mul] 43 | end 44 | 45 | def div() 46 | @insts << [:div] 47 | end 48 | 49 | def ceq() 50 | @insts << [:ceq] 51 | end 52 | 53 | def cgt() 54 | @insts << [:cgt] 55 | end 56 | 57 | def cgte() 58 | @insts << [:cgte] 59 | end 60 | 61 | def cons() 62 | @insts << [:cons] 63 | end 64 | 65 | def car() 66 | @insts << [:car] 67 | end 68 | 69 | def cdr() 70 | @insts << [:cdr] 71 | end 72 | 73 | def atom() 74 | @insts << [:atom] 75 | end 76 | 77 | def brk() 78 | @insts << [:brk] 79 | end 80 | 81 | def dbug() 82 | @insts << [:dbug] 83 | end 84 | 85 | def dum(a0) 86 | raise if !a0.is_a?(Fixnum) 87 | @insts << [:dum, a0] 88 | end 89 | 90 | def rap(a0) 91 | raise if !a0.is_a?(Fixnum) 92 | @insts << [:rap, a0] 93 | end 94 | 95 | def tsel(a0, a1) 96 | raise if !a0.is_a?(Symbol) 97 | raise if !a1.is_a?(Symbol) 98 | @insts << [:tsel, a0, a1] 99 | end 100 | 101 | end 102 | -------------------------------------------------------------------------------- /maps/48x48.map: -------------------------------------------------------------------------------- 1 | ################################################ 2 | #\.............................................# 3 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 4 | #..............................................# 5 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 6 | #..............................................# 7 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 8 | #..............................................# 9 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 10 | #..............................................# 11 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 12 | #..............................................# 13 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 14 | #..............................................# 15 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 16 | #..............................................# 17 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 18 | #..............................................# 19 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 20 | #..............................................# 21 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 22 | #..............................................# 23 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 24 | #......................=.=.....................# 25 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 26 | #......................=.=.....................# 27 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 28 | #..............................................# 29 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 30 | #..............................................# 31 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 32 | #..............................................# 33 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 34 | #..............................................# 35 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 36 | #..............................................# 37 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 38 | #..............................................# 39 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 40 | #..............................................# 41 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 42 | #..............................................# 43 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 44 | #..............................................# 45 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 46 | #............................................%.# 47 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 48 | ################################################ 49 | -------------------------------------------------------------------------------- /ghost.rb: -------------------------------------------------------------------------------- 1 | class Ghost 2 | attr_reader :name 3 | 4 | def initialize(name) 5 | @name = name 6 | 7 | @insts = [] 8 | @labels = {} 9 | @rlabels = {} 10 | @anon_num = 0 11 | end 12 | 13 | def check_rm(a) 14 | if a.is_a?(Fixnum) || a.is_a?(Ghost) 15 | return true 16 | end 17 | 18 | if !a.is_a?(Array) 19 | return false 20 | end 21 | 22 | if a.size != 1 23 | return false 24 | end 25 | 26 | return a[0].is_a?(Fixnum) || a[0].is_a?(Ghost) 27 | end 28 | 29 | def label(a) 30 | if !a.is_a?(Symbol) 31 | raise "Not a label: #{a}" 32 | end 33 | @labels[a] = @insts.size 34 | @rlabels[@insts.size] = a 35 | end 36 | 37 | def anon_label 38 | l = "_L#{@anon_num}" 39 | @anon_num += 1 40 | l.to_sym 41 | end 42 | 43 | def stringify(a) 44 | if a.is_a?(Ghost) 45 | a.name 46 | else 47 | a.to_s 48 | end 49 | end 50 | 51 | def emit 52 | ninst = 0 53 | @insts.each do |op, *args| 54 | o = [] 55 | c = [] 56 | 57 | if l = @rlabels[ninst] 58 | c << "@#{l}" 59 | end 60 | 61 | args.each do |a| 62 | if a.is_a?(Symbol) 63 | if !@labels[a] 64 | raise "Undefined label #{a}" 65 | end 66 | o << @labels[a] 67 | c << "#{a}" 68 | elsif a.is_a?(Array) 69 | o << "[#{stringify(a[0])}]" 70 | else 71 | o << stringify(a) 72 | end 73 | end 74 | l = op.to_s + ' ' + o * ',' 75 | if !c.empty? 76 | l += ' ; ' + c * ' ' 77 | end 78 | puts l 79 | 80 | ninst += 1 81 | end 82 | end 83 | 84 | def set_dir 85 | int(0) 86 | end 87 | 88 | def get_lpos 89 | int(1) 90 | end 91 | 92 | def get_id 93 | int(3) 94 | end 95 | 96 | def get_pos 97 | int(5) 98 | end 99 | 100 | def get_stat 101 | int(6) 102 | end 103 | 104 | def get_map 105 | int(7) 106 | end 107 | 108 | def dbg 109 | int(8) 110 | end 111 | 112 | def jmp(s) 113 | jeq(s, 0, 0) 114 | end 115 | end 116 | 117 | if !system('make ghost_inst.rb > make.log') 118 | raise "make failed" 119 | end 120 | 121 | require './ghost_inst.rb' 122 | 123 | A = Ghost.new('a') 124 | B = Ghost.new('b') 125 | C = Ghost.new('c') 126 | D = Ghost.new('d') 127 | E = Ghost.new('e') 128 | F = Ghost.new('f') 129 | G = Ghost.new('g') 130 | H = Ghost.new('h') 131 | PC = Ghost.new('pc') 132 | -------------------------------------------------------------------------------- /solution/ghost0.ghc: -------------------------------------------------------------------------------- 1 | mov [60],0 2 | mov [70],0 3 | mov [74],255 4 | mov [71],1 5 | mov [75],0 6 | mov [72],0 7 | mov [76],1 8 | mov [73],255 9 | mov [77],0 10 | int 3 11 | int 5 12 | mov [40],a 13 | mov [41],b 14 | int 1 15 | mov [50],a 16 | mov [51],b 17 | jgt 20,[40],[50] ; @calc_dist gx_is_larger 18 | mov d,[50] 19 | sub d,[40] 20 | jeq 22,0,0 ; x_compare_done 21 | mov d,[40] ; @gx_is_larger 22 | sub d,[50] 23 | mov [55],d ; @x_compare_done 24 | jgt 27,[41],[51] ; gy_is_larger 25 | mov d,[51] 26 | sub d,[41] 27 | jeq 29,0,0 ; y_compare_done 28 | mov d,[41] ; @gy_is_larger 29 | sub d,[51] 30 | add [55],d ; @y_compare_done 31 | jlt 62,[51],[41] ; neg_dy 32 | jgt 47,[50],[40] ; pos_dy_pos_dx 33 | mov a,[40] 34 | sub a,[50] 35 | mov b,[51] 36 | sub b,[41] 37 | jlt 42,b,a ; pos_dy_neg_dx_x 38 | mov [20],2 39 | mov [21],3 40 | mov [22],1 41 | mov [23],0 42 | jeq 93,0,0 ; got_priority 43 | mov [20],3 ; @pos_dy_neg_dx_x 44 | mov [21],2 45 | mov [22],0 46 | mov [23],1 47 | jeq 93,0,0 ; got_priority 48 | mov a,[50] ; @pos_dy_pos_dx 49 | sub a,[40] 50 | mov b,[51] 51 | sub b,[41] 52 | jlt 57,b,a ; pos_dy_pos_dx_x 53 | mov [20],2 54 | mov [21],1 55 | mov [22],3 56 | mov [23],0 57 | jeq 93,0,0 ; got_priority 58 | mov [20],1 ; @pos_dy_pos_dx_x 59 | mov [21],2 60 | mov [22],0 61 | mov [23],3 62 | jeq 93,0,0 ; got_priority 63 | jgt 78,[50],[40] ; @neg_dy neg_dy_pos_dx 64 | mov a,[40] 65 | sub a,[50] 66 | mov b,[41] 67 | sub b,[51] 68 | jlt 73,a,b ; neg_dy_neg_dx_y 69 | mov [20],3 70 | mov [21],0 71 | mov [22],2 72 | mov [23],1 73 | jeq 93,0,0 ; got_priority 74 | mov [20],0 ; @neg_dy_neg_dx_y 75 | mov [21],3 76 | mov [22],1 77 | mov [23],2 78 | jeq 93,0,0 ; got_priority 79 | mov a,[50] ; @neg_dy_pos_dx 80 | sub a,[40] 81 | mov b,[41] 82 | sub b,[51] 83 | jlt 88,a,b ; neg_dy_pos_dx_y 84 | mov [20],1 85 | mov [21],0 86 | mov [22],2 87 | mov [23],3 88 | jeq 93,0,0 ; got_priority 89 | mov [20],0 ; @neg_dy_pos_dx_y 90 | mov [21],1 91 | mov [22],3 92 | mov [23],2 93 | jeq 93,0,0 ; got_priority 94 | mov [57],252 ; @search_ppill 95 | mov b,[57] ; @search_ppill_y_loop 96 | add b,[51] 97 | mov [56],252 98 | mov a,[56] ; @search_ppill_x_loop 99 | add a,[50] 100 | int 7 101 | jeq 111,a,3 ; reverse 102 | add [56],1 103 | jeq 104,[56],5 ; search_ppill_x_loop_done 104 | jeq 97,0,0 ; search_ppill_x_loop 105 | add [57],1 ; @search_ppill_x_loop_done 106 | jeq 107,[57],5 ; search_ppill_done 107 | jeq 94,0,0 ; search_ppill_y_loop 108 | int 3 ; @search_ppill_done 109 | int 6 110 | and a,1 111 | jeq 119,a,0 ; shuffle 112 | jgt 119,[55],10 ; @reverse shuffle 113 | mov [60],1 114 | mov a,[20] 115 | mov [20],[23] 116 | mov [23],a 117 | mov a,[21] 118 | mov [21],[22] 119 | mov [22],a 120 | int 3 ; @shuffle 121 | add [80],a 122 | add [80],7 123 | mul [80],13 124 | jeq 139,[60],1 ; shuffle_done 125 | jlt 139,[55],2 ; shuffle_done 126 | jgt 139,[80],10 ; shuffle_done 127 | int 8 128 | add [81],a 129 | add [81],37 130 | mul [81],97 131 | mov a,[80] 132 | mov b,[81] 133 | div a,64 134 | div b,64 135 | add a,20 136 | add b,20 137 | mov c,[a] 138 | mov [a],[b] 139 | mov [b],c 140 | mov d,[20] ; @shuffle_done 141 | int 3 142 | int 6 143 | add b,2 144 | and b,3 145 | jeq 154,b,d ; invalid_0 146 | mov a,[40] 147 | mov c,70 148 | add c,d 149 | add a,[c] 150 | mov b,[41] 151 | add c,4 152 | add b,[c] 153 | int 7 154 | jgt 199,a,0 ; done 155 | mov d,[21] ; @invalid_0 156 | int 3 157 | int 6 158 | add b,2 159 | and b,3 160 | jeq 169,b,d ; invalid_1 161 | mov a,[40] 162 | mov c,70 163 | add c,d 164 | add a,[c] 165 | mov b,[41] 166 | add c,4 167 | add b,[c] 168 | int 7 169 | jgt 199,a,0 ; done 170 | mov d,[22] ; @invalid_1 171 | int 3 172 | int 6 173 | add b,2 174 | and b,3 175 | jeq 184,b,d ; invalid_2 176 | mov a,[40] 177 | mov c,70 178 | add c,d 179 | add a,[c] 180 | mov b,[41] 181 | add c,4 182 | add b,[c] 183 | int 7 184 | jgt 199,a,0 ; done 185 | mov d,[23] ; @invalid_2 186 | int 3 187 | int 6 188 | add b,2 189 | and b,3 190 | jeq 199,b,d ; invalid_3 191 | mov a,[40] 192 | mov c,70 193 | add c,d 194 | add a,[c] 195 | mov b,[41] 196 | add c,4 197 | add b,[c] 198 | int 7 199 | jgt 199,a,0 ; done 200 | mov a,d ; @done 201 | int 0 202 | mov g,230 203 | sub [g],[253] ; @loop 204 | add g,1 205 | mul [g],[3] 206 | add a,[g] 207 | mul [g],[7] 208 | add b,[g] 209 | int 7 210 | jlt 202,g,250 ; loop 211 | hlt 212 | -------------------------------------------------------------------------------- /maps/64x64.map: -------------------------------------------------------------------------------- 1 | ################################################################ 2 | #\.............................................................# 3 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 4 | #..............................................................# 5 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 6 | #..............................................................# 7 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 8 | #..............................................................# 9 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 10 | #..............................................................# 11 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 12 | #..............................................................# 13 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 14 | #..............................................................# 15 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 16 | #..............................................................# 17 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 18 | #..............................................................# 19 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 20 | #..............................................................# 21 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 22 | #..............................................................# 23 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 24 | #..............................................................# 25 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 26 | #..............................................................# 27 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 28 | #..............................................................# 29 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 30 | #..............................................................# 31 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 32 | #..............................=.=.............................# 33 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 34 | #..............................=.=.............................# 35 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 36 | #..............................................................# 37 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 38 | #..............................................................# 39 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 40 | #..............................................................# 41 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 42 | #..............................................................# 43 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 44 | #..............................................................# 45 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 46 | #..............................................................# 47 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 48 | #..............................................................# 49 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 50 | #..............................................................# 51 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 52 | #..............................................................# 53 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 54 | #..............................................................# 55 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 56 | #..............................................................# 57 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 58 | #..............................................................# 59 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 60 | #..............................................................# 61 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 62 | #............................................................%.# 63 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 64 | ################################################################ 65 | -------------------------------------------------------------------------------- /solution/ghost1.ghc: -------------------------------------------------------------------------------- 1 | mov [60],0 2 | mov [70],0 3 | mov [74],255 4 | mov [71],1 5 | mov [75],0 6 | mov [72],0 7 | mov [76],1 8 | mov [73],255 9 | mov [77],0 10 | int 3 11 | int 5 12 | mov [40],a 13 | mov [41],b 14 | int 1 15 | mov [50],a 16 | mov [51],b 17 | jgt 20,[40],[50] ; @calc_dist gx_is_larger 18 | mov d,[50] 19 | sub d,[40] 20 | jeq 22,0,0 ; x_compare_done 21 | mov d,[40] ; @gx_is_larger 22 | sub d,[50] 23 | mov [55],d ; @x_compare_done 24 | jgt 27,[41],[51] ; gy_is_larger 25 | mov d,[51] 26 | sub d,[41] 27 | jeq 29,0,0 ; y_compare_done 28 | mov d,[41] ; @gy_is_larger 29 | sub d,[51] 30 | add [55],d ; @y_compare_done 31 | jgt 40,d,2 ; @predict predict_done 32 | jeq 40,[90],0 ; predict_done 33 | mov c,[50] 34 | sub c,[90] 35 | mul c,3 36 | mov d,[51] 37 | sub d,[91] 38 | mul d,3 39 | add [50],c 40 | add [51],d 41 | mov [90],a ; @predict_done 42 | mov [91],b 43 | int 3 44 | jlt 75,[51],[41] ; neg_dy 45 | jgt 60,[50],[40] ; pos_dy_pos_dx 46 | mov a,[40] 47 | sub a,[50] 48 | mov b,[51] 49 | sub b,[41] 50 | jlt 55,b,a ; pos_dy_neg_dx_x 51 | mov [20],2 52 | mov [21],3 53 | mov [22],1 54 | mov [23],0 55 | jeq 106,0,0 ; got_priority 56 | mov [20],3 ; @pos_dy_neg_dx_x 57 | mov [21],2 58 | mov [22],0 59 | mov [23],1 60 | jeq 106,0,0 ; got_priority 61 | mov a,[50] ; @pos_dy_pos_dx 62 | sub a,[40] 63 | mov b,[51] 64 | sub b,[41] 65 | jlt 70,b,a ; pos_dy_pos_dx_x 66 | mov [20],2 67 | mov [21],1 68 | mov [22],3 69 | mov [23],0 70 | jeq 106,0,0 ; got_priority 71 | mov [20],1 ; @pos_dy_pos_dx_x 72 | mov [21],2 73 | mov [22],0 74 | mov [23],3 75 | jeq 106,0,0 ; got_priority 76 | jgt 91,[50],[40] ; @neg_dy neg_dy_pos_dx 77 | mov a,[40] 78 | sub a,[50] 79 | mov b,[41] 80 | sub b,[51] 81 | jlt 86,a,b ; neg_dy_neg_dx_y 82 | mov [20],3 83 | mov [21],0 84 | mov [22],2 85 | mov [23],1 86 | jeq 106,0,0 ; got_priority 87 | mov [20],0 ; @neg_dy_neg_dx_y 88 | mov [21],3 89 | mov [22],1 90 | mov [23],2 91 | jeq 106,0,0 ; got_priority 92 | mov a,[50] ; @neg_dy_pos_dx 93 | sub a,[40] 94 | mov b,[41] 95 | sub b,[51] 96 | jlt 101,a,b ; neg_dy_pos_dx_y 97 | mov [20],1 98 | mov [21],0 99 | mov [22],2 100 | mov [23],3 101 | jeq 106,0,0 ; got_priority 102 | mov [20],0 ; @neg_dy_pos_dx_y 103 | mov [21],1 104 | mov [22],3 105 | mov [23],2 106 | jeq 106,0,0 ; got_priority 107 | mov [57],252 ; @search_ppill 108 | mov b,[57] ; @search_ppill_y_loop 109 | add b,[51] 110 | mov [56],252 111 | mov a,[56] ; @search_ppill_x_loop 112 | add a,[50] 113 | int 7 114 | jeq 124,a,3 ; reverse 115 | add [56],1 116 | jeq 117,[56],5 ; search_ppill_x_loop_done 117 | jeq 110,0,0 ; search_ppill_x_loop 118 | add [57],1 ; @search_ppill_x_loop_done 119 | jeq 120,[57],5 ; search_ppill_done 120 | jeq 107,0,0 ; search_ppill_y_loop 121 | int 3 ; @search_ppill_done 122 | int 6 123 | and a,1 124 | jeq 132,a,0 ; shuffle 125 | jgt 132,[55],10 ; @reverse shuffle 126 | mov [60],1 127 | mov a,[20] 128 | mov [20],[23] 129 | mov [23],a 130 | mov a,[21] 131 | mov [21],[22] 132 | mov [22],a 133 | int 3 ; @shuffle 134 | add [80],a 135 | add [80],7 136 | mul [80],13 137 | jeq 152,[60],1 ; shuffle_done 138 | jlt 152,[55],2 ; shuffle_done 139 | jgt 152,[80],10 ; shuffle_done 140 | int 8 141 | add [81],a 142 | add [81],37 143 | mul [81],97 144 | mov a,[80] 145 | mov b,[81] 146 | div a,64 147 | div b,64 148 | add a,20 149 | add b,20 150 | mov c,[a] 151 | mov [a],[b] 152 | mov [b],c 153 | mov d,[20] ; @shuffle_done 154 | int 3 155 | int 6 156 | add b,2 157 | and b,3 158 | jeq 167,b,d ; invalid_0 159 | mov a,[40] 160 | mov c,70 161 | add c,d 162 | add a,[c] 163 | mov b,[41] 164 | add c,4 165 | add b,[c] 166 | int 7 167 | jgt 212,a,0 ; done 168 | mov d,[21] ; @invalid_0 169 | int 3 170 | int 6 171 | add b,2 172 | and b,3 173 | jeq 182,b,d ; invalid_1 174 | mov a,[40] 175 | mov c,70 176 | add c,d 177 | add a,[c] 178 | mov b,[41] 179 | add c,4 180 | add b,[c] 181 | int 7 182 | jgt 212,a,0 ; done 183 | mov d,[22] ; @invalid_1 184 | int 3 185 | int 6 186 | add b,2 187 | and b,3 188 | jeq 197,b,d ; invalid_2 189 | mov a,[40] 190 | mov c,70 191 | add c,d 192 | add a,[c] 193 | mov b,[41] 194 | add c,4 195 | add b,[c] 196 | int 7 197 | jgt 212,a,0 ; done 198 | mov d,[23] ; @invalid_2 199 | int 3 200 | int 6 201 | add b,2 202 | and b,3 203 | jeq 212,b,d ; invalid_3 204 | mov a,[40] 205 | mov c,70 206 | add c,d 207 | add a,[c] 208 | mov b,[41] 209 | add c,4 210 | add b,[c] 211 | int 7 212 | jgt 212,a,0 ; done 213 | mov a,d ; @done 214 | int 0 215 | mov g,230 216 | sub [g],[253] ; @loop 217 | add g,1 218 | mul [g],[3] 219 | add a,[g] 220 | mul [g],[7] 221 | add b,[g] 222 | int 7 223 | jlt 215,g,250 ; loop 224 | hlt 225 | -------------------------------------------------------------------------------- /solution/ghost2.ghc: -------------------------------------------------------------------------------- 1 | mov [60],0 2 | mov [70],0 3 | mov [74],255 4 | mov [71],1 5 | mov [75],0 6 | mov [72],0 7 | mov [76],1 8 | mov [73],255 9 | mov [77],0 10 | int 3 11 | int 5 12 | mov [40],a 13 | mov [41],b 14 | int 1 15 | mov [50],a 16 | mov [51],b 17 | jgt 20,[40],[50] ; @calc_dist gx_is_larger 18 | mov d,[50] 19 | sub d,[40] 20 | jeq 22,0,0 ; x_compare_done 21 | mov d,[40] ; @gx_is_larger 22 | sub d,[50] 23 | mov [55],d ; @x_compare_done 24 | jgt 27,[41],[51] ; gy_is_larger 25 | mov d,[51] 26 | sub d,[41] 27 | jeq 29,0,0 ; y_compare_done 28 | mov d,[41] ; @gy_is_larger 29 | sub d,[51] 30 | add [55],d ; @y_compare_done 31 | jgt 40,d,3 ; @predict predict_done 32 | jeq 40,[90],0 ; predict_done 33 | mov c,[50] 34 | sub c,[90] 35 | mul c,2 36 | mov d,[51] 37 | sub d,[91] 38 | mul d,2 39 | add [50],c 40 | add [51],d 41 | mov [90],a ; @predict_done 42 | mov [91],b 43 | int 3 44 | jlt 75,[51],[41] ; neg_dy 45 | jgt 60,[50],[40] ; pos_dy_pos_dx 46 | mov a,[40] 47 | sub a,[50] 48 | mov b,[51] 49 | sub b,[41] 50 | jlt 55,b,a ; pos_dy_neg_dx_x 51 | mov [20],2 52 | mov [21],3 53 | mov [22],1 54 | mov [23],0 55 | jeq 106,0,0 ; got_priority 56 | mov [20],3 ; @pos_dy_neg_dx_x 57 | mov [21],2 58 | mov [22],0 59 | mov [23],1 60 | jeq 106,0,0 ; got_priority 61 | mov a,[50] ; @pos_dy_pos_dx 62 | sub a,[40] 63 | mov b,[51] 64 | sub b,[41] 65 | jlt 70,b,a ; pos_dy_pos_dx_x 66 | mov [20],2 67 | mov [21],1 68 | mov [22],3 69 | mov [23],0 70 | jeq 106,0,0 ; got_priority 71 | mov [20],1 ; @pos_dy_pos_dx_x 72 | mov [21],2 73 | mov [22],0 74 | mov [23],3 75 | jeq 106,0,0 ; got_priority 76 | jgt 91,[50],[40] ; @neg_dy neg_dy_pos_dx 77 | mov a,[40] 78 | sub a,[50] 79 | mov b,[41] 80 | sub b,[51] 81 | jlt 86,a,b ; neg_dy_neg_dx_y 82 | mov [20],3 83 | mov [21],0 84 | mov [22],2 85 | mov [23],1 86 | jeq 106,0,0 ; got_priority 87 | mov [20],0 ; @neg_dy_neg_dx_y 88 | mov [21],3 89 | mov [22],1 90 | mov [23],2 91 | jeq 106,0,0 ; got_priority 92 | mov a,[50] ; @neg_dy_pos_dx 93 | sub a,[40] 94 | mov b,[41] 95 | sub b,[51] 96 | jlt 101,a,b ; neg_dy_pos_dx_y 97 | mov [20],1 98 | mov [21],0 99 | mov [22],2 100 | mov [23],3 101 | jeq 106,0,0 ; got_priority 102 | mov [20],0 ; @neg_dy_pos_dx_y 103 | mov [21],1 104 | mov [22],3 105 | mov [23],2 106 | jeq 106,0,0 ; got_priority 107 | mov [57],252 ; @search_ppill 108 | mov b,[57] ; @search_ppill_y_loop 109 | add b,[51] 110 | mov [56],252 111 | mov a,[56] ; @search_ppill_x_loop 112 | add a,[50] 113 | int 7 114 | jeq 124,a,3 ; reverse 115 | add [56],1 116 | jeq 117,[56],5 ; search_ppill_x_loop_done 117 | jeq 110,0,0 ; search_ppill_x_loop 118 | add [57],1 ; @search_ppill_x_loop_done 119 | jeq 120,[57],5 ; search_ppill_done 120 | jeq 107,0,0 ; search_ppill_y_loop 121 | int 3 ; @search_ppill_done 122 | int 6 123 | and a,1 124 | jeq 132,a,0 ; shuffle 125 | jgt 132,[55],10 ; @reverse shuffle 126 | mov [60],1 127 | mov a,[20] 128 | mov [20],[23] 129 | mov [23],a 130 | mov a,[21] 131 | mov [21],[22] 132 | mov [22],a 133 | int 3 ; @shuffle 134 | add [80],a 135 | add [80],7 136 | mul [80],13 137 | jeq 152,[60],1 ; shuffle_done 138 | jlt 152,[55],2 ; shuffle_done 139 | jgt 152,[80],10 ; shuffle_done 140 | int 8 141 | add [81],a 142 | add [81],37 143 | mul [81],97 144 | mov a,[80] 145 | mov b,[81] 146 | div a,64 147 | div b,64 148 | add a,20 149 | add b,20 150 | mov c,[a] 151 | mov [a],[b] 152 | mov [b],c 153 | mov d,[20] ; @shuffle_done 154 | int 3 155 | int 6 156 | add b,2 157 | and b,3 158 | jeq 167,b,d ; invalid_0 159 | mov a,[40] 160 | mov c,70 161 | add c,d 162 | add a,[c] 163 | mov b,[41] 164 | add c,4 165 | add b,[c] 166 | int 7 167 | jgt 212,a,0 ; done 168 | mov d,[21] ; @invalid_0 169 | int 3 170 | int 6 171 | add b,2 172 | and b,3 173 | jeq 182,b,d ; invalid_1 174 | mov a,[40] 175 | mov c,70 176 | add c,d 177 | add a,[c] 178 | mov b,[41] 179 | add c,4 180 | add b,[c] 181 | int 7 182 | jgt 212,a,0 ; done 183 | mov d,[22] ; @invalid_1 184 | int 3 185 | int 6 186 | add b,2 187 | and b,3 188 | jeq 197,b,d ; invalid_2 189 | mov a,[40] 190 | mov c,70 191 | add c,d 192 | add a,[c] 193 | mov b,[41] 194 | add c,4 195 | add b,[c] 196 | int 7 197 | jgt 212,a,0 ; done 198 | mov d,[23] ; @invalid_2 199 | int 3 200 | int 6 201 | add b,2 202 | and b,3 203 | jeq 212,b,d ; invalid_3 204 | mov a,[40] 205 | mov c,70 206 | add c,d 207 | add a,[c] 208 | mov b,[41] 209 | add c,4 210 | add b,[c] 211 | int 7 212 | jgt 212,a,0 ; done 213 | mov a,d ; @done 214 | int 0 215 | mov g,230 216 | sub [g],[253] ; @loop 217 | add g,1 218 | mul [g],[3] 219 | add a,[g] 220 | mul [g],[7] 221 | add b,[g] 222 | int 7 223 | jlt 215,g,250 ; loop 224 | hlt 225 | -------------------------------------------------------------------------------- /solution/ghost3.ghc: -------------------------------------------------------------------------------- 1 | mov [60],0 2 | mov [70],0 3 | mov [74],255 4 | mov [71],1 5 | mov [75],0 6 | mov [72],0 7 | mov [76],1 8 | mov [73],255 9 | mov [77],0 10 | int 3 11 | int 5 12 | mov [40],a 13 | mov [41],b 14 | int 1 15 | mov [50],a 16 | mov [51],b 17 | jgt 20,[40],[50] ; @calc_dist gx_is_larger 18 | mov d,[50] 19 | sub d,[40] 20 | jeq 22,0,0 ; x_compare_done 21 | mov d,[40] ; @gx_is_larger 22 | sub d,[50] 23 | mov [55],d ; @x_compare_done 24 | jgt 27,[41],[51] ; gy_is_larger 25 | mov d,[51] 26 | sub d,[41] 27 | jeq 29,0,0 ; y_compare_done 28 | mov d,[41] ; @gy_is_larger 29 | sub d,[51] 30 | add [55],d ; @y_compare_done 31 | jgt 40,d,3 ; @predict predict_done 32 | jeq 40,[90],0 ; predict_done 33 | mov c,[50] 34 | sub c,[90] 35 | mul c,1 36 | mov d,[51] 37 | sub d,[91] 38 | mul d,1 39 | add [50],c 40 | add [51],d 41 | mov [90],a ; @predict_done 42 | mov [91],b 43 | int 3 44 | jlt 75,[51],[41] ; neg_dy 45 | jgt 60,[50],[40] ; pos_dy_pos_dx 46 | mov a,[40] 47 | sub a,[50] 48 | mov b,[51] 49 | sub b,[41] 50 | jlt 55,b,a ; pos_dy_neg_dx_x 51 | mov [20],2 52 | mov [21],3 53 | mov [22],1 54 | mov [23],0 55 | jeq 106,0,0 ; got_priority 56 | mov [20],3 ; @pos_dy_neg_dx_x 57 | mov [21],2 58 | mov [22],0 59 | mov [23],1 60 | jeq 106,0,0 ; got_priority 61 | mov a,[50] ; @pos_dy_pos_dx 62 | sub a,[40] 63 | mov b,[51] 64 | sub b,[41] 65 | jlt 70,b,a ; pos_dy_pos_dx_x 66 | mov [20],2 67 | mov [21],1 68 | mov [22],3 69 | mov [23],0 70 | jeq 106,0,0 ; got_priority 71 | mov [20],1 ; @pos_dy_pos_dx_x 72 | mov [21],2 73 | mov [22],0 74 | mov [23],3 75 | jeq 106,0,0 ; got_priority 76 | jgt 91,[50],[40] ; @neg_dy neg_dy_pos_dx 77 | mov a,[40] 78 | sub a,[50] 79 | mov b,[41] 80 | sub b,[51] 81 | jlt 86,a,b ; neg_dy_neg_dx_y 82 | mov [20],3 83 | mov [21],0 84 | mov [22],2 85 | mov [23],1 86 | jeq 106,0,0 ; got_priority 87 | mov [20],0 ; @neg_dy_neg_dx_y 88 | mov [21],3 89 | mov [22],1 90 | mov [23],2 91 | jeq 106,0,0 ; got_priority 92 | mov a,[50] ; @neg_dy_pos_dx 93 | sub a,[40] 94 | mov b,[41] 95 | sub b,[51] 96 | jlt 101,a,b ; neg_dy_pos_dx_y 97 | mov [20],1 98 | mov [21],0 99 | mov [22],2 100 | mov [23],3 101 | jeq 106,0,0 ; got_priority 102 | mov [20],0 ; @neg_dy_pos_dx_y 103 | mov [21],1 104 | mov [22],3 105 | mov [23],2 106 | jeq 106,0,0 ; got_priority 107 | mov [57],252 ; @search_ppill 108 | mov b,[57] ; @search_ppill_y_loop 109 | add b,[51] 110 | mov [56],252 111 | mov a,[56] ; @search_ppill_x_loop 112 | add a,[50] 113 | int 7 114 | jeq 124,a,3 ; reverse 115 | add [56],1 116 | jeq 117,[56],5 ; search_ppill_x_loop_done 117 | jeq 110,0,0 ; search_ppill_x_loop 118 | add [57],1 ; @search_ppill_x_loop_done 119 | jeq 120,[57],5 ; search_ppill_done 120 | jeq 107,0,0 ; search_ppill_y_loop 121 | int 3 ; @search_ppill_done 122 | int 6 123 | and a,1 124 | jeq 132,a,0 ; shuffle 125 | jgt 132,[55],10 ; @reverse shuffle 126 | mov [60],1 127 | mov a,[20] 128 | mov [20],[23] 129 | mov [23],a 130 | mov a,[21] 131 | mov [21],[22] 132 | mov [22],a 133 | int 3 ; @shuffle 134 | add [80],a 135 | add [80],7 136 | mul [80],13 137 | jeq 152,[60],1 ; shuffle_done 138 | jlt 152,[55],2 ; shuffle_done 139 | jgt 152,[80],10 ; shuffle_done 140 | int 8 141 | add [81],a 142 | add [81],37 143 | mul [81],97 144 | mov a,[80] 145 | mov b,[81] 146 | div a,64 147 | div b,64 148 | add a,20 149 | add b,20 150 | mov c,[a] 151 | mov [a],[b] 152 | mov [b],c 153 | mov d,[20] ; @shuffle_done 154 | int 3 155 | int 6 156 | add b,2 157 | and b,3 158 | jeq 167,b,d ; invalid_0 159 | mov a,[40] 160 | mov c,70 161 | add c,d 162 | add a,[c] 163 | mov b,[41] 164 | add c,4 165 | add b,[c] 166 | int 7 167 | jgt 212,a,0 ; done 168 | mov d,[21] ; @invalid_0 169 | int 3 170 | int 6 171 | add b,2 172 | and b,3 173 | jeq 182,b,d ; invalid_1 174 | mov a,[40] 175 | mov c,70 176 | add c,d 177 | add a,[c] 178 | mov b,[41] 179 | add c,4 180 | add b,[c] 181 | int 7 182 | jgt 212,a,0 ; done 183 | mov d,[22] ; @invalid_1 184 | int 3 185 | int 6 186 | add b,2 187 | and b,3 188 | jeq 197,b,d ; invalid_2 189 | mov a,[40] 190 | mov c,70 191 | add c,d 192 | add a,[c] 193 | mov b,[41] 194 | add c,4 195 | add b,[c] 196 | int 7 197 | jgt 212,a,0 ; done 198 | mov d,[23] ; @invalid_2 199 | int 3 200 | int 6 201 | add b,2 202 | and b,3 203 | jeq 212,b,d ; invalid_3 204 | mov a,[40] 205 | mov c,70 206 | add c,d 207 | add a,[c] 208 | mov b,[41] 209 | add c,4 210 | add b,[c] 211 | int 7 212 | jgt 212,a,0 ; done 213 | mov a,d ; @done 214 | int 0 215 | mov g,230 216 | sub [g],[253] ; @loop 217 | add g,1 218 | mul [g],[3] 219 | add a,[g] 220 | mul [g],[7] 221 | add b,[g] 222 | int 7 223 | jlt 215,g,250 ; loop 224 | hlt 225 | -------------------------------------------------------------------------------- /akabei.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require './ghost.rb' 4 | 5 | adj = ARGV[0].to_i 6 | 7 | DIRS = [[0, -1], [1, 0], [0, 1], [-1, 0]] 8 | 9 | in_danger = [60] 10 | 11 | G.mov in_danger, 0 12 | 13 | diff_table_imm = 70 14 | 4.times do |d| 15 | G.mov [diff_table_imm + d], DIRS[d][0] % 256 16 | G.mov [diff_table_imm + d + 4], DIRS[d][1] % 256 17 | end 18 | 19 | G.get_id 20 | G.get_pos 21 | gx = [40] 22 | gy = [41] 23 | G.mov gx, A 24 | G.mov gy, B 25 | 26 | G.get_lpos 27 | lx = [50] 28 | ly = [51] 29 | G.mov lx, A 30 | G.mov ly, B 31 | 32 | G.label :calc_dist 33 | dist = [55] 34 | 35 | G.jgt :gx_is_larger, gx, lx 36 | G.mov D, lx 37 | G.sub D, gx 38 | G.jmp :x_compare_done 39 | 40 | G.label :gx_is_larger 41 | G.mov D, gx 42 | G.sub D, lx 43 | 44 | G.label :x_compare_done 45 | G.mov dist, D 46 | 47 | G.jgt :gy_is_larger, gy, ly 48 | G.mov D, ly 49 | G.sub D, gy 50 | G.jmp :y_compare_done 51 | 52 | G.label :gy_is_larger 53 | G.mov D, gy 54 | G.sub D, ly 55 | 56 | G.label :y_compare_done 57 | G.add dist, D 58 | 59 | if adj > 0 60 | G.label(:predict) 61 | 62 | G.jgt :predict_done, D, adj == 3 ? 2 : 3 63 | 64 | prev_lx = [90] 65 | prev_ly = [91] 66 | G.jeq :predict_done, prev_lx, 0 67 | 68 | G.mov C, lx 69 | G.sub C, prev_lx 70 | G.mul C, adj 71 | G.mov D, ly 72 | G.sub D, prev_ly 73 | G.mul D, adj 74 | 75 | G.add lx, C 76 | G.add ly, D 77 | 78 | G.label(:predict_done) 79 | G.mov prev_lx, A 80 | G.mov prev_ly, B 81 | 82 | G.get_id 83 | end 84 | 85 | # dx = [30] 86 | # dy = [31] 87 | # G.mov dx, lx 88 | # G.mov dy, ly 89 | # G.sub dx, A 90 | # G.sub dy, B 91 | 92 | p0_imm = 20 93 | p0 = [p0_imm] 94 | p1 = [p0_imm + 1] 95 | p2 = [p0_imm + 2] 96 | p3 = [p0_imm + 3] 97 | 98 | G.jlt :neg_dy, ly, gy 99 | 100 | G.jgt :pos_dy_pos_dx, lx, gx 101 | 102 | # ly>gy && lxgy && lx>gx 123 | G.label(:pos_dy_pos_dx) 124 | G.mov A, lx 125 | G.sub A, gx 126 | G.mov B, ly 127 | G.sub B, gy 128 | G.jlt :pos_dy_pos_dx_x, B, A 129 | 130 | G.mov p0, 2 131 | G.mov p1, 1 132 | G.mov p2, 3 133 | G.mov p3, 0 134 | G.jmp(:got_priority) 135 | 136 | G.label(:pos_dy_pos_dx_x) 137 | G.mov p0, 1 138 | G.mov p1, 2 139 | G.mov p2, 0 140 | G.mov p3, 3 141 | G.jmp(:got_priority) 142 | 143 | G.label(:neg_dy) 144 | 145 | G.jgt :neg_dy_pos_dx, lx, gx 146 | 147 | # lygx 168 | G.label(:neg_dy_pos_dx) 169 | G.mov A, lx 170 | G.sub A, gx 171 | G.mov B, gy 172 | G.sub B, ly 173 | G.jlt :neg_dy_pos_dx_y, A, B 174 | 175 | G.mov p0, 1 176 | G.mov p1, 0 177 | G.mov p2, 2 178 | G.mov p3, 3 179 | G.jmp(:got_priority) 180 | 181 | G.label(:neg_dy_pos_dx_y) 182 | G.mov p0, 0 183 | G.mov p1, 1 184 | G.mov p2, 3 185 | G.mov p3, 2 186 | G.jmp(:got_priority) 187 | 188 | G.label(:got_priority) 189 | 190 | G.label :search_ppill 191 | PPILL_W = 4 192 | x = [56] 193 | y = [57] 194 | G.mov y, 256 - PPILL_W 195 | 196 | G.label :search_ppill_y_loop 197 | 198 | G.mov B, y 199 | G.add B, ly 200 | 201 | G.mov x, 256 - PPILL_W 202 | 203 | G.label :search_ppill_x_loop 204 | 205 | G.mov A, x 206 | G.add A, lx 207 | 208 | G.get_map 209 | 210 | G.jeq :reverse, A, 3 211 | 212 | G.add x, 1 213 | G.jeq :search_ppill_x_loop_done, x, PPILL_W + 1 214 | G.jmp :search_ppill_x_loop 215 | 216 | G.label :search_ppill_x_loop_done 217 | 218 | G.add y, 1 219 | G.jeq :search_ppill_done, y, PPILL_W + 1 220 | G.jmp :search_ppill_y_loop 221 | 222 | G.label :search_ppill_done 223 | 224 | G.get_id 225 | G.get_stat 226 | G.and A, 1 227 | G.jeq :shuffle, A, 0 228 | 229 | G.label :reverse 230 | 231 | G.jgt :shuffle, dist, 10 232 | 233 | G.mov in_danger, 1 234 | 235 | G.mov A, p0 236 | G.mov p0, p3 237 | G.mov p3, A 238 | G.mov A, p1 239 | G.mov p1, p2 240 | G.mov p2, A 241 | 242 | # # Dump priorities 243 | # G.mov A, p0 244 | # G.mov B, p1 245 | # G.mov C, p2 246 | # G.mov D, p3 247 | # G.dbg 248 | 249 | G.label :shuffle 250 | if true 251 | G.get_id 252 | G.add [80], A 253 | G.add [80], 7 254 | G.mul [80], 13 255 | 256 | G.jeq :shuffle_done, in_danger, 1 257 | 258 | G.jlt :shuffle_done, dist, 2 259 | 260 | G.jgt :shuffle_done, [80], 10 261 | 262 | G.dbg 263 | 264 | G.add [81], A 265 | G.add [81], 37 266 | G.mul [81], 97 267 | G.mov A, [80] 268 | G.mov B, [81] 269 | G.div A, 64 270 | G.div B, 64 271 | G.add A, p0_imm 272 | G.add B, p0_imm 273 | G.mov C, [A] 274 | G.mov [A], [B] 275 | G.mov [B], C 276 | end 277 | G.label(:shuffle_done) 278 | 279 | 4.times do |d| 280 | # The direction. 281 | G.mov D, [p0_imm + d] 282 | 283 | G.get_id 284 | G.get_stat 285 | G.add B, 2 286 | G.and B, 3 287 | #G.dbg 288 | G.jeq :"invalid_#{d}", B, D 289 | 290 | G.mov A, gx 291 | G.mov C, diff_table_imm 292 | G.add C, D 293 | G.add A, [C] 294 | 295 | G.mov B, gy 296 | G.add C, 4 297 | G.add B, [C] 298 | 299 | #G.dbg 300 | G.get_map 301 | 302 | G.jgt :done, A, 0 303 | 304 | G.label :"invalid_#{d}" 305 | 306 | #G.dbg 307 | end 308 | 309 | G.label(:done) 310 | G.mov A, D 311 | G.set_dir 312 | 313 | G.mov G, 230 314 | G.label :loop 315 | G.sub [G], [253] 316 | G.add G, 1 317 | G.mul [G], [3] 318 | G.add A, [G] 319 | G.mul [G], [7] 320 | G.add B, [G] 321 | G.get_map 322 | G.jlt :loop, G, 250 323 | 324 | G.hlt 325 | 326 | G.emit 327 | -------------------------------------------------------------------------------- /dsl.rb: -------------------------------------------------------------------------------- 1 | require './lman' 2 | 3 | $funcs = {} 4 | 5 | # class Symbol 6 | # %i(+ - * /).each do |s| 7 | # define_method(s) do |a| 8 | # AST.new(s) + a 9 | # end 10 | # end 11 | # end 12 | 13 | class AST 14 | def initialize(op, *args) 15 | @op = op 16 | @args = args 17 | @func = nil 18 | end 19 | 20 | def to_s 21 | "#{@op}(#{@args * ', '})" 22 | end 23 | 24 | def var(n) 25 | a = @args[n] 26 | if a.is_a?(Fixnum) 27 | L.ldc(a) 28 | elsif a.is_a?(Symbol) 29 | L.ld(0, @func.var(a)) 30 | else 31 | a.emit(@func) 32 | end 33 | end 34 | 35 | def +(a) 36 | AST.new(:+, self, a) 37 | end 38 | 39 | def -(a) 40 | AST.new(:-, self, a) 41 | end 42 | 43 | def *(a) 44 | AST.new(:*, self, a) 45 | end 46 | 47 | def /(a) 48 | AST.new(:/, self, a) 49 | end 50 | 51 | def ==(a) 52 | AST.new(:==, self, a) 53 | end 54 | 55 | def >(a) 56 | AST.new(:>, self, a) 57 | end 58 | 59 | def >=(a) 60 | AST.new(:>=, self, a) 61 | end 62 | 63 | def [](n) 64 | a = self 65 | n.times{a = AST.new(:cdr, a)} 66 | AST.new(:car, a) 67 | end 68 | 69 | def at(n, sz) 70 | a = self 71 | n.times{a = AST.new(:cdr, a)} 72 | if n == sz - 1 73 | a 74 | else 75 | AST.new(:car, a) 76 | end 77 | end 78 | 79 | def stmt(n) 80 | var(n) 81 | end 82 | 83 | def emit(func) 84 | @func = func 85 | 86 | case @op 87 | when :ld 88 | var(0) 89 | 90 | when :ldf 91 | L.ldf(@args[0]) 92 | 93 | when :gld 94 | L.ld(2, @args[0]) 95 | 96 | when :gst 97 | var(1) 98 | L.st(2, @args[0]) 99 | 100 | when :ldc 101 | L.ldc(@args[0]) 102 | 103 | when :st 104 | var(1) 105 | L.st(0, func.var(@args[0])) 106 | 107 | when :arg 108 | L.ld(1, @args[0]) 109 | 110 | when :ret 111 | var(0) 112 | L.rtn 113 | 114 | when :car 115 | var(0) 116 | L.car 117 | 118 | when :cdr 119 | var(0) 120 | L.cdr 121 | 122 | when :cons 123 | var(0) 124 | var(1) 125 | L.cons 126 | 127 | when :atom 128 | var(0) 129 | L.atom 130 | 131 | when :if_ 132 | l1 = L.anon_label 133 | l2 = L.anon_label 134 | var(0) 135 | L.tsel(l1, l2) 136 | L.label(l1) 137 | stmt(1) 138 | L.label(l2) 139 | 140 | when :ifelse_ 141 | l1 = L.anon_label 142 | l2 = L.anon_label 143 | l3 = L.anon_label 144 | var(0) 145 | L.tsel(l1, l2) 146 | L.label(l1) 147 | stmt(1) 148 | L.ldc(0) 149 | L.tsel(l3, l3) 150 | L.label(l2) 151 | stmt(2) 152 | L.label(l3) 153 | 154 | when :while_ 155 | l0 = L.anon_label 156 | l1 = L.anon_label 157 | l2 = L.anon_label 158 | L.label(l0) 159 | var(0) 160 | L.tsel(l1, l2) 161 | L.label(l1) 162 | 163 | orig_while = $cur_while 164 | $cur_while = [l0, l2] 165 | #STDERR.puts "enter #{$cur_while}" 166 | stmt(1) 167 | #STDERR.puts "exit #{$cur_while}" 168 | $cur_while = orig_while 169 | 170 | L.ldc(0) 171 | L.tsel(l0, l0) 172 | L.label(l2) 173 | 174 | when :next_ 175 | #STDERR.puts "next #{$cur_while}" 176 | L.ldc(0) 177 | L.tsel($cur_while[0], $cur_while[0]) 178 | 179 | when :break_ 180 | L.ldc(0) 181 | L.tsel($cur_while[1], $cur_while[1]) 182 | 183 | when :do_ 184 | #STDERR.puts @args 185 | #STDERR.puts 186 | @args.size.times do |i| 187 | stmt(i) 188 | end 189 | 190 | when :call 191 | name = @args[0] 192 | args = @args[1..-1] 193 | 194 | if !$funcs[name] 195 | raise "Unknown function: #{name}" 196 | end 197 | if $funcs[name].num_args != args.size 198 | raise "Invalid argument count: #{name}" 199 | end 200 | 201 | args.size.times do |i| 202 | var(i + 1) 203 | end 204 | L.ldf(name) 205 | L.ap(args.size) 206 | 207 | when :+ 208 | var(0) 209 | var(1) 210 | L.add 211 | 212 | when :- 213 | var(0) 214 | var(1) 215 | L.sub 216 | 217 | when :* 218 | var(0) 219 | var(1) 220 | L.mul 221 | 222 | when :/ 223 | var(0) 224 | var(1) 225 | L.div 226 | 227 | when :== 228 | var(0) 229 | var(1) 230 | L.ceq 231 | 232 | when :> 233 | var(0) 234 | var(1) 235 | L.cgt 236 | 237 | when :>= 238 | var(0) 239 | var(1) 240 | L.cgte 241 | 242 | when :dbg 243 | var(0) 244 | L.dbug 245 | 246 | when :brk 247 | L.brk 248 | 249 | when :comment 250 | L.label("# #{@args[0]}".to_sym) 251 | 252 | else 253 | raise "Unknown op: #@op" 254 | end 255 | end 256 | end 257 | 258 | class Func 259 | def initialize(name, *args, &proc) 260 | @name = name 261 | @asts = [] 262 | @vars = {} 263 | 264 | args.each do |a| 265 | alloc_var(a) 266 | end 267 | @args = args 268 | 269 | instance_eval(&proc) 270 | 271 | $funcs[name] = self 272 | end 273 | 274 | def num_args 275 | @args.size 276 | end 277 | 278 | def var(s) 279 | if !@vars[s] 280 | raise "Unknown var: #{s}" 281 | end 282 | @vars[s] 283 | end 284 | 285 | def alloc_var(s) 286 | if !@vars[s] 287 | @vars[s] = @vars.size 288 | end 289 | end 290 | 291 | def ldf(l) 292 | AST.new(:ldf, l) 293 | end 294 | 295 | def ld(s) 296 | AST.new(:ld, s) 297 | end 298 | 299 | def gld(n) 300 | AST.new(:gld, n) 301 | end 302 | 303 | def gst(n, s) 304 | @asts << AST.new(:gst, n, s) 305 | nil 306 | end 307 | 308 | def ldc(n) 309 | AST.new(:ldc, n) 310 | end 311 | 312 | def arg(n) 313 | AST.new(:arg, n) 314 | end 315 | 316 | def car(a) 317 | AST.new(:car, a) 318 | end 319 | 320 | def cdr(a) 321 | AST.new(:cdr, a) 322 | end 323 | 324 | def cons(a, b) 325 | AST.new(:cons, a, b) 326 | end 327 | 328 | def tuple(*a) 329 | v = a.pop 330 | while !a.empty? 331 | v = cons(a.pop, v) 332 | end 333 | v 334 | end 335 | 336 | def list(*a) 337 | v = 0 338 | while !a.empty? 339 | v = cons(a.pop, v) 340 | end 341 | v 342 | end 343 | 344 | def inc(s, n) 345 | st(s, ld(s) + n) 346 | end 347 | 348 | def atom(a) 349 | AST.new(:atom, a) 350 | end 351 | 352 | def st(s, a) 353 | alloc_var(s) 354 | @asts << AST.new(:st, s, a) 355 | nil 356 | end 357 | 358 | def ret(a) 359 | @asts << AST.new(:ret, a) 360 | nil 361 | end 362 | 363 | def if_(s, a) 364 | raise "Not a statement" if a != nil 365 | @asts << AST.new(:if_, s, @asts.pop) 366 | nil 367 | end 368 | 369 | def ifelse_(s, a, b) 370 | raise "Not a statement" if a != nil 371 | raise "Not a statement" if b != nil 372 | b = @asts.pop 373 | a = @asts.pop 374 | @asts << AST.new(:ifelse_, s, a, b) 375 | nil 376 | end 377 | 378 | def while_(s, a) 379 | raise "Not a statement" if a != nil 380 | @asts << AST.new(:while_, s, @asts.pop) 381 | nil 382 | end 383 | 384 | def proc_impl(&a) 385 | oasts = @asts 386 | @asts = [] 387 | l = instance_eval(&a) 388 | r = AST.new(:do_, *@asts) 389 | @asts = oasts 390 | [r, l] 391 | end 392 | 393 | def whileP(s, &a) 394 | r, l = proc_impl(&a) 395 | if l 396 | raise "Not a statement" 397 | end 398 | @asts << AST.new(:while_, s, r) 399 | nil 400 | end 401 | 402 | def ifP(s, &a) 403 | r, l = proc_impl(&a) 404 | if l 405 | raise "Not a statement #{l} (cond=#{s})" 406 | end 407 | @asts << AST.new(:if_, s, r) 408 | nil 409 | end 410 | 411 | def exprP(&a) 412 | r, l = proc_impl(&a) 413 | if !l 414 | raise "Not an expr" 415 | end 416 | AST.new(:do_, r, l) 417 | end 418 | 419 | def do_(*stmts) 420 | asts = [] 421 | stmts.each do |a| 422 | raise "Not a statement" if a != nil 423 | asts << @asts.pop 424 | end 425 | @asts << AST.new(:do_, *asts.reverse) 426 | nil 427 | end 428 | 429 | def next_ 430 | @asts << AST.new(:next_) 431 | nil 432 | end 433 | 434 | def break_ 435 | @asts << AST.new(:break_) 436 | nil 437 | end 438 | 439 | def expr(*stmts) 440 | asts = [] 441 | asts << stmts.pop 442 | stmts.each do |a| 443 | raise "Not a statement" if a != nil 444 | asts << @asts.pop 445 | end 446 | AST.new(:do_, *asts.reverse) 447 | end 448 | 449 | def call(name, *args) 450 | AST.new(:call, name, *args) 451 | end 452 | 453 | def dbg(s) 454 | @asts << AST.new(:dbg, s) 455 | nil 456 | end 457 | 458 | def brk 459 | @asts << AST.new(:brk) 460 | nil 461 | end 462 | 463 | def hlt 464 | dbg(-42) 465 | brk 466 | end 467 | 468 | def comment(s) 469 | @asts << AST.new(:comment, s) 470 | nil 471 | end 472 | 473 | def emit 474 | L.label(@name) 475 | 476 | impl = "#{@name}_impl".to_sym 477 | @args.size.times do |i| 478 | L.ld(0, i) 479 | end 480 | (@vars.size - @args.size).times do |i| 481 | L.ldc(0) 482 | end 483 | 484 | L.ldf(impl) 485 | L.ap(@vars.size) 486 | L.rtn 487 | 488 | L.label(impl) 489 | 490 | @asts.each do |ast| 491 | ast.emit(self) 492 | end 493 | end 494 | end 495 | 496 | def emit 497 | $funcs.each do |name, func| 498 | func.emit 499 | end 500 | L.emit 501 | end 502 | 503 | if $0 == __FILE__ 504 | Func.new(:main, :state, :undocumented) do 505 | st(:ai_state, 0) 506 | ret(cons(:ai_state, ldf(:step))) 507 | end 508 | 509 | Func.new(:step, :ai, :state) do 510 | st(:map, ld(:state)[0]) 511 | st(:x, car(ld(:state)[1][1])) 512 | st(:y, cdr(ld(:state)[1][1])) 513 | 514 | st(:v, call(:getXY, :map, :x, :y)) 515 | dbg(ld(:v)) 516 | 517 | # st(:v, ld(:map)) 518 | # while_(:y, do_(st(:y, ld(:y) - 1), 519 | # st(:v, cdr(ld(:v))))) 520 | # st(:v, car(:v)) 521 | # dbg(ld(:v)) 522 | 523 | #dbg(ld(:x)) 524 | #dbg(ld(:y)) 525 | 526 | st(:s, ld(:ai)) 527 | st(:s, ld(:s) + 1) 528 | if_(ld(:s) == 24, st(:s, 0)) 529 | ret(cons(ld(:s), ld(:s) / 6)) 530 | end 531 | 532 | Func.new(:getXY, :map, :x, :y) do 533 | st(:v, ld(:map)) 534 | while_(:y, do_(st(:y, ld(:y) - 1), 535 | st(:v, cdr(:v)))) 536 | st(:v, car(:v)) 537 | while_(:x, do_(st(:x, ld(:x) - 1), 538 | st(:v, cdr(:v)))) 539 | ret(car(:v)) 540 | end 541 | 542 | emit 543 | end 544 | -------------------------------------------------------------------------------- /ai.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require './dsl' 4 | 5 | DIRS = [[0, -1], [1, 0], [0, 1], [-1, 0]] 6 | 7 | SCORE_SYMS = %i(score_u score_r score_d score_l) 8 | 9 | SCORE_MAX_PARAM = 300000 10 | 11 | SAFE_VIT_PARAM = 400 12 | 13 | NEVER_TOUCH_PILLMAP_LIMIT = 30000 14 | 15 | PILLMAP_LIMIT = 10000 16 | 17 | DIR_SCORE_DIST = 50 18 | #DIR_SCORE_DIST = 50 19 | #DIR_SCORE_DIST = 10 20 | 21 | SUBMAP_SIZE = 10 22 | 23 | def ret_step(s) 24 | st(:ai_state, tuple(:map_size, cons(:pill_map, :pill_num), 25 | :waiting, :game_score)) 26 | ret(cons(:ai_state, s)) 27 | end 28 | 29 | def map_each(map, &proc) 30 | whileP(atom(map) == 0) do 31 | st(:row, car(map)) 32 | st(map, cdr(map)) 33 | whileP(atom(:row) == 0) do 34 | st(:cell, car(:row)) 35 | st(:row, cdr(:row)) 36 | instance_eval(&proc) 37 | end 38 | end 39 | end 40 | 41 | def map_each_pos(map, &proc) 42 | st(:y, 0) 43 | whileP(atom(map) == 0) do 44 | st(:x, 0) 45 | st(:row, car(map)) 46 | st(map, cdr(map)) 47 | whileP(atom(:row) == 0) do 48 | st(:cell, car(:row)) 49 | st(:row, cdr(:row)) 50 | instance_eval(&proc) 51 | inc(:x, 1) 52 | end 53 | inc(:y, 1) 54 | end 55 | end 56 | 57 | Func.new(:main, :state, :undocumented) do 58 | st(:map, ld(:state)[0]) 59 | 60 | st(:map_size, call(:getMapSize, :map)) 61 | st(:pill_map, call(:getPillMap, :map)) 62 | 63 | st(:ai_state, tuple(:map_size, :pill_map, 0, 0)) 64 | #dbg(:ai_state) 65 | 66 | ret(cons(:ai_state, ldf(:step))) 67 | end 68 | 69 | Func.new(:getPillMap, :map) do 70 | st(:pills, 0) 71 | st(:pill_num, 0) 72 | map_each_pos(:map) do 73 | ifP((ld(:cell) > 1) * (ld(5) > :cell)) do 74 | st(:pills, cons(cons(cons(:x, :y), :cell), :pills)) 75 | inc(:pill_num, 1) 76 | end 77 | end 78 | ret(cons(:pills, :pill_num)) 79 | end 80 | 81 | Func.new(:getMapSize, :map) do 82 | st(:size, 0) 83 | map_each(:map) do 84 | inc(:size, 1) 85 | end 86 | ret(:size) 87 | end 88 | 89 | Func.new(:step, :ai_state, :state) do 90 | ret(call(:step_fast, :ai_state, :state)) 91 | end 92 | 93 | def step_prologue 94 | st(:map, ld(:state)[0]) 95 | st(:lman, ld(:state)[1]) 96 | st(:lvit, ld(:lman)[0]) 97 | st(:lpos, ld(:lman)[1]) 98 | st(:ldir, ld(:lman)[2]) 99 | st(:game_score, ld(:lman).at(4, 5)) 100 | st(:ghosts, ld(:state)[2]) 101 | st(:fruit, cdr(cdr(cdr(ld(:state))))) 102 | st(:lx, car(:lpos)) 103 | st(:ly, cdr(:lpos)) 104 | st(:worth_cell, 4) 105 | if_(:fruit, st(:worth_cell, 5)) 106 | 107 | st(:map_size, ld(:ai_state).at(0, 4)) 108 | st(:pill_map, car(ld(:ai_state).at(1, 4))) 109 | st(:pill_num, cdr(ld(:ai_state).at(1, 4))) 110 | st(:waiting, ld(:ai_state).at(2, 4)) 111 | st(:prev_game_score, ld(:ai_state).at(3, 4)) 112 | 113 | inc(:waiting, -1) 114 | ifP(ldc(0) > :waiting) do 115 | st(:waiting, 0) 116 | end 117 | 118 | st(:eating, ld(:game_score) - :prev_game_score) 119 | 120 | comment('Update pill map start') 121 | st(:pills, 0) 122 | #st(:pill_num, 0) 123 | 124 | ifP(ldc(PILLMAP_LIMIT) > ld(:pill_num)) do 125 | whileP(atom(:pill_map) == 0) do 126 | st(:pill, car(:pill_map)) 127 | st(:pos, car(:pill)) 128 | st(:pill_map, cdr(:pill_map)) 129 | ifelse_((car(:pos) == :lx) * (cdr(:pos) == :ly), 130 | inc(:pill_num, -1), 131 | st(:pills, cons(:pill, :pills))) 132 | end 133 | st(:pill_map, :pills) 134 | end 135 | 136 | comment('Update pill map done') 137 | 138 | #dbg(:ai_state) 139 | end 140 | 141 | Func.new(:getSubWall) do 142 | width = SUBMAP_SIZE * 2 + 3 143 | st(:cnt, width) 144 | st(:row, 0) 145 | whileP(:cnt) do 146 | st(:row, cons(0, :row)) 147 | inc(:cnt, -1) 148 | end 149 | ret(:row) 150 | end 151 | 152 | Func.new(:getSubMap, :map, :lx, :ly) do 153 | st(:rmap, 0) 154 | 155 | st(:y, -1) 156 | whileP(expr(inc(:y, 1), atom(:map) == 0)) do 157 | st(:x, -1) 158 | st(:row, car(:map)) 159 | st(:map, cdr(:map)) 160 | st(:rrow, 0) 161 | 162 | st(:dy, ld(:y) - :ly) 163 | if_(ldc(-SUBMAP_SIZE) > ld(:dy), next_) 164 | if_(ld(:dy) > SUBMAP_SIZE, break_) 165 | 166 | whileP(expr(inc(:x, 1), atom(:row) == 0)) do 167 | st(:cell, car(:row)) 168 | st(:row, cdr(:row)) 169 | 170 | st(:dx, ld(:x) - :lx) 171 | if_(ldc(-SUBMAP_SIZE) > ld(:dx), next_) 172 | if_(ld(:dx) > SUBMAP_SIZE, break_) 173 | 174 | #if_(ld(:dx) == 0, if_(ld(:dy) == 0, st(:cell, 999))) 175 | 176 | st(:rrow, cons(:cell, :rrow)) 177 | end 178 | 179 | st(:rmap, cons(:rrow, :rmap)) 180 | end 181 | 182 | st(:sub_map, 0) 183 | st(:sub_map, cons(call(:getSubWall), :sub_map)) 184 | 185 | whileP(atom(:rmap) == 0) do 186 | #dbg(:sub_map) 187 | 188 | st(:rrow, car(:rmap)) 189 | st(:rmap, cdr(:rmap)) 190 | st(:row, 0) 191 | 192 | st(:row, cons(0, :row)) 193 | 194 | whileP(atom(:rrow) == 0) do 195 | st(:cell, car(:rrow)) 196 | st(:rrow, cdr(:rrow)) 197 | 198 | st(:row, cons(:cell, :row)) 199 | end 200 | 201 | st(:row, cons(0, :row)) 202 | 203 | st(:sub_map, cons(:row, :sub_map)) 204 | end 205 | 206 | st(:sub_map, cons(call(:getSubWall), :sub_map)) 207 | 208 | ret(:sub_map) 209 | end 210 | 211 | def get_abs(s) 212 | if_(ldc(0) > s, st(s, ldc(0) - s)) 213 | end 214 | 215 | Func.new(:getOppDir, :dir) do 216 | if_(ld(:dir) == 0, ret(2)) 217 | if_(ld(:dir) == 1, ret(3)) 218 | if_(ld(:dir) == 2, ret(0)) 219 | if_(ld(:dir) == 3, ret(1)) 220 | hlt 221 | end 222 | 223 | def get_dir_score_prologue 224 | st(:lodir, call(:getOppDir, :ldir)) 225 | SCORE_SYMS.each_with_index do |sym, i| 226 | st(sym, 0) 227 | ifP(call(:getXY, :map, ld(:lx) + DIRS[i][0], ld(:ly) + DIRS[i][1]) == 0) do 228 | st(sym, SCORE_MAX_PARAM * -3) 229 | end 230 | ifP(ld(:lodir) == i) do 231 | ifP(ld(:eating) == 0) do 232 | #inc(sym, -SCORE_MAX_PARAM) 233 | inc(sym, -SCORE_MAX_PARAM / 5) 234 | #inc(sym, -SCORE_MAX_PARAM / 10) 235 | end 236 | end 237 | ifP(ld(:best_move) == i) do 238 | #inc(sym, SCORE_MAX_PARAM / 10) 239 | ifelse_(:going_to_fruit, 240 | inc(sym, SCORE_MAX_PARAM * 3 / 2), 241 | inc(sym, SCORE_MAX_PARAM / 3)) 242 | end 243 | 244 | ifP(ld(:lvit) > ldc(SAFE_VIT_PARAM)) do 245 | st(:lnpos, call(:getMoved, cons(:lx, :ly), i)) 246 | st(:ghost_iter, :ghosts) 247 | whileP(atom(:ghost_iter) == 0) do 248 | st(:ghost, car(:ghost_iter)) 249 | st(:ghost_iter, cdr(:ghost_iter)) 250 | st(:gvit, ld(:ghost)[0]) 251 | st(:gpos, ld(:ghost)[1]) 252 | st(:gdir, cdr(cdr(ld(:ghost)))) 253 | 254 | ifP(ld(:gvit) == 1) do 255 | ifP(ldc(2) >= call(:getDist, :lnpos, :gpos)) do 256 | inc(sym, SCORE_MAX_PARAM * 2) 257 | end 258 | st(:gnpos, call(:getMoved, :gpos, :gdir)) 259 | ifP(ldc(2) >= call(:getDist, :lnpos, :gnpos)) do 260 | #dbg(tuple(424243, i, :lnpos, :gnpos)) 261 | inc(sym, SCORE_MAX_PARAM * 2) 262 | end 263 | 264 | ifP(car(:lnpos) == car(:gpos)) do 265 | ifP(cdr(:lnpos) == cdr(:gpos)) do 266 | inc(sym, SCORE_MAX_PARAM * 20) 267 | end 268 | end 269 | 270 | ifP(car(:lnpos) == car(:gnpos)) do 271 | ifP(cdr(:lnpos) == cdr(:gnpos)) do 272 | inc(sym, SCORE_MAX_PARAM * 10) 273 | end 274 | end 275 | 276 | end 277 | end 278 | end 279 | 280 | ifP(ldc(SAFE_VIT_PARAM) > ld(:lvit)) do 281 | st(:lnpos, call(:getMoved, cons(:lx, :ly), i)) 282 | st(:ghost_iter, :ghosts) 283 | whileP(atom(:ghost_iter) == 0) do 284 | st(:ghost, car(:ghost_iter)) 285 | st(:ghost_iter, cdr(:ghost_iter)) 286 | st(:gpos, ld(:ghost)[1]) 287 | st(:gdir, cdr(cdr(ld(:ghost)))) 288 | st(:gnpos, call(:getMoved, :gpos, :gdir)) 289 | 290 | st(:dx, car(:gnpos) - car(:lnpos)) 291 | st(:dy, cdr(:gnpos) - cdr(:lnpos)) 292 | 293 | get_dir_score_core do |sym| 294 | st(sym, ld(sym) - ldc(SCORE_MAX_PARAM) / :d / :d) 295 | #st(sym, ld(sym) - ldc(SCORE_MAX_PARAM) / :d) 296 | end 297 | 298 | end 299 | end 300 | 301 | end 302 | end 303 | 304 | def get_dir_score_core(&calc_score) 305 | SCORE_SYMS.each_with_index do |sym, i| 306 | if i == 0 307 | st(:pd, ldc(0) - :dy) 308 | elsif i == 1 309 | st(:pd, :dx) 310 | elsif i == 2 311 | st(:pd, :dy) 312 | elsif i == 3 313 | st(:pd, ldc(0) - :dx) 314 | else 315 | raise 316 | end 317 | 318 | ifP(ld(:pd) > 0) do 319 | if i == 0 || i == 2 320 | st(:sd, :dx) 321 | elsif i == 1 || i == 3 322 | st(:sd, :dy) 323 | else 324 | raise 325 | end 326 | 327 | get_abs(:sd) 328 | 329 | ifP(ld(:pd) >= (:sd)) do 330 | st(:d, ld(:sd) + :pd) 331 | 332 | calc_score[sym] 333 | end 334 | 335 | end 336 | 337 | end 338 | nil 339 | end 340 | 341 | Func.new(:getDirScores, :map, :lx, :ly, :ldir, :worth_cell, :best_move, 342 | :lvit, :ghosts, :eating, :going_to_fruit) do 343 | get_dir_score_prologue 344 | 345 | st(:y, -1) 346 | whileP(expr(inc(:y, 1), atom(:map) == 0)) do 347 | st(:x, -1) 348 | st(:row, car(:map)) 349 | st(:map, cdr(:map)) 350 | 351 | st(:dy, ld(:y) - :ly) 352 | if_(ldc(-DIR_SCORE_DIST) > ld(:dy), next_) 353 | if_(ld(:dy) > DIR_SCORE_DIST, break_) 354 | 355 | whileP(expr(inc(:x, 1), atom(:row) == 0)) do 356 | st(:cell, car(:row)) 357 | st(:row, cdr(:row)) 358 | 359 | st(:dx, ld(:x) - :lx) 360 | if_(ldc(-DIR_SCORE_DIST) > ld(:dx), next_) 361 | if_(ld(:dx) > DIR_SCORE_DIST, break_) 362 | 363 | ifP((ld(:cell) > 1) * (ld(:worth_cell) > :cell)) do 364 | #dbg(cons(:x, :y)) 365 | 366 | get_dir_score_core do |sym| 367 | st(sym, ld(sym) + ldc(SCORE_MAX_PARAM) / :d / :d) 368 | end 369 | end 370 | end 371 | end 372 | 373 | ret(tuple(:score_u, :score_r, :score_d, :score_l)) 374 | end 375 | 376 | Func.new(:getDirScores2, :map, :lx, :ly, :ldir, 377 | :worth_cell, :pill_map, :best_move, 378 | :lvit, :ghosts, :eating, :going_to_fruit) do 379 | get_dir_score_prologue 380 | 381 | whileP(atom(:pill_map) == 0) do 382 | st(:pill, car(:pill_map)) 383 | st(:x, car(car(:pill))) 384 | st(:y, cdr(car(:pill))) 385 | st(:cell, cdr(:pill)) 386 | st(:pill_map, cdr(:pill_map)) 387 | 388 | if_(ld(:worth_cell) == :cell, next_) 389 | 390 | st(:dy, ld(:y) - :ly) 391 | st(:dx, ld(:x) - :lx) 392 | 393 | get_dir_score_core do |sym| 394 | st(sym, ld(sym) + ldc(SCORE_MAX_PARAM) / :d / :d) 395 | end 396 | end 397 | 398 | ret(tuple(:score_u, :score_r, :score_d, :score_l)) 399 | end 400 | 401 | Func.new(:step_fast, :ai_state, :state) do 402 | step_prologue 403 | 404 | comment('Call getSubMap') 405 | 406 | st(:sub_map, call(:getSubMap, :map, :lx, :ly)) 407 | #dbg(:sub_map) 408 | st(:dist, call(:getInitDistMap, :sub_map)) 409 | st(:cx, SUBMAP_SIZE + 1) 410 | st(:cy, SUBMAP_SIZE + 1) 411 | ifP(ldc(SUBMAP_SIZE) > :lx) do 412 | st(:cx, ld(:lx) + 1) 413 | end 414 | ifP(ldc(SUBMAP_SIZE) > :ly) do 415 | st(:cy, ld(:ly) + 1) 416 | end 417 | st(:cpos, cons(:cx, :cy)) 418 | st(:adj, cons(ld(:cx) - :lx, ld(:cy) - :ly)) 419 | 420 | st(:dist, call(:fillDistMap, :sub_map, :dist, :cpos)) 421 | #st(:sub_map, call(:setXY, :sub_map, SUBMAP_SIZE + 1, SUBMAP_SIZE + 1, 777)) 422 | #dbg(:sub_map) 423 | #dbg(:dist) 424 | st(:best_move, call(:getBestMove, :sub_map, :dist, :worth_cell, 425 | 1, 1, 1, 1)) 426 | st(:going_to_fruit, cdr(:best_move) == -1) 427 | st(:best_move, car(:best_move)) 428 | 429 | #st(:dir_scores, call(:getDirScores, :map, :lx, :ly, :ldir, :worth_cell)) 430 | ifelse_(ldc(PILLMAP_LIMIT) > ld(:pill_num), 431 | st(:dir_scores, call(:getDirScores2, :map, :lx, :ly, :ldir, 432 | :worth_cell, :pill_map, :best_move, 433 | :lvit, :ghosts, :eating, :going_to_fruit)), 434 | st(:dir_scores, call(:getDirScores, :map, :lx, :ly, :ldir, 435 | :worth_cell, :best_move, 436 | :lvit, :ghosts, :eating, :going_to_fruit))) 437 | 438 | dbg(tuple(:map_size, :pill_num, :dir_scores, :waiting, :eating)) 439 | 440 | ifP(ldc(SAFE_VIT_PARAM) > :lvit) do 441 | st(:best_move, -1) 442 | st(:best_score, SCORE_MAX_PARAM * -4) 443 | %i(ok_u ok_r ok_d ok_l).each_with_index do |ok, i| 444 | st(ok, call(:isOK_d, :map, :lpos, i, (i + 2) % 4, :ghosts, :dist, :adj)) 445 | 446 | ifP(ld(ok) == 2) do 447 | inc(:waiting, 3) 448 | ifP(ldc(1000) > ld(:fruit)) do 449 | ifP(ldc(200) > :waiting) do 450 | DIRS.each_with_index do |dir, i| 451 | ifP(call(:getXY, :map, 452 | ld(:lx) + dir[0], ld(:ly) + dir[1]) == 0) do 453 | ret_step(i) 454 | end 455 | end 456 | 457 | st(ok, 0) 458 | end 459 | end 460 | end 461 | 462 | ifP(ok) do 463 | st(:score, ld(:dir_scores).at(i, 4)) 464 | ifP(ld(:score) > :best_score) do 465 | st(:best_score, :score) 466 | st(:best_move, i) 467 | end 468 | end 469 | end 470 | ifP(ld(:best_move) >= 0) do 471 | ret_step(:best_move) 472 | end 473 | end 474 | 475 | %i(ok_u ok_r ok_d ok_l).each_with_index do |ok, i| 476 | st(:score, ld(:dir_scores).at(i, 4)) 477 | ifP(ld(:score) > :best_score) do 478 | st(:best_score, :score) 479 | st(:best_move, i) 480 | end 481 | end 482 | ifP(ld(:best_move) >= 0) do 483 | ret_step(:best_move) 484 | end 485 | 486 | dbg(-999) 487 | ret_step(2) 488 | end 489 | 490 | Func.new(:step_slow, :ai_state, :state) do 491 | step_prologue 492 | 493 | #st(:x, :lx) 494 | #st(:y, :ly) 495 | #dbg(cons(:lx, :ly)) 496 | #dbg(cons(:x, :y)) 497 | #dbg(ld(:move) == 0) 498 | 499 | st(:dist, call(:getInitDistMap, :map)) 500 | st(:dist, call(:fillDistMap, :map, :dist, :lpos)) 501 | #st(:dist, call(:setXY, :dist, 1, 1, 42)) 502 | #dbg(:dist) 503 | 504 | ifP(ldc(SAFE_VIT_PARAM) > :lvit) do 505 | %i(ok_u ok_r ok_d ok_l).each_with_index do |ok, i| 506 | st(ok, call(:isOK, :map, :lpos, i, (i + 2) % 4, :ghosts)) 507 | end 508 | 509 | st(:best_move, car(call(:getBestMove, :map, :dist, :worth_cell, 510 | :ok_u, :ok_r, :ok_d, :ok_l))) 511 | ifP(ld(:best_move) >= 0) do 512 | dbg(cons(list(:ok_u, :ok_r, :ok_d, :ok_l), :best_move)) 513 | ret_step(:best_move) 514 | end 515 | 516 | ifP(ldc(4) > ld(:ok_u) + :ok_r + :ok_d + :ok_l) do 517 | %i(ok_u ok_r ok_d ok_l).each_with_index do |ok, i| 518 | ifP(ok) do 519 | ifP(call(:getXY, :map, 520 | ld(:lx) + DIRS[i][0], ld(:ly) + DIRS[i][1])) do 521 | dbg(cons(i, list(:ok_u, :ok_r, :ok_d, :ok_l))) 522 | ret_step(i) 523 | end 524 | end 525 | end 526 | nil 527 | end 528 | 529 | dbg(list(:ok_u, :ok_r, :ok_d, :ok_l)) 530 | end 531 | 532 | st(:best_move, car(call(:getBestMove, :map, :dist, :worth_cell, 533 | 1, 1, 1, 1))) 534 | dbg(cons(:lvit, :best_move)) 535 | 536 | st(:move, :best_move) 537 | 538 | # whileP(exprP{ 539 | # st(:x, :lx) 540 | # st(:y, :ly) 541 | # if_(ld(:move) == 0, st(:y, ld(:y) - 1)) 542 | # if_(ld(:move) == 1, st(:x, ld(:x) + 1)) 543 | # if_(ld(:move) == 2, st(:y, ld(:y) + 1)) 544 | # if_(ld(:move) == 3, st(:x, ld(:x) - 1)) 545 | # call(:getXY, :map, :x, :y) == 0 546 | # }) do 547 | # st(:move, ld(:move) + 1) 548 | # if_(ld(:move) == 4, st(:move, 0)) 549 | # end 550 | 551 | #st(:a, 42) 552 | #st(:b, 43) 553 | #dbg(ld(:a) >= ld(:b)) 554 | 555 | ret_step(:move) 556 | end 557 | 558 | Func.new(:getBestMove, :map, :dist, :worth_cell, 559 | :ok_u, :ok_r, :ok_d, :ok_l) do 560 | st(:y, 0) 561 | st(:best_dist, 9999999) 562 | st(:best_move, -1) 563 | whileP(atom(:dist) == 0) do 564 | st(:x, 0) 565 | st(:row, car(:dist)) 566 | st(:dist, cdr(:dist)) 567 | 568 | whileP(atom(:row) == 0) do 569 | st(:v, car(:row)) 570 | st(:row, cdr(:row)) 571 | 572 | st(:d, car(:v)) 573 | ifP(ld(:d) > 0) do 574 | #dbg(list(:x, :y)) 575 | st(:c, call(:getXY, :map, :x, :y)) 576 | ifP((ld(:c) > 1) * (ld(:worth_cell) > :c)) do 577 | ifP(ld(:c) == 4) do 578 | dbg(tuple(49494949, :best_dist, cdr(:v))) 579 | st(:d, -1) 580 | end 581 | 582 | ifP(ld(:best_dist) > ld(:d)) do 583 | st(:move, cdr(:v)) 584 | st(:ok, ((ld(:move) == 0) * :ok_u + 585 | (ld(:move) == 1) * :ok_r + 586 | (ld(:move) == 2) * :ok_d + 587 | (ld(:move) == 3) * :ok_l)) 588 | 589 | ifP(:ok) do 590 | st(:best_dist, :d) 591 | st(:best_move, cdr(:v)) 592 | end 593 | end 594 | end 595 | end 596 | 597 | st(:x, ld(:x) + 1) 598 | end 599 | st(:y, ld(:y) + 1) 600 | end 601 | ret(cons(:best_move, :best_dist)) 602 | end 603 | 604 | Func.new(:getXY, :map, :x, :y) do 605 | st(:v, ld(:map)) 606 | while_(:y, do_(st(:y, ld(:y) - 1), 607 | st(:v, cdr(:v)))) 608 | st(:v, car(:v)) 609 | while_(:x, do_(st(:x, ld(:x) - 1), 610 | st(:v, cdr(:v)))) 611 | ret(car(:v)) 612 | end 613 | 614 | Func.new(:setXYRow, :row, :x, :v) do 615 | if_(:x, ret(cons(car(:row), call(:setXYRow, cdr(:row), ld(:x) - 1, :v)))) 616 | ret(cons(:v, cdr(:row))) 617 | end 618 | 619 | Func.new(:setXY, :map, :x, :y, :v) do 620 | if_(:y, ret(cons(car(:map), call(:setXY, cdr(:map), :x, ld(:y) - 1, :v)))) 621 | ret(cons(call(:setXYRow, car(:map), :x, :v), cdr(:map))) 622 | end 623 | 624 | Func.new(:fillDistMap, :map, :dist, :pos) do 625 | st(:x, car(:pos)) 626 | st(:y, cdr(:pos)) 627 | st(:dist, call(:setXY, :dist, :x, :y, cons(1, -1))) 628 | st(:tasks, list(cons(cons(:x, ld(:y) - 1), 0), 629 | cons(cons(ld(:x) + 1, :y), 1), 630 | cons(cons(:x, ld(:y) + 1), 2), 631 | cons(cons(ld(:x) - 1, :y), 3))) 632 | 633 | #st(:limit, 0) 634 | #st(:cnt, 0) 635 | 636 | st(:d, 2) 637 | 638 | #whileP((atom(:tasks) == 0) * (ldc(10) > ld(:d))) do 639 | #whileP((atom(:tasks) == 0) * :limit) do 640 | whileP((atom(:tasks) == 0)) do 641 | st(:ntasks, 0) 642 | whileP(atom(:tasks) == 0) do 643 | #inc(:limit, -1) 644 | #inc(:cnt, 1) 645 | 646 | st(:task, car(:tasks)) 647 | st(:tasks, cdr(:tasks)) 648 | st(:pos, car(:task)) 649 | st(:m, cdr(:task)) 650 | st(:x, car(:pos)) 651 | st(:y, cdr(:pos)) 652 | 653 | #dbg(:pos) 654 | #dbg(:m) 655 | #dbg(car(call(:getXY, :dist, :x, :y)) == 0) 656 | 657 | ifP(car(call(:getXY, :dist, :x, :y)) == 0) do 658 | st(:dist, call(:setXY, :dist, :x, :y, cons(:d, :m))) 659 | st(:ntasks, cons(cons(cons(ld(:x) + 1, :y), :m), :ntasks)) 660 | st(:ntasks, cons(cons(cons(ld(:x) - 1, :y), :m), :ntasks)) 661 | st(:ntasks, cons(cons(cons(:x, ld(:y) + 1), :m), :ntasks)) 662 | st(:ntasks, cons(cons(cons(:x, ld(:y) - 1), :m), :ntasks)) 663 | end 664 | end 665 | 666 | st(:d, ld(:d) + 1) 667 | st(:tasks, :ntasks) 668 | #dbg(:d) 669 | #dbg(:dist) 670 | #dbg(:tasks) 671 | end 672 | 673 | #dbg(:cnt) 674 | 675 | ret(:dist) 676 | end 677 | 678 | Func.new(:getInitDistRow, :row) do 679 | if_(atom(:row), ret(0)) 680 | st(:v, car(:row)) 681 | if_(ld(:v) == 0, (st(:v, -1))) 682 | if_(ld(:v) > 0, (st(:v, 0))) 683 | ret(cons(cons(:v, -1), call(:getInitDistRow, cdr(:row)))) 684 | end 685 | 686 | Func.new(:getInitDistMap, :map) do 687 | if_(atom(:map), ret(0)) 688 | ret(cons(call(:getInitDistRow, car(:map)), call(:getInitDistMap, cdr(:map)))) 689 | end 690 | 691 | Func.new(:getEmptyRow, :row) do 692 | if_(atom(:row), ret(0)) 693 | ret(cons(0, call(:getEmptyRow, cdr(:row)))) 694 | end 695 | 696 | Func.new(:getEmptyMap, :map) do 697 | if_(atom(:map), ret(0)) 698 | ret(cons(call(:getEmptyRow, car(:map)), call(:getEmptyMap, cdr(:map)))) 699 | end 700 | 701 | # The direction from :pos to :tpos. 702 | Func.new(:getDir, :pos, :tpos) do 703 | ifP(car(:pos) == car(:tpos)) do 704 | ifP(cdr(:pos) > cdr(:tpos)) do 705 | ret(0) 706 | end 707 | ret(2) 708 | end 709 | ifP(cdr(:pos) == cdr(:tpos)) do 710 | ifP(car(:pos) > car(:tpos)) do 711 | ret(3) 712 | end 713 | ret(1) 714 | end 715 | ret(-1) 716 | end 717 | 718 | Func.new(:getDist, :pos, :tpos) do 719 | st(:dx, car(:pos) - car(:tpos)) 720 | st(:dy, cdr(:pos) - cdr(:tpos)) 721 | if_(ldc(0) > :dx, st(:dx, ldc(0) - :dx)) 722 | if_(ldc(0) > :dy, st(:dy, ldc(0) - :dy)) 723 | ret(ld(:dx) + :dy) 724 | end 725 | 726 | Func.new(:getMoved, :pos, :dir) do 727 | 4.times do |i| 728 | ifP(ld(:dir) == i) do 729 | ret(cons(car(:pos) + DIRS[i][0], cdr(:pos) + DIRS[i][1])) 730 | end 731 | end 732 | hlt 733 | end 734 | 735 | Func.new(:isVisible, :map, :pos, :tpos, :dir) do 736 | #dbg(list(:pos, :tpos, :dir)) 737 | whileP((car(:pos) == car(:tpos)) * (cdr(:pos) == cdr(:tpos)) == 0) do 738 | #dbg(:pos) 739 | ifP(call(:getXY, :map, car(:pos), cdr(:pos)) == 0) do 740 | #dbg(:pos) 741 | ret(0) 742 | end 743 | st(:pos, call(:getMoved, :pos, :dir)) 744 | end 745 | ret(1) 746 | end 747 | 748 | Func.new(:isVisible_d, :map, :pos, :tpos, :dir) do 749 | #dbg(list(:pos, :tpos, :dir)) 750 | whileP((car(:pos) == car(:tpos)) * (cdr(:pos) == cdr(:tpos)) == 0) do 751 | #dbg(:pos) 752 | ifP(call(:getXY, :map, car(:pos), cdr(:pos)) == 0) do 753 | #dbg(:pos) 754 | ret(0) 755 | end 756 | st(:pos, call(:getMoved, :pos, :dir)) 757 | end 758 | ret(1) 759 | end 760 | 761 | def is_ok_impl(&check_ghost_dist) 762 | st(:lnpos, call(:getMoved, :lpos, :ldir)) 763 | 764 | st(:cell, call(:getXY, :map, car(:lnpos), cdr(:lnpos))) 765 | st(:danger_ret, 0) 766 | ifP(ld(:cell) == 3) do 767 | st(:danger_ret, 1) 768 | end 769 | 770 | st(:min_gdist, 999) 771 | 772 | whileP(atom(:ghosts) == 0) do 773 | st(:ghost, car(:ghosts)) 774 | st(:ghosts, cdr(:ghosts)) 775 | st(:gpos, ld(:ghost)[1]) 776 | st(:gdir, cdr(cdr(ld(:ghost)))) 777 | 778 | ifP(ld(:lodir) == :gdir) do 779 | ifP(call(:getDir, :gpos, :lpos) == :gdir) do 780 | ifP(call(:isVisible, :map, :gpos, :lpos, :gdir)) do 781 | ret(:danger_ret) 782 | end 783 | end 784 | end 785 | 786 | st(:gdist, call(:getDist, :lnpos, :gpos)) 787 | 788 | ifP(ld(:min_gdist) > :gdist) do 789 | st(:min_gdist, :gdist) 790 | end 791 | 792 | instance_eval(&check_ghost_dist) 793 | end 794 | 795 | ifP(ld(:cell) == 3) do 796 | #ifP(ld(:min_gdist) > 2) do 797 | ifP(ld(:min_gdist) > 1) do 798 | ret(2) 799 | end 800 | end 801 | 802 | ret(1) 803 | end 804 | 805 | Func.new(:isOK, :map, :lpos, :ldir, :lodir, :ghosts) do 806 | is_ok_impl do 807 | near_param = 2 808 | ifP(ldc(near_param) >= :gdist) do 809 | ret(:danger_ret) 810 | end 811 | end 812 | end 813 | 814 | Func.new(:isOK_d, :map, :lpos, :ldir, :lodir, :ghosts, :dist, :adj) do 815 | is_ok_impl do 816 | near_param = 2 817 | ifP(ldc(near_param) >= :gdist) do 818 | ifP(ldc(near_param + 2) >= 819 | car(call(:getXY, :dist, 820 | car(:gpos) + car(:adj), cdr(:gpos) + cdr(:adj)))) do 821 | ret(:danger_ret) 822 | end 823 | end 824 | # st(:gnpos, call(:getMoved, :gpos, :gdir)) 825 | # ifP(ldc(near_param) >= call(:getDist, :lnpos, :gnpos)) do 826 | # ifP(ldc(near_param + 2) >= 827 | # car(call(:getXY, :dist, 828 | # car(:gnpos) + car(:adj), cdr(:gnpos) + cdr(:adj)))) do 829 | # ret(0) 830 | # end 831 | # end 832 | end 833 | end 834 | 835 | emit 836 | -------------------------------------------------------------------------------- /sim.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "bufio" 4 | import "bytes" 5 | import "io" 6 | import "flag" 7 | import "fmt" 8 | import "os" 9 | import "strconv" 10 | import "strings" 11 | 12 | var flag_call_stat = flag.Bool("call_stat", false, "") 13 | var flag_pc_stat = flag.Bool("pc_stat", false, "") 14 | var flag_quiet = flag.Bool("quiet", false, "") 15 | 16 | // Utility 17 | 18 | func Error(msg string) { 19 | panic(msg) 20 | //fmt.Println(msg) 21 | //os.Exit(1) 22 | } 23 | 24 | func OpenFile(name string) *bufio.Reader { 25 | fp, err := os.Open(name) 26 | if err != nil { panic(err) } 27 | return bufio.NewReader(fp) 28 | } 29 | 30 | func ReadLines(filename string) []string { 31 | fmt.Printf("Parsing %s...\n", filename) 32 | fp := OpenFile(filename) 33 | lines := []string{} 34 | for true { 35 | line, err := fp.ReadString('\n') 36 | if err == io.EOF { break } 37 | toks := strings.Split(line, ";") 38 | line = strings.TrimRight(toks[0], " \n") 39 | lines = append(lines, line) 40 | } 41 | return lines 42 | } 43 | 44 | // For both GHC / GCC 45 | 46 | const ( 47 | MOV = iota 48 | INC 49 | DEC 50 | ADD 51 | SUB 52 | MUL 53 | DIV 54 | AND 55 | OR 56 | XOR 57 | JLT 58 | JEQ 59 | JGT 60 | INT 61 | HLT 62 | 63 | LDC 64 | LD 65 | // ADD SUB MUL DIV 66 | CEQ 67 | CGT 68 | CGTE 69 | ATOM 70 | CONS 71 | CAR 72 | CDR 73 | SEL 74 | JOIN 75 | LDF 76 | AP 77 | RTN 78 | DUM 79 | RAP 80 | STOP 81 | TSEL 82 | TAP 83 | TRAP 84 | ST 85 | DBUG 86 | BRK 87 | ) 88 | 89 | var OP_STRS = [...]string{ 90 | "MOV", 91 | "INC", 92 | "DEC", 93 | "ADD", 94 | "SUB", 95 | "MUL", 96 | "DIV", 97 | "AND", 98 | "OR", 99 | "XOR", 100 | "JLT", 101 | "JEQ", 102 | "JGT", 103 | "INT", 104 | "HLT", 105 | 106 | "LDC", 107 | "LD", 108 | // ADD SUB MUL DIV 109 | "CEQ", 110 | "CGT", 111 | "CGTE", 112 | "ATOM", 113 | "CONS", 114 | "CAR", 115 | "CDR", 116 | "SEL", 117 | "JOIN", 118 | "LDF", 119 | "AP", 120 | "RTN", 121 | "DUM", 122 | "RAP", 123 | "STOP", 124 | "TSEL", 125 | "TAP", 126 | "TRAP", 127 | "ST", 128 | "DBUG", 129 | "BRK", 130 | } 131 | 132 | // GHC 133 | 134 | const ( 135 | PC = 8 136 | ) 137 | 138 | const ( 139 | REG = iota 140 | IMM 141 | REG_REF 142 | IMM_REF 143 | ) 144 | 145 | type GHCArg struct { 146 | ty int 147 | v uint8 148 | } 149 | 150 | type GHCInst struct { 151 | op int 152 | args []GHCArg 153 | } 154 | 155 | type GHC []*GHCInst 156 | 157 | func ParseGHC(filename string) *GHC { 158 | lines := ReadLines(filename) 159 | ghc := new(GHC) 160 | for n, line := range(lines) { 161 | n++ 162 | if len(line) == 0 { 163 | continue 164 | } 165 | 166 | toks := strings.Split(line, " ") 167 | if len(toks) > 2 { 168 | Error(fmt.Sprintf("GHC: too many ops at %d: %s", n, line)) 169 | } 170 | 171 | op := -1 172 | for i, o := range(OP_STRS) { 173 | if o == strings.ToUpper(toks[0]) { 174 | op = i 175 | break 176 | } 177 | } 178 | if op == -1 || op > HLT { 179 | Error(fmt.Sprintf("GHC: invalid op at %d: %s", n, line)) 180 | } 181 | 182 | if op == HLT && len(toks) != 1 || op != HLT && len(toks) != 2 { 183 | Error(fmt.Sprintf("GHC: invalid args at %d: %s", n, line)) 184 | } 185 | 186 | inst := new(GHCInst) 187 | inst.op = op 188 | 189 | if op != HLT { 190 | toks = strings.Split(toks[1], ",") 191 | expected_num_args := 2 192 | if op == INC || op == DEC || op == INT { 193 | expected_num_args = 1 194 | } 195 | if op == JLT || op == JEQ || op == JGT { 196 | expected_num_args = 3 197 | } 198 | if len(toks) != expected_num_args { 199 | Error(fmt.Sprintf( 200 | "GHC: unexpected number of args at %d: %s", n, line)) 201 | } 202 | 203 | var args []GHCArg 204 | for _, a := range(toks) { 205 | var arg GHCArg 206 | ref := 0 207 | if a[0] == '[' { 208 | a = strings.TrimLeft(a, "[") 209 | a = strings.TrimRight(a, "]") 210 | ref = 2 211 | } 212 | 213 | if a[0] >= '0' && a[0] <= '9' { 214 | arg.ty = IMM | ref 215 | v, e := strconv.Atoi(a) 216 | if e != nil { panic(e) } 217 | if v < 0 || v > 255 { 218 | Error(fmt.Sprintf( 219 | "GHC: invalid arg at %d: %s", n, line)) 220 | } 221 | arg.v = uint8(v) 222 | } else if len(a) == 1 { 223 | arg.ty = REG | ref 224 | v := int(a[0] - 'a') 225 | if arg.v < 0 || arg.v > 7 { 226 | Error(fmt.Sprintf( 227 | "GHC: invalid arg at %d: %s", n, line)) 228 | } 229 | arg.v = uint8(v) 230 | } else if a == "pc" { 231 | arg.ty = REG | ref 232 | arg.v = PC 233 | } else { 234 | Error(fmt.Sprintf( 235 | "GHC: invalid arg at %d: %s", n, line)) 236 | } 237 | 238 | args = append(args, arg) 239 | } 240 | 241 | if op == INT || op == JLT || op == JEQ || op == JGT { 242 | if args[0].ty != IMM { 243 | Error(fmt.Sprintf( 244 | "GHC: invalid jmp target at %d: %s", n, line)) 245 | } 246 | } 247 | 248 | inst.args = args 249 | } 250 | 251 | *ghc = append(*ghc, inst) 252 | 253 | if len(*ghc) > 256 { 254 | Error(fmt.Sprintf("GHC: too many instructions at %d: %s", n, line)) 255 | } 256 | } 257 | 258 | return ghc 259 | } 260 | 261 | type GHCState struct { 262 | ghc GHC 263 | reg [9]uint8 264 | mem *[256]uint8 265 | mp *Map 266 | ghost *Ghost 267 | plan int 268 | } 269 | 270 | func (st *GHCState) getV(a GHCArg) uint8 { 271 | v := a.v 272 | if (a.ty & 1) == REG { 273 | v = st.reg[v] 274 | } 275 | return v 276 | } 277 | 278 | func (st *GHCState) get(a GHCArg) uint8 { 279 | v := st.getV(a) 280 | if (a.ty & 2) == 2 { 281 | v = st.mem[v] 282 | } 283 | return v 284 | } 285 | 286 | func (st *GHCState) set(a GHCArg, v uint8) { 287 | if (a.ty & 2) == 2 { 288 | st.mem[st.getV(a)] = v 289 | } else if a.ty == REG { 290 | st.reg[a.v] = v 291 | } else { 292 | Error("GHC: Invalid output operand") 293 | } 294 | } 295 | 296 | func (st *GHCState) runInt(id uint8) { 297 | switch id { 298 | case 0: 299 | plan := int(st.reg[0]) 300 | if plan >= 0 && plan < 4 { 301 | st.plan = plan 302 | } 303 | case 1: 304 | st.reg[0] = uint8(st.mp.lman.pos.x) 305 | st.reg[1] = uint8(st.mp.lman.pos.y) 306 | case 2: 307 | Error("GHC: int 2 is undefined") 308 | case 3: 309 | st.reg[0] = uint8(st.ghost.id) 310 | case 4: 311 | g := st.mp.ghosts[st.reg[0]] 312 | st.reg[0] = uint8(g.opos.x) 313 | st.reg[1] = uint8(g.opos.y) 314 | case 5: 315 | g := st.mp.ghosts[st.reg[0]] 316 | st.reg[0] = uint8(g.pos.x) 317 | st.reg[1] = uint8(g.pos.y) 318 | case 6: 319 | g := st.mp.ghosts[st.reg[0]] 320 | st.reg[0] = uint8(g.vit) 321 | st.reg[1] = uint8(g.plan) 322 | case 7: 323 | x := int(st.reg[0]) 324 | y := int(st.reg[1]) 325 | if x >= st.mp.width || y >= st.mp.height { 326 | st.reg[0] = 0 327 | } else { 328 | st.reg[0] = uint8(st.mp.get(x, y)) 329 | } 330 | case 8: 331 | var buf bytes.Buffer 332 | buf.WriteString("trace ghost") 333 | buf.WriteString(strconv.Itoa(st.ghost.id)) 334 | buf.WriteString(": ") 335 | buf.WriteString(strconv.Itoa(int(st.reg[8]))) 336 | buf.WriteString(" ") 337 | buf.WriteString(strconv.Itoa(int(st.reg[0]))) 338 | buf.WriteString(" ") 339 | buf.WriteString(strconv.Itoa(int(st.reg[1]))) 340 | buf.WriteString(" ") 341 | buf.WriteString(strconv.Itoa(int(st.reg[2]))) 342 | buf.WriteString(" ") 343 | buf.WriteString(strconv.Itoa(int(st.reg[3]))) 344 | buf.WriteString(" ") 345 | buf.WriteString(strconv.Itoa(int(st.reg[4]))) 346 | buf.WriteString(" ") 347 | buf.WriteString(strconv.Itoa(int(st.reg[5]))) 348 | buf.WriteString(" ") 349 | buf.WriteString(strconv.Itoa(int(st.reg[6]))) 350 | buf.WriteString(" ") 351 | buf.WriteString(strconv.Itoa(int(st.reg[7]))) 352 | fmt.Println(buf.String()) 353 | } 354 | } 355 | 356 | func (st *GHCState) run() int { 357 | t := 0 358 | for ; t < 1024 && int(st.reg[PC]) < len(st.ghc); t++ { 359 | inst := st.ghc[st.reg[PC]] 360 | 361 | switch inst.op { 362 | case MOV: 363 | st.set(inst.args[0], st.get(inst.args[1])) 364 | case INC: 365 | st.set(inst.args[0], st.get(inst.args[0]) + 1) 366 | case DEC: 367 | st.set(inst.args[0], st.get(inst.args[0]) - 1) 368 | case ADD: 369 | st.set(inst.args[0], st.get(inst.args[0]) + st.get(inst.args[1])) 370 | case SUB: 371 | st.set(inst.args[0], st.get(inst.args[0]) - st.get(inst.args[1])) 372 | case MUL: 373 | st.set(inst.args[0], st.get(inst.args[0]) * st.get(inst.args[1])) 374 | case DIV: 375 | st.set(inst.args[0], st.get(inst.args[0]) / st.get(inst.args[1])) 376 | case AND: 377 | st.set(inst.args[0], st.get(inst.args[0]) & st.get(inst.args[1])) 378 | case OR: 379 | st.set(inst.args[0], st.get(inst.args[0]) | st.get(inst.args[1])) 380 | case XOR: 381 | st.set(inst.args[0], st.get(inst.args[0]) ^ st.get(inst.args[1])) 382 | case JLT: 383 | if st.get(inst.args[1]) < st.get(inst.args[2]) { 384 | st.reg[PC] = inst.args[0].v - 1 385 | } 386 | case JEQ: 387 | if st.get(inst.args[1]) == st.get(inst.args[2]) { 388 | st.reg[PC] = inst.args[0].v - 1 389 | } 390 | case JGT: 391 | if st.get(inst.args[1]) > st.get(inst.args[2]) { 392 | st.reg[PC] = inst.args[0].v - 1 393 | } 394 | case INT: 395 | st.runInt(inst.args[0].v) 396 | case HLT: 397 | break 398 | default: 399 | panic("Unknown op") 400 | } 401 | 402 | st.reg[PC]++ 403 | } 404 | 405 | fmt.Printf("ghost%d plan (%d cycles) (%d,%d): %d\n", 406 | st.ghost.id, t, st.ghost.pos.x, st.ghost.pos.y, st.plan) 407 | 408 | return st.plan 409 | } 410 | 411 | func (ghc GHC) run(mp *Map, ghost *Ghost) int { 412 | if ghc == nil { return -1 } 413 | 414 | st := new(GHCState) 415 | st.ghc = ghc 416 | st.mp = mp 417 | st.ghost = ghost 418 | st.mem = &ghost.mem 419 | st.plan = -1 420 | //fmt.Printf("%d %d %d %d\n", st.mem[0], st.mem[1], st.mem[2], st.mem[3]) 421 | return st.run() 422 | } 423 | 424 | // GCC 425 | 426 | const ( 427 | TAG_INT = iota 428 | TAG_CONS 429 | TAG_CLOSURE 430 | 431 | TAG_FRAME 432 | TAG_DUM 433 | ) 434 | 435 | var TAG_STRS = [...]string{ 436 | "TAG_INT", 437 | "TAG_CONS", 438 | "TAG_CLOSURE", 439 | 440 | "TAG_FRAME", 441 | "TAG_DUM", 442 | } 443 | 444 | type Value struct { 445 | tag int 446 | v int 447 | c *Cons 448 | } 449 | 450 | type Cons struct { 451 | car Value 452 | cdr Value 453 | } 454 | 455 | func MakeValue(tag int, v int) Value { 456 | return Value{tag, v, nil} 457 | } 458 | 459 | func MakeIntValue(v int) Value { 460 | return MakeValue(TAG_INT, v) 461 | } 462 | 463 | func MakeCons(x Value, y Value) Value { 464 | c := new(Cons) 465 | c.car = x 466 | c.cdr = y 467 | return Value{TAG_CONS, 0, c} 468 | } 469 | 470 | func MakeTuple(values []Value) Value { 471 | if len(values) < 2 { 472 | panic("Tuple too small") 473 | } 474 | 475 | v := MakeCons(values[len(values) - 2], values[len(values) - 1]) 476 | for i := len(values) - 3; i >= 0; i-- { 477 | v = MakeCons(values[i], v) 478 | } 479 | return v 480 | } 481 | 482 | func MakeList(values []Value) Value { 483 | values = append(values, MakeIntValue(0)) 484 | return MakeTuple(values) 485 | } 486 | 487 | func (v Value) str() string { 488 | var buf bytes.Buffer 489 | switch v.tag { 490 | case TAG_INT: 491 | buf.WriteString(strconv.Itoa(v.v)) 492 | case TAG_CLOSURE: 493 | buf.WriteString("FUNC:") 494 | buf.WriteString(strconv.Itoa(v.v)) 495 | case TAG_CONS: 496 | buf.WriteString("(") 497 | buf.WriteString(v.c.car.str()) 498 | buf.WriteString(", ") 499 | buf.WriteString(v.c.cdr.str()) 500 | buf.WriteString(")") 501 | } 502 | return buf.String() 503 | } 504 | 505 | func (v Value) show() { 506 | fmt.Println(v.str) 507 | } 508 | 509 | type Frame struct { 510 | tag int 511 | parent *Frame 512 | v []Value 513 | } 514 | 515 | type GCCInst struct { 516 | op int 517 | args []int 518 | } 519 | 520 | type GCC []*GCCInst 521 | 522 | type GCCState struct { 523 | gcc GCC 524 | stack []Value 525 | calls []int 526 | fp *Frame 527 | mp *Map 528 | 529 | c int 530 | s int 531 | d int 532 | e int 533 | 534 | cycles int 535 | 536 | call_stat map[int]int 537 | pc_stat map[int]int 538 | } 539 | 540 | func MakeGCCState(mp *Map, gcc GCC) *GCCState { 541 | st := new(GCCState) 542 | st.mp = mp 543 | st.gcc = gcc 544 | st.stack = make([]Value, 1000) 545 | st.calls = make([]int, 10000) 546 | st.call_stat = make(map[int]int) 547 | st.pc_stat = make(map[int]int) 548 | return st 549 | } 550 | 551 | func ParseGCC(filename string) *GCC { 552 | lines := ReadLines(filename) 553 | gcc := new(GCC) 554 | for n, line := range(lines) { 555 | n++ 556 | if len(line) == 0 { 557 | continue 558 | } 559 | 560 | toks := strings.Split(line, " ") 561 | 562 | op := -1 563 | for i, o := range(OP_STRS) { 564 | if o == strings.ToUpper(toks[0]) { 565 | op = i 566 | break 567 | } 568 | } 569 | if op <= HLT && (op < ADD || op > DIV) { 570 | Error(fmt.Sprintf("GCC: invalid op at %d: %s", n, line)) 571 | } 572 | 573 | // TODO: Check the number of args. 574 | 575 | var args []int 576 | for _, tok := range(toks[1:]) { 577 | a, e := strconv.Atoi(tok) 578 | if e != nil { 579 | Error(fmt.Sprintf("GCC: invalid operand at %d: %s", n, line)) 580 | } 581 | args = append(args, a) 582 | } 583 | 584 | inst := new(GCCInst) 585 | inst.op = op 586 | inst.args = args 587 | *gcc = append(*gcc, inst) 588 | 589 | if len(*gcc) > 1048576 { 590 | Error(fmt.Sprintf("GCC: too many instructions at %d: %s", n, line)) 591 | } 592 | } 593 | 594 | return gcc 595 | } 596 | 597 | func (st *GCCState) error(msg string) { 598 | var buf bytes.Buffer 599 | buf.WriteString(fmt.Sprintf("GCC: pc=%d %s\n", st.c, msg)) 600 | buf.WriteString(fmt.Sprintf("Current frame:\n")) 601 | for i, v := range(st.fp.v) { 602 | buf.WriteString(fmt.Sprintf("%d: %s\n", i, v.str())) 603 | } 604 | buf.WriteString(fmt.Sprintf("Current stack:\n")) 605 | for i := st.s - 1; i >= 0; i-- { 606 | buf.WriteString(fmt.Sprintf("%d: %s\n", i, st.stack[i].str())) 607 | } 608 | Error(buf.String()) 609 | } 610 | 611 | func (st *GCCState) push(v Value) { 612 | st.stack[st.s] = v 613 | st.s++ 614 | } 615 | 616 | func (st *GCCState) pop() Value { 617 | st.s-- 618 | if st.s < 0 { 619 | st.error("empty stack") 620 | } 621 | return st.stack[st.s] 622 | } 623 | 624 | func (st *GCCState) pushCall(c int) { 625 | st.calls[st.d] = c 626 | st.d++ 627 | } 628 | 629 | func (st *GCCState) popCall() int { 630 | st.d-- 631 | return st.calls[st.d] 632 | } 633 | 634 | func (st *GCCState) checkType(v Value, tag int) { 635 | if tag != v.tag { 636 | st.error(fmt.Sprintf( 637 | "Unexpected tag type expected=%s actual=%s", 638 | TAG_STRS[tag], TAG_STRS[v.tag])) 639 | } 640 | } 641 | 642 | func (st *GCCState) call(n int, c int) { 643 | st.call_stat[c]++ 644 | 645 | fp := new(Frame) 646 | fp.tag = TAG_FRAME 647 | fp.v = make([]Value, n) 648 | fp.parent = st.fp 649 | 650 | for n--; n >= 0; n-- { 651 | fp.v[n] = st.pop() 652 | } 653 | 654 | st.fp = fp 655 | st.c = c 656 | } 657 | 658 | func (st *GCCState) getFrame(n int) *Frame { 659 | fp := st.fp 660 | for i := 0; i < n; i++ { 661 | fp = fp.parent 662 | } 663 | if fp.tag == TAG_DUM { 664 | st.error("Frame mismatch") 665 | } 666 | return fp 667 | } 668 | 669 | func (st *GCCState) runInst(inst *GCCInst) bool { 670 | //fmt.Printf("GCC inst: pc=%d %s\n", st.c, OP_STRS[inst.op]) 671 | 672 | switch inst.op { 673 | case LDC: 674 | st.push(MakeIntValue(inst.args[0])) 675 | 676 | case LD: 677 | fp := st.getFrame(inst.args[0]) 678 | v := fp.v[inst.args[1]] 679 | st.push(v) 680 | 681 | case ADD, SUB, MUL, DIV, CEQ, CGT, CGTE: 682 | y := st.pop() 683 | x := st.pop() 684 | st.checkType(x, TAG_INT) 685 | st.checkType(y, TAG_INT) 686 | z := MakeIntValue(0) 687 | switch inst.op { 688 | case ADD: 689 | z = MakeIntValue(x.v + y.v) 690 | case SUB: 691 | z = MakeIntValue(x.v - y.v) 692 | case MUL: 693 | z = MakeIntValue(x.v * y.v) 694 | case DIV: 695 | z = MakeIntValue(x.v / y.v) 696 | case CEQ: 697 | if (x.v == y.v) { z = MakeIntValue(1) } 698 | case CGT: 699 | if (x.v > y.v) { z = MakeIntValue(1) } 700 | case CGTE: 701 | if (x.v >= y.v) { z = MakeIntValue(1) } 702 | } 703 | st.push(z) 704 | 705 | case ATOM: 706 | x := st.pop() 707 | v := 0 708 | if x.tag == TAG_INT { v = 1 } 709 | y := MakeIntValue(v) 710 | st.push(y) 711 | 712 | case CONS: 713 | y := st.pop() 714 | x := st.pop() 715 | z := MakeCons(x, y) 716 | st.push(z) 717 | 718 | case CAR: 719 | x := st.pop() 720 | st.checkType(x, TAG_CONS) 721 | y := x.c.car 722 | st.push(y) 723 | 724 | case CDR: 725 | x := st.pop() 726 | st.checkType(x, TAG_CONS) 727 | y := x.c.cdr 728 | st.push(y) 729 | 730 | // SEL 731 | // JOIN 732 | 733 | case LDF: 734 | st.push(MakeValue(TAG_CLOSURE, inst.args[0])) 735 | 736 | case AP: 737 | x := st.pop() 738 | st.checkType(x, TAG_CLOSURE) 739 | f := x.v 740 | st.pushCall(st.c) 741 | st.call(inst.args[0], f) 742 | st.c-- 743 | 744 | case RTN: 745 | if st.d == 0 { 746 | return false 747 | } 748 | st.c = st.popCall() 749 | st.fp = st.fp.parent 750 | 751 | case DUM: 752 | fp := new(Frame) 753 | fp.tag = TAG_DUM 754 | fp.v = make([]Value, inst.args[0]) 755 | fp.parent = st.fp 756 | st.fp = fp 757 | 758 | // RAP 759 | // STOP 760 | case TSEL: 761 | x := st.pop() 762 | st.checkType(x, TAG_INT) 763 | if x.v == 0 { 764 | st.c = inst.args[1] 765 | } else { 766 | st.c = inst.args[0] 767 | } 768 | st.c-- 769 | 770 | // TAP 771 | // TRAP 772 | case ST: 773 | fp := st.getFrame(inst.args[0]) 774 | fp.v[inst.args[1]] = st.pop() 775 | 776 | case DBUG: 777 | x := st.pop() 778 | fmt.Printf("trace lambdaman: %s\n", x.str()) 779 | 780 | // BRK 781 | 782 | default: 783 | st.error(fmt.Sprintf("Not implemented: %s", OP_STRS[inst.op])) 784 | } 785 | return true 786 | } 787 | 788 | func (st *GCCState) MakeMapState() Value { 789 | mp := st.mp 790 | var st_v []Value 791 | 792 | var map_v []Value 793 | for y := 0; y < mp.height; y++ { 794 | var row []Value 795 | for x := 0; x < mp.width; x++ { 796 | v := MakeIntValue(int(mp.get(x, y))) 797 | row = append(row, v) 798 | } 799 | map_v = append(map_v, MakeList(row)) 800 | } 801 | st_v = append(st_v, MakeList(map_v)) 802 | 803 | lman := mp.lman 804 | var lman_v []Value 805 | lman_v = append(lman_v, MakeIntValue(lman.vit)) 806 | pos_v := MakeCons(MakeIntValue(lman.pos.x), MakeIntValue(lman.pos.y)) 807 | lman_v = append(lman_v, pos_v) 808 | lman_v = append(lman_v, MakeIntValue(lman.plan)) 809 | lman_v = append(lman_v, MakeIntValue(lman.life)) 810 | lman_v = append(lman_v, MakeIntValue(mp.score)) 811 | st_v = append(st_v, MakeTuple(lman_v)) 812 | 813 | var ghosts_v []Value 814 | for _, ghost := range(mp.ghosts) { 815 | var ghost_v []Value 816 | ghost_v = append(ghost_v, MakeIntValue(ghost.vit)) 817 | pos_v := MakeCons(MakeIntValue(ghost.pos.x), MakeIntValue(ghost.pos.y)) 818 | ghost_v = append(ghost_v, pos_v) 819 | ghost_v = append(ghost_v, MakeIntValue(ghost.plan)) 820 | ghosts_v = append(ghosts_v, MakeTuple(ghost_v)) 821 | } 822 | st_v = append(st_v, MakeList(ghosts_v)) 823 | 824 | st_v = append(st_v, MakeIntValue(mp.fruit)) 825 | 826 | return MakeTuple(st_v) 827 | } 828 | 829 | func (st *GCCState) run(limit int) { 830 | for st.cycles = 0; st.cycles < limit; st.cycles++ { 831 | st.pc_stat[st.c]++ 832 | 833 | //fmt.Printf("pc=%d %d\n", st.c, st.cycles) 834 | inst := st.gcc[st.c] 835 | if !st.runInst(inst) { 836 | return 837 | } 838 | st.c++ 839 | } 840 | st.error("Cycle limit exceeded") 841 | } 842 | 843 | func (gcc GCC) init(mp *Map) { 844 | st := MakeGCCState(mp, gcc) 845 | 846 | map_state := st.MakeMapState() 847 | // TODO: Implement 848 | ghost_ai := MakeValue(TAG_INT, 0) 849 | st.push(map_state) 850 | st.push(ghost_ai) 851 | st.call(2, 0) 852 | 853 | st.run(3072000 * 60) 854 | 855 | v := st.pop() 856 | st.checkType(v, TAG_CONS) 857 | mp.lman.ai_state = v.c.car 858 | st.checkType(v.c.cdr, TAG_CLOSURE) 859 | mp.lman.entry = v.c.cdr.v 860 | } 861 | 862 | func (gcc GCC) run(mp *Map) int { 863 | st := MakeGCCState(mp, gcc) 864 | 865 | map_state := st.MakeMapState() 866 | st.push(mp.lman.ai_state) 867 | st.push(map_state) 868 | st.call(2, mp.lman.entry) 869 | 870 | st.run(3072000) 871 | 872 | v := st.pop() 873 | st.checkType(v, TAG_CONS) 874 | mp.lman.ai_state = v.c.car 875 | st.checkType(v.c.cdr, TAG_INT) 876 | 877 | plan := v.c.cdr.v 878 | fmt.Printf("lman plan (%d cycles) (%d,%d): %d\n", 879 | st.cycles, st.mp.lman.pos.x, st.mp.lman.pos.y, plan) 880 | 881 | if *flag_call_stat { 882 | fmt.Println(st.call_stat) 883 | } 884 | if *flag_pc_stat { 885 | fmt.Println(st.pc_stat) 886 | } 887 | 888 | return plan 889 | } 890 | 891 | // Simulator 892 | 893 | const ( 894 | WALL = iota 895 | EMPTY 896 | PILL 897 | PPILL 898 | FRUIT 899 | LMAN 900 | GHOST 901 | ) 902 | 903 | type Pos struct { 904 | x int 905 | y int 906 | } 907 | 908 | type Lman struct { 909 | pos Pos 910 | opos Pos 911 | life int 912 | tick int 913 | plan int 914 | prog *GCC 915 | vit int 916 | eating int 917 | chain int 918 | 919 | ai_state Value 920 | entry int 921 | } 922 | 923 | type Ghost struct { 924 | pos Pos 925 | opos Pos 926 | tick int 927 | plan int 928 | prog *GHC 929 | id int 930 | vit int 931 | mem [256]uint8 932 | } 933 | 934 | type Map struct { 935 | lines [][]uint8 936 | width int 937 | height int 938 | lman *Lman 939 | ghosts []*Ghost 940 | fruit int 941 | score int 942 | tick int 943 | elapsed int 944 | } 945 | 946 | var ghost_ticks = [4]int{130, 132, 134, 136} 947 | var ghost_frighten_ticks = [4]int{195, 198, 201, 204} 948 | 949 | func ParseMap(map_name string) *Map { 950 | fmt.Printf("Parsing %s...\n", map_name) 951 | fp := OpenFile(map_name) 952 | var lines [][]uint8 953 | 954 | lman := new(Lman) 955 | lman.life = 3 956 | lman.tick = 0 957 | lman.plan = 2 958 | 959 | var ghosts []*Ghost 960 | 961 | for true { 962 | line, err := fp.ReadString('\n') 963 | if err == io.EOF { break } 964 | if len(line) < 2 { break } 965 | 966 | var row []uint8 967 | for x, c := range(line) { 968 | if c == '\n' { 969 | break 970 | } 971 | 972 | if c == '\\' { 973 | lman.pos = Pos{x, len(lines)} 974 | lman.opos = Pos{x, len(lines)} 975 | line = strings.Replace(line, "=", " ", -1) 976 | } else if c == '=' { 977 | ghost := new(Ghost) 978 | ghost.pos = Pos{x, len(lines)} 979 | ghost.opos = Pos{x, len(lines)} 980 | ghost.tick = 0 981 | ghost.plan = 2 982 | ghost.id = len(ghosts) 983 | ghosts = append(ghosts, ghost) 984 | } 985 | row = append(row, ByteToCell(c)) 986 | } 987 | 988 | lines = append(lines, row) 989 | } 990 | 991 | mp := new(Map) 992 | mp.lines = lines 993 | mp.width = len(lines[0]) 994 | mp.height = len(lines) 995 | mp.lman = lman 996 | mp.ghosts = ghosts 997 | return mp 998 | } 999 | 1000 | func movePos(pos Pos, plan int) Pos { 1001 | nx := pos.x 1002 | ny := pos.y 1003 | if plan == 0 { 1004 | ny = ny - 1 1005 | } else if plan == 1 { 1006 | nx = nx + 1 1007 | } else if plan == 2 { 1008 | ny = ny + 1 1009 | } else if plan == 3 { 1010 | nx = nx - 1 1011 | } 1012 | return Pos{nx, ny} 1013 | } 1014 | 1015 | func ByteToCell(c rune) uint8 { 1016 | switch c { 1017 | case '#': 1018 | return WALL 1019 | case ' ': 1020 | return EMPTY 1021 | case '.': 1022 | return PILL 1023 | case 'o': 1024 | return PPILL 1025 | case '%': 1026 | return FRUIT 1027 | case '\\': 1028 | return LMAN 1029 | case '=': 1030 | return GHOST 1031 | default: 1032 | panic(fmt.Sprintf("Invalid character '%c'", c)) 1033 | } 1034 | } 1035 | 1036 | func CellToByte(c uint8) uint8 { 1037 | return "# .o%\\="[c] 1038 | } 1039 | 1040 | func (mp* Map) get(x int, y int) uint8 { 1041 | return mp.lines[y][x] 1042 | } 1043 | 1044 | func (mp* Map) movePos(pos Pos, plan int) Pos { 1045 | npos := movePos(pos, plan) 1046 | nx := npos.x 1047 | ny := npos.y 1048 | if mp.lines[ny][nx] == '#' { 1049 | return pos 1050 | } 1051 | return Pos{nx, ny} 1052 | } 1053 | 1054 | func (mp* Map) isValidMove(pos Pos, plan int) bool { 1055 | npos := movePos(pos, plan) 1056 | nx := npos.x 1057 | ny := npos.y 1058 | return mp.lines[ny][nx] != WALL 1059 | } 1060 | 1061 | func (mp* Map) updateTimer(t *int) { 1062 | *t -= mp.elapsed 1063 | if *t < 0 { *t = 0 } 1064 | } 1065 | 1066 | func (mp* Map) tickStep1() { 1067 | if mp.tick > 2 && mp.lman.tick == 0 { 1068 | mp.lman.plan = mp.lman.prog.run(mp) 1069 | if mp.isValidMove(mp.lman.pos, mp.lman.plan) { 1070 | mp.lman.pos = mp.movePos(mp.lman.pos, mp.lman.plan) 1071 | } 1072 | } 1073 | 1074 | for _, ghost := range(mp.ghosts) { 1075 | if mp.tick > 2 && ghost.tick == 0 { 1076 | invalid_plan := (ghost.plan + 2) % 4 1077 | plan := -1 1078 | if ghost.prog != nil { 1079 | plan = ghost.prog.run(mp, ghost) 1080 | if plan == invalid_plan || !mp.isValidMove(ghost.pos, plan) { 1081 | plan = -1 1082 | } 1083 | } 1084 | if plan == -1 { 1085 | plan = ghost.plan 1086 | } 1087 | 1088 | ghost.plan = -1 1089 | 1090 | if plan != invalid_plan && mp.isValidMove(ghost.pos, plan) { 1091 | ghost.plan = plan 1092 | } else { 1093 | for i := 0; i < 4; i++ { 1094 | if invalid_plan == i { 1095 | continue 1096 | } 1097 | if mp.isValidMove(ghost.pos, i) { 1098 | ghost.plan = i 1099 | break 1100 | } 1101 | } 1102 | if ghost.plan == -1 { 1103 | if mp.isValidMove(ghost.pos, invalid_plan) { 1104 | ghost.plan = invalid_plan 1105 | } 1106 | } 1107 | } 1108 | 1109 | ghost.pos = mp.movePos(ghost.pos, ghost.plan) 1110 | } 1111 | } 1112 | } 1113 | 1114 | func (mp* Map) tickStep2() { 1115 | if mp.lman.vit == 0 { 1116 | mp.lman.chain = 0 1117 | 1118 | for _, ghost := range(mp.ghosts) { 1119 | if ghost.tick == 0 && ghost.vit > 0 { 1120 | ghost.vit = 0 1121 | } 1122 | } 1123 | } 1124 | // TODO: why this is the right thing... 1125 | mp.updateTimer(&mp.lman.vit) 1126 | 1127 | mp.updateTimer(&mp.fruit) 1128 | if (mp.tick >= 127 * 200 && mp.tick - mp.elapsed < 127 * 200 || 1129 | mp.tick >= 127 * 400 && mp.tick - mp.elapsed < 127 * 400) { 1130 | mp.fruit = 127 * 80 - mp.tick % (127 * 200) 1131 | } 1132 | } 1133 | 1134 | func (mp* Map) tickStep3() { 1135 | x := mp.lman.pos.x 1136 | y := mp.lman.pos.y 1137 | 1138 | cell := mp.get(x, y) 1139 | 1140 | switch cell { 1141 | case PILL: 1142 | mp.lines[y][x] = EMPTY 1143 | //fmt.Printf("eat pill\n"); 1144 | mp.lman.eating = 1 1145 | mp.score += 10 1146 | case PPILL: 1147 | mp.lines[y][x] = EMPTY 1148 | mp.lman.eating = 1 1149 | fmt.Printf("eat ppill!\n"); 1150 | // TODO: check if vit is zero? 1151 | mp.lman.vit = 127 * 20 1152 | mp.score += 50 1153 | for _, ghost := range(mp.ghosts) { 1154 | if ghost.vit != 2 { 1155 | ghost.vit = 1 1156 | } 1157 | ghost.plan = (ghost.plan + 2) % 4 1158 | } 1159 | case FRUIT: 1160 | if mp.fruit > 0 { 1161 | fmt.Printf("eat fruit\n"); 1162 | mp.lman.eating = 1 1163 | level := (mp.width * mp.height + 99) / 100 1164 | if level > 12 { level = 13 } 1165 | fruit_scores := []int{ 1166 | 100, 300, 500, 500, 700, 700, 1000, 1167 | 1000, 2000, 2000, 3000, 3000, 5000, 1168 | } 1169 | mp.fruit = 0 1170 | mp.score += fruit_scores[level] 1171 | } 1172 | } 1173 | } 1174 | 1175 | func (mp* Map) tickStep4() { 1176 | for _, ghost := range(mp.ghosts) { 1177 | if ghost.pos != mp.lman.pos || ghost.vit == 2 { 1178 | continue 1179 | } 1180 | 1181 | if mp.lman.vit > 0 { 1182 | ghost_scores := []int{200, 400, 800, 1600} 1183 | mp.score += ghost_scores[mp.lman.chain] 1184 | mp.lman.chain++ 1185 | if mp.lman.chain > 3 { mp.lman.chain = 3 } 1186 | ghost.pos = ghost.opos 1187 | ghost.plan = 2 1188 | ghost.vit = 2 1189 | //ghost.tick = ghost_ticks[ghost.id] 1190 | } else { 1191 | fmt.Printf("died!\n") 1192 | mp.lman.life-- 1193 | mp.lman.pos = mp.lman.opos 1194 | mp.lman.plan = 2 1195 | for _, ghost := range(mp.ghosts) { 1196 | ghost.pos = ghost.opos 1197 | ghost.plan = 2 1198 | } 1199 | break 1200 | } 1201 | } 1202 | } 1203 | 1204 | func (mp* Map) tickStep5() bool { 1205 | win := true 1206 | for _, row := range(mp.lines) { 1207 | for _, cell := range(row) { 1208 | if cell == PILL { 1209 | win = false 1210 | break 1211 | } 1212 | } 1213 | } 1214 | return win 1215 | } 1216 | 1217 | func (mp* Map) tickStep6() bool { 1218 | return mp.lman.life == 0 1219 | } 1220 | 1221 | func (mp* Map) tickStep7() { 1222 | if mp.lman.tick == 0 { 1223 | lman_ticks := [2]int{127, 137} 1224 | //eating := mp.lman.eating 1225 | //if mp.lman.vit > 0 { eating = 0 } 1226 | //fmt.Printf("lman eating? %d\n", mp.lman.eating) 1227 | mp.lman.tick = lman_ticks[mp.lman.eating] 1228 | mp.lman.eating = 0 1229 | } 1230 | 1231 | for i, ghost := range(mp.ghosts) { 1232 | if ghost.tick == 0 { 1233 | if ghost.vit > 0 { 1234 | //fmt.Printf("frightened!\n") 1235 | ghost.tick = ghost_frighten_ticks[i] 1236 | } else { 1237 | //fmt.Printf("not frightened\n") 1238 | ghost.tick = ghost_ticks[i] 1239 | } 1240 | } 1241 | } 1242 | 1243 | mp.elapsed = mp.lman.tick 1244 | for _, ghost := range(mp.ghosts) { 1245 | if mp.elapsed > ghost.tick { 1246 | mp.elapsed = ghost.tick 1247 | } 1248 | } 1249 | 1250 | mp.lman.tick -= mp.elapsed 1251 | for _, ghost := range(mp.ghosts) { 1252 | ghost.tick -= mp.elapsed 1253 | } 1254 | //fmt.Printf("e %d\n", mp.elapsed) 1255 | mp.tick += mp.elapsed 1256 | } 1257 | 1258 | func (mp* Map) show() { 1259 | var buf bytes.Buffer 1260 | for y := 0; y < mp.height; y++ { 1261 | for x := 0; x < mp.width; x++ { 1262 | c := CellToByte(mp.lines[y][x]) 1263 | 1264 | if c == '%' && mp.fruit > 0 { 1265 | c = '$' 1266 | } 1267 | 1268 | for i, ghost := range(mp.ghosts) { 1269 | if ghost.pos.x == x && ghost.pos.y == y { 1270 | c = byte('0' + i) 1271 | } 1272 | } 1273 | if mp.lman.pos.x == x && mp.lman.pos.y == y { 1274 | c = byte('/') 1275 | } 1276 | 1277 | buf.WriteByte(c) 1278 | } 1279 | buf.WriteByte('\n') 1280 | } 1281 | buf.WriteString("Score: ") 1282 | buf.WriteString(strconv.Itoa(mp.score)) 1283 | buf.WriteString(" Lives: ") 1284 | buf.WriteString(strconv.Itoa(mp.lman.life)) 1285 | buf.WriteString(" Ticks: ") 1286 | buf.WriteString(strconv.Itoa(mp.tick)) 1287 | buf.WriteString("\n") 1288 | fmt.Println(buf.String()) 1289 | } 1290 | 1291 | func main() { 1292 | flag.Parse() 1293 | 1294 | if flag.NArg() < 3 { 1295 | Error("Usage: go run sim.go MAP GCC GHC GHC...") 1296 | } 1297 | 1298 | map_name := flag.Arg(0) 1299 | mp := ParseMap(map_name) 1300 | 1301 | mp.lman.prog = ParseGCC(flag.Arg(1)) 1302 | 1303 | var ghcs []*GHC 1304 | for i := 2; i < flag.NArg(); i++ { 1305 | ghcs = append(ghcs, ParseGHC(flag.Arg(i))) 1306 | } 1307 | for i, ghost := range(mp.ghosts) { 1308 | ghost.prog = ghcs[i % len(ghcs)] 1309 | } 1310 | 1311 | fmt.Printf("Running init...\n") 1312 | mp.lman.prog.init(mp) 1313 | 1314 | fmt.Printf("Running game...\n") 1315 | 1316 | result := 0 1317 | 1318 | mp.tick = 1 1319 | eol := 127 * mp.width * mp.height * 16 1320 | for mp.tick < eol { 1321 | mp.tickStep1() 1322 | mp.tickStep2() 1323 | mp.tickStep3() 1324 | mp.tickStep4() 1325 | if mp.tickStep5() { 1326 | result = 1 1327 | break 1328 | } 1329 | if mp.tickStep6() { 1330 | result = 2 1331 | break 1332 | } 1333 | 1334 | if !*flag_quiet || mp.tick % 100 == 0 { 1335 | mp.show() 1336 | } 1337 | 1338 | mp.tickStep7() 1339 | } 1340 | 1341 | mp.show() 1342 | if result == 0 { 1343 | fmt.Println("Timeout") 1344 | } else if result == 1 { 1345 | fmt.Println("You win") 1346 | } else if result == 2 { 1347 | fmt.Println("You lose") 1348 | } 1349 | } 1350 | -------------------------------------------------------------------------------- /ld.gcc: -------------------------------------------------------------------------------- 1 | LD 0 0 ; @main 2 | LD 0 1 3 | LDC 0 4 | LDC 0 5 | LDC 0 6 | LDC 0 7 | LDF 9 ; main_impl 8 | AP 6 9 | RTN 10 | LD 0 0 ; @main_impl 11 | CAR 12 | ST 0 2 13 | LD 0 2 14 | LDF 102 ; getMapSize 15 | AP 1 16 | ST 0 3 17 | LD 0 2 18 | LDF 28 ; getPillMap 19 | AP 1 20 | ST 0 4 21 | LD 0 3 22 | LD 0 4 23 | CONS 24 | ST 0 5 25 | LD 0 5 26 | LDF 143 ; step 27 | CONS 28 | RTN 29 | LD 0 0 ; @getPillMap 30 | LDC 0 31 | LDC 0 32 | LDC 0 33 | LDC 0 34 | LDC 0 35 | LDC 0 36 | LDF 38 ; getPillMap_impl 37 | AP 7 38 | RTN 39 | LDC 0 ; @getPillMap_impl 40 | ST 0 1 41 | LDC 0 42 | ST 0 2 43 | LDC 0 44 | ST 0 3 45 | LD 0 0 ; @_L0 46 | ATOM 47 | LDC 0 48 | CEQ 49 | TSEL 49 98 ; _L1 _L2 50 | LDC 0 ; @_L1 51 | ST 0 4 52 | LD 0 0 53 | CAR 54 | ST 0 5 55 | LD 0 0 56 | CDR 57 | ST 0 0 58 | LD 0 5 ; @_L3 59 | ATOM 60 | LDC 0 61 | CEQ 62 | TSEL 62 92 ; _L4 _L5 63 | LD 0 5 ; @_L4 64 | CAR 65 | ST 0 6 66 | LD 0 5 67 | CDR 68 | ST 0 5 69 | LD 0 6 70 | LDC 1 71 | CGT 72 | LDC 4 73 | LD 0 6 74 | CGT 75 | MUL 76 | TSEL 76 86 ; _L6 _L7 77 | LD 0 4 ; @_L6 78 | LD 0 3 79 | CONS 80 | LD 0 1 81 | CONS 82 | ST 0 1 83 | LD 0 2 84 | LDC 1 85 | ADD 86 | ST 0 2 87 | LD 0 4 ; @_L7 88 | LDC 1 89 | ADD 90 | ST 0 4 91 | LDC 0 92 | TSEL 57 57 ; _L3 _L3 93 | LD 0 3 ; @_L5 94 | LDC 1 95 | ADD 96 | ST 0 3 97 | LDC 0 98 | TSEL 44 44 ; _L0 _L0 99 | LD 0 1 ; @_L2 100 | LD 0 2 101 | CONS 102 | RTN 103 | LD 0 0 ; @getMapSize 104 | LDC 0 105 | LDC 0 106 | LDC 0 107 | LDF 109 ; getMapSize_impl 108 | AP 4 109 | RTN 110 | LDC 0 ; @getMapSize_impl 111 | ST 0 1 112 | LD 0 0 ; @_L8 113 | ATOM 114 | LDC 0 115 | CEQ 116 | TSEL 116 141 ; _L9 _L10 117 | LD 0 0 ; @_L9 118 | CAR 119 | ST 0 2 120 | LD 0 0 121 | CDR 122 | ST 0 0 123 | LD 0 2 ; @_L11 124 | ATOM 125 | LDC 0 126 | CEQ 127 | TSEL 127 139 ; _L12 _L13 128 | LD 0 2 ; @_L12 129 | CAR 130 | ST 0 3 131 | LD 0 2 132 | CDR 133 | ST 0 2 134 | LD 0 1 135 | LDC 1 136 | ADD 137 | ST 0 1 138 | LDC 0 139 | TSEL 122 122 ; _L11 _L11 140 | LDC 0 ; @_L13 141 | TSEL 111 111 ; _L8 _L8 142 | LD 0 1 ; @_L10 143 | RTN 144 | LD 0 0 ; @step 145 | LD 0 1 146 | LDF 148 ; step_impl 147 | AP 2 148 | RTN 149 | LD 0 0 ; @step_impl 150 | LD 0 1 151 | LDF 1055 ; step_fast 152 | AP 2 153 | RTN 154 | LDC 0 ; @getSubWall 155 | LDC 0 156 | LDF 158 ; getSubWall_impl 157 | AP 2 158 | RTN 159 | LDC 23 ; @getSubWall_impl 160 | ST 0 0 161 | LDC 0 162 | ST 0 1 163 | LD 0 0 ; @_L14 164 | TSEL 164 174 ; _L15 _L16 165 | LDC 0 ; @_L15 166 | LD 0 1 167 | CONS 168 | ST 0 1 169 | LD 0 0 170 | LDC -1 171 | ADD 172 | ST 0 0 173 | LDC 0 174 | TSEL 162 162 ; _L14 _L14 175 | LD 0 1 ; @_L16 176 | RTN 177 | LD 0 0 ; @getSubMap 178 | LD 0 1 179 | LD 0 2 180 | LDC 0 181 | LDC 0 182 | LDC 0 183 | LDC 0 184 | LDC 0 185 | LDC 0 186 | LDC 0 187 | LDC 0 188 | LDC 0 189 | LDF 191 ; getSubMap_impl 190 | AP 12 191 | RTN 192 | LDC 0 ; @getSubMap_impl 193 | ST 0 3 194 | LDC -1 195 | ST 0 4 196 | LD 0 4 ; @_L17 197 | LDC 1 198 | ADD 199 | ST 0 4 200 | LD 0 0 201 | ATOM 202 | LDC 0 203 | CEQ 204 | TSEL 204 273 ; _L18 _L19 205 | LDC -1 ; @_L18 206 | ST 0 5 207 | LD 0 0 208 | CAR 209 | ST 0 6 210 | LD 0 0 211 | CDR 212 | ST 0 0 213 | LDC 0 214 | ST 0 7 215 | LD 0 4 216 | LD 0 2 217 | SUB 218 | ST 0 8 219 | LDC -10 220 | LD 0 8 221 | CGT 222 | TSEL 222 224 ; _L20 _L21 223 | LDC 0 ; @_L20 224 | TSEL 195 195 ; _L17 _L17 225 | LD 0 8 ; @_L21 226 | LDC 10 227 | CGT 228 | TSEL 228 230 ; _L22 _L23 229 | LDC 0 ; @_L22 230 | TSEL 273 273 ; _L19 _L19 231 | LD 0 5 ; @_L24 232 | LDC 1 233 | ADD 234 | ST 0 5 235 | LD 0 6 236 | ATOM 237 | LDC 0 238 | CEQ 239 | TSEL 239 267 ; _L25 _L26 240 | LD 0 6 ; @_L25 241 | CAR 242 | ST 0 9 243 | LD 0 6 244 | CDR 245 | ST 0 6 246 | LD 0 5 247 | LD 0 1 248 | SUB 249 | ST 0 10 250 | LDC -10 251 | LD 0 10 252 | CGT 253 | TSEL 253 255 ; _L27 _L28 254 | LDC 0 ; @_L27 255 | TSEL 230 230 ; _L24 _L24 256 | LD 0 10 ; @_L28 257 | LDC 10 258 | CGT 259 | TSEL 259 261 ; _L29 _L30 260 | LDC 0 ; @_L29 261 | TSEL 267 267 ; _L26 _L26 262 | LD 0 9 ; @_L30 263 | LD 0 7 264 | CONS 265 | ST 0 7 266 | LDC 0 267 | TSEL 230 230 ; _L24 _L24 268 | LD 0 7 ; @_L26 269 | LD 0 3 270 | CONS 271 | ST 0 3 272 | LDC 0 273 | TSEL 195 195 ; _L17 _L17 274 | LDC 0 ; @_L19 275 | ST 0 11 276 | LDF 153 ; getSubWall 277 | AP 0 278 | LD 0 11 279 | CONS 280 | ST 0 11 281 | LD 0 3 ; @_L31 282 | ATOM 283 | LDC 0 284 | CEQ 285 | TSEL 285 324 ; _L32 _L33 286 | LD 0 3 ; @_L32 287 | CAR 288 | ST 0 7 289 | LD 0 3 290 | CDR 291 | ST 0 3 292 | LDC 0 293 | ST 0 6 294 | LDC 0 295 | LD 0 6 296 | CONS 297 | ST 0 6 298 | LD 0 7 ; @_L34 299 | ATOM 300 | LDC 0 301 | CEQ 302 | TSEL 302 314 ; _L35 _L36 303 | LD 0 7 ; @_L35 304 | CAR 305 | ST 0 9 306 | LD 0 7 307 | CDR 308 | ST 0 7 309 | LD 0 9 310 | LD 0 6 311 | CONS 312 | ST 0 6 313 | LDC 0 314 | TSEL 297 297 ; _L34 _L34 315 | LDC 0 ; @_L36 316 | LD 0 6 317 | CONS 318 | ST 0 6 319 | LD 0 6 320 | LD 0 11 321 | CONS 322 | ST 0 11 323 | LDC 0 324 | TSEL 280 280 ; _L31 _L31 325 | LDF 153 ; @_L33 getSubWall 326 | AP 0 327 | LD 0 11 328 | CONS 329 | ST 0 11 330 | LD 0 11 331 | RTN 332 | LD 0 0 ; @getOppDir 333 | LDF 335 ; getOppDir_impl 334 | AP 1 335 | RTN 336 | LD 0 0 ; @getOppDir_impl 337 | LDC 0 338 | CEQ 339 | TSEL 339 341 ; _L37 _L38 340 | LDC 2 ; @_L37 341 | RTN 342 | LD 0 0 ; @_L38 343 | LDC 1 344 | CEQ 345 | TSEL 345 347 ; _L39 _L40 346 | LDC 3 ; @_L39 347 | RTN 348 | LD 0 0 ; @_L40 349 | LDC 2 350 | CEQ 351 | TSEL 351 353 ; _L41 _L42 352 | LDC 0 ; @_L41 353 | RTN 354 | LD 0 0 ; @_L42 355 | LDC 3 356 | CEQ 357 | TSEL 357 359 ; _L43 _L44 358 | LDC 1 ; @_L43 359 | RTN 360 | LDC -42 ; @_L44 361 | DBUG 362 | BRK 363 | LD 0 0 ; @getDirScores 364 | LD 0 1 365 | LD 0 2 366 | LD 0 3 367 | LD 0 4 368 | LD 0 5 369 | LDC 0 370 | LDC 0 371 | LDC 0 372 | LDC 0 373 | LDC 0 374 | LDC 0 375 | LDC 0 376 | LDC 0 377 | LDC 0 378 | LDC 0 379 | LDC 0 380 | LDC 0 381 | LDC 0 382 | LDC 0 383 | LDF 385 ; getDirScores_impl 384 | AP 20 385 | RTN 386 | LD 0 3 ; @getDirScores_impl 387 | LDF 331 ; getOppDir 388 | AP 1 389 | ST 0 6 390 | LDC 0 391 | ST 0 7 392 | LD 0 0 393 | LD 0 1 394 | LDC 0 395 | ADD 396 | LD 0 2 397 | LDC -1 398 | ADD 399 | LDF 1880 ; getXY 400 | AP 3 401 | LDC 0 402 | CEQ 403 | TSEL 403 405 ; _L45 _L46 404 | LDC -900000 ; @_L45 405 | ST 0 7 406 | LD 0 6 ; @_L46 407 | LDC 0 408 | CEQ 409 | TSEL 409 413 ; _L47 _L48 410 | LD 0 7 ; @_L47 411 | LDC -300000 412 | ADD 413 | ST 0 7 414 | LD 0 5 ; @_L48 415 | LDC 0 416 | CEQ 417 | TSEL 417 421 ; _L49 _L50 418 | LD 0 7 ; @_L49 419 | LDC 30000 420 | ADD 421 | ST 0 7 422 | LDC 0 ; @_L50 423 | ST 0 8 424 | LD 0 0 425 | LD 0 1 426 | LDC 1 427 | ADD 428 | LD 0 2 429 | LDC 0 430 | ADD 431 | LDF 1880 ; getXY 432 | AP 3 433 | LDC 0 434 | CEQ 435 | TSEL 435 437 ; _L51 _L52 436 | LDC -900000 ; @_L51 437 | ST 0 8 438 | LD 0 6 ; @_L52 439 | LDC 1 440 | CEQ 441 | TSEL 441 445 ; _L53 _L54 442 | LD 0 8 ; @_L53 443 | LDC -300000 444 | ADD 445 | ST 0 8 446 | LD 0 5 ; @_L54 447 | LDC 1 448 | CEQ 449 | TSEL 449 453 ; _L55 _L56 450 | LD 0 8 ; @_L55 451 | LDC 30000 452 | ADD 453 | ST 0 8 454 | LDC 0 ; @_L56 455 | ST 0 9 456 | LD 0 0 457 | LD 0 1 458 | LDC 0 459 | ADD 460 | LD 0 2 461 | LDC 1 462 | ADD 463 | LDF 1880 ; getXY 464 | AP 3 465 | LDC 0 466 | CEQ 467 | TSEL 467 469 ; _L57 _L58 468 | LDC -900000 ; @_L57 469 | ST 0 9 470 | LD 0 6 ; @_L58 471 | LDC 2 472 | CEQ 473 | TSEL 473 477 ; _L59 _L60 474 | LD 0 9 ; @_L59 475 | LDC -300000 476 | ADD 477 | ST 0 9 478 | LD 0 5 ; @_L60 479 | LDC 2 480 | CEQ 481 | TSEL 481 485 ; _L61 _L62 482 | LD 0 9 ; @_L61 483 | LDC 30000 484 | ADD 485 | ST 0 9 486 | LDC 0 ; @_L62 487 | ST 0 10 488 | LD 0 0 489 | LD 0 1 490 | LDC -1 491 | ADD 492 | LD 0 2 493 | LDC 0 494 | ADD 495 | LDF 1880 ; getXY 496 | AP 3 497 | LDC 0 498 | CEQ 499 | TSEL 499 501 ; _L63 _L64 500 | LDC -900000 ; @_L63 501 | ST 0 10 502 | LD 0 6 ; @_L64 503 | LDC 3 504 | CEQ 505 | TSEL 505 509 ; _L65 _L66 506 | LD 0 10 ; @_L65 507 | LDC -300000 508 | ADD 509 | ST 0 10 510 | LD 0 5 ; @_L66 511 | LDC 3 512 | CEQ 513 | TSEL 513 517 ; _L67 _L68 514 | LD 0 10 ; @_L67 515 | LDC 30000 516 | ADD 517 | ST 0 10 518 | LDC -1 ; @_L68 519 | ST 0 11 520 | LD 0 11 ; @_L69 521 | LDC 1 522 | ADD 523 | ST 0 11 524 | LD 0 0 525 | ATOM 526 | LDC 0 527 | CEQ 528 | TSEL 528 727 ; _L70 _L71 529 | LDC -1 ; @_L70 530 | ST 0 12 531 | LD 0 0 532 | CAR 533 | ST 0 13 534 | LD 0 0 535 | CDR 536 | ST 0 0 537 | LD 0 11 538 | LD 0 2 539 | SUB 540 | ST 0 14 541 | LDC -100 542 | LD 0 14 543 | CGT 544 | TSEL 544 546 ; _L72 _L73 545 | LDC 0 ; @_L72 546 | TSEL 519 519 ; _L69 _L69 547 | LD 0 14 ; @_L73 548 | LDC 100 549 | CGT 550 | TSEL 550 552 ; _L74 _L75 551 | LDC 0 ; @_L74 552 | TSEL 727 727 ; _L71 _L71 553 | LD 0 12 ; @_L76 554 | LDC 1 555 | ADD 556 | ST 0 12 557 | LD 0 13 558 | ATOM 559 | LDC 0 560 | CEQ 561 | TSEL 561 725 ; _L77 _L78 562 | LD 0 13 ; @_L77 563 | CAR 564 | ST 0 15 565 | LD 0 13 566 | CDR 567 | ST 0 13 568 | LD 0 12 569 | LD 0 1 570 | SUB 571 | ST 0 16 572 | LDC -100 573 | LD 0 16 574 | CGT 575 | TSEL 575 577 ; _L79 _L80 576 | LDC 0 ; @_L79 577 | TSEL 552 552 ; _L76 _L76 578 | LD 0 16 ; @_L80 579 | LDC 100 580 | CGT 581 | TSEL 581 583 ; _L81 _L82 582 | LDC 0 ; @_L81 583 | TSEL 725 725 ; _L78 _L78 584 | LD 0 15 ; @_L82 585 | LDC 1 586 | CGT 587 | LD 0 4 588 | LD 0 15 589 | CGT 590 | MUL 591 | TSEL 591 723 ; _L83 _L84 592 | LDC 0 ; @_L83 593 | LD 0 14 594 | SUB 595 | ST 0 17 596 | LD 0 17 597 | LDC 0 598 | CGT 599 | TSEL 599 625 ; _L85 _L86 600 | LD 0 16 ; @_L85 601 | ST 0 18 602 | LDC 0 603 | LD 0 18 604 | CGT 605 | TSEL 605 609 ; _L87 _L88 606 | LDC 0 ; @_L87 607 | LD 0 18 608 | SUB 609 | ST 0 18 610 | LD 0 17 ; @_L88 611 | LD 0 18 612 | CGTE 613 | TSEL 613 625 ; _L89 _L90 614 | LD 0 18 ; @_L89 615 | LD 0 17 616 | ADD 617 | ST 0 19 618 | LD 0 7 619 | LDC 300000 620 | LD 0 19 621 | DIV 622 | LD 0 19 623 | DIV 624 | ADD 625 | ST 0 7 626 | LD 0 16 ; @_L86 627 | ST 0 17 628 | LD 0 17 629 | LDC 0 630 | CGT 631 | TSEL 631 657 ; _L91 _L92 632 | LD 0 14 ; @_L91 633 | ST 0 18 634 | LDC 0 635 | LD 0 18 636 | CGT 637 | TSEL 637 641 ; _L93 _L94 638 | LDC 0 ; @_L93 639 | LD 0 18 640 | SUB 641 | ST 0 18 642 | LD 0 17 ; @_L94 643 | LD 0 18 644 | CGTE 645 | TSEL 645 657 ; _L95 _L96 646 | LD 0 18 ; @_L95 647 | LD 0 17 648 | ADD 649 | ST 0 19 650 | LD 0 8 651 | LDC 300000 652 | LD 0 19 653 | DIV 654 | LD 0 19 655 | DIV 656 | ADD 657 | ST 0 8 658 | LD 0 14 ; @_L92 659 | ST 0 17 660 | LD 0 17 661 | LDC 0 662 | CGT 663 | TSEL 663 689 ; _L97 _L98 664 | LD 0 16 ; @_L97 665 | ST 0 18 666 | LDC 0 667 | LD 0 18 668 | CGT 669 | TSEL 669 673 ; _L99 _L100 670 | LDC 0 ; @_L99 671 | LD 0 18 672 | SUB 673 | ST 0 18 674 | LD 0 17 ; @_L100 675 | LD 0 18 676 | CGTE 677 | TSEL 677 689 ; _L101 _L102 678 | LD 0 18 ; @_L101 679 | LD 0 17 680 | ADD 681 | ST 0 19 682 | LD 0 9 683 | LDC 300000 684 | LD 0 19 685 | DIV 686 | LD 0 19 687 | DIV 688 | ADD 689 | ST 0 9 690 | LDC 0 ; @_L98 691 | LD 0 16 692 | SUB 693 | ST 0 17 694 | LD 0 17 695 | LDC 0 696 | CGT 697 | TSEL 697 723 ; _L103 _L104 698 | LD 0 14 ; @_L103 699 | ST 0 18 700 | LDC 0 701 | LD 0 18 702 | CGT 703 | TSEL 703 707 ; _L105 _L106 704 | LDC 0 ; @_L105 705 | LD 0 18 706 | SUB 707 | ST 0 18 708 | LD 0 17 ; @_L106 709 | LD 0 18 710 | CGTE 711 | TSEL 711 723 ; _L107 _L108 712 | LD 0 18 ; @_L107 713 | LD 0 17 714 | ADD 715 | ST 0 19 716 | LD 0 10 717 | LDC 300000 718 | LD 0 19 719 | DIV 720 | LD 0 19 721 | DIV 722 | ADD 723 | ST 0 10 724 | LDC 0 ; @_L84 725 | TSEL 552 552 ; _L76 _L76 726 | LDC 0 ; @_L78 727 | TSEL 519 519 ; _L69 _L69 728 | LD 0 7 ; @_L71 729 | LD 0 8 730 | LD 0 9 731 | LD 0 10 732 | CONS 733 | CONS 734 | CONS 735 | RTN 736 | LD 0 0 ; @getDirScores2 737 | LD 0 1 738 | LD 0 2 739 | LD 0 3 740 | LD 0 4 741 | LD 0 5 742 | LD 0 6 743 | LDC 0 744 | LDC 0 745 | LDC 0 746 | LDC 0 747 | LDC 0 748 | LDC 0 749 | LDC 0 750 | LDC 0 751 | LDC 0 752 | LDC 0 753 | LDC 0 754 | LDC 0 755 | LDF 757 ; getDirScores2_impl 756 | AP 19 757 | RTN 758 | LD 0 3 ; @getDirScores2_impl 759 | LDF 331 ; getOppDir 760 | AP 1 761 | ST 0 7 762 | LDC 0 763 | ST 0 8 764 | LD 0 0 765 | LD 0 1 766 | LDC 0 767 | ADD 768 | LD 0 2 769 | LDC -1 770 | ADD 771 | LDF 1880 ; getXY 772 | AP 3 773 | LDC 0 774 | CEQ 775 | TSEL 775 777 ; _L109 _L110 776 | LDC -900000 ; @_L109 777 | ST 0 8 778 | LD 0 7 ; @_L110 779 | LDC 0 780 | CEQ 781 | TSEL 781 785 ; _L111 _L112 782 | LD 0 8 ; @_L111 783 | LDC -300000 784 | ADD 785 | ST 0 8 786 | LD 0 6 ; @_L112 787 | LDC 0 788 | CEQ 789 | TSEL 789 793 ; _L113 _L114 790 | LD 0 8 ; @_L113 791 | LDC 30000 792 | ADD 793 | ST 0 8 794 | LDC 0 ; @_L114 795 | ST 0 9 796 | LD 0 0 797 | LD 0 1 798 | LDC 1 799 | ADD 800 | LD 0 2 801 | LDC 0 802 | ADD 803 | LDF 1880 ; getXY 804 | AP 3 805 | LDC 0 806 | CEQ 807 | TSEL 807 809 ; _L115 _L116 808 | LDC -900000 ; @_L115 809 | ST 0 9 810 | LD 0 7 ; @_L116 811 | LDC 1 812 | CEQ 813 | TSEL 813 817 ; _L117 _L118 814 | LD 0 9 ; @_L117 815 | LDC -300000 816 | ADD 817 | ST 0 9 818 | LD 0 6 ; @_L118 819 | LDC 1 820 | CEQ 821 | TSEL 821 825 ; _L119 _L120 822 | LD 0 9 ; @_L119 823 | LDC 30000 824 | ADD 825 | ST 0 9 826 | LDC 0 ; @_L120 827 | ST 0 10 828 | LD 0 0 829 | LD 0 1 830 | LDC 0 831 | ADD 832 | LD 0 2 833 | LDC 1 834 | ADD 835 | LDF 1880 ; getXY 836 | AP 3 837 | LDC 0 838 | CEQ 839 | TSEL 839 841 ; _L121 _L122 840 | LDC -900000 ; @_L121 841 | ST 0 10 842 | LD 0 7 ; @_L122 843 | LDC 2 844 | CEQ 845 | TSEL 845 849 ; _L123 _L124 846 | LD 0 10 ; @_L123 847 | LDC -300000 848 | ADD 849 | ST 0 10 850 | LD 0 6 ; @_L124 851 | LDC 2 852 | CEQ 853 | TSEL 853 857 ; _L125 _L126 854 | LD 0 10 ; @_L125 855 | LDC 30000 856 | ADD 857 | ST 0 10 858 | LDC 0 ; @_L126 859 | ST 0 11 860 | LD 0 0 861 | LD 0 1 862 | LDC -1 863 | ADD 864 | LD 0 2 865 | LDC 0 866 | ADD 867 | LDF 1880 ; getXY 868 | AP 3 869 | LDC 0 870 | CEQ 871 | TSEL 871 873 ; _L127 _L128 872 | LDC -900000 ; @_L127 873 | ST 0 11 874 | LD 0 7 ; @_L128 875 | LDC 3 876 | CEQ 877 | TSEL 877 881 ; _L129 _L130 878 | LD 0 11 ; @_L129 879 | LDC -300000 880 | ADD 881 | ST 0 11 882 | LD 0 6 ; @_L130 883 | LDC 3 884 | CEQ 885 | TSEL 885 889 ; _L131 _L132 886 | LD 0 11 ; @_L131 887 | LDC 30000 888 | ADD 889 | ST 0 11 890 | LD 0 5 ; @_L133 891 | ATOM 892 | LDC 0 893 | CEQ 894 | TSEL 894 1047 ; _L134 _L135 895 | LD 0 5 ; @_L134 896 | CAR 897 | CAR 898 | ST 0 12 899 | LD 0 5 900 | CAR 901 | CDR 902 | ST 0 13 903 | LD 0 5 904 | CDR 905 | ST 0 5 906 | LD 0 13 907 | LD 0 2 908 | SUB 909 | ST 0 14 910 | LD 0 12 911 | LD 0 1 912 | SUB 913 | ST 0 15 914 | LDC 0 915 | LD 0 14 916 | SUB 917 | ST 0 16 918 | LD 0 16 919 | LDC 0 920 | CGT 921 | TSEL 921 947 ; _L136 _L137 922 | LD 0 15 ; @_L136 923 | ST 0 17 924 | LDC 0 925 | LD 0 17 926 | CGT 927 | TSEL 927 931 ; _L138 _L139 928 | LDC 0 ; @_L138 929 | LD 0 17 930 | SUB 931 | ST 0 17 932 | LD 0 16 ; @_L139 933 | LD 0 17 934 | CGTE 935 | TSEL 935 947 ; _L140 _L141 936 | LD 0 17 ; @_L140 937 | LD 0 16 938 | ADD 939 | ST 0 18 940 | LD 0 8 941 | LDC 300000 942 | LD 0 18 943 | DIV 944 | LD 0 18 945 | DIV 946 | ADD 947 | ST 0 8 948 | LD 0 15 ; @_L137 949 | ST 0 16 950 | LD 0 16 951 | LDC 0 952 | CGT 953 | TSEL 953 979 ; _L142 _L143 954 | LD 0 14 ; @_L142 955 | ST 0 17 956 | LDC 0 957 | LD 0 17 958 | CGT 959 | TSEL 959 963 ; _L144 _L145 960 | LDC 0 ; @_L144 961 | LD 0 17 962 | SUB 963 | ST 0 17 964 | LD 0 16 ; @_L145 965 | LD 0 17 966 | CGTE 967 | TSEL 967 979 ; _L146 _L147 968 | LD 0 17 ; @_L146 969 | LD 0 16 970 | ADD 971 | ST 0 18 972 | LD 0 9 973 | LDC 300000 974 | LD 0 18 975 | DIV 976 | LD 0 18 977 | DIV 978 | ADD 979 | ST 0 9 980 | LD 0 14 ; @_L143 981 | ST 0 16 982 | LD 0 16 983 | LDC 0 984 | CGT 985 | TSEL 985 1011 ; _L148 _L149 986 | LD 0 15 ; @_L148 987 | ST 0 17 988 | LDC 0 989 | LD 0 17 990 | CGT 991 | TSEL 991 995 ; _L150 _L151 992 | LDC 0 ; @_L150 993 | LD 0 17 994 | SUB 995 | ST 0 17 996 | LD 0 16 ; @_L151 997 | LD 0 17 998 | CGTE 999 | TSEL 999 1011 ; _L152 _L153 1000 | LD 0 17 ; @_L152 1001 | LD 0 16 1002 | ADD 1003 | ST 0 18 1004 | LD 0 10 1005 | LDC 300000 1006 | LD 0 18 1007 | DIV 1008 | LD 0 18 1009 | DIV 1010 | ADD 1011 | ST 0 10 1012 | LDC 0 ; @_L149 1013 | LD 0 15 1014 | SUB 1015 | ST 0 16 1016 | LD 0 16 1017 | LDC 0 1018 | CGT 1019 | TSEL 1019 1045 ; _L154 _L155 1020 | LD 0 14 ; @_L154 1021 | ST 0 17 1022 | LDC 0 1023 | LD 0 17 1024 | CGT 1025 | TSEL 1025 1029 ; _L156 _L157 1026 | LDC 0 ; @_L156 1027 | LD 0 17 1028 | SUB 1029 | ST 0 17 1030 | LD 0 16 ; @_L157 1031 | LD 0 17 1032 | CGTE 1033 | TSEL 1033 1045 ; _L158 _L159 1034 | LD 0 17 ; @_L158 1035 | LD 0 16 1036 | ADD 1037 | ST 0 18 1038 | LD 0 11 1039 | LDC 300000 1040 | LD 0 18 1041 | DIV 1042 | LD 0 18 1043 | DIV 1044 | ADD 1045 | ST 0 11 1046 | LDC 0 ; @_L155 1047 | TSEL 889 889 ; _L133 _L133 1048 | LD 0 8 ; @_L135 1049 | LD 0 9 1050 | LD 0 10 1051 | LD 0 11 1052 | CONS 1053 | CONS 1054 | CONS 1055 | RTN 1056 | LD 0 0 ; @step_fast 1057 | LD 0 1 1058 | LDC 0 1059 | LDC 0 1060 | LDC 0 1061 | LDC 0 1062 | LDC 0 1063 | LDC 0 1064 | LDC 0 1065 | LDC 0 1066 | LDC 0 1067 | LDC 0 1068 | LDC 0 1069 | LDC 0 1070 | LDC 0 1071 | LDC 0 1072 | LDC 0 1073 | LDC 0 1074 | LDC 0 1075 | LDC 0 1076 | LDC 0 1077 | LDC 0 1078 | LDC 0 1079 | LDC 0 1080 | LDC 0 1081 | LDC 0 1082 | LDC 0 1083 | LDF 1085 ; step_fast_impl 1084 | AP 27 1085 | RTN 1086 | LD 0 1 ; @step_fast_impl 1087 | CAR 1088 | ST 0 2 1089 | LD 0 1 1090 | CDR 1091 | CAR 1092 | ST 0 3 1093 | LD 0 3 1094 | CAR 1095 | ST 0 4 1096 | LD 0 3 1097 | CDR 1098 | CAR 1099 | ST 0 5 1100 | LD 0 3 1101 | CDR 1102 | CDR 1103 | CAR 1104 | ST 0 6 1105 | LD 0 1 1106 | CDR 1107 | CDR 1108 | CAR 1109 | ST 0 7 1110 | LD 0 1 1111 | CDR 1112 | CDR 1113 | CDR 1114 | ST 0 8 1115 | LD 0 5 1116 | CAR 1117 | ST 0 9 1118 | LD 0 5 1119 | CDR 1120 | ST 0 10 1121 | LDC 4 1122 | ST 0 11 1123 | LD 0 8 1124 | TSEL 1124 1126 ; _L160 _L161 1125 | LDC 5 ; @_L160 1126 | ST 0 11 1127 | LD 0 0 ; @_L161 1128 | CAR 1129 | ST 0 12 1130 | LD 0 0 1131 | CDR 1132 | CAR 1133 | ST 0 13 1134 | LD 0 0 1135 | CDR 1136 | CDR 1137 | ST 0 14 1138 | LDC 0 1139 | ST 0 15 1140 | LD 0 13 ; @_L162 1141 | ATOM 1142 | LDC 0 1143 | CEQ 1144 | TSEL 1144 1172 ; _L163 _L164 1145 | LD 0 13 ; @_L163 1146 | CAR 1147 | ST 0 16 1148 | LD 0 13 1149 | CDR 1150 | ST 0 13 1151 | LD 0 16 1152 | CAR 1153 | LD 0 9 1154 | CEQ 1155 | LD 0 16 1156 | CDR 1157 | LD 0 10 1158 | CEQ 1159 | MUL 1160 | TSEL 1160 1166 ; _L165 _L166 1161 | LD 0 14 ; @_L165 1162 | LDC -1 1163 | ADD 1164 | ST 0 14 1165 | LDC 0 1166 | TSEL 1170 1170 ; _L167 _L167 1167 | LD 0 16 ; @_L166 1168 | LD 0 15 1169 | CONS 1170 | ST 0 15 1171 | LDC 0 ; @_L167 1172 | TSEL 1139 1139 ; _L162 _L162 1173 | LD 0 15 ; @_L164 1174 | ST 0 13 1175 | LD 0 12 1176 | LD 0 13 1177 | LD 0 14 1178 | CONS 1179 | CONS 1180 | ST 0 0 1181 | LD 0 2 1182 | LD 0 9 1183 | LD 0 10 1184 | LDF 176 ; getSubMap 1185 | AP 3 1186 | ST 0 17 1187 | LD 0 17 1188 | LDF 2172 ; getInitDistMap 1189 | AP 1 1190 | ST 0 18 1191 | LD 0 17 1192 | LD 0 18 1193 | LDC 11 1194 | LDC 11 1195 | CONS 1196 | LDF 1974 ; fillDistMap 1197 | AP 3 1198 | ST 0 18 1199 | LD 0 17 1200 | LD 0 18 1201 | LD 0 11 1202 | LDC 1 1203 | LDC 1 1204 | LDC 1 1205 | LDC 1 1206 | LDF 1757 ; getBestMove 1207 | AP 7 1208 | ST 0 19 1209 | LDC 10000 1210 | LD 0 14 1211 | CGT 1212 | TSEL 1212 1224 ; _L168 _L169 1213 | LD 0 2 ; @_L168 1214 | LD 0 9 1215 | LD 0 10 1216 | LD 0 6 1217 | LD 0 11 1218 | LD 0 13 1219 | LD 0 19 1220 | LDF 735 ; getDirScores2 1221 | AP 7 1222 | ST 0 20 1223 | LDC 0 1224 | TSEL 1233 1233 ; _L170 _L170 1225 | LD 0 2 ; @_L169 1226 | LD 0 9 1227 | LD 0 10 1228 | LD 0 6 1229 | LD 0 11 1230 | LD 0 19 1231 | LDF 362 ; getDirScores 1232 | AP 6 1233 | ST 0 20 1234 | LD 0 12 ; @_L170 1235 | LD 0 14 1236 | LD 0 20 1237 | CONS 1238 | CONS 1239 | DBUG 1240 | LDC 400 1241 | LD 0 4 1242 | CGT 1243 | TSEL 1243 1344 ; _L171 _L172 1244 | LDC -1 ; @_L171 1245 | ST 0 19 1246 | LDC -1200000 1247 | ST 0 21 1248 | LD 0 2 1249 | LD 0 5 1250 | LDC 0 1251 | LDC 2 1252 | LD 0 7 1253 | LDF 2410 ; isOK 1254 | AP 5 1255 | ST 0 22 1256 | LD 0 22 1257 | TSEL 1257 1268 ; _L173 _L174 1258 | LD 0 20 ; @_L173 1259 | CAR 1260 | ST 0 23 1261 | LD 0 23 1262 | LD 0 21 1263 | CGT 1264 | TSEL 1264 1268 ; _L175 _L176 1265 | LD 0 23 ; @_L175 1266 | ST 0 21 1267 | LDC 0 1268 | ST 0 19 1269 | LD 0 2 ; @_L174 1270 | LD 0 5 1271 | LDC 1 1272 | LDC 3 1273 | LD 0 7 1274 | LDF 2410 ; isOK 1275 | AP 5 1276 | ST 0 24 1277 | LD 0 24 1278 | TSEL 1278 1290 ; _L177 _L178 1279 | LD 0 20 ; @_L177 1280 | CDR 1281 | CAR 1282 | ST 0 23 1283 | LD 0 23 1284 | LD 0 21 1285 | CGT 1286 | TSEL 1286 1290 ; _L179 _L180 1287 | LD 0 23 ; @_L179 1288 | ST 0 21 1289 | LDC 1 1290 | ST 0 19 1291 | LD 0 2 ; @_L178 1292 | LD 0 5 1293 | LDC 2 1294 | LDC 0 1295 | LD 0 7 1296 | LDF 2410 ; isOK 1297 | AP 5 1298 | ST 0 25 1299 | LD 0 25 1300 | TSEL 1300 1313 ; _L181 _L182 1301 | LD 0 20 ; @_L181 1302 | CDR 1303 | CDR 1304 | CAR 1305 | ST 0 23 1306 | LD 0 23 1307 | LD 0 21 1308 | CGT 1309 | TSEL 1309 1313 ; _L183 _L184 1310 | LD 0 23 ; @_L183 1311 | ST 0 21 1312 | LDC 2 1313 | ST 0 19 1314 | LD 0 2 ; @_L182 1315 | LD 0 5 1316 | LDC 3 1317 | LDC 1 1318 | LD 0 7 1319 | LDF 2410 ; isOK 1320 | AP 5 1321 | ST 0 26 1322 | LD 0 26 1323 | TSEL 1323 1336 ; _L185 _L186 1324 | LD 0 20 ; @_L185 1325 | CDR 1326 | CDR 1327 | CDR 1328 | ST 0 23 1329 | LD 0 23 1330 | LD 0 21 1331 | CGT 1332 | TSEL 1332 1336 ; _L187 _L188 1333 | LD 0 23 ; @_L187 1334 | ST 0 21 1335 | LDC 3 1336 | ST 0 19 1337 | LD 0 19 ; @_L186 1338 | LDC 0 1339 | CGTE 1340 | TSEL 1340 1344 ; _L189 _L190 1341 | LD 0 0 ; @_L189 1342 | LD 0 19 1343 | CONS 1344 | RTN 1345 | LD 0 20 ; @_L172 1346 | CAR 1347 | ST 0 23 1348 | LD 0 23 1349 | LD 0 21 1350 | CGT 1351 | TSEL 1351 1355 ; _L191 _L192 1352 | LD 0 23 ; @_L191 1353 | ST 0 21 1354 | LDC 0 1355 | ST 0 19 1356 | LD 0 20 ; @_L192 1357 | CDR 1358 | CAR 1359 | ST 0 23 1360 | LD 0 23 1361 | LD 0 21 1362 | CGT 1363 | TSEL 1363 1367 ; _L193 _L194 1364 | LD 0 23 ; @_L193 1365 | ST 0 21 1366 | LDC 1 1367 | ST 0 19 1368 | LD 0 20 ; @_L194 1369 | CDR 1370 | CDR 1371 | CAR 1372 | ST 0 23 1373 | LD 0 23 1374 | LD 0 21 1375 | CGT 1376 | TSEL 1376 1380 ; _L195 _L196 1377 | LD 0 23 ; @_L195 1378 | ST 0 21 1379 | LDC 2 1380 | ST 0 19 1381 | LD 0 20 ; @_L196 1382 | CDR 1383 | CDR 1384 | CDR 1385 | ST 0 23 1386 | LD 0 23 1387 | LD 0 21 1388 | CGT 1389 | TSEL 1389 1393 ; _L197 _L198 1390 | LD 0 23 ; @_L197 1391 | ST 0 21 1392 | LDC 3 1393 | ST 0 19 1394 | LD 0 19 ; @_L198 1395 | LDC 0 1396 | CGTE 1397 | TSEL 1397 1401 ; _L199 _L200 1398 | LD 0 0 ; @_L199 1399 | LD 0 19 1400 | CONS 1401 | RTN 1402 | LDC -999 ; @_L200 1403 | DBUG 1404 | LD 0 0 1405 | LDC 2 1406 | CONS 1407 | RTN 1408 | LD 0 0 ; @step_slow 1409 | LD 0 1 1410 | LDC 0 1411 | LDC 0 1412 | LDC 0 1413 | LDC 0 1414 | LDC 0 1415 | LDC 0 1416 | LDC 0 1417 | LDC 0 1418 | LDC 0 1419 | LDC 0 1420 | LDC 0 1421 | LDC 0 1422 | LDC 0 1423 | LDC 0 1424 | LDC 0 1425 | LDC 0 1426 | LDC 0 1427 | LDC 0 1428 | LDC 0 1429 | LDC 0 1430 | LDC 0 1431 | LDC 0 1432 | LDF 1434 ; step_slow_impl 1433 | AP 24 1434 | RTN 1435 | LD 0 1 ; @step_slow_impl 1436 | CAR 1437 | ST 0 2 1438 | LD 0 1 1439 | CDR 1440 | CAR 1441 | ST 0 3 1442 | LD 0 3 1443 | CAR 1444 | ST 0 4 1445 | LD 0 3 1446 | CDR 1447 | CAR 1448 | ST 0 5 1449 | LD 0 3 1450 | CDR 1451 | CDR 1452 | CAR 1453 | ST 0 6 1454 | LD 0 1 1455 | CDR 1456 | CDR 1457 | CAR 1458 | ST 0 7 1459 | LD 0 1 1460 | CDR 1461 | CDR 1462 | CDR 1463 | ST 0 8 1464 | LD 0 5 1465 | CAR 1466 | ST 0 9 1467 | LD 0 5 1468 | CDR 1469 | ST 0 10 1470 | LDC 4 1471 | ST 0 11 1472 | LD 0 8 1473 | TSEL 1473 1475 ; _L201 _L202 1474 | LDC 5 ; @_L201 1475 | ST 0 11 1476 | LD 0 0 ; @_L202 1477 | CAR 1478 | ST 0 12 1479 | LD 0 0 1480 | CDR 1481 | CAR 1482 | ST 0 13 1483 | LD 0 0 1484 | CDR 1485 | CDR 1486 | ST 0 14 1487 | LDC 0 1488 | ST 0 15 1489 | LD 0 13 ; @_L203 1490 | ATOM 1491 | LDC 0 1492 | CEQ 1493 | TSEL 1493 1521 ; _L204 _L205 1494 | LD 0 13 ; @_L204 1495 | CAR 1496 | ST 0 16 1497 | LD 0 13 1498 | CDR 1499 | ST 0 13 1500 | LD 0 16 1501 | CAR 1502 | LD 0 9 1503 | CEQ 1504 | LD 0 16 1505 | CDR 1506 | LD 0 10 1507 | CEQ 1508 | MUL 1509 | TSEL 1509 1515 ; _L206 _L207 1510 | LD 0 14 ; @_L206 1511 | LDC -1 1512 | ADD 1513 | ST 0 14 1514 | LDC 0 1515 | TSEL 1519 1519 ; _L208 _L208 1516 | LD 0 16 ; @_L207 1517 | LD 0 15 1518 | CONS 1519 | ST 0 15 1520 | LDC 0 ; @_L208 1521 | TSEL 1488 1488 ; _L203 _L203 1522 | LD 0 15 ; @_L205 1523 | ST 0 13 1524 | LD 0 12 1525 | LD 0 13 1526 | LD 0 14 1527 | CONS 1528 | CONS 1529 | ST 0 0 1530 | LD 0 2 1531 | LDF 2172 ; getInitDistMap 1532 | AP 1 1533 | ST 0 17 1534 | LD 0 2 1535 | LD 0 17 1536 | LD 0 5 1537 | LDF 1974 ; fillDistMap 1538 | AP 3 1539 | ST 0 17 1540 | LDC 400 1541 | LD 0 4 1542 | CGT 1543 | TSEL 1543 1737 ; _L209 _L210 1544 | LD 0 2 ; @_L209 1545 | LD 0 5 1546 | LDC 0 1547 | LDC 2 1548 | LD 0 7 1549 | LDF 2410 ; isOK 1550 | AP 5 1551 | ST 0 18 1552 | LD 0 2 1553 | LD 0 5 1554 | LDC 1 1555 | LDC 3 1556 | LD 0 7 1557 | LDF 2410 ; isOK 1558 | AP 5 1559 | ST 0 19 1560 | LD 0 2 1561 | LD 0 5 1562 | LDC 2 1563 | LDC 0 1564 | LD 0 7 1565 | LDF 2410 ; isOK 1566 | AP 5 1567 | ST 0 20 1568 | LD 0 2 1569 | LD 0 5 1570 | LDC 3 1571 | LDC 1 1572 | LD 0 7 1573 | LDF 2410 ; isOK 1574 | AP 5 1575 | ST 0 21 1576 | LD 0 2 1577 | LD 0 17 1578 | LD 0 11 1579 | LD 0 18 1580 | LD 0 19 1581 | LD 0 20 1582 | LD 0 21 1583 | LDF 1757 ; getBestMove 1584 | AP 7 1585 | ST 0 22 1586 | LD 0 22 1587 | LDC 0 1588 | CGTE 1589 | TSEL 1589 1605 ; _L211 _L212 1590 | LD 0 18 ; @_L211 1591 | LD 0 19 1592 | LD 0 20 1593 | LD 0 21 1594 | LDC 0 1595 | CONS 1596 | CONS 1597 | CONS 1598 | CONS 1599 | LD 0 22 1600 | CONS 1601 | DBUG 1602 | LD 0 0 1603 | LD 0 22 1604 | CONS 1605 | RTN 1606 | LDC 4 ; @_L212 1607 | LD 0 18 1608 | LD 0 19 1609 | ADD 1610 | LD 0 20 1611 | ADD 1612 | LD 0 21 1613 | ADD 1614 | CGT 1615 | TSEL 1615 1727 ; _L213 _L214 1616 | LD 0 18 ; @_L213 1617 | TSEL 1617 1643 ; _L215 _L216 1618 | LD 0 2 ; @_L215 1619 | LD 0 9 1620 | LDC 0 1621 | ADD 1622 | LD 0 10 1623 | LDC -1 1624 | ADD 1625 | LDF 1880 ; getXY 1626 | AP 3 1627 | TSEL 1627 1643 ; _L217 _L218 1628 | LDC 0 ; @_L217 1629 | LD 0 18 1630 | LD 0 19 1631 | LD 0 20 1632 | LD 0 21 1633 | LDC 0 1634 | CONS 1635 | CONS 1636 | CONS 1637 | CONS 1638 | CONS 1639 | DBUG 1640 | LD 0 0 1641 | LDC 0 1642 | CONS 1643 | RTN 1644 | LD 0 19 ; @_L216 1645 | TSEL 1645 1671 ; _L219 _L220 1646 | LD 0 2 ; @_L219 1647 | LD 0 9 1648 | LDC 1 1649 | ADD 1650 | LD 0 10 1651 | LDC 0 1652 | ADD 1653 | LDF 1880 ; getXY 1654 | AP 3 1655 | TSEL 1655 1671 ; _L221 _L222 1656 | LDC 1 ; @_L221 1657 | LD 0 18 1658 | LD 0 19 1659 | LD 0 20 1660 | LD 0 21 1661 | LDC 0 1662 | CONS 1663 | CONS 1664 | CONS 1665 | CONS 1666 | CONS 1667 | DBUG 1668 | LD 0 0 1669 | LDC 1 1670 | CONS 1671 | RTN 1672 | LD 0 20 ; @_L220 1673 | TSEL 1673 1699 ; _L223 _L224 1674 | LD 0 2 ; @_L223 1675 | LD 0 9 1676 | LDC 0 1677 | ADD 1678 | LD 0 10 1679 | LDC 1 1680 | ADD 1681 | LDF 1880 ; getXY 1682 | AP 3 1683 | TSEL 1683 1699 ; _L225 _L226 1684 | LDC 2 ; @_L225 1685 | LD 0 18 1686 | LD 0 19 1687 | LD 0 20 1688 | LD 0 21 1689 | LDC 0 1690 | CONS 1691 | CONS 1692 | CONS 1693 | CONS 1694 | CONS 1695 | DBUG 1696 | LD 0 0 1697 | LDC 2 1698 | CONS 1699 | RTN 1700 | LD 0 21 ; @_L224 1701 | TSEL 1701 1727 ; _L227 _L228 1702 | LD 0 2 ; @_L227 1703 | LD 0 9 1704 | LDC -1 1705 | ADD 1706 | LD 0 10 1707 | LDC 0 1708 | ADD 1709 | LDF 1880 ; getXY 1710 | AP 3 1711 | TSEL 1711 1727 ; _L229 _L230 1712 | LDC 3 ; @_L229 1713 | LD 0 18 1714 | LD 0 19 1715 | LD 0 20 1716 | LD 0 21 1717 | LDC 0 1718 | CONS 1719 | CONS 1720 | CONS 1721 | CONS 1722 | CONS 1723 | DBUG 1724 | LD 0 0 1725 | LDC 3 1726 | CONS 1727 | RTN 1728 | LD 0 18 ; @_L214 1729 | LD 0 19 1730 | LD 0 20 1731 | LD 0 21 1732 | LDC 0 1733 | CONS 1734 | CONS 1735 | CONS 1736 | CONS 1737 | DBUG 1738 | LD 0 2 ; @_L210 1739 | LD 0 17 1740 | LD 0 11 1741 | LDC 1 1742 | LDC 1 1743 | LDC 1 1744 | LDC 1 1745 | LDF 1757 ; getBestMove 1746 | AP 7 1747 | ST 0 22 1748 | LD 0 4 1749 | LD 0 22 1750 | CONS 1751 | DBUG 1752 | LD 0 22 1753 | ST 0 23 1754 | LD 0 0 1755 | LD 0 23 1756 | CONS 1757 | RTN 1758 | LD 0 0 ; @getBestMove 1759 | LD 0 1 1760 | LD 0 2 1761 | LD 0 3 1762 | LD 0 4 1763 | LD 0 5 1764 | LD 0 6 1765 | LDC 0 1766 | LDC 0 1767 | LDC 0 1768 | LDC 0 1769 | LDC 0 1770 | LDC 0 1771 | LDC 0 1772 | LDC 0 1773 | LDC 0 1774 | LDC 0 1775 | LDF 1777 ; getBestMove_impl 1776 | AP 17 1777 | RTN 1778 | LDC 0 ; @getBestMove_impl 1779 | ST 0 7 1780 | LDC 9999999 1781 | ST 0 8 1782 | LDC -1 1783 | ST 0 9 1784 | LD 0 1 ; @_L231 1785 | ATOM 1786 | LDC 0 1787 | CEQ 1788 | TSEL 1788 1878 ; _L232 _L233 1789 | LDC 0 ; @_L232 1790 | ST 0 10 1791 | LD 0 1 1792 | CAR 1793 | ST 0 11 1794 | LD 0 1 1795 | CDR 1796 | ST 0 1 1797 | LD 0 11 ; @_L234 1798 | ATOM 1799 | LDC 0 1800 | CEQ 1801 | TSEL 1801 1872 ; _L235 _L236 1802 | LD 0 11 ; @_L235 1803 | CAR 1804 | ST 0 12 1805 | LD 0 11 1806 | CDR 1807 | ST 0 11 1808 | LD 0 12 1809 | CAR 1810 | ST 0 13 1811 | LD 0 13 1812 | LDC 0 1813 | CGT 1814 | TSEL 1814 1866 ; _L237 _L238 1815 | LD 0 0 ; @_L237 1816 | LD 0 10 1817 | LD 0 7 1818 | LDF 1880 ; getXY 1819 | AP 3 1820 | ST 0 14 1821 | LD 0 14 1822 | LDC 1 1823 | CGT 1824 | LD 0 2 1825 | LD 0 14 1826 | CGT 1827 | MUL 1828 | TSEL 1828 1866 ; _L239 _L240 1829 | LD 0 8 ; @_L239 1830 | LD 0 13 1831 | CGT 1832 | TSEL 1832 1866 ; _L241 _L242 1833 | LD 0 12 ; @_L241 1834 | CDR 1835 | ST 0 15 1836 | LD 0 15 1837 | LDC 0 1838 | CEQ 1839 | LD 0 3 1840 | MUL 1841 | LD 0 15 1842 | LDC 1 1843 | CEQ 1844 | LD 0 4 1845 | MUL 1846 | ADD 1847 | LD 0 15 1848 | LDC 2 1849 | CEQ 1850 | LD 0 5 1851 | MUL 1852 | ADD 1853 | LD 0 15 1854 | LDC 3 1855 | CEQ 1856 | LD 0 6 1857 | MUL 1858 | ADD 1859 | ST 0 16 1860 | LD 0 16 1861 | TSEL 1861 1866 ; _L243 _L244 1862 | LD 0 13 ; @_L243 1863 | ST 0 8 1864 | LD 0 12 1865 | CDR 1866 | ST 0 9 1867 | LD 0 10 ; @_L238 1868 | LDC 1 1869 | ADD 1870 | ST 0 10 1871 | LDC 0 1872 | TSEL 1796 1796 ; _L234 _L234 1873 | LD 0 7 ; @_L236 1874 | LDC 1 1875 | ADD 1876 | ST 0 7 1877 | LDC 0 1878 | TSEL 1783 1783 ; _L231 _L231 1879 | LD 0 9 ; @_L233 1880 | RTN 1881 | LD 0 0 ; @getXY 1882 | LD 0 1 1883 | LD 0 2 1884 | LDC 0 1885 | LDF 1887 ; getXY_impl 1886 | AP 4 1887 | RTN 1888 | LD 0 0 ; @getXY_impl 1889 | ST 0 3 1890 | LD 0 2 ; @_L245 1891 | TSEL 1891 1900 ; _L246 _L247 1892 | LD 0 2 ; @_L246 1893 | LDC 1 1894 | SUB 1895 | ST 0 2 1896 | LD 0 3 1897 | CDR 1898 | ST 0 3 1899 | LDC 0 1900 | TSEL 1889 1889 ; _L245 _L245 1901 | LD 0 3 ; @_L247 1902 | CAR 1903 | ST 0 3 1904 | LD 0 1 ; @_L248 1905 | TSEL 1905 1914 ; _L249 _L250 1906 | LD 0 1 ; @_L249 1907 | LDC 1 1908 | SUB 1909 | ST 0 1 1910 | LD 0 3 1911 | CDR 1912 | ST 0 3 1913 | LDC 0 1914 | TSEL 1903 1903 ; _L248 _L248 1915 | LD 0 3 ; @_L250 1916 | CAR 1917 | RTN 1918 | LD 0 0 ; @setXYRow 1919 | LD 0 1 1920 | LD 0 2 1921 | LDF 1923 ; setXYRow_impl 1922 | AP 3 1923 | RTN 1924 | LD 0 1 ; @setXYRow_impl 1925 | TSEL 1925 1937 ; _L251 _L252 1926 | LD 0 0 ; @_L251 1927 | CAR 1928 | LD 0 0 1929 | CDR 1930 | LD 0 1 1931 | LDC 1 1932 | SUB 1933 | LD 0 2 1934 | LDF 1917 ; setXYRow 1935 | AP 3 1936 | CONS 1937 | RTN 1938 | LD 0 2 ; @_L252 1939 | LD 0 0 1940 | CDR 1941 | CONS 1942 | RTN 1943 | LD 0 0 ; @setXY 1944 | LD 0 1 1945 | LD 0 2 1946 | LD 0 3 1947 | LDF 1949 ; setXY_impl 1948 | AP 4 1949 | RTN 1950 | LD 0 2 ; @setXY_impl 1951 | TSEL 1951 1964 ; _L253 _L254 1952 | LD 0 0 ; @_L253 1953 | CAR 1954 | LD 0 0 1955 | CDR 1956 | LD 0 1 1957 | LD 0 2 1958 | LDC 1 1959 | SUB 1960 | LD 0 3 1961 | LDF 1942 ; setXY 1962 | AP 4 1963 | CONS 1964 | RTN 1965 | LD 0 0 ; @_L254 1966 | CAR 1967 | LD 0 1 1968 | LD 0 3 1969 | LDF 1917 ; setXYRow 1970 | AP 3 1971 | LD 0 0 1972 | CDR 1973 | CONS 1974 | RTN 1975 | LD 0 0 ; @fillDistMap 1976 | LD 0 1 1977 | LD 0 2 1978 | LDC 0 1979 | LDC 0 1980 | LDC 0 1981 | LDC 0 1982 | LDC 0 1983 | LDC 0 1984 | LDC 0 1985 | LDF 1987 ; fillDistMap_impl 1986 | AP 10 1987 | RTN 1988 | LD 0 2 ; @fillDistMap_impl 1989 | CAR 1990 | ST 0 3 1991 | LD 0 2 1992 | CDR 1993 | ST 0 4 1994 | LD 0 1 1995 | LD 0 3 1996 | LD 0 4 1997 | LDC 1 1998 | LDC -1 1999 | CONS 2000 | LDF 1942 ; setXY 2001 | AP 4 2002 | ST 0 1 2003 | LD 0 3 2004 | LD 0 4 2005 | LDC 1 2006 | SUB 2007 | CONS 2008 | LDC 0 2009 | CONS 2010 | LD 0 3 2011 | LDC 1 2012 | ADD 2013 | LD 0 4 2014 | CONS 2015 | LDC 1 2016 | CONS 2017 | LD 0 3 2018 | LD 0 4 2019 | LDC 1 2020 | ADD 2021 | CONS 2022 | LDC 2 2023 | CONS 2024 | LD 0 3 2025 | LDC 1 2026 | SUB 2027 | LD 0 4 2028 | CONS 2029 | LDC 3 2030 | CONS 2031 | LDC 0 2032 | CONS 2033 | CONS 2034 | CONS 2035 | CONS 2036 | ST 0 5 2037 | LDC 2 2038 | ST 0 6 2039 | LD 0 5 ; @_L255 2040 | ATOM 2041 | LDC 0 2042 | CEQ 2043 | TSEL 2043 2136 ; _L256 _L257 2044 | LDC 0 ; @_L256 2045 | ST 0 7 2046 | LD 0 5 ; @_L258 2047 | ATOM 2048 | LDC 0 2049 | CEQ 2050 | TSEL 2050 2128 ; _L259 _L260 2051 | LD 0 5 ; @_L259 2052 | CAR 2053 | ST 0 8 2054 | LD 0 5 2055 | CDR 2056 | ST 0 5 2057 | LD 0 8 2058 | CAR 2059 | ST 0 2 2060 | LD 0 8 2061 | CDR 2062 | ST 0 9 2063 | LD 0 2 2064 | CAR 2065 | ST 0 3 2066 | LD 0 2 2067 | CDR 2068 | ST 0 4 2069 | LD 0 1 2070 | LD 0 3 2071 | LD 0 4 2072 | LDF 1880 ; getXY 2073 | AP 3 2074 | CAR 2075 | LDC 0 2076 | CEQ 2077 | TSEL 2077 2126 ; _L261 _L262 2078 | LD 0 1 ; @_L261 2079 | LD 0 3 2080 | LD 0 4 2081 | LD 0 6 2082 | LD 0 9 2083 | CONS 2084 | LDF 1942 ; setXY 2085 | AP 4 2086 | ST 0 1 2087 | LD 0 3 2088 | LDC 1 2089 | ADD 2090 | LD 0 4 2091 | CONS 2092 | LD 0 9 2093 | CONS 2094 | LD 0 7 2095 | CONS 2096 | ST 0 7 2097 | LD 0 3 2098 | LDC 1 2099 | SUB 2100 | LD 0 4 2101 | CONS 2102 | LD 0 9 2103 | CONS 2104 | LD 0 7 2105 | CONS 2106 | ST 0 7 2107 | LD 0 3 2108 | LD 0 4 2109 | LDC 1 2110 | ADD 2111 | CONS 2112 | LD 0 9 2113 | CONS 2114 | LD 0 7 2115 | CONS 2116 | ST 0 7 2117 | LD 0 3 2118 | LD 0 4 2119 | LDC 1 2120 | SUB 2121 | CONS 2122 | LD 0 9 2123 | CONS 2124 | LD 0 7 2125 | CONS 2126 | ST 0 7 2127 | LDC 0 ; @_L262 2128 | TSEL 2045 2045 ; _L258 _L258 2129 | LD 0 6 ; @_L260 2130 | LDC 1 2131 | ADD 2132 | ST 0 6 2133 | LD 0 7 2134 | ST 0 5 2135 | LDC 0 2136 | TSEL 2038 2038 ; _L255 _L255 2137 | LD 0 1 ; @_L257 2138 | RTN 2139 | LD 0 0 ; @getInitDistRow 2140 | LDC 0 2141 | LDF 2143 ; getInitDistRow_impl 2142 | AP 2 2143 | RTN 2144 | LD 0 0 ; @getInitDistRow_impl 2145 | ATOM 2146 | TSEL 2146 2148 ; _L263 _L264 2147 | LDC 0 ; @_L263 2148 | RTN 2149 | LD 0 0 ; @_L264 2150 | CAR 2151 | ST 0 1 2152 | LD 0 1 2153 | LDC 0 2154 | CEQ 2155 | TSEL 2155 2157 ; _L265 _L266 2156 | LDC -1 ; @_L265 2157 | ST 0 1 2158 | LD 0 1 ; @_L266 2159 | LDC 0 2160 | CGT 2161 | TSEL 2161 2163 ; _L267 _L268 2162 | LDC 0 ; @_L267 2163 | ST 0 1 2164 | LD 0 1 ; @_L268 2165 | LDC -1 2166 | CONS 2167 | LD 0 0 2168 | CDR 2169 | LDF 2138 ; getInitDistRow 2170 | AP 1 2171 | CONS 2172 | RTN 2173 | LD 0 0 ; @getInitDistMap 2174 | LDF 2176 ; getInitDistMap_impl 2175 | AP 1 2176 | RTN 2177 | LD 0 0 ; @getInitDistMap_impl 2178 | ATOM 2179 | TSEL 2179 2181 ; _L269 _L270 2180 | LDC 0 ; @_L269 2181 | RTN 2182 | LD 0 0 ; @_L270 2183 | CAR 2184 | LDF 2138 ; getInitDistRow 2185 | AP 1 2186 | LD 0 0 2187 | CDR 2188 | LDF 2172 ; getInitDistMap 2189 | AP 1 2190 | CONS 2191 | RTN 2192 | LD 0 0 ; @getEmptyRow 2193 | LDF 2195 ; getEmptyRow_impl 2194 | AP 1 2195 | RTN 2196 | LD 0 0 ; @getEmptyRow_impl 2197 | ATOM 2198 | TSEL 2198 2200 ; _L271 _L272 2199 | LDC 0 ; @_L271 2200 | RTN 2201 | LDC 0 ; @_L272 2202 | LD 0 0 2203 | CDR 2204 | LDF 2191 ; getEmptyRow 2205 | AP 1 2206 | CONS 2207 | RTN 2208 | LD 0 0 ; @getEmptyMap 2209 | LDF 2211 ; getEmptyMap_impl 2210 | AP 1 2211 | RTN 2212 | LD 0 0 ; @getEmptyMap_impl 2213 | ATOM 2214 | TSEL 2214 2216 ; _L273 _L274 2215 | LDC 0 ; @_L273 2216 | RTN 2217 | LD 0 0 ; @_L274 2218 | CAR 2219 | LDF 2191 ; getEmptyRow 2220 | AP 1 2221 | LD 0 0 2222 | CDR 2223 | LDF 2207 ; getEmptyMap 2224 | AP 1 2225 | CONS 2226 | RTN 2227 | LD 0 0 ; @getDir 2228 | LD 0 1 2229 | LDF 2231 ; getDir_impl 2230 | AP 2 2231 | RTN 2232 | LD 0 0 ; @getDir_impl 2233 | CAR 2234 | LD 0 1 2235 | CAR 2236 | CEQ 2237 | TSEL 2237 2247 ; _L275 _L276 2238 | LD 0 0 ; @_L275 2239 | CDR 2240 | LD 0 1 2241 | CDR 2242 | CGT 2243 | TSEL 2243 2245 ; _L277 _L278 2244 | LDC 0 ; @_L277 2245 | RTN 2246 | LDC 2 ; @_L278 2247 | RTN 2248 | LD 0 0 ; @_L276 2249 | CDR 2250 | LD 0 1 2251 | CDR 2252 | CEQ 2253 | TSEL 2253 2263 ; _L279 _L280 2254 | LD 0 0 ; @_L279 2255 | CAR 2256 | LD 0 1 2257 | CAR 2258 | CGT 2259 | TSEL 2259 2261 ; _L281 _L282 2260 | LDC 3 ; @_L281 2261 | RTN 2262 | LDC 1 ; @_L282 2263 | RTN 2264 | LDC -1 ; @_L280 2265 | RTN 2266 | LD 0 0 ; @getDist 2267 | LD 0 1 2268 | LDC 0 2269 | LDC 0 2270 | LDF 2272 ; getDist_impl 2271 | AP 4 2272 | RTN 2273 | LD 0 0 ; @getDist_impl 2274 | CAR 2275 | LD 0 1 2276 | CAR 2277 | SUB 2278 | ST 0 2 2279 | LD 0 0 2280 | CDR 2281 | LD 0 1 2282 | CDR 2283 | SUB 2284 | ST 0 3 2285 | LDC 0 2286 | LD 0 2 2287 | CGT 2288 | TSEL 2288 2292 ; _L283 _L284 2289 | LDC 0 ; @_L283 2290 | LD 0 2 2291 | SUB 2292 | ST 0 2 2293 | LDC 0 ; @_L284 2294 | LD 0 3 2295 | CGT 2296 | TSEL 2296 2300 ; _L285 _L286 2297 | LDC 0 ; @_L285 2298 | LD 0 3 2299 | SUB 2300 | ST 0 3 2301 | LD 0 2 ; @_L286 2302 | LD 0 3 2303 | ADD 2304 | RTN 2305 | LD 0 0 ; @getMoved 2306 | LD 0 1 2307 | LDF 2309 ; getMoved_impl 2308 | AP 2 2309 | RTN 2310 | LD 0 1 ; @getMoved_impl 2311 | LDC 0 2312 | CEQ 2313 | TSEL 2313 2323 ; _L287 _L288 2314 | LD 0 0 ; @_L287 2315 | CAR 2316 | LDC 0 2317 | ADD 2318 | LD 0 0 2319 | CDR 2320 | LDC -1 2321 | ADD 2322 | CONS 2323 | RTN 2324 | LD 0 1 ; @_L288 2325 | LDC 1 2326 | CEQ 2327 | TSEL 2327 2337 ; _L289 _L290 2328 | LD 0 0 ; @_L289 2329 | CAR 2330 | LDC 1 2331 | ADD 2332 | LD 0 0 2333 | CDR 2334 | LDC 0 2335 | ADD 2336 | CONS 2337 | RTN 2338 | LD 0 1 ; @_L290 2339 | LDC 2 2340 | CEQ 2341 | TSEL 2341 2351 ; _L291 _L292 2342 | LD 0 0 ; @_L291 2343 | CAR 2344 | LDC 0 2345 | ADD 2346 | LD 0 0 2347 | CDR 2348 | LDC 1 2349 | ADD 2350 | CONS 2351 | RTN 2352 | LD 0 1 ; @_L292 2353 | LDC 3 2354 | CEQ 2355 | TSEL 2355 2365 ; _L293 _L294 2356 | LD 0 0 ; @_L293 2357 | CAR 2358 | LDC -1 2359 | ADD 2360 | LD 0 0 2361 | CDR 2362 | LDC 0 2363 | ADD 2364 | CONS 2365 | RTN 2366 | LDC -42 ; @_L294 2367 | DBUG 2368 | BRK 2369 | LD 0 0 ; @isVisible 2370 | LD 0 1 2371 | LD 0 2 2372 | LD 0 3 2373 | LDF 2375 ; isVisible_impl 2374 | AP 4 2375 | RTN 2376 | LD 0 1 ; @_L295 2377 | CAR 2378 | LD 0 2 2379 | CAR 2380 | CEQ 2381 | LD 0 1 2382 | CDR 2383 | LD 0 2 2384 | CDR 2385 | CEQ 2386 | MUL 2387 | LDC 0 2388 | CEQ 2389 | TSEL 2389 2408 ; _L296 _L297 2390 | LD 0 0 ; @_L296 2391 | LD 0 1 2392 | CAR 2393 | LD 0 1 2394 | CDR 2395 | LDF 1880 ; getXY 2396 | AP 3 2397 | LDC 0 2398 | CEQ 2399 | TSEL 2399 2401 ; _L298 _L299 2400 | LDC 0 ; @_L298 2401 | RTN 2402 | LD 0 1 ; @_L299 2403 | LD 0 3 2404 | LDF 2304 ; getMoved 2405 | AP 2 2406 | ST 0 1 2407 | LDC 0 2408 | TSEL 2375 2375 ; _L295 _L295 2409 | LDC 1 ; @_L297 2410 | RTN 2411 | LD 0 0 ; @isOK 2412 | LD 0 1 2413 | LD 0 2 2414 | LD 0 3 2415 | LD 0 4 2416 | LDC 0 2417 | LDC 0 2418 | LDC 0 2419 | LDC 0 2420 | LDF 2422 ; isOK_impl 2421 | AP 9 2422 | RTN 2423 | LD 0 1 ; @isOK_impl 2424 | LD 0 2 2425 | LDF 2304 ; getMoved 2426 | AP 2 2427 | ST 0 5 2428 | LD 0 4 ; @_L300 2429 | ATOM 2430 | LDC 0 2431 | CEQ 2432 | TSEL 2432 2477 ; _L301 _L302 2433 | LD 0 4 ; @_L301 2434 | CAR 2435 | ST 0 6 2436 | LD 0 4 2437 | CDR 2438 | ST 0 4 2439 | LD 0 6 2440 | CDR 2441 | CAR 2442 | ST 0 7 2443 | LD 0 6 2444 | CDR 2445 | CDR 2446 | ST 0 8 2447 | LD 0 3 2448 | LD 0 8 2449 | CEQ 2450 | TSEL 2450 2466 ; _L303 _L304 2451 | LD 0 7 ; @_L303 2452 | LD 0 1 2453 | LDF 2226 ; getDir 2454 | AP 2 2455 | LD 0 8 2456 | CEQ 2457 | TSEL 2457 2466 ; _L305 _L306 2458 | LD 0 0 ; @_L305 2459 | LD 0 7 2460 | LD 0 1 2461 | LD 0 8 2462 | LDF 2368 ; isVisible 2463 | AP 4 2464 | TSEL 2464 2466 ; _L307 _L308 2465 | LDC 0 ; @_L307 2466 | RTN 2467 | LDC 2 ; @_L304 2468 | LD 0 5 2469 | LD 0 7 2470 | LDF 2265 ; getDist 2471 | AP 2 2472 | CGTE 2473 | TSEL 2473 2475 ; _L309 _L310 2474 | LDC 0 ; @_L309 2475 | RTN 2476 | LDC 0 ; @_L310 2477 | TSEL 2427 2427 ; _L300 _L300 2478 | LDC 1 ; @_L302 2479 | RTN 2480 | -------------------------------------------------------------------------------- /maps/200x200.map: -------------------------------------------------------------------------------- 1 | ######################################################################################################################################################################################################## 2 | #\.....................................................................................................................................................................................................# 3 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 4 | #......................................................................................................................................................................................................# 5 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 6 | #......................................................................................................................................................................................................# 7 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 8 | #......................................................................................................................................................................................................# 9 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 10 | #......................................................................................................................................................................................................# 11 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 12 | #......................................................................................................................................................................................................# 13 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 14 | #......................................................................................................................................................................................................# 15 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 16 | #......................................................................................................................................................................................................# 17 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 18 | #......................................................................................................................................................................................................# 19 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 20 | #......................................................................................................................................................................................................# 21 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 22 | #......................................................................................................................................................................................................# 23 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 24 | #......................................................................................................................................................................................................# 25 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 26 | #......................................................................................................................................................................................................# 27 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 28 | #......................................................................................................................................................................................................# 29 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 30 | #......................................................................................................................................................................................................# 31 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 32 | #......................................................................................................................................................................................................# 33 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 34 | #......................................................................................................................................................................................................# 35 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 36 | #......................................................................................................................................................................................................# 37 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 38 | #......................................................................................................................................................................................................# 39 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 40 | #......................................................................................................................................................................................................# 41 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 42 | #......................................................................................................................................................................................................# 43 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 44 | #......................................................................................................................................................................................................# 45 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 46 | #......................................................................................................................................................................................................# 47 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 48 | #......................................................................................................................................................................................................# 49 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 50 | #......................................................................................................................................................................................................# 51 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 52 | #......................................................................................................................................................................................................# 53 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 54 | #......................................................................................................................................................................................................# 55 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 56 | #......................................................................................................................................................................................................# 57 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 58 | #......................................................................................................................................................................................................# 59 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 60 | #......................................................................................................................................................................................................# 61 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 62 | #......................................................................................................................................................................................................# 63 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 64 | #......................................................................................................................................................................................................# 65 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 66 | #......................................................................................................................................................................................................# 67 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 68 | #......................................................................................................................................................................................................# 69 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 70 | #......................................................................................................................................................................................................# 71 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 72 | #......................................................................................................................................................................................................# 73 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 74 | #......................................................................................................................................................................................................# 75 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 76 | #......................................................................................................................................................................................................# 77 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 78 | #......................................................................................................................................................................................................# 79 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 80 | #......................................................................................................................................................................................................# 81 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 82 | #......................................................................................................................................................................................................# 83 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 84 | #......................................................................................................................................................................................................# 85 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 86 | #......................................................................................................................................................................................................# 87 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 88 | #......................................................................................................................................................................................................# 89 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 90 | #......................................................................................................................................................................................................# 91 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 92 | #......................................................................................................................................................................................................# 93 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 94 | #......................................................................................................................................................................................................# 95 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 96 | #......................................................................................................................................................................................................# 97 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 98 | #......................................................................................................................................................................................................# 99 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 100 | #..................................................................................................=.=.................................................................................................# 101 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 102 | #..................................................................................................=.=.................................................................................................# 103 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 104 | #......................................................................................................................................................................................................# 105 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 106 | #......................................................................................................................................................................................................# 107 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 108 | #......................................................................................................................................................................................................# 109 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 110 | #......................................................................................................................................................................................................# 111 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 112 | #......................................................................................................................................................................................................# 113 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 114 | #......................................................................................................................................................................................................# 115 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 116 | #......................................................................................................................................................................................................# 117 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 118 | #......................................................................................................................................................................................................# 119 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 120 | #......................................................................................................................................................................................................# 121 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 122 | #......................................................................................................................................................................................................# 123 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 124 | #......................................................................................................................................................................................................# 125 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 126 | #......................................................................................................................................................................................................# 127 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 128 | #......................................................................................................................................................................................................# 129 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 130 | #......................................................................................................................................................................................................# 131 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 132 | #......................................................................................................................................................................................................# 133 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 134 | #......................................................................................................................................................................................................# 135 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 136 | #......................................................................................................................................................................................................# 137 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 138 | #......................................................................................................................................................................................................# 139 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 140 | #......................................................................................................................................................................................................# 141 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 142 | #......................................................................................................................................................................................................# 143 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 144 | #......................................................................................................................................................................................................# 145 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 146 | #......................................................................................................................................................................................................# 147 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 148 | #......................................................................................................................................................................................................# 149 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 150 | #......................................................................................................................................................................................................# 151 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 152 | #......................................................................................................................................................................................................# 153 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 154 | #......................................................................................................................................................................................................# 155 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 156 | #......................................................................................................................................................................................................# 157 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 158 | #......................................................................................................................................................................................................# 159 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 160 | #......................................................................................................................................................................................................# 161 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 162 | #......................................................................................................................................................................................................# 163 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 164 | #......................................................................................................................................................................................................# 165 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 166 | #......................................................................................................................................................................................................# 167 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 168 | #......................................................................................................................................................................................................# 169 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 170 | #......................................................................................................................................................................................................# 171 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 172 | #......................................................................................................................................................................................................# 173 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 174 | #......................................................................................................................................................................................................# 175 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 176 | #......................................................................................................................................................................................................# 177 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 178 | #......................................................................................................................................................................................................# 179 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 180 | #......................................................................................................................................................................................................# 181 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 182 | #......................................................................................................................................................................................................# 183 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 184 | #......................................................................................................................................................................................................# 185 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 186 | #......................................................................................................................................................................................................# 187 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 188 | #......................................................................................................................................................................................................# 189 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 190 | #......................................................................................................................................................................................................# 191 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 192 | #......................................................................................................................................................................................................# 193 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 194 | #......................................................................................................................................................................................................# 195 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 196 | #......................................................................................................................................................................................................# 197 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 198 | #....................................................................................................................................................................................................%.# 199 | #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.## 200 | ######################################################################################################################################################################################################## 201 | --------------------------------------------------------------------------------