[ / / / / / / / / / / / / / ] [ dir / asmr / canada / d / demonsaw / firechan / ita / monarchy / strek ][Options][ watchlist ]

/tech/ - Technology

You can now write text to your AI-generated image at https://aiproto.com It is currently free to use for Proto members.
Name
Email
Subject
Comment *
File
Select/drop/paste files here
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Expand all images

File (hide): 5650dc794359fdf⋯.jpg (111.85 KB, 1280x720, 16:9, maxresdefault.jpg) (h) (u)

[–]

 No.812126>>812187 [Watch Thread][Show All Posts]

The last thread had a dumb task with a mechanism (a test website with ranked performance) that encouraged people to work to redo and enhance their earlier work. Let's see if we can replicate both of those aspects with this thread.

New dumb task

implement the bare bones of a roguelike game. Display some text and accept player input that moves a player across that text.

New Reason To Do More Work

Every entry should add something to the previous entry. The first one's going to do virtually nothing. Replies to that should replicate it's work and also tack some new feature: ideally, an extension to the game world - up/down stairs, levels that raise bridges. But you could also add color, arrow-key input, etc.

A possible lesson

Risk aversion is a big part of programming, because some really unpleasant ordeals can crop up long after you're deeply invested into a project. It's popular to talk about the risk of having to spend a lot of time chasing bugs, especially memory or security-related bugs, but inflexibility is a problem too: a suddenly important feature can not sound like a big deal and yet can be totally at odds with your design so far. "I can't do that without threads, and there's nothing thread-safe about this program." Or: "I can't do that efficiently without mutable state, which I've avoided."

First Entry

64 constant -maze
64 constant |maze
-maze |maze * constant /maze
: | ( "line" -- )
0 parse tuck here swap dup allot move
-maze swap - here swap dup allot bl fill ;
create maze
| #######
| # #
| # #
| # ~ #
| # #
| #######
here /maze over maze - - dup allot bl fill

variable player
maze -maze + 1 + player !

create output /maze allot

: .maze ( -- )
maze output /maze move
[char] @ player @ maze - output + c!
output /maze -trailing bounds do
i -maze -trailing cr type
-maze +loop ;

: peek ( n-dir -- c ) player @ + c@ ;
: peer ( n-dir -- c )
2* player @ + dup maze < if drop [char] # else c@ then ;

: chars( ( "cc" -- cc )
[char] ) parse drop count 8 lshift swap c@ or
POSTPONE literal ; immediate

: step ( n-dir -- )
dup peek 8 lshift over peer or case
chars( ) of player +! endof
chars( #) of player +! endof
chars( ~) of player +! endof
chars( ~ ) of player +!
cr ." Ooh! A dollar! You pick it up nonchalantly." key drop
bl player @ c! endof
endcase ;

: play ( -- )
begin page .maze key case
[char] h of -1 step endof
[char] j of -maze step endof
[char] k of -maze negate step endof
[char] l of 1 step endof
27 ( ESC ) of abort endof
endcase again ;

You can play this with 'gforth game.fs -e play'

Movement uses vi keys.

 No.812138>>812140 >>812145

can we at least do it in rust


 No.812140

>>812138

yeah you have to replicate the features, not the language. With reference to https://rosettacode.org/wiki/Keyboard_input/Keypress_check I started some Ada before deciding to get the thread up while I learn more.

with Ada.Text_IO;   use Ada.Text_IO;

procedure keytest is
Ch : Character;
Available : Boolean;
begin
loop
Get_Immediate (Ch, Available);
if Available then
Put_Line("Key entered: " & Ch);
exit;
end if;
end loop;
end keytest;


 No.812145

>>812138

no, gtfo faggot


 No.812161>>812163

What is this bullshit? No one can even read forth, how is anyone going to add to it?


 No.812163>>812165

>>812161

dude I can read that and most of it's not even mine. You can also install gforth and run it to see what it does.

the task again is not language-dependent. Write it whatever language you want.


 No.812165>>812166

>>812163

>requires knowledge of forth

>has no objective measure of quality

>barrier to entry increases with time

It's just a bad thread.


 No.812166

>>812165

nobody who could have possibly posted an entry would be stopped by any of that. You're just larping when you pretend it's a problem for you.


 No.812169

File (hide): 512924615bc7bf2⋯.png (263.74 KB, 1000x800, 5:4, helper can do.png) (h) (u)

Great thread dude!

Could you like make a ubuntu version of cogmind and make it open source instead of costing money https://www.youtube.com/watch?v=Cki73qtA32w

i can help with encouragement


 No.812187>>812236

File (hide): 0b1df90eb319554⋯.jpg (9.03 KB, 250x241, 250:241, 51fYzbYoXFL._UX250_.jpg) (h) (u)

>>812126 (OP)

Are you asking people to write a game for you?

The last thread might have had a lot of shitflinging but at least it encouraged people to autistically optimize their solution.

A game? Seriously nigger?


 No.812236>>812249

>>812187

yes this is my homework.

please make it as fun as possible

I said 'any language' but actually it needs to be in a language called PROLOG I hope that's OK

posters would derive no benefit whatever from making simple games like this so please slave away for me


 No.812247>>812248 >>812253 >>812264

the last thread was interesting because it was doable in a small amount of time with more time being added for autism and efficiency. this is way too big and time consuming. and try writing this in C.


 No.812248

>>812247

this.

/thread


 No.812249>>812266

>>812236

Please tell me you're joking.


 No.812253

>>812247

>writing anything in C

never gonna make it


 No.812264>>812284

>>812247

>try writing this in C

k.

#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>

char maze[6][8] = {
"#######",
"# #",
"# #",
"# ~ #",
"# #",
"#######",
};
int player_x = 1;
int player_y = 1;

void print_maze (void) {
printf("\033[2J\033[1;1H");
char copy[sizeof(maze[0])];
for (int i = 0; i < 6; i++) {
if (player_y == i) {
strcpy(copy, maze[i]);
copy[player_x] = '@';
printf("%s\n", copy);
}
else {
printf("%s\n", maze[i]);
}
}
}

/* https://rosettacode.org/wiki/Keyboard_input/Keypress_check#C */
void set_mode(int want_key) {
static struct termios old, new;
if (!want_key) {
tcsetattr(STDIN_FILENO, TCSANOW, &old);
return;
}

tcgetattr(STDIN_FILENO, &old);
new = old;
new.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &new);
}

