Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Post top tier code

Name: Anonymous 2014-07-22 13:29

Can be yours or not, I just want to see something good.

Name: Anonymous 2014-07-22 14:04

#include"stdio.h"
#include"conio.h"
#include"iostream.h"

void main(void){
int i;
while(i<10){
int i2;
printf_s("\rstarting");
while(i2<10){
putchar('.');
i2 = i2 + 1;
}
i = i + 1;
sleep(1);
}
printf_s("press any key...");
getch();
}

Name: Anonymous 2014-07-22 14:27

conio.h
top lel

Name: Anonymous 2014-07-22 15:11

>>3
It's lel

Name: Anonymous 2014-07-22 17:55

Bitpack!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <stdbool.h>

typedef struct {
unsigned char *p, *q;
size_t n, tmp, bits;
} bitptr;

void bitinit(bitptr *, void *, size_t, size_t);
void bitnext(bitptr *);
void bitprev(bitptr *);
void bitset(bitptr *, bool);
bool bitval(bitptr *);
void bitrewind(bitptr *);
size_t bitsize(bitptr *);
void bitpack(bitptr *, bitptr *, size_t, size_t);
void bitunpack(bitptr *, bitptr *, size_t, size_t);

void bitinit(bitptr *p, void *q, size_t n, size_t bits) {
p->p = p->q = q;
p->tmp = n;
p->bits = bits;
p->n = 0;
while(n--) bitnext(p);
}

void bitnext(bitptr *p) {
if(++p->n == CHAR_BIT) {
p->n = 0;
p->q++;
}
}

void bitprev(bitptr *p) {
if(p->n-- == 0) {
p->n = CHAR_BIT - 1;
p->q--;
}
}

void bitset(bitptr *p, bool b) {
if(b)
*p->q |= (b << p->n);
else
*p->q &= ~(b << p->n);
}

bool bitval(bitptr *p) {
return *p->q & (1 << p->n);
}

void bitrewind(bitptr *p) {
size_t n;

p->q = p->p;
p->n = p->tmp;
for(n = p->tmp; n--; bitnext(p));

}

size_t bitsize(bitptr *p) {
return p->bits;
}
#define bitsize(p) ((p)->bits)

void bitpack(bitptr *p, bitptr *q, size_t size, size_t nmemb) {

size_t n;

while(nmemb--) {
n = size;
while(n--) {
bitset(p, bitval(q));
bitnext(p);
bitnext(q);
}
if((n = bitsize(q) - size) != 0)
while(n--) bitnext(q);
}

}

void bitunpack(bitptr *p, bitptr *q, size_t size, size_t nmemb) {

size_t n;

while(nmemb--) {
n = size;
while(n--) {
bitset(p, bitval(q));
bitnext(p);
bitnext(q);
}
if((n = bitsize(p) - size) != 0)
while(n--) bitnext(p);
}

}

#define objsize(obj) (sizeof obj * CHAR_BIT)
static const char map[] = "abcdefghijklmnopqrstuvwxyz";
#define mapletter(x) (strchr(map, x) - map)

int main(void) {

bitptr p, s;
char buf[3] = {0}, x[] = { mapletter('h'), mapletter('e'), mapletter('l'), mapletter('l'), mapletter('o'), 0 };
size_t n;

bitinit(&p, buf, 0, objsize(buf[0]));
bitinit(&s, x, 0, objsize(x[0]));
bitpack(&p, &s, 4, sizeof x - 1);
bitrewind(&p);
bitrewind(&s);
printf("Message 'hello' stored in 3 bytes array. contents of s.p:\n");
memset(x, 0, sizeof x);
bitunpack(&s, &p, 4, sizeof x - 1);
for(n = 0; n < sizeof x - 1; n++)
s.p[n] = map[s.p[n]];

puts((void *)s.p);

return 0;
}

Name: Anonymous 2014-07-23 1:29

>>5
Packing/unpacking one bit at a time like that is going to be horribly slow. Probably better to use an array of unsigned int and use shifts and masks to pack sizeof(unsigned) * CHAR_BIT bits at a time wherever possible. The cfbcopyarea routines in the Linux kernel do this but the implementation there is rather wizardly.

