Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getchar does not read input #2

Closed
Lithrein opened this issue Jan 31, 2021 · 4 comments
Closed

getchar does not read input #2

Lithrein opened this issue Jan 31, 2021 · 4 comments

Comments

@Lithrein
Copy link

I've not been able to fix it but your tetris is unplaybable because there is no way to interact with the program. The problem is caused by the extern call stty cbreak -echo min 0 which causes getchar to never read anything. I've tried to change it to stty cbreak -echo min 1 time 0 but it causes the program to hang. I've also tried to hardcode a stream of input values ([27, 91, 65] (↑), etc.) but the only value which does not cause the program to hang is -1 (ie, no input).

@2bt
Copy link
Owner

2bt commented Jan 31, 2021

Thanks for the report. You've got to believe me this used to work great. Something must have changed with getchar() – it just won't unblock anymore. :(

I found a fix, just add the following to main.c:

int getchar() {
    char c;
    if (read(0, &c, 1) == 1) return c;
    return -1;
}

Alas, the code is not so pretty anymore. I shall see what I can do about that.

@Lithrein
Copy link
Author

Thank you! Indeed the shape is not as good as a before. Maybe, you can shape it in the form of a tetromino.

m[444],c,x;g(c){return!!read(0,&c,1)?c:-1;}main(o,a){for(system("stty cbreak   \
-echo min 0"),srand(a);o=f();o<42?a=(x=o/2%7)<3?x:x<4?f():x<5?m[f()<23?x:m[x-23]
]:x<6?g():rand()%f(),m[x=o%2?f():m[6]++]*=o<28,a=m[x]+=o>13?a:-a:o<45?putchar(o%
3?o%2*75+f():a):o<63?f(),c=!a^o/54?x+o%9*75:c:usleep(20000));system("stty sane")
;}f(){return x=c++["NCRM7@BD;527e4R37Q<Q9M27e@Q:OQ9MQ9Q;MQ9OMQ;Q9B7MQEQ:Q:OM27e\
^MQEMQ:OQ8KMQEOQ8OMQDMKQ:OMMQDQ:OQ:P7KMQ;OQ:Q927fDP7MMQ8MQ;Q:27fSRE5RE<Q6D952<f\
fR;<Q62<fr[JZ?[a[y`NT=>T?@LD2C^bT<7V<@<gC6K7bn6U7g^68?^^D;?27gjD:=NDTBC27gp@=27\
gv2=P8RE5RF<R;;TL747hB47K25T=9D;9859_lTA:F?:T=9R26FQ9859_lF59@:26hY`?B7`;RI98=9\
bn>D`3N8T@?T>=gxS825=2;h6252<h328k:RI=X66DM6R:9T6AF6A29i]X2?T?9F9?F9?RE5RE<TL7=\
27bn2<ivR[5RD<=R9;R97N98L9jM27=2;jD>7k6T5;L558a[25C9T;5>/jl2BT5;T576:7SN456F7jo\
T;52<j=[JZ?[j[wR[5RD<R;;[JZ?[cTL7D_7YZQ[O[O=2;kK25[92<kHn^7[JZ?ZQR35TL9l525kw=2\
5C_Y25l6[9/"]-47;}/************************************************************/

@2bt
Copy link
Owner

2bt commented Jan 31, 2021

Yes, thanks. I think I will take some time later to work it in nicely.

@2bt
Copy link
Owner

2bt commented Feb 1, 2021

I actually got it one byte shorter in the end. :)

I also added snake, merely by replacing that string literal.

@2bt 2bt closed this as completed Feb 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants