#include <stdio.h> /* putchar() */

#ifdef _WIN32
# include <conio.h> /* getch() */
# ifdef __MINGW_H
#  include <stdlib.h> /* system() */
#  define clrscr() system("cls")   /* TODO check if this works */
# endif
#else
# define getch() getchar()
# define clrscr() printf("\e[H\e[2J")
#endif

#define START_POS 0x003f003f
#define END_POS   0x00000000

#define MY_W   64
#define MY_H   64

#define F_CONTROL -10
#define F_ISFREE  (F_CONTROL-4)
#define F_GETBIT  (F_CONTROL-5)
#define F_BASE64  (F_CONTROL-6)

#define F_OUTPUT  -2
#define F_CLRSCR  -3

#define F_POWERS  -9

/* this code only uses putchar(), getch(), clrscr() for its I/O */

int main(int t, int _, int a) { return

// launcher (no args)
(t >= 0 && t < 34640) ? main(-1, START_POS, END_POS) :

// main loop (_=position, a=endpos)
(t == -1) ?
  _ + main(F_POWERS, main(F_CLRSCR, _, F_OUTPUT), 0) == a ? 0 :
  main(t, main(F_CONTROL, _, t), a) :

// output (_=userdata, a=output-proc)
(t == F_OUTPUT) ?
  a >= 35400 ? 0 :
  main(F_POWERS, putchar(main(a, _, a)), 0) ? _ :
  main(t, _, a+1) :

// clrscr (_=userdata, a=F_OUTPUT)
(t == F_CLRSCR) ? main(F_POWERS, clrscr(), 0) ? a : main(a, _, 34640) :

// display viewport (_=pos)
t == 35018 ? 60 : t == 35019 ? 62 :   // player character
(t >= 34640) ?
  (t % 40 == 38) ? 32 :
  (t % 40 == 39) ? 10 :       // x coord == t/2 % 20, y coord == t/40 - 866
  main(F_ISFREE, _ + t/2%20-9 + (t/40-866-9<<16), a) ? 32 :
  35 :

// control (_=oldpos)
// control_0 (_=oldpos) calls getch
// control_1 (_=char, a=oldpos) handles upper/lowercase conversion
// control_2 (_=oldpos, a=char converted) maps letters to position offsets
// control_3 (_=oldpos, a=posoffset) returns newpos, if it's free
(t == F_CONTROL) ? main(t-1, getch(), _) :
(t == F_CONTROL-1) ? main(t-1, a, _>92 ? _-109 : _-77) :
(t == F_CONTROL-2) ? main(t-1, _,
  a == 10 ? -65536 : a == -9 ? 1 : a == -12 ? -1 : a == 6 ? 65536 : 0 ) :
(t == F_CONTROL-3) ? main(t-1, _+a, a) ? _+a : _ :

// get is_free? (_=pos)
// x coord == low word, y coord = high word
(t == F_ISFREE) ? _>>16<0 || _>>16>=MY_H || (_&65535)>=MY_W ? 0 : main(t-1, (_&65535) + (_>>16)*MY_H, a) :

// get powers of _ (main(F_POWERS+a, b, 1) returns b^a)
(t == F_POWERS) ? a :
(t > F_POWERS && t < F_POWERS+6) ? main(t-1, _, a*_) :

// get data bit (_=datapos)
(t == F_GETBIT) ? main(t-1, _, _/6) & main(F_POWERS + _%6, 2, 1) :

// convert encoded base64 -> 6bit numbers (a=datapos)
(t == F_BASE64) ? main(t-1, main(t*2, _, a), a) :
(t == F_BASE64-1) ? (_>95?_-71:_>60?_-65:_<44?_+19:_>47?_+4:_+16) :

// data storage
/* seed=1213970146 */
"1/Xj37/92vbXAvNnCy5GtX1HyNa/qZ+WXV+l+l028oeT1i9y764wzWXXPwhzZ5F1TGexzH35L9ZnO\
0mpeSrclX++mypwWcJLeV6uR73uxf7aua1Xh2mTqW72VL2r2ubvvSzuemqqkTcqtzcs46uX3t1l1V\
NVZUd02rPr19+176GrWuzjaVlabjWNGT/sdrdrcXeXW4sg2YvVeN+8p9d3FOuq+ywWitmv1afR3Vt\
rWNeXdtdr3ma9da+o2NnG7VQVq6f1abj19b/qB1qrt1moK2z32pO2r+57VVzUzUr20Fb7i2t1XL3w\
ev4ZnWnsOb5q60FaLrNO9R/5W/jOvd+SPpJlKtusNYW+vvb8d62+dVYWqFh5VF0c9d7W73V372a1q\
1uJxEqrmq5Dr09r/Vbvurv8zqCRPtsKD6qbsvV9tyevYItFtphtbt6l7WftrXmzaRPbt4uKtAn9tc\
atUs2au2Vd1za/qq94p70m2dk6W15NyZsk5tUN129l86tya1arrV9olqwVrquVblmubXt6bkXSffm\
dauK7v4Ohsu476dZYj21u8qYR53tO2bp525ZprtcrzrV3y7brxVrjKO6CJnXmbH3y6x/uL8Wbe13q\
noq8wW7QVmWt2e5bNz3efbd1dh1aXbMgb1143rapd8Vbo7TK7lj9ybdCU/eTvP6r79P"
[a]

;}