Name: Anonymous 2014-07-23 4:35

>>5
#define objsize(obj) (sizeof obj * CHAR_BIT)
What if it overflows?

Name: Anonymous 2014-07-23 6:24

>>6
I did not go for efficiency! I'd use assembly if I had to. From a quick glance I didn't understand cfb_copyarea, but it's been some time since I had to write C.

Except bitpacking, >>5 implements the concept of bitpointers, so you get single access to each bit with a pointer called bitptr. For example you can do this:
bitptr *p, *q;
/* p gets initialized to something */
q = p; // now q points to the same bitptr, incrementing q will increment p
*q = *p; // q is a copy of p, incrementing q does not affect p

Of course in C++ this could be written to be almost like a real pointer, with operator overloading.

>>7
AFAIK it can't, but a quick search does not reveal any reputable sources, or heck, even something relevant. The days I searched ISO pdf drafts is over, so I don't know. Assuming it can, the behavior is still defined. Overflow of unsigned integers is defined, therefore you'd just get less bits available than what you asked. Nothing catastrophic, like your PDP-7 exploding.

Name: Anonymous 2014-07-24 17:11

>>8
Yes, I get that. Personally I'd probably just use a plain integer type as the pointer type, and just have each function extract the index within the last word of the bit array via a modulo operation.

Storing an extra position (q) for seeking is an interesting idea; but since it's extra state to manage you might consider adding a stream abstraction on top of the basic bit-buffer implementation instead of combining them like this.

Name: Anonymous 2014-07-25 5:04

>>9
a plain integer type as the pointer type
Don't let lambda hear that

Name: Anonymous 2014-07-25 9:18

/* With gcc3.1, must omit -ansi to compile eol comments */

#include <stdio.h>
#include <stdlib.h>

static int ch, lastch;

/* ---------------- */

static void putlast(void)
{
if (0 != lastch) fputc(lastch, stdout);
lastch = ch;
ch = 0;
} /* putlast */

/* ---------------- */

/* gobble chars until star slash appears */
static int stdcomment(void)
{
int ch, lastch;

ch = 0;
do {
lastch = ch;
if (EOF == (ch = fgetc(stdin))) return EOF;
} while (!(('*' == lastch) && ('/' == ch)));
return ch;
} /* stdcomment */

/* ---------------- */

/* gobble chars until EOLine or EOF. i.e. // comments */
static int eolcomment(void)
{
int ch, lastch;

ch = '\0';
do {
lastch = ch;
if (EOF == (ch = fgetc(stdin))) return EOF;
} while (!(('\n' == ch) && ('\\' != lastch)));
return ch;
} /* eolcomment */

/* ---------------- */

/* echo chars until '"' or EOF */
static int echostring(void)
{
putlast();
if (EOF == (ch = fgetc(stdin))) return EOF;
do {
putlast();
if (EOF == (ch = fgetc(stdin))) return EOF;
if (('\\' == ch) && ('\\' == lastch)) {
putlast();
ch = '\0';
}
} while (!(('"' == ch) && ('\\' != lastch)));
return ch;
} /* echostring */

/* ---------------- */

int main(void)
{
lastch = '\0';
while (EOF != (ch = fgetc(stdin))) {
if ('/' == lastch)
if (ch == '*') {
lastch = '\0';
if (EOF == stdcomment()) break;
ch = ' ';
putlast();
}
else if (ch == '/') {
lastch = '\0';
if (EOF == eolcomment()) break;
ch = '\n';
putlast(); // Eolcomment here
// Eolcomment line \
with continuation line.
}
else {
putlast();
}
else if (('"' == ch) && ('\\' != lastch)
&& ('\'' != lastch)) {
if ('"' != (ch = echostring())) {
fputs("\"Unterminated\" string\n", stderr);

/* You can exercise this code by feeding the
program an unterminated string, then EOF */
fputs("checking for\
continuation line string\n", stderr);
fputs("checking for" "concat string\n", stderr);
printf("What\\" /* embedded string */ "%s joke!\n",
/* doh */ "a /*#(K1N5");

return EXIT_FAILURE;
}
putlast();
}
else {
putlast();
}
} /* while */
putlast(/* embedded comment */);
return 0;
} /* main */

Name: Anonymous 2014-07-29 11:17

>>11
if ('/' == lastch)
if (ch == '*')
I want to kick you in the balls, asshole.

Name: Anonymous 2014-07-29 11:40

function [tblNode, tblPath, mapx] = initGraph(map, m2, node)

moveset = [1,0; 0,-1; -1,0; 0,1];

n = size(node,1);

p = sum(node(:,3)) / 2;

pcount=1;

tblNode = zeros(n, 6);

tblPath = zeros(p, 3);

mapx = map; %% .- (m2>0);

for(iterN = 1:n)

nodeXY = node(iterN, 1:2);

mapx(nodeXY(1), nodeXY(2)) = 0;

for(iterP = 1:4)

pid = 0;

cyx = nodeXY .+ moveset(iterP, :);

if(mapx(cyx(1), cyx(2)) > 1)

pid = mapx(cyx(1), cyx(2)) - 1;

nids = tblPath(pid, [1,2]);

nid = nids(nids!=iterN)

endif;


if(mapx(cyx(1), cyx(2)) == 1)

pid = pcount;

pcount += 1;

[mapx, dC, nid] = scanGraph(mapx, m2, cyx, pid);

tblPath(pid,:) = [iterN, nid, dC];

tblPath(pid,:)

endif;

tblNode(iterN, iterP) = pid;

endfor;

tblNode(iterN, [5,6]) = node(iterN, [1,2]);

tblNode(iterN,:)

mapx(nodeXY(1), nodeXY(2)) = 1;

endfor;

endfunction;

Name: Anonymous 2014-07-29 12:27

Here's a grid graph implemetation of mine, complete with ascii print too. Main feature is the 1-1 encoding of edges to bits, so for a grid of size WxH, exactly 2HW - H - W bits of memory (in theory -- I don't expect std::vector<bool> to behave exactly like that) are used to represent the edges. The magic of this is in the functions Index2Edge and Edge2Index which translate an edge {u, v} to its corresponding index i in the bool vector.

I'm posting it because I think it's kinda relevant to what >>13 does, I think his code does something for ICFP '14?

#include <vector>
#include <deque>
#include <iostream>
#include <algorithm>
#include <cstdlib>

class Grid {
public:
typedef struct { int x, y; } Point;
typedef struct { Point u, v; } Edge;
Grid(void);
Grid(int, int, bool = false);
void Init(int, int, bool = false);
bool IsCorner(const Point&) const;
bool IsOuter(const Point&) const;
bool IsInner(const Point&) const;
int N(const Point&) const;
int N(const Point&, std::deque<Point>&) const;
int Neighbours(const Point&) const;
int Neighbours(const Point&, std::deque<Point>&) const;
void AddEdge(const Edge&);
void RemoveEdge(const Edge&);
bool ExistsEdge(const Edge&) const;
void Print(std::ostream& o, const char * = nullptr) const;
int GetHeight(void) const;
int GetWidth(void) const;
void Edge2Index(const Edge&, int&) const;
void Index2Edge(int, Edge&) const;
private:
int w, h;
std::vector<bool> edges;
};

Grid::Grid(void) {
;
}

Grid::Grid(int w, int h, bool value) {
Grid::Init(w, h, value);
}

void Grid::Init(int w, int h, bool value) {
Grid::w = w;
Grid::h = h;
Grid::edges.resize(2 * h*w - h - w, value);
}

int Grid::GetHeight(void) const {
return Grid::h;
}

int Grid::GetWidth(void) const {
return Grid::w;
}

/* Number of neighbours connected to p */
int Grid::N(const Grid::Point& p) const {
int i, n = 0;
if (p.x != 0) {
Grid::Edge2Index({ p, { p.x - 1, p.y } }, i);
n += Grid::edges[i];
}
if (p.y != 0) {
Grid::Edge2Index({ p, { p.x, p.y - 1 } }, i);
n += Grid::edges[i];
}
if (p.x != Grid::w - 1) {
Grid::Edge2Index({ p, { p.x + 1, p.y } }, i);
n += Grid::edges[i];
}
if (p.y != Grid::h - 1) {
Grid::Edge2Index({ p, { p.x, p.y + 1 } }, i);
n += Grid::edges[i];
}
return n;
}

