about summary refs log tree commit diff stats
path: root/subx/072slice.subx
Commit message (Expand)AuthorAgeFilesLines
* Merge branch 'master' into surveyKartik Agaram2019-07-031-2/+2
|\
| * 5218Kartik Agaram2019-05-221-1/+1
| * 5213Kartik Agaram2019-05-201-1/+1
* | .Kartik Agaram2019-07-011-0/+113
* | unsigned comparison for addresses in more placesKartik Agaram2019-07-011-2/+2
* | .Kartik Agaram2019-06-121-7/+0
|/
* Merge branch 'master' into dquotes-1Kartik Agaram2019-05-101-2/+14
|\
| * 5151 - use mmap everywhere we need a heapKartik Agaram2019-05-101-2/+14
* | standardize function namesKartik Agaram2019-05-021-12/+12
|/
* 5090Kartik Agaram2019-04-131-10/+2
* 5060Kartik Agaram2019-04-061-3/+51
* 5059Kartik Agaram2019-04-051-1/+1
* 5056Kartik Agaram2019-04-051-2/+144
* 5053Kartik Agaram2019-04-031-113/+0
* 5024Kartik Agaram2019-03-271-11/+11
* 5011Kartik Agaram2019-03-201-2/+2
* 5009Kartik Agaram2019-03-201-1/+1
* 4999Kartik Agaram2019-03-101-1/+3
* 4996 - back on pack.subxKartik Agaram2019-03-081-0/+2
* 4981 - no, go back to 3 phasesKartik Agaram2019-02-181-6/+5
* 4968Kartik Agaram2019-02-141-0/+275
* 4966Kartik Agaram2019-02-141-5/+5
* 4961Kartik Agaram2019-02-141-11/+29
* 4955Kartik Agaram2019-02-101-0/+7
* 4954Kartik Agaram2019-02-101-0/+102
* 4951Kartik Agaram2019-02-031-7/+5
* 4950Kartik Agaram2019-02-031-0/+520
"mi">1 end end debug.sethook(foo, "c") window = curses.initscr() tower = {{6, 5, 4, 3, 2}, {}, {}} function len(array) local result = 0 for k in pairs(array) do result = result+1 end return result end function pop(array) return table.remove(array) end function lines(window) local lines, cols = window:getmaxyx() return lines end function cols(window) local lines, cols = window:getmaxyx() return cols end function render_disk(window, line, col, size) col = col-size+1 for i=1,size do window:attron(curses.color_pair(size)) window:mvaddstr(line, col, " ") window:attroff(curses.color_pair(size)) col = col+2 end end function render_tower(window, line, col, tower_index, tower) window:attron(curses.A_BOLD) window:mvaddch(line+2, col, string.char(96+tower_index)) window:attroff(curses.A_BOLD) window:attron(curses.color_pair(7)) window:mvaddstr(line+1, col-6, " ") window:attroff(curses.color_pair(7)) for i, n in ipairs(tower) do render_disk(window, line, col, n) line = line - 1 end for i=1,5-len(tower)+1 do window:attron(curses.color_pair(7)) window:mvaddstr(line, col, " ") window:attroff(curses.color_pair(7)) line = line - 1 end window:mvaddstr(30, 0, "profile: ") for k,v in pairs(count) do window:addstr(k) window:addstr(": ") window:addstr(v) window:addstr("; ") end end function render(window) window:clear() local lines, cols = window:getmaxyx() local line = math.floor(lines/2) local col = math.floor(cols/4) for i,t in ipairs(tower) do render_tower(window, line, i*col, i, t) end curses.refresh() end function make_move(from, to) local disk = pop(tower[from]) table.insert(tower[to], disk) end function update(window) window:mvaddstr(lines(window)-2, 5, "tower to remove top disk from? ") local from = string.byte(curses.getch()) - 96 window:mvaddstr(lines(window)-1, 5, "tower to stack it on? ") local to = string.byte(curses.getch()) - 96 make_move(from, to) end function main() curses.start_color() curses.use_default_colors() for i=1,7 do curses.init_pair(i, 0, i) end while true do render(window) update(window) end curses.endwin() end main()