char look (int x, int y) {
if (y < 0 || y > sizeof(*maze)) return '\0';
if (x < 0 || x > sizeof(maze[0])) return '\0';
return maze[y][x];
}

int sees (int d_x, int d_y, char *s) {
int at_x = player_x + d_x;
int at_y = player_y + d_y;
while (*s) {
if (*s != look(at_x, at_y)) return 0;
at_x += d_x;
at_y += d_y;
s++;
}
return 1;
}

void step (int x, int y) {
if (sees(x, y, " ")) { player_y += y; player_x += x; }
else if (sees(x, y, "~")) { player_y += y; player_x += x;
printf("Ooh! A dollar! You pick it up nonchalantly.\n");
getchar();
maze[player_y][player_x] = ' ';
}
}

int main () {
set_mode(1);
while (1) {
print_maze();
switch(getchar()) {
case 'h': step(-1, 0); break;
case 'j': step(0, 1); break;
case 'k': step(0, -1); break;
case 'l': step(1, 0); break;
case 27: set_mode(0); exit(0);
}
}
}

literally 10 minutes of coding **and 30 minutes of debugging. fuck C's support for arrays. This is what people whine about Forth not having?

Just look at that hard-coded 6 in print_maze. I know that can be replaced with some sizeof() construction, but I give up.**


 No.812266


 No.812284>>812288

>>812264

good job.

improved with advanced decision making.


#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>

char maze[6][8] = {
"#######",
"# #",
"# W #",
"# ~ #",
"# #",
"#######",
};
int player_x = 1;
int player_y = 1;

void print_maze (void) {
printf("\033[2J\033[1;1H");
char copy[sizeof(maze[0])];
for (int i = 0; i < 6; i++) {
if (player_y == i) {
strcpy(copy, maze[i]);
copy[player_x] = '@';
printf("%s\n", copy);
}
else {
printf("%s\n", maze[i]);
}
}
}

/* https://rosettacode.org/wiki/Keyboard_input/Keypress_check#C */
void set_mode(int want_key) {
static struct termios old, new;
if (!want_key) {
tcsetattr(STDIN_FILENO, TCSANOW, &old);
return;
}

tcgetattr(STDIN_FILENO, &old);
new = old;
new.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &new);
}

char look (int x, int y) {
if (y < 0 || y > sizeof(*maze)) return '\0';
if (x < 0 || x > sizeof(maze[0])) return '\0';
return maze[y][x];
}

int sees (int d_x, int d_y, char *s) {
int at_x = player_x + d_x;
int at_y = player_y + d_y;
while (*s) {
if (*s != look(at_x, at_y)) return 0;
at_x += d_x;
at_y += d_y;
s++;
}
return 1;
}

int getChoice(char *question) {
char choice;
printf("%s\n",question);
printf("Choice:");
choice=getchar();
printf("\n");
return choice;
}