/* Number and deque list of neighbours connected to p */
int Grid::N(const Grid::Point& p, std::deque<Point>& d) const {
int i, n = 0;
if (p.x != 0) {
Grid::Edge2Index({ p, { p.x - 1, p.y } }, i);
if (Grid::edges[i]) {
n++;
d.push_back({ p.x - 1, p.y });

}
}
if (p.y != 0) {
Grid::Edge2Index({ p, { p.x, p.y - 1 } }, i);
if (Grid::edges[i]) {
n++;
d.push_back({ p.x, p.y - 1 });
}
}
if (p.x != Grid::w - 1) {
Grid::Edge2Index({ p, { p.x + 1, p.y } }, i);
if (Grid::edges[i]) {
n++;
d.push_back({ p.x + 1, p.y });
}
}
if (p.y != Grid::h - 1) {
Grid::Edge2Index({ p, { p.x, p.y + 1 } }, i);
if (Grid::edges[i]) {
n++;
d.push_back({ p.x, p.y + 1 });
}
}
return n;
}

/* Number of points that can possibly be connected to p */
int Grid::Neighbours(const Point& p) const {
if (IsInner(p)) return 4;
else if (IsCorner(p)) return 2;
else return 3;
}

/* List of points that can possibly be connected to p */
int Grid::Neighbours(const Point& p, std::deque<Point>& d) const {
int n = 0;
if (p.x > 0)
n++, d.push_back({ p.x - 1, p.y });
if (p.y > 0)
n++, d.push_back({ p.x, p.y - 1 });
if (p.x < w - 1)
n++, d.push_back({ p.x + 1, p.y });
if (p.y < h - 1)
n++, d.push_back({ p.x, p.y + 1 });
return n;
}

bool Grid::IsCorner(const Grid::Point& p) const {
return (p.x == 0 || p.x == Grid::w - 1)
&& (p.y == 0 || p.y == Grid::h - 1);
}

bool Grid::IsOuter(const Grid::Point& p) const {
return !p.x || !p.y || p.x == Grid::w - 1 || p.y == Grid::h - 1;
}

bool Grid::IsInner(const Grid::Point& p) const {
return p.x && p.y && p.x != Grid::w - 1 && p.y != Grid::h - 1;
}

/* Converts a user edge {p, q} to private class index for the edges vector */
void Grid::Edge2Index(const Grid::Edge& e, int &i) const {
if (e.u.y == e.v.y)
i = e.u.y * (w - 1) + std::min({ e.u.x, e.v.x });
else
i = h*(w - 1) + std::min({ e.u.y, e.v.y }) * w + e.u.x;
}

/* Translates an index to an edge {p, q} */
void Grid::Index2Edge(int i, Grid::Edge& e) const {
div_t x;
if (i < (w - 1)*h) {
x = div(i, w - 1);
e.v.x = 1 + (e.u.x = x.rem);
e.u.y = e.v.y = x.quot;
}
else {
i -= (w - 1)*h;
x = div(i, w);
e.u.x = e.v.x = x.rem;
e.v.y = 1 + (e.u.y = x.quot);
}
}

void Grid::AddEdge(const Grid::Edge& e) {
int i;
Grid::Edge2Index(e, i);
Grid::edges[i] = true;
}

void Grid::RemoveEdge(const Grid::Edge& e) {
int i;
Grid::Edge2Index(e, i);
Grid::edges[i] = false;
}

bool Grid::ExistsEdge(const Grid::Edge& e) const {
int i;
Grid::Edge2Index(e, i);
return Grid::edges[i];
}

void Grid::Print(std::ostream& o, const char *prefix) const {
for (int j = 0; j < Grid::h; j++) {
if (prefix) o << prefix;
for (int i = 0; i < Grid::w; i++) {
if (Grid::N({ i, j }))
o << '*';
else
o << ' ';
if (i != Grid::w - 1) {
if (Grid::ExistsEdge({ { i, j }, { i + 1, j } }))
o << "---";
else
o << " ";
}
}
o << std::endl;
if (prefix) o << prefix;
if (j != Grid::h - 1)
for (int i = 0; i < Grid::w; i++) {
if (Grid::ExistsEdge({ { i, j }, { i, j + 1 } }))
o << '|';
else
o << ' ';
if (i != Grid::w - 1)
o << " ";
}
o << std::endl;
}
}

