Skip to content

Instantly share code, notes, and snippets.

View zacharycarter's full-sized avatar
👋

Tail Wag Games zacharycarter

👋
View GitHub Profile
######..#######..#####.....####..#########......#####.....####..
#.......#######..#####.....####..#########......###..........#..
...........####..#######..#####.................##...........#..
...........#..#...#....#......#.................##...######..#..
..................#....#......#......#..######.......#.......###
...#####..........#....#......#..#......#....#.......#.......#..
...#...#...#..##.......#................#....#..##...######..#..
####......######.......#...###..........#.......###..........#..
#.........######..#....##..#####.....####.......###..........#..
#........#######..#######..#####.....####....#..####......#####.
#define STB_HERRINGBONE_WANG_TILE_IMPLEMENTATION
#include "stb_herringbone_wang_tile.h"
import random, times, deques
type
DungeonKind {.pure.} = enum
Caves
CellKind {.pure.} = enum
Empty, Floor, Wall, Count
Cell = object
proc season(month: range[1..12]): string =
case month
of 1, 2, 12: return "winter"
of 4, 5, 6: return "spring"
of 7, 8, 9: return "summer"
of 10, 11: return "autumn"
echo season(5) # in.nim(2, 3) Error: not all cases are covered
proc season(month: range[1..12]): string =
case month
of 1, 2, 12: return "winter"
of 4, 5, 6: return "spring"
of 7, 8, 9: return "summer"
of 10, 11: return "autumn"
echo season(5)
proc `[]`*[Idx, T](a: openarray[T], x: Slice[Idx]): seq[T] =
# https://github.com/nim-lang/Nim/tree/master/lib/system.nim#L3381
var L = ord(x.b) - ord(x.a) + 1
newSeq(result, L)
for i in 0.. <L:
result[i] = a[Idx(ord(x.a) + i)]
import options
import typetraits
template hasValue[T](o: Option[T]): bool =
proc default(): T = discard
let isSome = o.isSome()
(let `o` {.inject.} = (if isSome: o.get() else: default()); isSome)
let x = some(123)
var the_sum = 0
echo(the-sum)
import rst
echo repr parseRST("Hello World!")
import macros
proc getProcDef(fromProc: NimNode): NimNode =
let procDef = copyNimTree(fromProc)
# Strip proc of its "body", not sure if there is a better way to do this
var indexOfBody = 0
for item in fromProc:
if item.kind() == nnkStmtList: break
indexOfBody += 1