void step (int x, int y) {
if (sees(x, y, " ")) { player_y += y; player_x += x; }
else if (sees(x, y, "~")) { player_y += y; player_x += x;
printf("Ooh! A dollar! You pick it up nonchalantly.\n");
getchar();
maze[player_y][player_x] = ' ';
}

else if (sees(x, y, "W")) { player_y += y; player_x += x;
char *question="A bluehaired non-binary appears, what would you like to do?\n \
1: Use your priviledge to kill the nonbinary?\n \
2: Apologize for being a cis white male";
switch (getChoice(question)) {
case '1':
printf("You use (((priviledge))) to to kill the nonbinary\n");
getchar();
break;
case '2':
printf("You apologize for being a cis white male. You are sent to prison.\n");
printf("YOU LOOSE, GAME OVER\n");
exit(0);
}

maze[player_y][player_x] = ' ';
}
}

int main () {
set_mode(1);
while (1) {
print_maze();
switch(getchar()) {
case 'h': step(-1, 0); break;
case 'j': step(0, 1); break;
case 'k': step(0, -1); break;
case 'l': step(1, 0); break;
case 27: set_mode(0); exit(0);
}
}
}


 No.812288>>812293

>>812284

you forgot to set_mode(0) on exit. Here, I made it atexit() for you:

#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>

char maze[6][8] = {
"#######",
"# #",
"# $W #",
"# ~ #",
"# #",
"#######",
};
int player_x = 1;
int player_y = 1;

void print_maze (void) {
printf("\033[2J\033[1;1H");
char copy[sizeof(maze[0])];
for (int i = 0; i < 6; i++) {
if (player_y == i) {
strcpy(copy, maze[i]);
copy[player_x] = '@';
printf("%s\n", copy);
}
else {
printf("%s\n", maze[i]);
}
}
}

/* https://rosettacode.org/wiki/Keyboard_input/Keypress_check#C */
void set_mode(int want_key) {
static struct termios old, new;
if (!want_key) {
tcsetattr(STDIN_FILENO, TCSANOW, &old);
return;
}

tcgetattr(STDIN_FILENO, &old);
new = old;
new.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &new);
}
void reset_mode (void) { set_mode(0); }

char look (int x, int y) {
if (y < 0 || y > sizeof(*maze)) return '\0';
if (x < 0 || x > sizeof(maze[0])) return '\0';
return maze[y][x];
}

int sees (int d_x, int d_y, char *s) {
int at_x = player_x + d_x;
int at_y = player_y + d_y;
while (*s) {
if (*s != look(at_x, at_y)) return 0;
at_x += d_x;
at_y += d_y;
s++;
}
return 1;
}

int getChoice(char *question) {
char choice;
printf("%s\n",question);
printf("Choice:");
choice=getchar();
printf("\n");
return choice;
}

void step (int x, int y) {
if (sees(x, y, " ")) { player_y += y; player_x += x; }
else if (sees(x, y, "~")) { player_y += y; player_x += x;
printf("Ooh! A dollar! You pick it up nonchalantly.\n");
getchar();
maze[player_y][player_x] = ' ';
}
else if (sees(x, y, "$ ")) { player_y += y; player_x += x;
maze[player_y][player_x] = ' ';
maze[player_y+y][player_x+x] = '$';
}
else if (sees(x, y, "$W")) { player_y += y; player_x += x;
printf("You hear a strangled scream about 'rock privilege'... weird.\n");
getchar();
maze[player_y][player_x] = ' ';
maze[player_y+y][player_x+x] = '$';
}
else if (sees(x, y, "W")) { player_y += y; player_x += x;
char *question="A bluehaired non-binary appears, what would you like to do?\n \
1: Use your priviledge to kill the nonbinary?\n \
2: Apologize for being a cis white male";
switch (getChoice(question)) {
case '1':
printf("You use (((priviledge))) to to kill the nonbinary\n");
getchar();
break;
case '2':
printf("You apologize for being a cis white male. You are sent to prison.\n");
printf("YOU LOOSE, GAME OVER\n");
exit(0);
}
maze[player_y][player_x] = ' ';
}
}

int main () {
atexit(reset_mode);
set_mode(1);
while (1) {
print_maze();
switch(getchar()) {
case 'h': step(-1, 0); break;
case 'j': step(0, 1); break;
case 'k': step(0, -1); break;
case 'l': step(1, 0); break;
case 27: exit(0);
}
}
}


 No.812293

>>812288

>jewish game

>lets you crush a shiksa with a rock

>doesn't let you roll it over a dollah on the ground

I just didn't think about it I swear




[Return][Go to top][Catalog][Screencap][Nerve Center][Cancer][Update] ( Scroll to new posts) ( Auto) 5
19 replies | 2 images | Page ?
[Post a Reply]
[ / / / / / / / / / / / / / ] [ dir / asmr / canada / d / demonsaw / firechan / ita / monarchy / strek ][ watchlist ]