Name: Anonymous 2014-07-29 20:12

>>14
No comment on the code whatsoever? I'm disappointed...

Name: Anonymous 2014-07-29 21:12

bumping again. These faggots take the #1 post with bullshit unrelated to /prog/.

Name: sage 2014-07-30 0:20

>>14
This will be perfect for my next chess program implemented on a calculator with only 112 bits of memory

Name: Anonymous 2014-07-30 1:05

>>14
Yep, >>13 builds a couple of tables for a recursive graph search, and a spatial edge index. mapx(LocY, LocX) gives an edge index+1 >=2, or ==1 on a Node, then you can get the next two Nodes for a given edge, and up to four Edges for a given Node..
The nice bit is these should work concurrently, so depth 4 and starting on an edge gives [all nodes(4)] connected to [all edges(3)] connected to [all nodes(2)] connected to [initial edge(1)], in four operations =)

Name: Anonymous 2014-07-30 1:25

>>18
What are you searching the graph for? What kind of tables does it build? What do you mean by spatial edge index?

I'm sorry but I don't understand your code nor your post -- undoubtedly it's something smart and I'd appreciate if you could explain it further.

Name: Anonymous 2014-07-30 2:11

So, this would be a spatial edge index for a 5x8 map, with 3 edges marked by values 2-4, two nodes with values of 1, and 0's for the walls.
00000000
02221330
02004030
02221330
00000000

Then you just look-up the element at y,x to find the edge Id for a target item (lambda-man / ghost / remaining pills / power-pill / fruit..)

Name: Anonymous 2014-07-30 2:41

There is two tables that form a circular database =) it's mostly key values with some minimal extra info. So you have a list of edges accessed by the edge id, which just tells you the node id's for that edge, and the length of the edge. And you have a list of nodes that tell you which edge id's connect to that node, and the y,x coord of the node..
So if you're at (2,2) on the map above, the spatial index will tell you you are on edge id 2. Then if you look in the edge table, it tells you the next nodes are node id 1 & 2, and the length of the edge is 7..

Name: Anonymous 2014-07-30 2:44

>>6

Packing/unpacking one bit at a time like that is going to be horribly slow.
It won't be, because memory is the bottleneck and superscalar architecture can unpack several bit at once.
I.e.
x = word & 1;
y = word & 2;
z = word & 4;

would be as fast as single x = word & 1

Name: Anonymous 2014-07-30 2:53

>>21
That's mighty cool. Thanks for explaining.

>>22
Eh, how is memory the bottleneck? I doubt that with all the abstraction my x = bitval(p); bitnext(p); y = bitval(p); bitnext(p); z = bitval(p); will be translated into 3 AND instructors. I don't know how superscalar architecture works, but I doubt it does miracles. This needs to be written in assembly for proper optimization.

Name: Anonymous 2014-07-30 2:58

>>7
Also, to reply to >>7 on a second thought, objsize is not part of the code, but part of the example that followed. So, 1) it won't overflow, since I use it on small objects in the example, 2) objsize is not relevant.

Name: Anonymous 2014-07-30 3:00

>>23

all the abstraction
declare them inline

Name: Anonymous 2014-07-30 3:21

>>25
I just realized that I smoked crack when I wrote the code in >>5. There's a HUGE bug with the variable called 'tmp'. I tried to understand what it does and I finally realize that for values other than tmp = 0, nothing works as expected. I don't use the value of tmp when I increase q whenever n hits CHAR_BIT. That's nonsense, because tmp is supposed to represent (although it's not clear by the variable naming), the offset pointed to by the bitpointer.

So yeah, I will rewrite all this in C++.

Name: Anonymous 2014-07-30 5:15

Delivered, bitptr in C++. I didn't write the bitpack/unpack routines, I just implemented the concept of a bitpointer.
#include <climits> // CHAR_BIT
#include <cstdlib> // div, div_t

class bitref;

class bitptr {
friend class bitref;
public:
bitptr(void *memory = nullptr, int offset = 0);
bitptr& operator+=(int j);
bitptr& operator-=(int j);
bitptr& operator++();
bitptr& operator--();
bitptr operator++(int);
bitptr operator--(int);
bitref operator*() const;
bool operator==(const bitptr& rhs) const;
bitptr& operator=(void *rhs);

private:
unsigned char *p;
int i;
};

class bitref {
public:
bitref(const bitptr& p) : p(p.p), i(p.i) {};
bitref& operator=(bool b) {
if (b)
*p |= 1 << i;
else
*p &= ~(unsigned char)(1 << i);
return *this;
}
bool operator==(bool b) {
return b == (*p & (1 << i));
}
explicit operator bool() const { return *p & (1 << i); }
private:
unsigned char *p;
int i;
};

bitptr::bitptr(void *memory, int offset) {
div_t d;
p = static_cast<unsigned char *>(memory);
d = div(offset, CHAR_BIT);
p += d.quot;
i = d.rem;
}

bitptr& bitptr::operator+=(int j) {
div_t d;
d = div(j + i, CHAR_BIT);
p += d.quot;
i = d.rem;
return *this;
}

bitptr& bitptr::operator-=(int j) {
return *this += -j;
}

bitptr& bitptr::operator++() {
if (++i == CHAR_BIT) ++p, i = 0;
return *this;
}

bitptr& bitptr::operator--() {
if (--i == -1) --p, i = CHAR_BIT - 1;
return *this;
}

bitptr bitptr::operator++(int) {
bitptr val{ *this };
++*this;
return val;
}

bitptr bitptr::operator--(int) {
bitptr val{ *this };
--*this;
return val;
}

bitref bitptr::operator*(void) const {
return bitref(*this);
}

bool bitptr::operator==(const bitptr& q) const {
return p == q.p && i == q.i;
}

bitptr& bitptr::operator=(void *q) {
p = static_cast<unsigned char *>(q);
i = 0;
return *this;
}
// Example
int main(void) {
bitptr p, q;
char c = 0;
p = static_cast<void*>(&c);
q = p;
*p = *q;
q++;
*q = 1;
return 0;
}

Name: Anonymous 2014-07-30 5:25

>>27
Ah, I forgot to overload []. Add these definitions (and appropriate declarations in the class declaration of course):
bitptr bitptr::operator+(int j) const {
bitptr val{ *this };
val += j;
return val;
}

bitptr bitptr::operator-(int j) const {
bitptr val{ *this };
val -= j;
return val;
}

bitref bitptr::operator[](int j) const {
return *(*this + j);
};


With this, you can dump the binary of "Hello world" to output, like this:
char s = "Hello world";
bitptr p{static_cast<void*>(s)};
for(int i = 0; i < 11*CHAR_BIT; i++)
std::cout << p[i] ? "1" : "0";
std::cout << std::endl;

Name: Anonymous 2014-07-30 5:27

>>28
also to make + symmetric, more definitions need to be added (to make things like *(42 + p) and 42[p] work).

Name: Anonymous 2014-07-31 4:48

More fragments... =)

%% initmap.m %%

Fname = "classic.txt"

b = getMap(Fname);

b2 = b != tvalues(2);

bx = b == tvalues(6);

%%imshow(bx)

%%pause;

bz = reMap(bx, b2);

%%break;

zf = [0,1,0; 1,4,1; 0,1,0];

x = size(b2,2);

y = size(b2,1);

b3 = zeros(y,x);

b3(2:end-1, 2:end-1) = zfilter(bz, zf);

%imshow(b3 ./ 8)

bx = ((b3 > 4) .- (b3 == 6)) == 1;

by = zeros(y,x);

by(bx) = [1:sum(bx(:))];

imshow(by ./ sum(bx(:)));

nodes = sum(bx(:));

node = zeros(nodes, 3);

for(itery = 1:y)

for(iterx = 1:x)

if(bx(itery, iterx))

item = by(itery, iterx);

link = b3(itery, iterx) - 4;

node(item, :) = [itery, iterx, link];

endif;

endfor;

endfor;

figure(2);

plot(node(:,1), '-r', node(:,2), '-b', node(:,3), '-g');

maxTicks = fun_Eol(y,x);

%% end %%

function bx = reMap(bx, b2);

z2 = [0,1,0; 1,1,1; 0,1,0];

oldbx = b2;

i=0;

%%imshow(bx)

%%pause;

while(sum(oldbx(:) == bx(:)) < length(bx(:)))

oldbx = bx;

bn = (zfilter(bx, z2) > 0);

bx(2:end-1, 2:end-1) = bn;

bx = bx .* b2;

%%imshow(bx);

%%sleep(0.5);

%%++i

endwhile;

endfunction;

Name: Anonymous 2014-07-31 18:13

>>30
what is this language? matlab?

Name: Anonymous 2014-07-31 22:55

Octave, so pretty much matlab...
matlab doesn't like the endif, endfor, etc.. but everything else should be fine =)

Name: Anonymous 2014-07-31 23:14

This is the main loop as it is currently, everything else (~11 scripts) is just setting up this bit..

%% simstep.m %%

for(iterx = 1:ghosts+1)

tick = 0;

inktick = min([gtcounter, lmancounter] .- tick);

tick += inktick;

g_move = sum(gtcounter == tick);

g_id = [1:ghosts];

if(g_move>0)

gidx = g_id(gtcounter == tick);

for(iterg = 1:g_move)

id = gidx(iterg);

[gl, gs] = MoveGhost(glocate(id, :), gstatus(id,:), bz);

glocate(id,:) = gl;

gstatus(id, 2:3) = gs;

gtcounter(id) += tickgh(1, mod(id-1, 4)+1);

endfor;

endif;

lmove = lmancounter == tick;

if(lmove)

[xl, xs] = MoveGhost(lmanlocate, lmanstatus, bz); %%MoveLman();

lmanlocate = xl;

lmanstatus([2,3]) = xs;

lmancounter += ticklman(1);

endif;

endfor;

clf;

imshow(bz);

hold on; plot(glocate(:,2), glocate(:,1), 'rx', 'linewidth', 2);

plot(lmanlocate(:,2), lmanlocate(:,1), 'b+', 'linewidth', 2);

%% end %%

function [nloc,nstat] = MoveGhost(loc, status, map)

moveset = [1,0; 0,-1; -1,0; 0,1];

moves = zeros(4,1);

mid = [1:4];

for(iter = 1:4)

y = loc(1) + moveset(iter,1);

x = loc(2) + moveset(iter,2);

if( (status(2) == -moveset(iter,1)) + (status(3) == -moveset(iter,2))== 2)

lastmove = iter;

endif;

moves(iter) = map(y,x);

endfor;

nmoves = sum(moves);

if(nmoves == 1)

nstat = moveset(lastmove, :);

endif;

if(nmoves == 2)

moves(lastmove) = 0;

nstat = moveset(mid(moves==1),:);

endif;

if(nmoves > 2)

moves(lastmove) = 0;

rp = randperm(nmoves-1);

xm = mid(moves==1);

xm = xm(rp(1));

nstat = moveset(xm, :);

endif;

%%nstat

nloc = loc .+ nstat(1,:);

nstat = nstat(1,:);

endfunction;

Name: Anonymous 2014-08-02 15:48

val _ = print ("Hello, world!\n")

implement main0 () = ()

Name: Anonymous 2014-08-03 0:35

Octave/Matlab/Scilab are shit languages, Luke. Learn Mathematica and Scheme.

Name: Anonymous 2014-08-03 4:33

>>35
Actually, all languages are shit.

Name: Anonymous 2014-08-03 6:41

If it ain't Ruby, it's crap.

Name: od says 2014-08-03 7:34

inb4 sicp

for our databases: PostgreSQL
for our services: Go
for our scripts: Racket
for our frontends: AngularJS (to be replaced asap by Web Components)

Name: od says 2014-08-03 7:41

Name: Anonymous 2014-08-03 8:45

>>39

static typing
instant fail.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List