mirror of
https://github.com/abakh/nbsdgames.git
synced 2025-01-03 14:56:23 -05:00
Cleanup,PSE,Plan9
This commit is contained in:
parent
1e3bcb176c
commit
d1aace14f8
18
README.md
18
README.md
@ -31,6 +31,8 @@ These include:
|
||||
|
||||
They natively run on Linux, BSD, MacOS and are known to work on Windows as well (using PDCurses, thanks to Laura Michaels for providing advice).
|
||||
|
||||
They have been ported to Plan9 by Jens Staal!
|
||||
|
||||
The difficulty and/or dimensions are adjustable through simple command line options, you can play a minesweeper game that take hours to complete, or exprience hexadecimal sudoku and 8x8 fifteen-like puzzles!
|
||||
|
||||
I have encounterd Fisher, Muncher and Miketron on MikeOS and RedSquare on KolibriOS.
|
||||
@ -64,15 +66,21 @@ the deb package: https://github.com/untakenstupidnick/nbsdgames/releases/downloa
|
||||
It's available on AUR thanks to Elias Riedel Gårding: https://aur.archlinux.org/packages/nbsdgames-git/
|
||||
(The commands start with nbsd_ to avoid conflict)
|
||||
|
||||
It's been made available for openSUSE thanks to Jan Brezina: https://build.opensuse.org/package/show/home:Zinjanthropus/nbsdgames
|
||||
It's been made available for openSUSE thanks to Zinjanthropus: https://build.opensuse.org/package/show/home:Zinjanthropus/nbsdgames
|
||||
## How do these look like
|
||||
![Screenshot from 4 games in tmux](https://raw.githubusercontent.com/untakenstupidnick/new-bsd-games/master/screenshot.png)
|
||||
Linux+xterm+tmux
|
||||
![Screenshot from 4 games in tmux](https://raw.githubusercontent.com/untakenstupidnick/nbsdgames/master/screenshot.png)
|
||||
|
||||
Plan9
|
||||
![Screenshot from the games in Plan9](https://raw.githubusercontent.com/untakenstupidnick/nbsdgames/master/screenshot_plan9.png)
|
||||
|
||||
## How to contribute
|
||||
* Share these with your friends
|
||||
* Share these with your friends and others
|
||||
* Your stars make the repo more findable in github
|
||||
* Tell me your feature requests, bug reports, etc.
|
||||
* Tell me the games you want to be added (but in the same genre, i can't port Angry Birds to curses! :)
|
||||
* Make a package for your distro (or put it on repos if it's not there)
|
||||
* Make a package for your distro (or put it on repos if the package is not there)
|
||||
* Does anyone understand debian's .orig.tar.gz and the process to make packages to the repos? Any help would be appreciated.
|
||||
Also thank to all the people who helped in the previous versions, i didn't expect such an amount of assistance <3
|
||||
|
||||
|
||||
Also thank to all the people who helped in the previous versions, all what i requested was done! i didn't expect such an amount of assistance on this project :heart:
|
||||
|
BIN
screenshot_plan9.png
Normal file
BIN
screenshot_plan9.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
@ -1,7 +1,18 @@
|
||||
# -*- Makefile -*-
|
||||
|
||||
all: jewels sudoku mines reversi checkers battleship rabbithole sos pipes fifteen memoblocks fisher muncher miketron redsquare
|
||||
|
||||
scorefiles:
|
||||
touch /usr/games/pp_scores
|
||||
touch /usr/games/jw_scores
|
||||
touch /usr/games/mt_scores
|
||||
touch /usr/games/mnch_scores
|
||||
touch /usr/games/fsh_scores
|
||||
chmod 666 /usr/games/pp_scores
|
||||
chmod 666 /usr/games/jw_scores
|
||||
chmod 666 /usr/games/mt_scores
|
||||
chmod 666 /usr/games/mnch_scores
|
||||
chmod 666 /usr/games/fsh_scores
|
||||
|
||||
jewels: jewels.c config.h
|
||||
$(CC) jewels.c -lncurses -o ./jewels
|
||||
sudoku: sudoku.c
|
||||
@ -38,6 +49,6 @@ uninstall:
|
||||
rm $(PREFIX)/jewels $(PREFIX)/sudoku $(PREFIX)/checkers $(PREFIX)/mines $(PREFIX)/reversi $(PREFIX)/battleship $(PREFIX)/rabbithole $(PREFIX)/sos $(PREFIX)/pipes $(PREFIX)/fifteen $(PREFIX)/memoblocks $(PREFIX)/fisher $(PREFIX)/muncher $(PREFIX)/miketron $(PREFIX)/redsquare
|
||||
copy_sources:
|
||||
cp Makefile config.h jewels.c sudoku.c mines.c reversi.c checkers.c battleship.c rabbithole.c sos.c pipes.c fifteen.c memoblocks.c fisher.c muncher.c miketron.c redsquare.c $(PREFIX)
|
||||
install: jewels sudoku mines reversi checkers battleship rabbithole sos pipes fifteen memoblocks fisher muncher miketron redsquare
|
||||
install: scorefiles jewels sudoku mines reversi checkers battleship rabbithole sos pipes fifteen memoblocks fisher muncher miketron redsquare
|
||||
cp jewels sudoku mines reversi checkers battleship rabbithole sos pipes fifteen memoblocks fisher muncher miketron redsquare $(PREFIX)
|
||||
|
||||
|
@ -1,3 +1,13 @@
|
||||
/*
|
||||
_
|
||||
|_)
|
||||
|_)ATTLESHIP
|
||||
|
||||
Authored by abakh <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lncurses
|
||||
*/
|
||||
#include <curses.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
@ -13,18 +23,9 @@
|
||||
#define ALL 0x7c
|
||||
#define RED 3
|
||||
#define CYAN 2
|
||||
/*
|
||||
_
|
||||
|_)
|
||||
|_)ATTLESHIP
|
||||
|
||||
Authored by Hossein Bakhtiarifar <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lncurses
|
||||
*/
|
||||
typedef signed char byte;
|
||||
typedef unsigned char bitbox;
|
||||
|
||||
bool multiplayer;
|
||||
byte py,px;//cursor
|
||||
|
||||
@ -68,11 +69,11 @@ void mouseinput(bool ingame){
|
||||
ungetch('r');
|
||||
}
|
||||
void rectangle(byte sy,byte sx){
|
||||
for(byte y=0;y<=10+1;y++){
|
||||
for(byte y=0;y<=10+1;++y){
|
||||
mvaddch(sy+y,sx,ACS_VLINE);
|
||||
mvaddch(sy+y,sx+10*2,ACS_VLINE);
|
||||
}
|
||||
for(byte x=0;x<=10*2;x++){
|
||||
for(byte x=0;x<=10*2;++x){
|
||||
mvaddch(sy,sx+x,ACS_HLINE);
|
||||
mvaddch(sy+10+1,sx+x,ACS_HLINE);
|
||||
}
|
||||
@ -118,8 +119,8 @@ void MID(byte *y , byte *x, byte direction){
|
||||
}
|
||||
void genocide(bool side , byte type){
|
||||
byte y,x;
|
||||
for(y=0;y<10;y++){
|
||||
for(x=0;x<10;x++){
|
||||
for(y=0;y<10;++y){
|
||||
for(x=0;x<10;++x){
|
||||
if(game[side][y][x] == type)
|
||||
game[side][y][x] = SEA;
|
||||
}
|
||||
@ -128,8 +129,8 @@ void genocide(bool side , byte type){
|
||||
void header(bool side){
|
||||
score[0]=score[1]=0;
|
||||
byte y,x;
|
||||
for(y=0;y<10;y++){
|
||||
for(x=0;x<10;x++){
|
||||
for(y=0;y<10;++y){
|
||||
for(x=0;x<10;++x){
|
||||
if(game[!side][y][x] == HIT)
|
||||
score[side]++;
|
||||
if(game[side][y][x] == HIT)
|
||||
@ -153,8 +154,8 @@ void draw(bool side,byte sy,byte sx,bool regular){//the game's board
|
||||
rectangle(sy,sx);
|
||||
chtype ch ;
|
||||
byte y,x;
|
||||
for(y=0;y<10;y++){
|
||||
for(x=0;x<10;x++){
|
||||
for(y=0;y<10;++y){
|
||||
for(x=0;x<10;++x){
|
||||
ch =A_NORMAL;
|
||||
if(y==py && x==px)
|
||||
ch |= A_STANDOUT;
|
||||
@ -177,8 +178,8 @@ void draw_trackboard(bool side,byte sy,byte sx){
|
||||
rectangle(sy,sx);
|
||||
chtype ch ;
|
||||
byte y,x;
|
||||
for(y=0;y<10;y++){
|
||||
for(x=0;x<10;x++){
|
||||
for(y=0;y<10;++y){
|
||||
for(x=0;x<10;++x){
|
||||
ch =A_NORMAL;
|
||||
if(y==py && x==px-10)
|
||||
ch |= A_STANDOUT;
|
||||
@ -200,7 +201,7 @@ void autoset(bool side){
|
||||
byte y=0,x=0,direction=0, invain=0;
|
||||
byte realy,realx;
|
||||
byte l;
|
||||
for(byte type=2;type<7;type++){
|
||||
for(byte type=2;type<7;++type){
|
||||
SetLocation:
|
||||
realy=rand()%10;
|
||||
realx=rand()%10;
|
||||
@ -209,10 +210,10 @@ void autoset(bool side){
|
||||
y=realy;
|
||||
x=realx;
|
||||
direction=rand()%4;
|
||||
for(l=0;(type != 6 && l<type) || (type==6 && l<3) ; l++){//there are two kinds of ship sized 3 tiles
|
||||
for(l=0;(type != 6 && l<type) || (type==6 && l<3) ; ++l){//there are two kinds of ship sized 3 tiles
|
||||
if( y<0 || x<0 || y>=10 || x>=10 || game[side][y][x] != SEA ){
|
||||
genocide(side,type);
|
||||
invain++;
|
||||
++invain;
|
||||
direction= (direction+1)%4;
|
||||
if(invain<4)
|
||||
goto SetDirection;
|
||||
@ -242,7 +243,7 @@ void set_the_board(bool side){
|
||||
byte realy,realx;
|
||||
byte l;
|
||||
py=px=0;
|
||||
for(byte type=2;type<7;type++){
|
||||
for(byte type=2;type<7;++type){
|
||||
mvaddstr(15,0,"Put your ");
|
||||
print_type(type);
|
||||
addstr(" in its position: ");
|
||||
@ -254,13 +255,13 @@ void set_the_board(bool side){
|
||||
if( input == KEY_MOUSE )
|
||||
mouseinput(0);
|
||||
if( (input=='k' || input==KEY_UP) && py>0)
|
||||
py--;
|
||||
--py;
|
||||
if( (input=='j' || input==KEY_DOWN) && py<9)
|
||||
py++;
|
||||
++py;
|
||||
if( (input=='h' || input==KEY_LEFT) && px>0)
|
||||
px--;
|
||||
--px;
|
||||
if( (input=='l' || input==KEY_RIGHT) && px<9)
|
||||
px++;
|
||||
++px;
|
||||
if( input=='\n' )
|
||||
break;
|
||||
if( input=='q' )
|
||||
@ -274,10 +275,10 @@ void set_the_board(bool side){
|
||||
SetDirection:
|
||||
y=realy;
|
||||
x=realx;
|
||||
for(l=0;(type != 6 && l<type) || (type==6 && l<3) ; l++){//there are two kinds of ship sized 3 tiles
|
||||
for(l=0;(type != 6 && l<type) || (type==6 && l<3) ; ++l){//there are two kinds of ship sized 3 tiles
|
||||
if( y<0 || x<0 || y>=10 || x>=10 || game[side][y][x] != SEA ){
|
||||
genocide(side,type);
|
||||
invain++;
|
||||
++invain;
|
||||
direction= (direction+1)%4;
|
||||
if(invain<4)
|
||||
goto SetDirection;
|
||||
@ -352,9 +353,9 @@ byte shoot(bool turn, byte y , byte x){
|
||||
}
|
||||
void sink_announce(bool side){
|
||||
byte type,y,x;
|
||||
for(type=2;type<7;type++){
|
||||
for(y=0;y<10;y++){
|
||||
for(x=0;x<10;x++){
|
||||
for(type=2;type<7;++type){
|
||||
for(y=0;y<10;++y){
|
||||
for(x=0;x<10;++x){
|
||||
if( game[!side][y][x] == type )
|
||||
goto Next;
|
||||
}
|
||||
@ -397,8 +398,8 @@ void cheat(bool side){
|
||||
|
||||
if i implemented the logical thinking thing, it would become a difficult, unenjoyable game.*/
|
||||
byte y,x;
|
||||
for(y=0;y<10;y++){
|
||||
for(x=0;x<10;x++){
|
||||
for(y=0;y<10;++y){
|
||||
for(x=0;x<10;++x){
|
||||
if(game[!side][y][x]>0){
|
||||
shoot(side,y,x);
|
||||
firstinrowy=y;
|
||||
@ -438,7 +439,7 @@ void decide(bool side){// sink_announce is responsible for unsetting the global
|
||||
r= shoot(side,y,x);
|
||||
if( r != 1 ){
|
||||
goindirection = (goindirection+1)%4;//the ship is oriented in another way then
|
||||
shotinvain++;
|
||||
++shotinvain;
|
||||
|
||||
if(shotinvain==4){ // this only occurs in case of a ship being shot before but not sunk ( e.g. in exprimenting for the direction)
|
||||
shotinvain=0;
|
||||
@ -533,7 +534,7 @@ int main(void){
|
||||
init_pair(2,COLOR_YELLOW,-1);
|
||||
init_pair(3,COLOR_CYAN,-1);
|
||||
init_pair(4,COLOR_RED,-1);
|
||||
for(byte b=0;b<4;b++)
|
||||
for(byte b=0;b<4;++b)
|
||||
colors[b]=COLOR_PAIR(b+1);
|
||||
}
|
||||
int input;
|
||||
@ -599,13 +600,13 @@ int main(void){
|
||||
if(input == KEY_MOUSE)
|
||||
mouseinput(1);
|
||||
if( (input=='k' || input==KEY_UP) && py>0)
|
||||
py--;
|
||||
--py;
|
||||
if( (input=='j' || input==KEY_DOWN) && py<9)
|
||||
py++;
|
||||
++py;
|
||||
if( (input=='h' || input==KEY_LEFT) && px>10)
|
||||
px--;
|
||||
--px;
|
||||
if( (input=='l' || input==KEY_RIGHT) && px<19)
|
||||
px++;
|
||||
++px;
|
||||
if( input=='q')
|
||||
sigint_handler(EXIT_SUCCESS);
|
||||
if( input=='\n'){
|
||||
|
@ -1,3 +1,14 @@
|
||||
/*
|
||||
.-.
|
||||
| '
|
||||
'._.HECKERS
|
||||
|
||||
Authored by abakh <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
Compile with -lncurses
|
||||
*/
|
||||
|
||||
#include <curses.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
@ -16,17 +27,8 @@
|
||||
#define ALT_IMG 2
|
||||
#define ALT_NRM 3
|
||||
#define WIN 100000
|
||||
/*
|
||||
.-.
|
||||
| '
|
||||
'._.HECKERS
|
||||
|
||||
Authored by Hossein Bakhtiarifar <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
Compile with -lncurses
|
||||
*/
|
||||
typedef signed char byte;
|
||||
|
||||
byte py,px;//cursor
|
||||
byte cy,cx;//selected(choosen) piece
|
||||
int dpt;
|
||||
@ -38,18 +40,18 @@ byte jumpagainy , jumpagainx;
|
||||
bool kinged;//if a piece jumps over multiple others and becomes a king it cannot continue jumping
|
||||
|
||||
bool in(byte A[4],byte B[4],byte a,byte b){
|
||||
for(byte c=0;c<4;c++)
|
||||
for(byte c=0;c<4;++c)
|
||||
if(A[c]==a && B[c]==b)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
void rectangle(byte sy,byte sx){
|
||||
byte y,x;
|
||||
for(y=0;y<=8+1;y++){
|
||||
for(y=0;y<=8+1;++y){
|
||||
mvaddch(sy+y,sx,ACS_VLINE);
|
||||
mvaddch(sy+y,sx+8*2,ACS_VLINE);
|
||||
}
|
||||
for(x=0;x<=8*2;x++){
|
||||
for(x=0;x<=8*2;++x){
|
||||
mvaddch(sy,sx+x,ACS_HLINE);
|
||||
mvaddch(sy+8+1,sx+x,ACS_HLINE);
|
||||
}
|
||||
@ -61,8 +63,8 @@ void rectangle(byte sy,byte sx){
|
||||
void header(void){
|
||||
score[0]=score[1]=0;
|
||||
byte y,x;
|
||||
for(y=0;y<8;y++){
|
||||
for(x=0;x<8;x++){
|
||||
for(y=0;y<8;++y){
|
||||
for(x=0;x<8;++x){
|
||||
if(game[y][x]){
|
||||
if(game[y][x]<0)
|
||||
score[0]++;
|
||||
@ -79,8 +81,8 @@ void draw(byte sy,byte sx){//the game's board
|
||||
rectangle(sy,sx);
|
||||
chtype ch ;
|
||||
byte y,x;
|
||||
for(y=0;y<8;y++){
|
||||
for(x=0;x<8;x++){
|
||||
for(y=0;y<8;++y){
|
||||
for(x=0;x<8;++x){
|
||||
ch=A_NORMAL;
|
||||
if(y==py && x==px)
|
||||
ch |= A_STANDOUT;
|
||||
@ -109,8 +111,8 @@ void draw(byte sy,byte sx){//the game's board
|
||||
//place the pieces on the board
|
||||
void fill(void){
|
||||
byte y,x;
|
||||
for(y=0;y<8;y++){
|
||||
for(x=0;x<8;x++){
|
||||
for(y=0;y<8;++y){
|
||||
for(x=0;x<8;++x){
|
||||
game[y][x]=0;
|
||||
if( (y%2) != (x%2)){
|
||||
if(y<3) game[y][x]=1;
|
||||
@ -126,18 +128,18 @@ bool moves(byte ty,byte tx,byte mvy[4],byte mvx[4]){
|
||||
byte t= game[ty][tx];
|
||||
move(15,0);
|
||||
byte dy,dx;
|
||||
for(dy=-1;dy<2;dy++){
|
||||
for(dx=-1;dx<2;dx++){
|
||||
for(dy=-1;dy<2;++dy){
|
||||
for(dx=-1;dx<2;++dx){
|
||||
if( !dy || !dx || (!ty && dy<0) || (!tx && dx<0) || (dy==-t) || (ty+dy>=8) || (tx+dx>=8) )
|
||||
;
|
||||
else if(!game[ty+dy][tx+dx]){
|
||||
ret=1;
|
||||
mvy[ndx]=ty+dy;
|
||||
mvx[ndx]=tx+dx;
|
||||
ndx++;
|
||||
++ndx;
|
||||
}
|
||||
else
|
||||
ndx++;
|
||||
++ndx;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@ -145,11 +147,11 @@ bool moves(byte ty,byte tx,byte mvy[4],byte mvx[4]){
|
||||
//would be much faster than applying moves() on every tile
|
||||
bool can_move(byte side){
|
||||
byte y , x ,t, dy , dx;
|
||||
for(y=0;y<8;y++){
|
||||
for(x=0;x<8;x++){
|
||||
for(y=0;y<8;++y){
|
||||
for(x=0;x<8;++x){
|
||||
if( (t=game[y][x])*side > 0 ){
|
||||
for(dy=-1;dy<2;dy++){
|
||||
for(dx=-1;dx<2;dx++){
|
||||
for(dy=-1;dy<2;++dy){
|
||||
for(dx=-1;dx<2;++dx){
|
||||
if( !dy || !dx || (!y && dy<0) || (!x && dx<0) || (dy==-t) || (y+dy>=8) || (x+dx>=8) )
|
||||
;
|
||||
else if( !game[y+dy][x+dx] )
|
||||
@ -169,8 +171,8 @@ bool jumps(byte ty,byte tx,byte mvy[4],byte mvx[4]){
|
||||
byte ey,ex;
|
||||
byte t= game[ty][tx];
|
||||
byte dy,dx;
|
||||
for(dy=-1;dy<2;dy++){
|
||||
for(dx=-1;dx<2;dx++){
|
||||
for(dy=-1;dy<2;++dy){
|
||||
for(dx=-1;dx<2;++dx){
|
||||
ey = dy*2;
|
||||
ex = dx*2;
|
||||
if(!dy || !dx ||(dy==-t)|| (ty+ey<0) || (tx+ex<0) || (ty+ey>=8) || (tx+ex>=8) )
|
||||
@ -179,10 +181,10 @@ bool jumps(byte ty,byte tx,byte mvy[4],byte mvx[4]){
|
||||
ret=1;
|
||||
mvy[ndx]=ty+ey;
|
||||
mvx[ndx]=tx+ex;
|
||||
ndx++;
|
||||
++ndx;
|
||||
}
|
||||
else
|
||||
ndx++;
|
||||
++ndx;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@ -192,14 +194,14 @@ byte can_jump(byte ty,byte tx){
|
||||
byte dy,dx,t=game[ty][tx];
|
||||
byte ey,ex;
|
||||
byte ret=0;
|
||||
for(dy=-1;dy<2;dy++){
|
||||
for(dx=-1;dx<2;dx++){
|
||||
for(dy=-1;dy<2;++dy){
|
||||
for(dx=-1;dx<2;++dx){
|
||||
ey=dy*2;
|
||||
ex=dx*2;
|
||||
if((dy==-t)||(ty+ey<0)||(tx+ex<0)||(ty+ey>=8)||(tx+ex>=8) )
|
||||
;
|
||||
else if(!game[ty+dy*2][tx+dx*2]&&game[ty+dy][tx+dx]*t<0){
|
||||
ret++;
|
||||
++ret;
|
||||
if(ret>1)
|
||||
return ret;
|
||||
}
|
||||
@ -213,8 +215,8 @@ byte forced_jump(byte side){
|
||||
byte y,x;
|
||||
byte foo,ret;
|
||||
foo=ret=0;
|
||||
for(y=0;y<8;y++){
|
||||
for(x=0;x<8;x++){
|
||||
for(y=0;y<8;++y){
|
||||
for(x=0;x<8;++x){
|
||||
if(game[y][x]*side>0 && (foo=can_jump(y,x)) )
|
||||
ret+=foo;
|
||||
if(ret>1)
|
||||
@ -248,15 +250,15 @@ double advantage(byte side){
|
||||
own=opp=0;
|
||||
byte foo;
|
||||
byte y,x;
|
||||
for(y=0;y<8;y++){
|
||||
for(x=0;x<8;x++){
|
||||
for(y=0;y<8;++y){
|
||||
for(x=0;x<8;++x){
|
||||
foo=game[y][x]*side;
|
||||
if(foo>0){
|
||||
own++;//so it wont sacrfice two pawns for a king ( 2 kings == 3 pawns)
|
||||
++own;//so it wont sacrfice two pawns for a king ( 2 kings == 3 pawns)
|
||||
own+=foo;
|
||||
}
|
||||
else if(foo<0){
|
||||
opp++;
|
||||
++opp;
|
||||
opp-=foo;
|
||||
}
|
||||
}
|
||||
@ -277,12 +279,12 @@ double posadvantage(byte side){
|
||||
/*This encourages the AI to king its pawns and concentrate its kings in the center.
|
||||
The idea is : With forces concentrated in the center, movements to all of the board would be in the game tree's horizon of sight(given enough depth);
|
||||
and with forces being focused , its takes less movements to make an attack. */
|
||||
for(y=0;y<8;y++){
|
||||
for(x=0;x<8;x++){
|
||||
for(y=0;y<8;++y){
|
||||
for(x=0;x<8;++x){
|
||||
foo=game[y][x]*side;
|
||||
if(foo>0){
|
||||
adv+=foo;
|
||||
adv++;
|
||||
++adv;
|
||||
if(foo==1)
|
||||
adv+= 1/( abs(y-goal) );//adding positional value
|
||||
else if(foo==2)
|
||||
@ -290,7 +292,7 @@ double posadvantage(byte side){
|
||||
}
|
||||
else if( foo<0 ){
|
||||
oppadv-=foo;
|
||||
oppadv++;
|
||||
++oppadv;
|
||||
if(foo==-1)
|
||||
adv+=1/( abs(y-oppgoal) );
|
||||
else if(foo==-2)
|
||||
@ -335,8 +337,8 @@ double decide(byte side,byte depth,byte s){//s is the type of move, it doesn't s
|
||||
else
|
||||
nexts=ALT_IMG;
|
||||
|
||||
for(y=0;y<8;y++){
|
||||
for(x=0;x<8;x++){
|
||||
for(y=0;y<8;++y){
|
||||
for(x=0;x<8;++x){
|
||||
if(fj && (s==NORMAL || s==ALT_NRM) && jumpagainy>=0 && (jumpagainy!=y || jumpagainx!=x) )
|
||||
continue;
|
||||
if(game[y][x]*side>0){
|
||||
@ -348,7 +350,7 @@ double decide(byte side,byte depth,byte s){//s is the type of move, it doesn't s
|
||||
else
|
||||
canmove=moves(y,x,mvy,mvx);
|
||||
if(canmove){
|
||||
for(n=0;n<4;n++){
|
||||
for(n=0;n<4;++n){
|
||||
if(mvy[n] != -1){//a real move
|
||||
toy=mvy[n];
|
||||
tox=mvx[n];
|
||||
@ -573,7 +575,7 @@ int main(int argc,char** argv){
|
||||
previousadv=adv;
|
||||
adv= advantage(1) + (score[0]*score[1]);//just taking the dry scores to account too,nothing special
|
||||
if(previousadv==adv)
|
||||
todraw++;
|
||||
++todraw;
|
||||
else
|
||||
todraw=0;
|
||||
}
|
||||
@ -623,13 +625,13 @@ int main(int argc,char** argv){
|
||||
if( input == KEY_MOUSE )
|
||||
mouseinput();
|
||||
if( (input=='k' || input==KEY_UP) && py>0)
|
||||
py--;
|
||||
--py;
|
||||
if( (input=='j' || input==KEY_DOWN) && py<7)
|
||||
py++;
|
||||
++py;
|
||||
if( (input=='h' || input==KEY_LEFT) && px>0)
|
||||
px--;
|
||||
--px;
|
||||
if( (input=='l' || input==KEY_RIGHT) && px<7)
|
||||
px++;
|
||||
++px;
|
||||
if( input=='q'){
|
||||
result=2;
|
||||
goto End;
|
||||
|
@ -1,38 +1,36 @@
|
||||
/*
|
||||
--.
|
||||
|__
|
||||
| IFTEEN
|
||||
|
||||
Authored by abakh <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lncurses
|
||||
*/
|
||||
#include <curses.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <time.h>
|
||||
#include <signal.h>
|
||||
/*
|
||||
.--
|
||||
|__
|
||||
| IFTEEN
|
||||
|
||||
Authored by Hossein Bakhtiarifar <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lncurses
|
||||
*/
|
||||
typedef signed char byte;
|
||||
|
||||
/* The Plan9 compiler can not handle VLAs */
|
||||
#ifdef Plan9
|
||||
#define size 4
|
||||
#endif
|
||||
|
||||
typedef signed char byte;
|
||||
#ifndef Plan9
|
||||
#else
|
||||
byte size;
|
||||
#endif
|
||||
byte py,px;
|
||||
byte ey,ex; //the empty tile
|
||||
chtype green=A_BOLD; //bold when there is no color
|
||||
void rectangle(byte sy,byte sx){
|
||||
for(byte y=0;y<=size+1;y++){
|
||||
for(byte y=0;y<=size+1;++y){
|
||||
mvaddch(sy+y,sx,ACS_VLINE);
|
||||
mvaddch(sy+y,sx+size*2,ACS_VLINE);
|
||||
}
|
||||
for(byte x=0;x<=size*2;x++){
|
||||
for(byte x=0;x<=size*2;++x){
|
||||
mvaddch(sy,sx+x,ACS_HLINE);
|
||||
mvaddch(sy+size+1,sx+x,ACS_HLINE);
|
||||
}
|
||||
@ -42,7 +40,7 @@ void rectangle(byte sy,byte sx){
|
||||
mvaddch(sy+size+1,sx+size*2,ACS_LRCORNER);
|
||||
}
|
||||
void logo(byte sy,byte sx){
|
||||
mvaddstr(sy,sx, ".--");
|
||||
mvaddstr(sy,sx, "--.");
|
||||
mvaddstr(sy+1,sx,"|__");
|
||||
mvaddstr(sy+2,sx,"| IFTEEN");
|
||||
}
|
||||
@ -67,8 +65,8 @@ void draw(byte sy,byte sx,char board[size][size],char check[size][size]){
|
||||
rectangle(sy,sx);
|
||||
chtype prnt;
|
||||
byte y,x;
|
||||
for(y=0;y<size;y++){
|
||||
for(x=0;x<size;x++){
|
||||
for(y=0;y<size;++y){
|
||||
for(x=0;x<size;++x){
|
||||
prnt=board[y][x];
|
||||
if(check[y][x]==board[y][x] && check[y][x] != ' ')
|
||||
prnt |= green;
|
||||
@ -80,8 +78,8 @@ void draw(byte sy,byte sx,char board[size][size],char check[size][size]){
|
||||
}
|
||||
void fill(char board[size][size]){
|
||||
byte y,x;
|
||||
for(y=0;y<size;y++){
|
||||
for(x=0;x<size;x++){
|
||||
for(y=0;y<size;++y){
|
||||
for(x=0;x<size;++x){
|
||||
board[y][x]= int2sgn(y*size+x+1);
|
||||
}
|
||||
}
|
||||
@ -110,8 +108,8 @@ void slide_multi(char board[size][size],byte y,byte x){
|
||||
}
|
||||
bool issolved(char board[size][size],char check[size][size]){
|
||||
byte y,x;
|
||||
for(y=0;y<size;y++){
|
||||
for(x=0;x<size;x++){
|
||||
for(y=0;y<size;++y){
|
||||
for(x=0;x<size;++x){
|
||||
if(board[y][x]!=check[y][x])
|
||||
return 0;
|
||||
}
|
||||
@ -119,7 +117,7 @@ bool issolved(char board[size][size],char check[size][size]){
|
||||
return 1;
|
||||
}
|
||||
void shuffle(char board[size][size]){
|
||||
for(int m=0;m<1000;m++){
|
||||
for(int m=0;m<1000;++m){
|
||||
switch(rand()%4){
|
||||
case 0:
|
||||
slide_one(board,ey,ex+1);
|
||||
@ -188,20 +186,18 @@ void gameplay(void){
|
||||
int main(int argc, char** argv){
|
||||
#ifndef Plan9
|
||||
size=4;
|
||||
#endif
|
||||
if(argc==2){
|
||||
if(!strcmp("help",argv[1])){
|
||||
printf("Usage: %s [size]\n",argv[0]);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#ifndef Plan9
|
||||
size=atoi(argv[1]);
|
||||
#endif
|
||||
if(size<3 || size>7){
|
||||
fprintf(stderr,"3<=size<=7\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
signal(SIGINT,sigint_handler);
|
||||
srand(time(NULL)%UINT_MAX);
|
||||
initscr();
|
||||
@ -240,13 +236,13 @@ int main(int argc, char** argv){
|
||||
if( input==KEY_MOUSE )
|
||||
mouseinput();
|
||||
if( (input=='k' || input==KEY_UP) && py>0)
|
||||
py--;
|
||||
--py;
|
||||
if( (input=='j' || input==KEY_DOWN) && py<size-1)
|
||||
py++;
|
||||
++py;
|
||||
if( (input=='h' || input==KEY_LEFT) && px>0)
|
||||
px--;
|
||||
--px;
|
||||
if( (input=='l' || input==KEY_RIGHT) && px<size-1)
|
||||
px++;
|
||||
++px;
|
||||
if( input=='q')
|
||||
sigint_handler(0);
|
||||
if(input=='\n'){
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
O__/|
|
||||
___|_/ | __
|
||||
| / | |__
|
||||
| ISHER*/
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
@ -14,7 +19,7 @@
|
||||
#define HLEN LEN/2
|
||||
#define WID 80
|
||||
#define HWID WID/2
|
||||
|
||||
typedef signed char byte;
|
||||
#ifdef Plan9
|
||||
int usleep(long usec) {
|
||||
int second = usec/1000000;
|
||||
@ -26,8 +31,9 @@ int usleep(long usec) {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
// 12 lines of water
|
||||
// 80 columns
|
||||
|
||||
typedef signed char byte;
|
||||
chtype colors[4]={A_NORMAL,A_STANDOUT};
|
||||
byte fish[10]={0};//positions
|
||||
byte caught=-1;
|
||||
@ -41,41 +47,34 @@ byte clb,clbtime=0;
|
||||
FILE* scorefile;
|
||||
|
||||
int input;
|
||||
/*
|
||||
O__/|
|
||||
___|_/ | __
|
||||
| / | |__
|
||||
| ISHER*/
|
||||
// 12 lines of water
|
||||
// 80 columns
|
||||
byte digit_count(int num){
|
||||
byte ret=0;
|
||||
do{
|
||||
ret++;
|
||||
++ret;
|
||||
num/=10;
|
||||
}while(num);
|
||||
return ret;
|
||||
}
|
||||
void filled_rect(byte sy,byte sx,byte ey,byte ex){
|
||||
byte y,x;
|
||||
for(y=sy;y<ey;y++)
|
||||
for(x=sx;x<ex;x++)
|
||||
for(y=sy;y<ey;++y)
|
||||
for(x=sx;x<ex;++x)
|
||||
mvaddch(y,x,' ');
|
||||
}
|
||||
void green_border(void){
|
||||
byte y,x;
|
||||
for(y=0;y<LEN;y++){
|
||||
for(y=0;y<LEN;++y){
|
||||
mvaddch(y,WID-1,' '|colors[2]);
|
||||
mvaddch(y,0,' '|colors[2]);
|
||||
}
|
||||
for(x=0;x<WID;x++){
|
||||
for(x=0;x<WID;++x){
|
||||
mvaddch(LEN-1,x,' '|colors[2]);
|
||||
mvaddch(0,x,' '|colors[2]);
|
||||
}
|
||||
|
||||
}
|
||||
void star_line(byte y){
|
||||
for(byte x=1;x<WID-1;x++)
|
||||
for(byte x=1;x<WID-1;++x)
|
||||
mvaddch(y,x,'.');
|
||||
}
|
||||
void draw(void){
|
||||
@ -162,18 +161,18 @@ void draw(void){
|
||||
}
|
||||
}
|
||||
}
|
||||
for(y=-3;y<0;y++)
|
||||
for(y=-3;y<0;++y)
|
||||
mvaddch(HLEN+y,HWID,ACS_VLINE);
|
||||
attroff(colors[0]);
|
||||
attron(colors[1]);
|
||||
filled_rect(HLEN,0,LEN,WID);
|
||||
for(y=0;y<hook;y++)
|
||||
for(y=0;y<hook;++y)
|
||||
mvaddch(HLEN+y,HWID,ACS_VLINE);
|
||||
if(caught==-1)
|
||||
mvaddch(HLEN+hook,HWID,')');
|
||||
else
|
||||
mvaddch(HLEN+hook,HWID,sym[caught]);
|
||||
for(y=0;y<10;y++)
|
||||
for(y=0;y<10;++y)
|
||||
mvaddch(HLEN+1+y,fish[y],sym[y]);
|
||||
attroff(colors[1]);
|
||||
|
||||
@ -204,7 +203,7 @@ byte scorewrite(void){// only saves the top 10, returns the place in the chart
|
||||
while( fscanf(scorefile,"%59s : %ld\n",fuckingname,&fuckingscore) == 2 && location<SAVE_TO_NUM ){
|
||||
strcpy(namebuff[location],fuckingname);
|
||||
scorebuff[location] = fuckingscore;
|
||||
location++;
|
||||
++location;
|
||||
|
||||
memset(fuckingname,0,60);
|
||||
fuckingscore=0;
|
||||
@ -221,7 +220,7 @@ byte scorewrite(void){// only saves the top 10, returns the place in the chart
|
||||
byte itreached=location;
|
||||
byte ret = -1;
|
||||
bool wroteit=0;
|
||||
for(location=0;location<=itreached && location<SAVE_TO_NUM-wroteit;location++){
|
||||
for(location=0;location<=itreached && location<SAVE_TO_NUM-wroteit;++location){
|
||||
if(!wroteit && (location>=itreached || score>=scorebuff[location]) ){
|
||||
fprintf(scorefile,"%s : %ld\n",getenv("USER"),score);
|
||||
ret=location;
|
||||
@ -287,7 +286,7 @@ void showscores(byte playerrank){
|
||||
printw(">>>");
|
||||
printw("%s",pname);
|
||||
mvprintw(2+2*rank,WID-1-digit_count(pscore),"%d",pscore);
|
||||
rank++;
|
||||
++rank;
|
||||
}
|
||||
attroff(colors[3]);
|
||||
refresh();
|
||||
@ -317,14 +316,14 @@ void sigint_handler(int x){
|
||||
puts("Quit.");
|
||||
exit(x);
|
||||
}
|
||||
void main(void){
|
||||
int main(void){
|
||||
signal(SIGINT,sigint_handler);
|
||||
initscr();
|
||||
noecho();
|
||||
cbreak();
|
||||
keypad(stdscr,1);
|
||||
srand(time(NULL)%UINT_MAX);
|
||||
for(byte n=0;n<10;n++)
|
||||
for(byte n=0;n<10;++n)
|
||||
fish[n]=rand()%80;
|
||||
if(has_colors()){
|
||||
start_color();
|
||||
@ -332,7 +331,7 @@ void main(void){
|
||||
init_pair(2,COLOR_BLACK,COLOR_BLUE);
|
||||
init_pair(3,COLOR_WHITE,COLOR_GREEN);
|
||||
init_pair(4,COLOR_BLACK,COLOR_WHITE);
|
||||
for(byte b=0;b<4;b++)
|
||||
for(byte b=0;b<4;++b)
|
||||
colors[b]=COLOR_PAIR(b+1);
|
||||
}
|
||||
byte n;
|
||||
@ -347,7 +346,7 @@ void main(void){
|
||||
draw();
|
||||
refresh();
|
||||
input=getch();
|
||||
for(n=0;n<10;n++){
|
||||
for(n=0;n<10;++n){
|
||||
if(stop[n]){
|
||||
if(rand()%(n+15)==0)//this is to make the fish move
|
||||
stop[n]=0;
|
||||
@ -365,7 +364,7 @@ void main(void){
|
||||
if(hook>n+1){
|
||||
caught= -1;
|
||||
hook=0;
|
||||
hooknum--;
|
||||
--hooknum;
|
||||
}
|
||||
if(hook==n+1 && caught==-1){
|
||||
caught=n;
|
||||
@ -378,9 +377,9 @@ void main(void){
|
||||
if(rand()%(14-n)==0)//this is to make it stop
|
||||
stop[n]=1;
|
||||
}
|
||||
if(input==KEY_UP)
|
||||
if(input==KEY_UP){
|
||||
if(hook>0)
|
||||
hook--;
|
||||
--hook;
|
||||
if(hook==0 && caught!=-1){
|
||||
count[caught]++;
|
||||
score+=(caught+1)*(caught+1);
|
||||
@ -388,10 +387,10 @@ void main(void){
|
||||
clbtime=10;//celebrate catching the fish
|
||||
caught=-1;
|
||||
}
|
||||
|
||||
}
|
||||
if(input==KEY_DOWN){
|
||||
if(hook<11)
|
||||
hook++;
|
||||
++hook;
|
||||
if(fish[hook-1]==40 && caught==-1){
|
||||
caught=hook-1;
|
||||
if(n%2)
|
||||
@ -426,4 +425,5 @@ void main(void){
|
||||
if(input!='q' && input!='n' && input!='N')
|
||||
goto Start;
|
||||
endwin();
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,3 +1,16 @@
|
||||
/*
|
||||
Jewels
|
||||
|
||||
Authored by abakh <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lnucrses
|
||||
|
||||
A pair of jewels appear on top of the window, And you can move and rotate them while they are falling down.
|
||||
If you make a vertical or horizontal row of 4 jewels they will explode and add up to your score.
|
||||
Like Tetris,You will lose the game when the center of the uppermost row is filled.
|
||||
|
||||
TODO make it like puyo puyo instead of the remake of of what i poorly remembered*/
|
||||
#include <curses.h>
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
@ -8,21 +21,8 @@
|
||||
#define WID 19
|
||||
#define DELAY 2
|
||||
#define SAVE_TO_NUM 10
|
||||
|
||||
/*
|
||||
Jewels
|
||||
|
||||
Authored by Hossein Bakhtiarifar <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lnucrses
|
||||
|
||||
A pair of jewels appear on top of the window, And you can move and rotate them while they are falling down.
|
||||
If you make a vertical or horizontal row of 4 jewels they will explode and add up to your score.
|
||||
Like Tetris,You will lose the game when the center of the uppermost row is filled.
|
||||
*/
|
||||
|
||||
typedef signed char byte;
|
||||
|
||||
chtype board[LEN][WID];
|
||||
chtype colors[6]={0};
|
||||
chtype next1,next2;
|
||||
@ -57,7 +57,7 @@ byte scorewrite(long score){// only saves the top 10
|
||||
while( fscanf(scorefile,"%59s : %ld\n",fuckingname,&fuckingscore) == 2 && location<SAVE_TO_NUM ){
|
||||
strcpy(namebuff[location],fuckingname);
|
||||
scorebuff[location] = fuckingscore;
|
||||
location++;
|
||||
++location;
|
||||
|
||||
memset(fuckingname,0,60);
|
||||
fuckingscore=0;
|
||||
@ -75,7 +75,7 @@ byte scorewrite(long score){// only saves the top 10
|
||||
byte ret = -1;
|
||||
bool wroteit=0;
|
||||
|
||||
for(location=0;location<=itreached && location<SAVE_TO_NUM-wroteit;location++){
|
||||
for(location=0;location<=itreached && location<SAVE_TO_NUM-wroteit;++location){
|
||||
if(!wroteit && (location>=itreached || score>=scorebuff[location]) ){
|
||||
fprintf(scorefile,"%s : %ld\n",getenv("USER"),score);
|
||||
ret=location;
|
||||
@ -118,7 +118,7 @@ void showscores(byte playerrank){
|
||||
if(rank == playerrank)
|
||||
printf(">>>");
|
||||
printf("%d) %s : %ld\n",rank+1,pname,pscore);
|
||||
rank++;
|
||||
++rank;
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
@ -126,9 +126,9 @@ void showscores(byte playerrank){
|
||||
bool fall(void){
|
||||
bool jfall,kfall,ret;
|
||||
jfall=kfall=ret=0;
|
||||
for(int y=LEN-1;y>0;y--){
|
||||
for(int y=LEN-1;y>0;--y){
|
||||
chtype c,d;
|
||||
for(int x=WID-1;x>=0;x--){
|
||||
for(int x=WID-1;x>=0;--x){
|
||||
c=board[y][x];
|
||||
d=board[y-1][x];
|
||||
if(!c && d){
|
||||
@ -143,7 +143,7 @@ bool fall(void){
|
||||
}
|
||||
}
|
||||
if(jfall&&kfall)
|
||||
jy++;
|
||||
++jy;
|
||||
else
|
||||
jy = LEN+1;
|
||||
return ret;
|
||||
@ -214,15 +214,15 @@ bool explode(byte combo){
|
||||
chtype c,uc;
|
||||
byte n;
|
||||
byte y,x;
|
||||
for(y=0;y<LEN;y++){
|
||||
for(y=0;y<LEN;++y){
|
||||
c=uc=n=0;
|
||||
for(x=0;x<WID;x++){
|
||||
for(x=0;x<WID;++x){
|
||||
uc = c;
|
||||
c = board[y][x];
|
||||
if(c && c == uc){
|
||||
n++;
|
||||
++n;
|
||||
if(n>=3 && x==WID-1){//the chain ends because the row ends
|
||||
x++;
|
||||
++x;
|
||||
goto HrExplsn;
|
||||
}
|
||||
}
|
||||
@ -230,7 +230,7 @@ bool explode(byte combo){
|
||||
HrExplsn:
|
||||
score+=n*10*(n-2)*combo;
|
||||
ret=1;
|
||||
for(;n>=0;n--)
|
||||
for(;n>=0;--n)
|
||||
board[y][x-1-n]=0;
|
||||
n=0;
|
||||
}
|
||||
@ -238,15 +238,15 @@ bool explode(byte combo){
|
||||
n=0;
|
||||
}
|
||||
}
|
||||
for(x=0;x<WID;x++){
|
||||
for(x=0;x<WID;++x){
|
||||
c=uc=n=0;
|
||||
for(byte y=0;y<LEN;y++){
|
||||
for(byte y=0;y<LEN;++y){
|
||||
uc=c;
|
||||
c = board[y][x];
|
||||
if(c && c == uc){
|
||||
n++;
|
||||
++n;
|
||||
if(n>=3 && y==LEN-1){
|
||||
y++;
|
||||
++y;
|
||||
goto VrExplsn;
|
||||
}
|
||||
}
|
||||
@ -254,7 +254,7 @@ bool explode(byte combo){
|
||||
VrExplsn:
|
||||
score+=n*10*(n-2)*combo;
|
||||
ret=1;
|
||||
for(;n>=0;n--)
|
||||
for(;n>=0;--n)
|
||||
board[y-1-n][x]=0;
|
||||
n=0;
|
||||
}
|
||||
@ -279,8 +279,8 @@ void draw(void){
|
||||
mvaddstr(1,0,"Next:");
|
||||
addch(next1);
|
||||
addch(next2);
|
||||
for(byte y=0;y<LEN;y++){
|
||||
for(byte x=0;x<WID;x++){
|
||||
for(byte y=0;y<LEN;++y){
|
||||
for(byte x=0;x<WID;++x){
|
||||
chtype c = board[y][x];
|
||||
if(c)
|
||||
mvaddch(y,middle+x,c);
|
||||
@ -310,7 +310,7 @@ int main(void){
|
||||
init_pair(4,COLOR_BLUE,-1);//array this thing
|
||||
init_pair(5,COLOR_YELLOW,-1);
|
||||
init_pair(6,COLOR_CYAN,-1);
|
||||
for(byte n=0;n<6;n++){
|
||||
for(byte n=0;n<6;++n){
|
||||
colors[n] = COLOR_PAIR(n+1);
|
||||
}
|
||||
}
|
||||
@ -374,7 +374,7 @@ int main(void){
|
||||
}
|
||||
combo=1;
|
||||
while(explode(combo)){ // explode, fall, explode, fall until nothing is left
|
||||
combo++;
|
||||
++combo;
|
||||
while(fall());
|
||||
draw();
|
||||
}
|
||||
|
@ -1,40 +1,38 @@
|
||||
/*
|
||||
. . _
|
||||
|\/| |_)
|
||||
| |EMORY|_)LOCKS
|
||||
|
||||
Authored by abakh <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lncurses
|
||||
*/
|
||||
#include <curses.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <signal.h>
|
||||
/*
|
||||
. . _
|
||||
|\/| |_)
|
||||
| |EMORY|_)LOCKS
|
||||
|
||||
Authored by Hossein Bakhtiarifar <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lncurses
|
||||
*/
|
||||
typedef signed char byte;
|
||||
typedef unsigned char ubyte;
|
||||
|
||||
/* The Plan9 compiler can not handle VLAs */
|
||||
#ifdef Plan9
|
||||
#define size 8
|
||||
#define size2 16
|
||||
#endif
|
||||
|
||||
typedef signed char byte;
|
||||
typedef unsigned char ubyte;
|
||||
#ifndef Plan9
|
||||
#else
|
||||
byte size,size2;//size2 is there to avoid a lot of multiplications
|
||||
#endif
|
||||
byte py,px;
|
||||
byte fy,fx; //the first tile
|
||||
chtype colors[6]={0};
|
||||
void rectangle(byte sy,byte sx){
|
||||
for(byte y=0;y<=size+1;y++){
|
||||
for(byte y=0;y<=size+1;++y){
|
||||
mvaddch(sy+y,sx,ACS_VLINE);
|
||||
mvaddch(sy+y,sx+size2+1,ACS_VLINE);
|
||||
}
|
||||
for(byte x=0;x<=size2+1;x++){
|
||||
for(byte x=0;x<=size2+1;++x){
|
||||
mvaddch(sy,sx+x,ACS_HLINE);
|
||||
mvaddch(sy+size+1,sx+x,ACS_HLINE);
|
||||
}
|
||||
@ -65,8 +63,8 @@ void draw(byte sy,byte sx,chtype board[size][size2],bool show[size][size2]){
|
||||
rectangle(sy,sx);
|
||||
byte y,x;
|
||||
chtype prnt;
|
||||
for(y=0;y<size;y++){
|
||||
for(x=0;x<size2;x++){
|
||||
for(y=0;y<size;++y){
|
||||
for(x=0;x<size2;++x){
|
||||
if(show[y][x] || (y==fy && x==fx) )
|
||||
prnt=board[y][x];
|
||||
else
|
||||
@ -81,8 +79,8 @@ void draw(byte sy,byte sx,chtype board[size][size2],bool show[size][size2]){
|
||||
void fill(chtype board[size][size2]){
|
||||
ubyte y,x,m;
|
||||
int n;
|
||||
for(y=0;y<size;y++){
|
||||
for(x=0;x<size2;x++){
|
||||
for(y=0;y<size;++y){
|
||||
for(x=0;x<size2;++x){
|
||||
n=(y*size2+x)/2;
|
||||
if(size*size<193) //(1+0*64)%6 == (1+3*64)%6 so this won't work in n=193 and above
|
||||
m=n%6;
|
||||
@ -95,8 +93,8 @@ void fill(chtype board[size][size2]){
|
||||
}
|
||||
bool issolved(bool show[size][size2]){
|
||||
byte y,x;
|
||||
for(y=0;y<size;y++){
|
||||
for(x=0;x<size2;x++){
|
||||
for(y=0;y<size;++y){
|
||||
for(x=0;x<size2;++x){
|
||||
if(!show[y][x])
|
||||
return 0;
|
||||
}
|
||||
@ -107,7 +105,7 @@ void shuffle(chtype board[size][size2]){
|
||||
int n=size*size*3;
|
||||
chtype a;
|
||||
byte ay,ax,by,bx;
|
||||
for(int m=0;m<n;m++){
|
||||
for(int m=0;m<n;++m){
|
||||
ay=rand()%size;
|
||||
ax=rand()%(size2);
|
||||
by=rand()%size;
|
||||
@ -206,7 +204,7 @@ int main(int argc, char** argv){
|
||||
init_pair(4,COLOR_CYAN,-1);
|
||||
init_pair(5,COLOR_MAGENTA,-1);
|
||||
init_pair(6,COLOR_RED,-1);
|
||||
for(byte b=0;b<6;b++){
|
||||
for(byte b=0;b<6;++b){
|
||||
colors[b]=COLOR_PAIR(b+1);
|
||||
}
|
||||
}
|
||||
@ -243,13 +241,13 @@ int main(int argc, char** argv){
|
||||
if( input==KEY_MOUSE )
|
||||
mouseinput();
|
||||
if( (input=='k' || input==KEY_UP) && py>0)
|
||||
py--;
|
||||
--py;
|
||||
if( (input=='j' || input==KEY_DOWN) && py<size-1)
|
||||
py++;
|
||||
++py;
|
||||
if( (input=='h' || input==KEY_LEFT) && px>0)
|
||||
px--;
|
||||
--px;
|
||||
if( (input=='l' || input==KEY_RIGHT) && px<size2-1)
|
||||
px++;
|
||||
++px;
|
||||
if( input=='q')
|
||||
sigint_handler(0);
|
||||
if(input=='\n'){
|
||||
|
@ -1,3 +1,12 @@
|
||||
/*
|
||||
|\/|
|
||||
| |IKETRON
|
||||
|
||||
Authored by abakh <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lncurses
|
||||
*/
|
||||
#include <curses.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -14,17 +23,9 @@
|
||||
#define MINWID 40
|
||||
#define MAXWID 80
|
||||
enum {UP=1,RIGHT,DOWN,LEFT,FLIGHT,NOTRAIL,BOMB,SPAWN,STOP,SUPERFOOD,TRAIL};
|
||||
/*
|
||||
|\/|
|
||||
| |IKETRON
|
||||
typedef signed char byte;
|
||||
|
||||
Authored by Hossein Bakhtiarifar <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lncurses
|
||||
*/
|
||||
|
||||
/* The Plan9 compiler can not handle VLAs */
|
||||
/* The Plan9 compiler can not handle VLAs and usleep is a POSIX function */
|
||||
#ifdef Plan9
|
||||
#define len 10
|
||||
#define wid 40
|
||||
@ -37,33 +38,35 @@ int usleep(long usec) {
|
||||
nanosleep(&sleepy, (struct timespec *) NULL);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
int len,wid;
|
||||
#endif
|
||||
|
||||
typedef signed char byte;
|
||||
#ifndef Plan9
|
||||
int len,wid,py,px;
|
||||
#else
|
||||
int py,px;
|
||||
#endif
|
||||
int immunity,flight,notrail;
|
||||
byte direction;
|
||||
long score;
|
||||
chtype colors[6]={0};
|
||||
FILE *scorefile,*lol;
|
||||
|
||||
byte pse_msg=100;
|
||||
//no need to a epilepsy variable like in muncher as zeroing the colors suffices
|
||||
|
||||
FILE *scorefile;
|
||||
char error[150]={0};
|
||||
|
||||
void move_tron(void){
|
||||
switch(direction){
|
||||
case UP:
|
||||
py--;
|
||||
--py;
|
||||
break;
|
||||
case DOWN:
|
||||
py++;
|
||||
++py;
|
||||
break;
|
||||
case LEFT:
|
||||
px--;
|
||||
--px;
|
||||
break;
|
||||
case RIGHT:
|
||||
px++;
|
||||
++px;
|
||||
break;
|
||||
}
|
||||
if(py==-1)
|
||||
@ -105,7 +108,7 @@ byte scorewrite(void){// only saves the top 10, returns the place in the chart
|
||||
while( fscanf(scorefile,"%59s : %ld\n",fuckingname,&fuckingscore) == 2 && location<SAVE_TO_NUM ){
|
||||
strcpy(namebuff[location],fuckingname);
|
||||
scorebuff[location] = fuckingscore;
|
||||
location++;
|
||||
++location;
|
||||
|
||||
memset(fuckingname,0,60);
|
||||
fuckingscore=0;
|
||||
@ -123,7 +126,7 @@ byte scorewrite(void){// only saves the top 10, returns the place in the chart
|
||||
byte ret = -1;
|
||||
bool wroteit=0;
|
||||
|
||||
for(location=0;location<=itreached && location<SAVE_TO_NUM-wroteit;location++){
|
||||
for(location=0;location<=itreached && location<SAVE_TO_NUM-wroteit;++location){
|
||||
if(!wroteit && (location>=itreached || score>=scorebuff[location]) ){
|
||||
fprintf(scorefile,"%s : %ld\n",getenv("USER"),score);
|
||||
ret=location;
|
||||
@ -153,7 +156,7 @@ void showscores(byte playerrank){
|
||||
move(3,0);
|
||||
byte b=0;
|
||||
if ( fscanf(scorefile,"%s : %ld\n",formername,&formerscore)==2){
|
||||
halfdelay(2);
|
||||
halfdelay(1);
|
||||
printw("*****CONGRATULATIONS!****\n");
|
||||
printw(" You bet the\n");
|
||||
printw(" previous\n");
|
||||
@ -199,14 +202,14 @@ void showscores(byte playerrank){
|
||||
if(rank == playerrank)
|
||||
printw(">>>");
|
||||
printw("%d) %s : %ld\n",rank+1,pname,pscore);
|
||||
rank++;
|
||||
++rank;
|
||||
}
|
||||
addch('\n');
|
||||
refresh();
|
||||
}
|
||||
void put_stuff(byte board[len][wid],byte num){
|
||||
byte y,x;
|
||||
for(byte n=0;n<num;n++){
|
||||
for(byte n=0;n<num;++n){
|
||||
do{
|
||||
y=rand()%len;
|
||||
x=rand()%wid;
|
||||
@ -225,11 +228,11 @@ void put_stuff(byte board[len][wid],byte num){
|
||||
}
|
||||
}
|
||||
void rectangle(void){
|
||||
for(int y=0;y<=len;y++){
|
||||
for(int y=0;y<=len;++y){
|
||||
mvaddch(3+y,0,ACS_VLINE);
|
||||
mvaddch(4+y,1+wid,ACS_VLINE);
|
||||
}
|
||||
for(int x=0;x<=wid;x++){
|
||||
for(int x=0;x<=wid;++x){
|
||||
mvaddch(3,x,ACS_HLINE);
|
||||
mvaddch(4+len,x,ACS_HLINE);
|
||||
}
|
||||
@ -243,8 +246,8 @@ void draw(byte board[len][wid]){
|
||||
static byte effect=0;
|
||||
chtype prnt;
|
||||
rectangle();
|
||||
for(y=0;y<len;y++){
|
||||
for(x=0;x<wid;x++){
|
||||
for(y=0;y<len;++y){
|
||||
for(x=0;x<wid;++x){
|
||||
if(board[y][x]<0){
|
||||
prnt=' '|A_STANDOUT|colors[abs(board[y][x])%6];
|
||||
board[y][x]++;
|
||||
@ -277,6 +280,10 @@ void draw(byte board[len][wid]){
|
||||
mvaddch(4+y,x+1,prnt);
|
||||
}
|
||||
}
|
||||
if(pse_msg>0){
|
||||
mvprintw(len+5,0,"Suffering PSE? Press e.");
|
||||
--pse_msg;
|
||||
}
|
||||
effect=(effect+1)%6;
|
||||
}
|
||||
void explode(byte board[len][wid],int by,int bx){
|
||||
@ -297,21 +304,17 @@ void explode(byte board[len][wid],int by,int bx){
|
||||
int x=sx;
|
||||
while(y!=ey){
|
||||
while(x!=ex){
|
||||
x++;
|
||||
++x;
|
||||
if(x==wid)
|
||||
x=0;
|
||||
if(board[y][x]==BOMB)
|
||||
explode(board,y,x);
|
||||
board[y][x]=-10;
|
||||
fprintf(lol,"y:%d x:%d\n",y,x);
|
||||
fflush(lol);
|
||||
}
|
||||
x=sx;
|
||||
y++;
|
||||
++y;
|
||||
if(y==len)
|
||||
y=0;
|
||||
fprintf(lol,"y:%d x:%d\n",y,x);
|
||||
fflush(lol);
|
||||
|
||||
}
|
||||
}
|
||||
@ -355,6 +358,7 @@ void sigint_handler(int x){
|
||||
exit(x);
|
||||
}
|
||||
int main(int argc, char** argv){
|
||||
#ifndef Plan9
|
||||
bool autoset=0;
|
||||
signal(SIGINT,sigint_handler);
|
||||
if(argc>3 || (argc==2 && !strcmp("help",argv[1])) ){
|
||||
@ -366,11 +370,7 @@ int main(int argc, char** argv){
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if(argc==3){
|
||||
#ifndef Plan9
|
||||
bool lool = sscanf(argv[1],"%d",&len) && sscanf(argv[2],"%d",&wid);
|
||||
#else
|
||||
bool lool = sscanf(argv[1],"%d",len) && sscanf(argv[2],"%d",wid);
|
||||
#endif
|
||||
if(!lool){
|
||||
puts("Invalid input.");
|
||||
return EXIT_FAILURE;
|
||||
@ -385,7 +385,6 @@ int main(int argc, char** argv){
|
||||
autoset=1;
|
||||
}
|
||||
initscr();
|
||||
#ifndef Plan9
|
||||
if(autoset){
|
||||
len=LINES-7;
|
||||
if(len<MINLEN)
|
||||
@ -402,10 +401,9 @@ int main(int argc, char** argv){
|
||||
#endif
|
||||
srand(time(NULL)%UINT_MAX);
|
||||
byte board[len][wid];
|
||||
byte predirection;
|
||||
int prex,prey;
|
||||
bool halfspeed=0;
|
||||
int constant=150*(80*24)/(len*wid);
|
||||
const int constant=150*(80*24)/(len*wid);//that is added to score
|
||||
initscr();
|
||||
noecho();
|
||||
cbreak();
|
||||
@ -420,13 +418,13 @@ int main(int argc, char** argv){
|
||||
init_pair(4,COLOR_CYAN,-1);
|
||||
init_pair(5,COLOR_MAGENTA,-1);
|
||||
init_pair(6,COLOR_RED,-1);
|
||||
for(byte b= 0;b<6;b++){
|
||||
for(byte b= 0;b<6;++b){
|
||||
colors[b]=COLOR_PAIR(b+1);
|
||||
}
|
||||
|
||||
}
|
||||
lol=fopen("lol","w");
|
||||
Start:
|
||||
immunity=flight=notrail=0;
|
||||
curs_set(0);
|
||||
halfdelay(1);
|
||||
score=0;
|
||||
@ -435,27 +433,31 @@ int main(int argc, char** argv){
|
||||
px=wid/2;
|
||||
memset(board,0,len*wid);
|
||||
put_stuff(board,20);
|
||||
int prepreinput,preinput,input;
|
||||
|
||||
int preinput,input;
|
||||
while(1){
|
||||
erase();
|
||||
logo();
|
||||
mvprintw(1,12,"Score:%ld",score);
|
||||
draw(board);
|
||||
refresh();
|
||||
prepreinput=preinput;
|
||||
preinput=input;
|
||||
input = getch();
|
||||
if(immunity)
|
||||
mvprintw(2,12,"Immunity:%ld",immunity);
|
||||
else if(flight)
|
||||
mvprintw(2,12,"Flight:%ld",flight);
|
||||
else if(notrail)
|
||||
mvprintw(2,12,"NoTrail:%ld",notrail);
|
||||
draw(board);
|
||||
refresh();
|
||||
|
||||
preinput=input;
|
||||
input = getch();
|
||||
if(input!=ERR)//hide message when a key is entered
|
||||
pse_msg=0;
|
||||
|
||||
if(board[py][px]==SPAWN)
|
||||
put_stuff(board,5);
|
||||
else if(board[py][px]==BOMB){
|
||||
explode(board,py,px);
|
||||
for(byte b=0;b<10;b++){
|
||||
for(byte b=0;b<10;++b){
|
||||
draw(board);
|
||||
refresh();
|
||||
usleep(100000);
|
||||
@ -486,7 +488,6 @@ int main(int argc, char** argv){
|
||||
if( input == KEY_F(1) || input=='?' )
|
||||
help();
|
||||
halfspeed=!halfspeed;
|
||||
predirection=direction;
|
||||
if( (input=='k' || input==KEY_UP) ){
|
||||
direction=UP;
|
||||
halfspeed=1;
|
||||
@ -501,52 +502,52 @@ int main(int argc, char** argv){
|
||||
direction=RIGHT;
|
||||
if( input=='q')
|
||||
sigint_handler(0);
|
||||
|
||||
if(input=='e'){
|
||||
for(int b=0;b<6;++b){
|
||||
colors[b]=0;
|
||||
}
|
||||
pse_msg=0;
|
||||
}
|
||||
if(input!=ERR){
|
||||
if(preinput==input){//if it wasn't there, hitting two keys in less than 0.1 sec would not work
|
||||
//the i part is there to prevent it from working too often =) you could just move diagonally that way and get a big score
|
||||
//just hitting UP and LEFT repeatedly. the trick works in the original, but not very well because of it's limitations.
|
||||
usleep(100000);
|
||||
flushinp();
|
||||
}
|
||||
if(prepreinput==input)
|
||||
usleep(100000);
|
||||
|
||||
}
|
||||
|
||||
if( !((direction==UP||direction==DOWN)&&!halfspeed) && !immunity && !flight && !notrail)
|
||||
board[py][px]=TRAIL;
|
||||
|
||||
if(direction==UP && halfspeed){
|
||||
py--;
|
||||
--py;
|
||||
if(py==-1)
|
||||
py=len-1;
|
||||
halfspeed=1;
|
||||
}
|
||||
else if(direction==DOWN && halfspeed){
|
||||
py++;
|
||||
++py;
|
||||
if(py==len)
|
||||
py=0;
|
||||
}
|
||||
else if(direction==LEFT){
|
||||
px--;
|
||||
--px;
|
||||
if(px==-1)
|
||||
px=wid-1;
|
||||
}
|
||||
else if(direction==RIGHT){
|
||||
px++;
|
||||
++px;
|
||||
if(px==wid)
|
||||
px=0;
|
||||
}
|
||||
score++;
|
||||
++score;
|
||||
if(!(score%100))
|
||||
put_stuff(board,5);
|
||||
if(immunity)
|
||||
immunity--;
|
||||
--immunity;
|
||||
else if(flight)
|
||||
flight--;
|
||||
--flight;
|
||||
else if(notrail)
|
||||
notrail--;
|
||||
--notrail;
|
||||
}
|
||||
nocbreak();
|
||||
cbreak();
|
||||
|
@ -1,3 +1,12 @@
|
||||
/*
|
||||
|\/|
|
||||
| |INES
|
||||
|
||||
Authored by abakh <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lncurses
|
||||
*/
|
||||
#include <curses.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@ -7,37 +16,26 @@
|
||||
#include <stdbool.h>
|
||||
#define FLAG 9
|
||||
#define UNCLEAR 10
|
||||
/*
|
||||
|\/|
|
||||
| |INES
|
||||
typedef signed char byte;
|
||||
|
||||
Authored by Hossein Bakhtiarifar <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lncurses
|
||||
*/
|
||||
|
||||
/* The Plan9 compiler can not handle VLAs */
|
||||
#ifdef Plan9
|
||||
#ifdef Plan9 //The Plan9 compiler can not handle VLAs
|
||||
#define len 8
|
||||
#define wid 8
|
||||
#else
|
||||
int len,wid;
|
||||
#endif
|
||||
|
||||
typedef signed char byte;
|
||||
#ifndef Plan9
|
||||
int len,wid,py,px,flags;
|
||||
#else
|
||||
int py,px,flags;
|
||||
#endif
|
||||
int untouched;
|
||||
int mscount;
|
||||
chtype colors[6]={0};
|
||||
|
||||
void rectangle(int sy,int sx){
|
||||
for(int y=0;y<=len+1;y++){
|
||||
for(int y=0;y<=len+1;++y){
|
||||
mvaddch(sy+y,sx,ACS_VLINE);
|
||||
mvaddch(sy+y,sx+wid*2,ACS_VLINE);
|
||||
}
|
||||
for(int x=0;x<=wid*2;x++){
|
||||
for(int x=0;x<=wid*2;++x){
|
||||
mvaddch(sy,sx+x,ACS_HLINE);
|
||||
mvaddch(sy+len+1,sx+x,ACS_HLINE);
|
||||
}
|
||||
@ -52,8 +50,8 @@ void draw(int sy,int sx,byte board[len][wid]){
|
||||
chtype attr ;
|
||||
char prnt;
|
||||
int y,x;
|
||||
for(y=0;y<len;y++){
|
||||
for(x=0;x<wid;x++){
|
||||
for(y=0;y<len;++y){
|
||||
for(x=0;x<wid;++x){
|
||||
attr=A_NORMAL;
|
||||
if(y==py && x==px)
|
||||
attr |= A_STANDOUT;
|
||||
@ -80,8 +78,8 @@ void draw(int sy,int sx,byte board[len][wid]){
|
||||
//show the mines
|
||||
void drawmines(int sy,int sx,byte board[len][wid],bool mines[len][wid]){
|
||||
int y,x;
|
||||
for(y=0;y<len;y++){
|
||||
for(x=0;x<wid;x++){
|
||||
for(y=0;y<len;++y){
|
||||
for(x=0;x<wid;++x){
|
||||
if(mines[y][x]){
|
||||
if(y==py&&x==px)
|
||||
mvaddch(sy+y+1,sx+x*2+1,'X');
|
||||
@ -97,7 +95,7 @@ void drawmines(int sy,int sx,byte board[len][wid],bool mines[len][wid]){
|
||||
void mine(bool mines[len][wid]){
|
||||
int y=rand()%len;
|
||||
int x=rand()%wid;
|
||||
for(int n=0;n<mscount;n++){
|
||||
for(int n=0;n<mscount;++n){
|
||||
while(mines[y][x]){
|
||||
y=rand()%len;
|
||||
x=rand()%wid;
|
||||
@ -111,18 +109,18 @@ bool click(byte board[len][wid],bool mines[len][wid],int ty,int tx){
|
||||
return 0;
|
||||
else{//untouched
|
||||
if(board[ty][tx]==FLAG)
|
||||
flags--;
|
||||
--flags;
|
||||
board[ty][tx]=0;
|
||||
untouched--;
|
||||
--untouched;
|
||||
|
||||
}
|
||||
int y,x;
|
||||
for(y=ty-1;y<ty+2;y++){
|
||||
for(y=ty-1;y<ty+2;++y){
|
||||
if(y<0)
|
||||
y=0;
|
||||
if(y>=len)
|
||||
break;
|
||||
for (x=tx-1;x<tx+2;x++){
|
||||
for (x=tx-1;x<tx+2;++x){
|
||||
if(x<0)
|
||||
x=0;
|
||||
if(x>=wid)
|
||||
@ -134,12 +132,12 @@ bool click(byte board[len][wid],bool mines[len][wid],int ty,int tx){
|
||||
}
|
||||
|
||||
if(!board[ty][tx]){//there are no mines in the adjacent tiles
|
||||
for(y=ty-1;y<ty+2;y++){
|
||||
for(y=ty-1;y<ty+2;++y){
|
||||
if(y<0)
|
||||
y=0;
|
||||
if(y>=len)
|
||||
break;
|
||||
for(x=tx-1;x<tx+2;x++){
|
||||
for(x=tx-1;x<tx+2;++x){
|
||||
if(x<0)
|
||||
x=0;
|
||||
if(x>=wid)
|
||||
@ -216,6 +214,7 @@ void gameplay(void){
|
||||
}
|
||||
int main(int argc, char** argv){
|
||||
signal(SIGINT,sigint_handler);
|
||||
#ifndef Plan9
|
||||
if(argc>4 || (argc==2 && !strcmp("help",argv[1])) ){
|
||||
printf("Usage: %s [len wid [minescount]]\n",argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
@ -225,11 +224,7 @@ int main(int argc, char** argv){
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if(argc>=3){
|
||||
#ifndef Plan9
|
||||
bool lool = sscanf(argv[1],"%d",&len) && sscanf(argv[2],"%d",&wid);
|
||||
#else
|
||||
bool lool = sscanf(argv[1],"%d",len) && sscanf(argv[2],"%d",wid);
|
||||
#endif
|
||||
if(!lool){
|
||||
puts("Invalid input.");
|
||||
return EXIT_FAILURE;
|
||||
@ -241,9 +236,7 @@ int main(int argc, char** argv){
|
||||
|
||||
}
|
||||
else
|
||||
#ifndef Plan9
|
||||
len=wid=8;
|
||||
#endif
|
||||
if(argc==4){
|
||||
if( !sscanf(argv[3],"%d",&mscount)){
|
||||
puts("Invalid input.");
|
||||
@ -256,6 +249,9 @@ int main(int argc, char** argv){
|
||||
}
|
||||
else
|
||||
mscount = len*wid/6;
|
||||
#else
|
||||
mscount=len*wid/6;
|
||||
#endif
|
||||
srand(time(NULL)%UINT_MAX);
|
||||
initscr();
|
||||
mousemask(ALL_MOUSE_EVENTS,NULL);
|
||||
@ -271,7 +267,7 @@ int main(int argc, char** argv){
|
||||
init_pair(4,COLOR_RED,-1);
|
||||
init_pair(5,COLOR_RED,COLOR_YELLOW);
|
||||
init_pair(6,COLOR_RED,COLOR_MAGENTA);
|
||||
for(byte b= 0;b<6;b++){
|
||||
for(byte b= 0;b<6;++b){
|
||||
colors[b]=COLOR_PAIR(b+1);
|
||||
}
|
||||
|
||||
@ -329,13 +325,13 @@ int main(int argc, char** argv){
|
||||
if( input==KEY_MOUSE )
|
||||
mouseinput(sy,sx);
|
||||
if( (input=='k' || input==KEY_UP) && py>0)
|
||||
py--;
|
||||
--py;
|
||||
if( (input=='j' || input==KEY_DOWN) && py<len-1)
|
||||
py++;
|
||||
++py;
|
||||
if( (input=='h' || input==KEY_LEFT) && px>0)
|
||||
px--;
|
||||
--px;
|
||||
if( (input=='l' || input==KEY_RIGHT) && px<wid-1)
|
||||
px++;
|
||||
++px;
|
||||
if( input=='q')
|
||||
sigint_handler(0);
|
||||
if(input=='x' && getch()=='y' && getch()=='z' && getch()=='z' && getch()=='y' ){
|
||||
@ -361,11 +357,11 @@ int main(int argc, char** argv){
|
||||
if(input==' '){
|
||||
if(board[py][px] == -1){
|
||||
board[py][px]=FLAG;
|
||||
flags++;
|
||||
++flags;
|
||||
}
|
||||
else if(board[py][px] == FLAG){
|
||||
board[py][px]=UNCLEAR;
|
||||
flags--;
|
||||
--flags;
|
||||
}
|
||||
else if(board[py][px] == UNCLEAR)
|
||||
board[py][px]=-1;
|
||||
|
@ -1,6 +1,16 @@
|
||||
/*
|
||||
|\/|
|
||||
| |UNCHER
|
||||
|
||||
Authored by abakh <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lncurses
|
||||
*/
|
||||
#include <curses.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <limits.h>
|
||||
#include <time.h>
|
||||
#include <signal.h>
|
||||
@ -12,15 +22,7 @@
|
||||
#define MINWID 40
|
||||
#define MAXWID 80
|
||||
enum {UP=1,RIGHT,DOWN,LEFT,FOOD,SUPERFOOD,TRAP};
|
||||
/*
|
||||
|\/|
|
||||
| |UNCHER
|
||||
|
||||
Authored by Hossein Bakhtiarifar <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lncurses
|
||||
*/
|
||||
typedef signed char byte;
|
||||
|
||||
/* The Plan9 compiler can not handle VLAs */
|
||||
#ifdef Plan9
|
||||
@ -35,20 +37,24 @@ int usleep(long usec) {
|
||||
nanosleep(&sleepy, (struct timespec *) NULL);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
int len,wid;
|
||||
#endif
|
||||
|
||||
typedef signed char byte;
|
||||
#ifndef Plan9
|
||||
int len,wid,py,px;
|
||||
#else
|
||||
int py,px;
|
||||
#endif
|
||||
int py,px;//pointer
|
||||
|
||||
byte pse_msg=20;//flashing animations might hurt some people
|
||||
bool epilepsy=0;
|
||||
char alt_animation[4]={'-','\\','|','/'};
|
||||
|
||||
int immunity;
|
||||
byte direction;
|
||||
long score;
|
||||
chtype colors[6]={0};
|
||||
|
||||
FILE* scorefile;
|
||||
char error[150]={0};
|
||||
|
||||
void logo(void){
|
||||
mvaddstr(1,0,"|\\/|");
|
||||
mvaddstr(2,0,"| |UNCHER");
|
||||
@ -79,7 +85,7 @@ byte scorewrite(void){// only saves the top 10, returns the place in the chart
|
||||
while( fscanf(scorefile,"%59s : %ld\n",fuckingname,&fuckingscore) == 2 && location<SAVE_TO_NUM ){
|
||||
strcpy(namebuff[location],fuckingname);
|
||||
scorebuff[location] = fuckingscore;
|
||||
location++;
|
||||
++location;
|
||||
|
||||
memset(fuckingname,0,60);
|
||||
fuckingscore=0;
|
||||
@ -97,7 +103,7 @@ byte scorewrite(void){// only saves the top 10, returns the place in the chart
|
||||
byte ret = -1;
|
||||
bool wroteit=0;
|
||||
|
||||
for(location=0;location<=itreached && location<SAVE_TO_NUM-wroteit;location++){
|
||||
for(location=0;location<=itreached && location<SAVE_TO_NUM-wroteit;++location){
|
||||
if(!wroteit && (location>=itreached || score>=scorebuff[location]) ){
|
||||
fprintf(scorefile,"%s : %ld\n",getenv("USER"),score);
|
||||
ret=location;
|
||||
@ -173,17 +179,17 @@ void showscores(byte playerrank){
|
||||
if(rank == playerrank)
|
||||
printw(">>>");
|
||||
printw("%d) %s : %ld\n",rank+1,pname,pscore);
|
||||
rank++;
|
||||
++rank;
|
||||
}
|
||||
addch('\n');
|
||||
refresh();
|
||||
}
|
||||
void rectangle(void){
|
||||
for(int y=0;y<=len;y++){
|
||||
for(int y=0;y<=len;++y){
|
||||
mvaddch(3+y,0,ACS_VLINE);
|
||||
mvaddch(4+y,1+wid,ACS_VLINE);
|
||||
}
|
||||
for(int x=0;x<=wid;x++){
|
||||
for(int x=0;x<=wid;++x){
|
||||
mvaddch(3,x,ACS_HLINE);
|
||||
mvaddch(4+len,x,ACS_HLINE);
|
||||
}
|
||||
@ -222,7 +228,7 @@ void place_food(byte board[len][wid]){
|
||||
goto Again;
|
||||
board[y][x]=TRAP;
|
||||
|
||||
num--;
|
||||
--num;
|
||||
}
|
||||
if(score>2000 && !(rand()%5)){
|
||||
do{
|
||||
@ -237,25 +243,40 @@ void draw(byte board[len][wid]){
|
||||
static byte effect=0;
|
||||
chtype prnt;
|
||||
rectangle();
|
||||
for(y=0;y<len;y++){
|
||||
for(x=0;x<wid;x++){
|
||||
for(y=0;y<len;++y){
|
||||
for(x=0;x<wid;++x){
|
||||
if(y==py && x==px){
|
||||
prnt='r'|colors[2]|A_STANDOUT;
|
||||
if(immunity)
|
||||
prnt='r'|colors[effect]|A_BOLD;
|
||||
if(immunity){
|
||||
if(epilepsy)
|
||||
prnt='r';
|
||||
else
|
||||
prnt='r'|colors[effect]|A_BOLD;
|
||||
}
|
||||
}
|
||||
else if(board[y][x]==TRAP)
|
||||
prnt='^'|colors[((y*x)/15)%6];
|
||||
else if(board[y][x]==FOOD)
|
||||
prnt='%'|colors[(y+x)%6];
|
||||
else if(board[y][x]==SUPERFOOD)
|
||||
prnt='%'|colors[effect];
|
||||
else if(board[y][x]==SUPERFOOD){
|
||||
if(epilepsy)
|
||||
prnt=alt_animation[effect/10];
|
||||
else
|
||||
prnt='%'|colors[effect];
|
||||
}
|
||||
else
|
||||
prnt= ' ';
|
||||
mvaddch(4+y,x+1,prnt);
|
||||
}
|
||||
}
|
||||
effect=(effect+1)%6;
|
||||
if(epilepsy)
|
||||
effect=(effect+1)%40;
|
||||
else
|
||||
effect=(effect+1)%6;
|
||||
if(pse_msg && !epilepsy){
|
||||
mvprintw(len+5,0,"Suffering PSE? Press e.");
|
||||
--pse_msg;
|
||||
}
|
||||
}
|
||||
void help(void){
|
||||
nocbreak();
|
||||
@ -297,6 +318,7 @@ void sigint_handler(int x){
|
||||
int main(int argc, char** argv){
|
||||
bool autoset=0;
|
||||
signal(SIGINT,sigint_handler);
|
||||
#ifndef Plan9
|
||||
if(argc>3 || (argc==2 && !strcmp("help",argv[1])) ){
|
||||
printf("Usage: %s [len wid]\n",argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
@ -306,11 +328,7 @@ int main(int argc, char** argv){
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if(argc==3){
|
||||
#ifndef Plan9
|
||||
bool lool = sscanf(argv[1],"%d",&len) && sscanf(argv[2],"%d",&wid);
|
||||
#else
|
||||
bool lool = sscanf(argv[1],"%d",len) && sscanf(argv[2],"%d",wid);
|
||||
#endif
|
||||
if(!lool){
|
||||
puts("Invalid input.");
|
||||
return EXIT_FAILURE;
|
||||
@ -324,9 +342,10 @@ int main(int argc, char** argv){
|
||||
else{
|
||||
autoset=1;
|
||||
}
|
||||
#endif
|
||||
initscr();
|
||||
if(autoset){
|
||||
#ifndef Plan9
|
||||
if(autoset){
|
||||
len=LINES-7;
|
||||
if(len<MINLEN)
|
||||
len=MINLEN;
|
||||
@ -338,8 +357,8 @@ int main(int argc, char** argv){
|
||||
wid=MINWID;
|
||||
else if(wid>MAXWID)
|
||||
wid=MAXWID;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
srand(time(NULL)%UINT_MAX);
|
||||
byte board[len][wid];
|
||||
bool halfspeed=0;
|
||||
@ -357,7 +376,7 @@ int main(int argc, char** argv){
|
||||
init_pair(4,COLOR_CYAN,-1);
|
||||
init_pair(5,COLOR_MAGENTA,-1);
|
||||
init_pair(6,COLOR_RED,-1);
|
||||
for(byte b= 0;b<6;b++){
|
||||
for(byte b= 0;b<6;++b){
|
||||
colors[b]=COLOR_PAIR(b+1);
|
||||
}
|
||||
|
||||
@ -365,7 +384,7 @@ int main(int argc, char** argv){
|
||||
Start:
|
||||
curs_set(0);
|
||||
halfdelay(1);
|
||||
score=direction=0;
|
||||
score=direction=immunity=0;
|
||||
py=len/2;
|
||||
px=wid/2;
|
||||
memset(board,0,len*wid);
|
||||
@ -382,10 +401,12 @@ int main(int argc, char** argv){
|
||||
if( board[py][px]==FOOD ){
|
||||
score+= constant;
|
||||
board[py][px]=0;
|
||||
for(byte b=0;b<6;b++){
|
||||
mvaddch(4+py,px+1,'r'|colors[b]|A_STANDOUT);
|
||||
refresh();
|
||||
usleep(100000/5);
|
||||
if(!epilepsy){
|
||||
for(byte b=0;b<6;++b){
|
||||
mvaddch(4+py,px+1,'r'|colors[b]|A_STANDOUT);
|
||||
refresh();
|
||||
usleep(100000/5);
|
||||
}
|
||||
}
|
||||
place_food(board);
|
||||
}
|
||||
@ -419,7 +440,8 @@ int main(int argc, char** argv){
|
||||
direction=LEFT;
|
||||
if( (input=='l' || input==KEY_RIGHT) && px<wid-1 )
|
||||
direction=RIGHT;
|
||||
|
||||
if( input=='e')
|
||||
epilepsy=1;
|
||||
if( input=='q')
|
||||
sigint_handler(0);
|
||||
if( input=='p'){
|
||||
@ -440,25 +462,25 @@ int main(int argc, char** argv){
|
||||
if(direction==UP && halfspeed){
|
||||
if(!py)
|
||||
break;
|
||||
py--;
|
||||
--py;
|
||||
}
|
||||
else if(direction==DOWN && halfspeed){
|
||||
if(py==len-1)
|
||||
break;
|
||||
py++;
|
||||
++py;
|
||||
}
|
||||
else if(direction==LEFT){
|
||||
if(!px)
|
||||
break;
|
||||
px--;
|
||||
--px;
|
||||
}
|
||||
else if(direction==RIGHT){
|
||||
if(px==wid-1)
|
||||
break;
|
||||
px++;
|
||||
++px;
|
||||
}
|
||||
if(immunity)
|
||||
immunity--;
|
||||
--immunity;
|
||||
}
|
||||
nocbreak();
|
||||
cbreak();
|
||||
|
@ -1,3 +1,14 @@
|
||||
/*
|
||||
_
|
||||
|_)
|
||||
| IPES
|
||||
|
||||
Authored by abakh <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lncurses
|
||||
*/
|
||||
|
||||
#include <curses.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@ -16,30 +27,18 @@
|
||||
#define SAVE_TO_NUM 10
|
||||
#define SY 0
|
||||
#define SX 7
|
||||
/*
|
||||
_
|
||||
|_)
|
||||
| IPES
|
||||
|
||||
Authored by Hossein Bakhtiarifar <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lncurses
|
||||
*/
|
||||
typedef signed char byte;
|
||||
typedef unsigned char bitbox;
|
||||
|
||||
/* The Plan9 compiler can not handle VLAs */
|
||||
#ifdef Plan9
|
||||
#define wid 20
|
||||
#define len 14
|
||||
#else
|
||||
int len,wid;
|
||||
#endif
|
||||
|
||||
typedef signed char byte;
|
||||
typedef unsigned char bitbox;
|
||||
#ifndef Plan9
|
||||
int len,wid,py,px,fy,fx;//p: pointer f: fluid
|
||||
#else
|
||||
int py,px,fy,fx;//p: pointer f: fluid
|
||||
#endif
|
||||
bitbox tocome[5]={0};//the row of pipes in the left side
|
||||
chtype green=A_BOLD;//will use bold font instead of green if colors are not available
|
||||
long score;
|
||||
@ -78,7 +77,7 @@ byte scorewrite(void){// only saves the top 10, returns the place in the chart
|
||||
while( fscanf(scorefile,"%59s : %ld\n",fuckingname,&fuckingscore) == 2 && location<SAVE_TO_NUM ){
|
||||
strcpy(namebuff[location],fuckingname);
|
||||
scorebuff[location] = fuckingscore;
|
||||
location++;
|
||||
++location;
|
||||
|
||||
memset(fuckingname,0,60);
|
||||
fuckingscore=0;
|
||||
@ -96,7 +95,7 @@ byte scorewrite(void){// only saves the top 10, returns the place in the chart
|
||||
byte ret = -1;
|
||||
bool wroteit=0;
|
||||
|
||||
for(location=0;location<=itreached && location<SAVE_TO_NUM-wroteit;location++){
|
||||
for(location=0;location<=itreached && location<SAVE_TO_NUM-wroteit;++location){
|
||||
if(!wroteit && (location>=itreached || score>=scorebuff[location]) ){
|
||||
fprintf(scorefile,"%s : %ld\n",getenv("USER"),score);
|
||||
ret=location;
|
||||
@ -167,7 +166,7 @@ void showscores(byte playerrank){
|
||||
printw("%d",rank+1);
|
||||
attroff(green);
|
||||
printw(") %s : %ld",pname,pscore);
|
||||
rank++;
|
||||
++rank;
|
||||
}
|
||||
refresh();
|
||||
}
|
||||
@ -175,16 +174,16 @@ void showscores(byte playerrank){
|
||||
void MID(bitbox direction){
|
||||
switch(direction){
|
||||
case UP:
|
||||
fy--;
|
||||
--fy;
|
||||
break;
|
||||
case DOWN:
|
||||
fy++;
|
||||
++fy;
|
||||
break;
|
||||
case LEFT:
|
||||
fx--;
|
||||
--fx;
|
||||
break;
|
||||
case RIGHT:
|
||||
fx++;
|
||||
++fx;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -202,11 +201,11 @@ bitbox opposite(bitbox direction){
|
||||
return 0;
|
||||
}
|
||||
void rectangle(void){
|
||||
for(int y=0;y<=len;y++){
|
||||
for(int y=0;y<=len;++y){
|
||||
mvaddch(SY+y,SX,ACS_VLINE);
|
||||
mvaddch(SY+y,SX+wid+1,ACS_VLINE);
|
||||
}
|
||||
for(int x=0;x<=wid;x++){
|
||||
for(int x=0;x<=wid;++x){
|
||||
mvaddch(SY,SX+x,ACS_HLINE);
|
||||
mvaddch(SY+len+1,SX+x,ACS_HLINE);
|
||||
}
|
||||
@ -278,8 +277,8 @@ void addpipe(int y,int x,bitbox pipe , bool highlight){
|
||||
//display
|
||||
void draw(bitbox board[len][wid]){
|
||||
int y,x;
|
||||
for(y=0;y<len;y++){
|
||||
for(x=0;x<wid;x++){
|
||||
for(y=0;y<len;++y){
|
||||
for(x=0;x<wid;++x){
|
||||
addpipe(SY+1+y,SX+x+1,board[y][x], (y==py&&x==px) );//its highlighted when y==py and x==px
|
||||
}
|
||||
}
|
||||
@ -351,6 +350,7 @@ void gameplay(void){
|
||||
}
|
||||
int main(int argc, char** argv){
|
||||
signal(SIGINT,sigint_handler);
|
||||
#ifndef Plan9
|
||||
if(argc>3 || (argc==2 && !strcmp("help",argv[1])) ){
|
||||
printf("Usage: %s [len wid]\n",argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
@ -360,11 +360,7 @@ int main(int argc, char** argv){
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if(argc==3){
|
||||
#ifndef Plan9
|
||||
bool lool = sscanf(argv[1],"%d",&len) && sscanf(argv[2],"%d",&wid);
|
||||
#else
|
||||
bool lool = sscanf(argv[1],"%d",len) && sscanf(argv[2],"%d",wid);
|
||||
#endif
|
||||
if(!lool){
|
||||
puts("Invalid input.");
|
||||
return EXIT_FAILURE;
|
||||
@ -376,11 +372,10 @@ int main(int argc, char** argv){
|
||||
|
||||
}
|
||||
else{
|
||||
#ifndef Plan9
|
||||
wid=20;
|
||||
len=14;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
initscr();
|
||||
mousemask(ALL_MOUSE_EVENTS,NULL);
|
||||
time_t tstart , now, lasttime, giventime=len*wid/4;
|
||||
@ -389,7 +384,7 @@ int main(int argc, char** argv){
|
||||
int input;
|
||||
byte foo;
|
||||
bool flow,fast;
|
||||
Start: //TODO in all the games, some things have to be moved behind the start . definize sy and sx
|
||||
Start:
|
||||
flow=0;
|
||||
fast=0;
|
||||
score=0;
|
||||
@ -400,7 +395,7 @@ int main(int argc, char** argv){
|
||||
board[fy][fx]= 1 << (rand()%4);
|
||||
direction= board[fy][fx];
|
||||
board[fy][fx]|=FILLED;
|
||||
for(foo=0;foo<5;foo++)
|
||||
for(foo=0;foo<5;++foo)
|
||||
tocome[foo]=pipegen();
|
||||
tstart = time(NULL);
|
||||
lasttime=0;
|
||||
@ -437,7 +432,7 @@ int main(int argc, char** argv){
|
||||
mvprintw(4,0,"Score:");
|
||||
mvprintw(5,0,"%ld",score);
|
||||
}
|
||||
for(foo=0;foo<5;foo++)
|
||||
for(foo=0;foo<5;++foo)
|
||||
addpipe(11-foo,4,tocome[foo],0);
|
||||
draw(board);
|
||||
refresh();
|
||||
@ -451,9 +446,9 @@ int main(int argc, char** argv){
|
||||
if(fy<len && fx<wid && fy>=0&& fx>=0 && ( board[fy][fx]&opposite(direction) ) ){
|
||||
if(board[fy][fx] != CROSSOVER && board[fy][fx] != (CROSSOVER|FILLED) )
|
||||
direction = board[fy][fx] & ~opposite(direction);
|
||||
score++;
|
||||
++score;
|
||||
if(fast)
|
||||
score++;
|
||||
++score;
|
||||
}
|
||||
else
|
||||
goto End;
|
||||
@ -474,18 +469,18 @@ int main(int argc, char** argv){
|
||||
if( input == KEY_MOUSE )
|
||||
mouseinput();
|
||||
if( (input=='k' || input==KEY_UP) && py>0 )
|
||||
py--;
|
||||
--py;
|
||||
if( (input=='j' || input==KEY_DOWN) && py<len-1 )
|
||||
py++;
|
||||
++py;
|
||||
if( (input=='h' || input==KEY_LEFT) && px>0 )
|
||||
px--;
|
||||
--px;
|
||||
if( (input=='l' || input==KEY_RIGHT) && px<wid-1 )
|
||||
px++;
|
||||
++px;
|
||||
if( input == '\n' && !(board[py][px] & FILLED) ){
|
||||
if(board[py][px])
|
||||
score-=3;
|
||||
board[py][px]=tocome[0];
|
||||
for(foo=0;foo<4;foo++)
|
||||
for(foo=0;foo<4;++foo)
|
||||
tocome[foo]=tocome[foo+1];
|
||||
tocome[4]= pipegen();
|
||||
}
|
||||
|
@ -1,3 +1,14 @@
|
||||
/*
|
||||
_
|
||||
|_)
|
||||
| \ABBITHOLE
|
||||
|
||||
Authored by abakh <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lncurses
|
||||
*/
|
||||
|
||||
#include <curses.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@ -10,30 +21,17 @@
|
||||
#define LEFT 8
|
||||
#define VISITED 16
|
||||
#define CARROT 32
|
||||
/*
|
||||
_
|
||||
|_)
|
||||
| \ABBITHOLE
|
||||
|
||||
Authored by Hossein Bakhtiarifar <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lncurses
|
||||
*/
|
||||
typedef signed char byte;
|
||||
typedef unsigned char bitbox;
|
||||
|
||||
/* The Plan9 compiler can not handle VLAs */
|
||||
#ifdef Plan9
|
||||
#define len 10
|
||||
#define wid 20
|
||||
#endif
|
||||
|
||||
typedef signed char byte;
|
||||
typedef unsigned char bitbox;
|
||||
#ifndef Plan9
|
||||
int len,wid,py,px;
|
||||
#else
|
||||
int py,px;
|
||||
int len,wid;
|
||||
#endif
|
||||
int py,px;
|
||||
|
||||
chtype colors[6]={0};
|
||||
|
||||
@ -46,26 +44,26 @@ point MID(int y,int x,bitbox direction){//move in direction
|
||||
point pt = {y,x};
|
||||
switch(direction){
|
||||
case UP:
|
||||
pt.y--;
|
||||
--pt.y;
|
||||
return pt;
|
||||
case DOWN:
|
||||
pt.y++;
|
||||
++pt.y;
|
||||
return pt;
|
||||
case LEFT:
|
||||
pt.x--;
|
||||
--pt.x;
|
||||
return pt;
|
||||
case RIGHT:
|
||||
pt.x++;
|
||||
++pt.x;
|
||||
return pt;
|
||||
}
|
||||
return pt;
|
||||
}
|
||||
void rectangle(int sy,int sx){
|
||||
for(int y=0;y<=len*2;y++){
|
||||
for(int y=0;y<=len*2;++y){
|
||||
mvaddch(sy+y,sx,ACS_VLINE);
|
||||
mvaddch(sy+y,sx+wid*2,ACS_VLINE);
|
||||
}
|
||||
for(int x=0;x<=wid*2;x++){
|
||||
for(int x=0;x<=wid*2;++x){
|
||||
mvaddch(sy,sx+x,ACS_HLINE);
|
||||
mvaddch(sy+len*2,sx+x,ACS_HLINE);
|
||||
}
|
||||
@ -80,8 +78,8 @@ void draw(int sy,int sx,bitbox board[len][wid]){
|
||||
bitbox d;
|
||||
chtype prnt;
|
||||
point pt;
|
||||
for(y=0;y<len;y++){
|
||||
for(x=0;x<wid;x++){
|
||||
for(y=0;y<len;++y){
|
||||
for(x=0;x<wid;++x){
|
||||
prnt=0;
|
||||
if( board[y][x] & CARROT )
|
||||
prnt='%'|A_BOLD|colors[3];
|
||||
@ -121,7 +119,7 @@ void make_maze(bitbox board[len][wid],point f){
|
||||
}
|
||||
direction= 1 << (dnumber= (dnumber+1)%4 );
|
||||
pt= MID(f.y,f.x,direction);
|
||||
ds_tried++;
|
||||
++ds_tried;
|
||||
}
|
||||
}
|
||||
void carrotify(bitbox board[len][wid],int count){
|
||||
@ -134,7 +132,7 @@ void carrotify(bitbox board[len][wid],int count){
|
||||
x=rand()%wid;
|
||||
}
|
||||
board[y][x] |= CARROT;
|
||||
c--;
|
||||
--c;
|
||||
}
|
||||
}
|
||||
void help(void){
|
||||
@ -180,6 +178,7 @@ void sigint_handler(int x){
|
||||
int main(int argc, char** argv){
|
||||
bool autoset=0;
|
||||
signal(SIGINT,sigint_handler);
|
||||
#ifndef Plan9
|
||||
if(argc>3 || (argc==2 && !strcmp("help",argv[1])) ){
|
||||
printf("Usage: %s [len wid]\n",argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
@ -189,11 +188,7 @@ int main(int argc, char** argv){
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if(argc==3){
|
||||
#ifndef Plan9
|
||||
bool lool = sscanf(argv[1],"%d",&len) && sscanf(argv[2],"%d",&wid);
|
||||
#else
|
||||
bool lool = sscanf(argv[1],"%d",len) && sscanf(argv[2],"%d",wid);
|
||||
#endif
|
||||
if(!lool){
|
||||
puts("Invalid input.");
|
||||
return EXIT_FAILURE;
|
||||
@ -207,6 +202,7 @@ int main(int argc, char** argv){
|
||||
else{
|
||||
autoset=1;
|
||||
}
|
||||
#endif
|
||||
initscr();
|
||||
#ifndef Plan9
|
||||
if(autoset){
|
||||
@ -246,7 +242,7 @@ int main(int argc, char** argv){
|
||||
init_pair(4,COLOR_RED,-1);
|
||||
init_pair(5,COLOR_RED,COLOR_YELLOW);
|
||||
init_pair(6,COLOR_RED,COLOR_MAGENTA);
|
||||
for(byte b= 0;b<6;b++){
|
||||
for(byte b= 0;b<6;++b){
|
||||
colors[b]=COLOR_PAIR(b+1);
|
||||
}
|
||||
|
||||
@ -260,7 +256,7 @@ int main(int argc, char** argv){
|
||||
while(1){
|
||||
board[py][px] |= VISITED;
|
||||
if( board[py][px] & CARROT ){
|
||||
carrots_found++;
|
||||
++carrots_found;
|
||||
board[py][px] &= ~CARROT;
|
||||
}
|
||||
now=time(NULL);
|
||||
@ -300,17 +296,17 @@ int main(int argc, char** argv){
|
||||
if( input == KEY_F(1) || input=='?' )
|
||||
help();
|
||||
if( (input=='k' || input==KEY_UP) && py>0 && (board[py][px]&UP) )
|
||||
py--;
|
||||
--py;
|
||||
if( (input=='j' || input==KEY_DOWN) && py<len-1 && (board[py][px]&DOWN) )
|
||||
py++;
|
||||
++py;
|
||||
if( (input=='h' || input==KEY_LEFT) && px>0 && (board[py][px]&LEFT) )
|
||||
px--;
|
||||
--px;
|
||||
if( (input=='l' || input==KEY_RIGHT) && px<wid-1 && (board[py][px]&RIGHT) )
|
||||
px++;
|
||||
++px;
|
||||
if( input=='q')
|
||||
sigint_handler(0);
|
||||
if( board[py][px] & CARROT ){
|
||||
carrots_found++;
|
||||
++carrots_found;
|
||||
board[py][px] &= ~CARROT;
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,13 @@
|
||||
/*
|
||||
_ _
|
||||
|_) (_
|
||||
| \ed_)quare
|
||||
|
||||
authored by abakh <abakh@tuta.io>
|
||||
no rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lncurses
|
||||
*/
|
||||
#include <curses.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@ -11,17 +21,8 @@
|
||||
#define DEAD 0
|
||||
#define ALIVE 1
|
||||
#define RED 2
|
||||
/*
|
||||
_ _
|
||||
|_) (_
|
||||
| \ED_)QUARE
|
||||
|
||||
Authored by Hossein Bakhtiarifar <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lncurses
|
||||
*/
|
||||
typedef signed char byte;
|
||||
|
||||
int level;
|
||||
byte py,px;
|
||||
byte cy,cx;//cross
|
||||
@ -30,8 +31,8 @@ int anum,rnum;//reds and otherwise alive cell counts
|
||||
chtype colors[6]={0};
|
||||
void cp(byte a[RLEN][RWID],byte b[RLEN][RWID]){
|
||||
byte y,x;
|
||||
for(y=0;y<RLEN;y++)
|
||||
for(x=0;x<RWID;x++)
|
||||
for(y=0;y<RLEN;++y)
|
||||
for(x=0;x<RWID;++x)
|
||||
b[y][x]=a[y][x];
|
||||
}
|
||||
void logo(void){
|
||||
@ -41,11 +42,11 @@ void logo(void){
|
||||
addstr("| \\ED_)QUARE");
|
||||
}
|
||||
void rectangle(int sy,int sx){
|
||||
for(int y=0;y<=LEN;y++){
|
||||
for(int y=0;y<=LEN;++y){
|
||||
mvaddch(sy+y,sx,ACS_VLINE);
|
||||
mvaddch(sy+y,sx+WID+1,ACS_VLINE);
|
||||
}
|
||||
for(int x=0;x<=WID;x++){
|
||||
for(int x=0;x<=WID;++x){
|
||||
mvaddch(sy,sx+x,ACS_HLINE);
|
||||
mvaddch(sy+LEN+1,sx+x,ACS_HLINE);
|
||||
}
|
||||
@ -57,12 +58,12 @@ void rectangle(int sy,int sx){
|
||||
void count(byte board[LEN][WID]){
|
||||
byte y,x;
|
||||
anum=rnum=0;
|
||||
for(y=0;y<LEN;y++){
|
||||
for(x=0;x<WID;x++){
|
||||
for(y=0;y<LEN;++y){
|
||||
for(x=0;x<WID;++x){
|
||||
if(board[y][x]==ALIVE)
|
||||
anum++;
|
||||
++anum;
|
||||
else if(board[y][x]==RED)
|
||||
rnum++;
|
||||
++rnum;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -71,8 +72,8 @@ void draw(byte board[RLEN][RWID]){
|
||||
rectangle(3,0);
|
||||
chtype prnt;
|
||||
byte y,x;
|
||||
for(y=0;y<LEN;y++){
|
||||
for(x=0;x<WID;x++){
|
||||
for(y=0;y<LEN;++y){
|
||||
for(x=0;x<WID;++x){
|
||||
if(y==cy && x==cx){
|
||||
prnt='X';
|
||||
if(board[y][x]==ALIVE)
|
||||
@ -98,8 +99,8 @@ void draw(byte board[RLEN][RWID]){
|
||||
}
|
||||
void rand_level(byte board[RLEN][RWID]){
|
||||
byte y,x;
|
||||
for(y=0;y<LEN/2;y++){
|
||||
for(x=0;x<WID;x++){
|
||||
for(y=0;y<LEN/2;++y){
|
||||
for(x=0;x<WID;++x){
|
||||
if(rand()%2){
|
||||
if(rand()%3)
|
||||
board[y][x]=ALIVE;
|
||||
@ -116,11 +117,11 @@ void live(byte board[RLEN][RWID]){
|
||||
byte alives,reds;
|
||||
byte preboard[RLEN][RWID];
|
||||
cp(board,preboard);
|
||||
for(y=0;y<LEN;y++){
|
||||
for(x=0;x<WID;x++){
|
||||
for(y=0;y<LEN;++y){
|
||||
for(x=0;x<WID;++x){
|
||||
alives=reds=0;
|
||||
for(dy=-1;dy<2;dy++){
|
||||
for(dx=-1;dx<2;dx++){
|
||||
for(dy=-1;dy<2;++dy){
|
||||
for(dx=-1;dx<2;++dx){
|
||||
if(!dy && !dx)
|
||||
continue;
|
||||
ry=y+dy;
|
||||
@ -135,9 +136,9 @@ void live(byte board[RLEN][RWID]){
|
||||
rx=0;
|
||||
|
||||
if(preboard[ry][rx]==ALIVE)
|
||||
alives++;
|
||||
++alives;
|
||||
else if(preboard[ry][rx]==RED)
|
||||
reds++;
|
||||
++reds;
|
||||
}
|
||||
}
|
||||
if(board[y][x]){
|
||||
@ -163,7 +164,7 @@ void live(byte board[RLEN][RWID]){
|
||||
}
|
||||
}
|
||||
void add_line(byte board[LEN][WID],byte line,const char* str){
|
||||
for(byte x=0;str[x]!='\0';x++){
|
||||
for(byte x=0;str[x]!='\0';++x){
|
||||
if(str[x]=='#')
|
||||
board[line][x]=ALIVE;
|
||||
/*else
|
||||
@ -171,7 +172,7 @@ void add_line(byte board[LEN][WID],byte line,const char* str){
|
||||
}
|
||||
}
|
||||
void new_level(byte board[LEN][WID]){
|
||||
level++;
|
||||
++level;
|
||||
memset(board,0,RLEN*RWID);
|
||||
switch(level){
|
||||
case 0:
|
||||
@ -317,8 +318,8 @@ void new_level(byte board[LEN][WID]){
|
||||
}
|
||||
void rm_square(byte board[LEN][WID],byte prey,byte prex){
|
||||
byte dy,dx,ry,rx;
|
||||
for(dy=0;dy<2;dy++){
|
||||
for(dx=0;dx<2;dx++){
|
||||
for(dy=0;dy<2;++dy){
|
||||
for(dx=0;dx<2;++dx){
|
||||
ry=prey+dy;
|
||||
if(ry==-1)
|
||||
ry=LEN-1;
|
||||
@ -335,8 +336,8 @@ void rm_square(byte board[LEN][WID],byte prey,byte prex){
|
||||
}
|
||||
void mk_square(byte board[LEN][WID]){
|
||||
byte dy,dx,ry,rx;
|
||||
for(dy=0;dy<2;dy++){
|
||||
for(dx=0;dx<2;dx++){
|
||||
for(dy=0;dy<2;++dy){
|
||||
for(dx=0;dx<2;++dx){
|
||||
ry=py+dy;
|
||||
if(ry==-1)
|
||||
ry=LEN-1;
|
||||
@ -354,13 +355,13 @@ void mk_square(byte board[LEN][WID]){
|
||||
//detect if there is a square and enable the player to move
|
||||
void reemerge(byte board[LEN][WID]){
|
||||
byte y,x,dy,dx,ry,rx;
|
||||
for(y=0;y<LEN;y++)
|
||||
for(x=0;x<WID;x++)
|
||||
for(y=0;y<LEN;++y)
|
||||
for(x=0;x<WID;++x)
|
||||
if(board[y][x]==RED)
|
||||
goto FoundTheFirst;
|
||||
FoundTheFirst:
|
||||
for(dy=0;dy<2;dy++){
|
||||
for(dx=0;dx<2;dx++){
|
||||
for(dy=0;dy<2;++dy){
|
||||
for(dx=0;dx<2;++dx){
|
||||
ry=y+dy;
|
||||
if(ry==-1)
|
||||
ry=LEN-1;
|
||||
@ -456,7 +457,7 @@ int main(void){
|
||||
init_pair(4,COLOR_RED,-1);
|
||||
init_pair(5,COLOR_RED,COLOR_YELLOW);
|
||||
init_pair(6,COLOR_RED,COLOR_MAGENTA);
|
||||
for(byte b= 0;b<6;b++){
|
||||
for(byte b= 0;b<6;++b){
|
||||
colors[b]=COLOR_PAIR(b+1);
|
||||
}
|
||||
|
||||
@ -480,22 +481,22 @@ int main(void){
|
||||
while(1){
|
||||
switch(rand()%5){//move the cross
|
||||
case 0:
|
||||
cx++;
|
||||
++cx;
|
||||
if(cx==WID)
|
||||
cx=0;
|
||||
break;
|
||||
case 1:
|
||||
cy--;
|
||||
--cy;
|
||||
if(cy==-1)
|
||||
cy=LEN-1;
|
||||
break;
|
||||
case 2:
|
||||
cx--;
|
||||
--cx;
|
||||
if(cx==-1)
|
||||
cx=WID-1;
|
||||
break;
|
||||
case 3:
|
||||
cy++;
|
||||
++cy;
|
||||
if(cy==LEN)
|
||||
cy=0;
|
||||
break;
|
||||
@ -503,7 +504,7 @@ int main(void){
|
||||
;//stay there
|
||||
}
|
||||
if(board[cy][cx]==RED)
|
||||
cinred++;
|
||||
++cinred;
|
||||
else
|
||||
cinred=0;
|
||||
count(board);
|
||||
@ -549,22 +550,22 @@ int main(void){
|
||||
prey=py;
|
||||
prex=px;
|
||||
if(input=='k' || input==KEY_UP){
|
||||
py--;
|
||||
--py;
|
||||
if(py==-1)
|
||||
py=LEN-1;
|
||||
}
|
||||
else if(input=='j' || input==KEY_DOWN){
|
||||
py++;
|
||||
++py;
|
||||
if(py==LEN)
|
||||
py=0;
|
||||
}
|
||||
else if(input=='h' || input==KEY_LEFT){
|
||||
px--;
|
||||
--px;
|
||||
if(px==-1)
|
||||
px=WID-1;
|
||||
}
|
||||
else if(input=='l' || input==KEY_RIGHT){
|
||||
px++;
|
||||
++px;
|
||||
if(px==WID)
|
||||
px=0;
|
||||
}
|
||||
|
@ -1,19 +1,20 @@
|
||||
#include <curses.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
/*
|
||||
_
|
||||
|_)
|
||||
| \EVERSI
|
||||
|
||||
Authored by Hossein Bakhtiarifar <abakh@tuta.io>
|
||||
Authored by abakh <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lncurses
|
||||
*/
|
||||
#include <curses.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
typedef signed char byte;
|
||||
|
||||
byte py,px;//cursor
|
||||
const char piece[2] = {'O','X'};
|
||||
char game[8][8];//main board
|
||||
@ -21,11 +22,11 @@ byte computer[2] = {0,0};
|
||||
byte score[2];//set by header()
|
||||
|
||||
void rectangle(byte sy,byte sx){
|
||||
for(byte y=0;y<=8+1;y++){
|
||||
for(byte y=0;y<=8+1;++y){
|
||||
mvaddch(sy+y,sx,ACS_VLINE);
|
||||
mvaddch(sy+y,sx+8*2,ACS_VLINE);
|
||||
}
|
||||
for(byte x=0;x<=8*2;x++){
|
||||
for(byte x=0;x<=8*2;++x){
|
||||
mvaddch(sy,sx+x,ACS_HLINE);
|
||||
mvaddch(sy+8+1,sx+x,ACS_HLINE);
|
||||
}
|
||||
@ -37,8 +38,8 @@ void rectangle(byte sy,byte sx){
|
||||
|
||||
void header(void){//abuse, used to count the pieces on each side too
|
||||
score[0]=score[1]=0;
|
||||
for(byte y=0;y<8;y++){
|
||||
for(byte x=0;x<8;x++){
|
||||
for(byte y=0;y<8;++y){
|
||||
for(byte x=0;x<8;++x){
|
||||
if(game[y][x]){
|
||||
if(game[y][x]==piece[0])
|
||||
score[0]++;
|
||||
@ -55,8 +56,8 @@ void header(void){//abuse, used to count the pieces on each side too
|
||||
void draw(byte sy,byte sx){//the game's board
|
||||
rectangle(sy,sx);
|
||||
chtype attr ;
|
||||
for(byte y=0;y<8;y++){
|
||||
for(byte x=0;x<8;x++){
|
||||
for(byte y=0;y<8;++y){
|
||||
for(byte x=0;x<8;++x){
|
||||
attr=A_NORMAL;
|
||||
if(y==py && x==px)
|
||||
attr |= A_STANDOUT;
|
||||
@ -72,8 +73,8 @@ bool can_reverse(byte ty , byte tx,char board[8][8],char piece){//can place a pi
|
||||
byte y,x,count;
|
||||
if(board[ty][tx])
|
||||
return false;
|
||||
for(byte dy=-1;dy<2;dy++){ //changes the direction
|
||||
for(byte dx=-1;dx<2;dx++){
|
||||
for(byte dy=-1;dy<2;++dy){ //changes the direction
|
||||
for(byte dx=-1;dx<2;++dx){
|
||||
if(dx==0&&dy==0)//it would be itself
|
||||
dx=1;
|
||||
count=0;
|
||||
@ -90,7 +91,7 @@ bool can_reverse(byte ty , byte tx,char board[8][8],char piece){//can place a pi
|
||||
}
|
||||
|
||||
if(board[y][x]!=piece){
|
||||
count++;
|
||||
++count;
|
||||
y+=dy;
|
||||
x+=dx;
|
||||
}
|
||||
@ -107,8 +108,8 @@ bool can_reverse(byte ty , byte tx,char board[8][8],char piece){//can place a pi
|
||||
void reverse(byte ty,byte tx,char board[8][8],char piece){//place a piece there
|
||||
board[ty][tx]=piece;
|
||||
byte y,x;
|
||||
for(byte dy=-1;dy<2;dy++){//changes the direction
|
||||
for(byte dx=-1;dx<2;dx++){
|
||||
for(byte dy=-1;dy<2;++dy){//changes the direction
|
||||
for(byte dx=-1;dx<2;++dx){
|
||||
if(dy==0 && dx==0)
|
||||
dx=1;
|
||||
y=ty+dy;
|
||||
@ -136,8 +137,8 @@ void reverse(byte ty,byte tx,char board[8][8],char piece){//place a piece there
|
||||
}
|
||||
|
||||
bool can_move(char board[8][8],char piece){//can move at all?
|
||||
for(byte y=0;y<8;y++)
|
||||
for(byte x=0;x<8;x++)
|
||||
for(byte y=0;y<8;++y)
|
||||
for(byte x=0;x<8;++x)
|
||||
if(can_reverse(y,x,board,piece))
|
||||
return true;
|
||||
return false;
|
||||
@ -146,18 +147,18 @@ bool can_move(char board[8][8],char piece){//can move at all?
|
||||
double advantage(char board[8][8],char piece){
|
||||
double own=0;
|
||||
double opp=0;
|
||||
for(byte y=0;y<8;y++){
|
||||
for(byte x=0;x<8;x++){
|
||||
for(byte y=0;y<8;++y){
|
||||
for(byte x=0;x<8;++x){
|
||||
if(board[y][x]){
|
||||
if(board[y][x]==piece){
|
||||
own++;
|
||||
++own;
|
||||
if( ((y==7 || y==0)&&(x!=7 && x!=0)) || ((x==7 || x==0)&&(y!=7 && y!=0)) )//edges
|
||||
own+=100;
|
||||
if( (y==7 || y==0)&&(x==7 || x==0) )//corners
|
||||
own+=10000;
|
||||
}
|
||||
else{
|
||||
opp++;
|
||||
++opp;
|
||||
if( ((y==7 || y==0)&&(x!=7 && x!=0)) || ((x==7 || x==0)&&(y!=7 && y!=0)) )
|
||||
opp+=100;
|
||||
if( (y==7 || y==0)&&(x==7 || x==0) )
|
||||
@ -171,8 +172,8 @@ double advantage(char board[8][8],char piece){
|
||||
}
|
||||
|
||||
void cp(char A[8][8],char B[8][8]){//copy the board A to B
|
||||
for(byte y=0;y<8;y++)
|
||||
for(byte x=0;x<8;x++)
|
||||
for(byte y=0;y<8;++y)
|
||||
for(byte x=0;x<8;++x)
|
||||
B[y][x]=A[y][x];
|
||||
}
|
||||
|
||||
@ -183,8 +184,8 @@ double decide(char board[8][8],char piece,char opponet,byte depth){//AI algorith
|
||||
double adv,bestadv;
|
||||
adv=bestadv=0;
|
||||
byte besty,bestx;
|
||||
for(byte y=0;y<8;y++){
|
||||
for(byte x=0;x<8;x++){
|
||||
for(byte y=0;y<8;++y){
|
||||
for(byte x=0;x<8;++x){
|
||||
if(can_reverse(y,x,board,piece) ){
|
||||
cp(board,plan);//backtrack
|
||||
reverse(y,x,plan,piece);
|
||||
@ -338,13 +339,13 @@ int main(int argc , char** argv){
|
||||
cantmove=0;
|
||||
}
|
||||
else
|
||||
cantmove++;
|
||||
++cantmove;
|
||||
goto Turn;
|
||||
|
||||
}
|
||||
|
||||
if(!can_move(game,piece[turn])){
|
||||
cantmove++;
|
||||
++cantmove;
|
||||
goto Turn;
|
||||
}
|
||||
else{
|
||||
@ -364,13 +365,13 @@ int main(int argc , char** argv){
|
||||
if( input==KEY_MOUSE )
|
||||
mouseinput();
|
||||
if( (input=='k' || input==KEY_UP) && py>0)
|
||||
py--;
|
||||
--py;
|
||||
if( (input=='j' || input==KEY_DOWN) && py<7)
|
||||
py++;
|
||||
++py;
|
||||
if( (input=='h' || input==KEY_LEFT) && px>0)
|
||||
px--;
|
||||
--px;
|
||||
if( (input=='l' || input==KEY_RIGHT) && px<7)
|
||||
px++;
|
||||
++px;
|
||||
if( input=='q'){
|
||||
resign=1;
|
||||
goto End;
|
||||
|
101
sources/sos.c
101
sources/sos.c
@ -1,3 +1,13 @@
|
||||
/*
|
||||
_ _ _
|
||||
(_'| |(_'
|
||||
._):_:._)
|
||||
|
||||
Authored by abakh <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lncurses
|
||||
*/
|
||||
#include <curses.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@ -5,28 +15,16 @@
|
||||
#include <time.h>
|
||||
#include <signal.h>
|
||||
#define NOTHING 123
|
||||
/*
|
||||
_ _ _
|
||||
(_'| |(_'
|
||||
._):_:._)
|
||||
|
||||
Authored by Hossein Bakhtiarifar <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lncurses
|
||||
*/
|
||||
typedef signed char byte;
|
||||
|
||||
#ifdef Plan9
|
||||
#define len 5
|
||||
#define wid 6
|
||||
#else
|
||||
int len,wid;
|
||||
#endif
|
||||
|
||||
typedef signed char byte;
|
||||
#ifndef Plan9
|
||||
int len,wid,py,px;
|
||||
#else
|
||||
int py,px;
|
||||
#endif
|
||||
chtype colors[6]={A_BOLD};
|
||||
int score[2] ={0};
|
||||
int computer[2]={0};
|
||||
@ -45,11 +43,11 @@ void color(byte colored[len][wid],int y,int x,bool side){
|
||||
colored[y][x]=side;
|
||||
}
|
||||
void rectangle(int sy,int sx){
|
||||
for(int y=0;y<=len+1;y++){
|
||||
for(int y=0;y<=len+1;++y){
|
||||
mvaddch(sy+y,sx,ACS_VLINE);
|
||||
mvaddch(sy+y,sx+wid*2,ACS_VLINE);
|
||||
}
|
||||
for(int x=0;x<=wid*2;x++){
|
||||
for(int x=0;x<=wid*2;++x){
|
||||
mvaddch(sy,sx+x,ACS_HLINE);
|
||||
mvaddch(sy+len+1,sx+x,ACS_HLINE);
|
||||
}
|
||||
@ -64,8 +62,8 @@ void draw(int sy,int sx,char board[len][wid],byte colored[len][wid]){
|
||||
chtype attr ;
|
||||
char prnt;
|
||||
int y,x;
|
||||
for(y=0;y<len;y++){
|
||||
for(x=0;x<wid;x++){
|
||||
for(y=0;y<len;++y){
|
||||
for(x=0;x<wid;++x){
|
||||
attr=A_NORMAL;
|
||||
if(y==py && x==px)
|
||||
attr |= A_STANDOUT;
|
||||
@ -84,19 +82,19 @@ byte did_sos(char board[len][wid], int y , int x ){
|
||||
byte dy,dx;
|
||||
byte soses=0;
|
||||
if(board[y][x]== 'S'){
|
||||
for(dy=-1;dy<2;dy++){
|
||||
for(dx=-1;dx<2;dx++){
|
||||
for(dy=-1;dy<2;++dy){
|
||||
for(dx=-1;dx<2;++dx){
|
||||
if(rd(board,y+dy,x+dx)=='O' && rd(board,y+2*dy,x+2*dx) == 'S' )
|
||||
soses++;
|
||||
++soses;
|
||||
}
|
||||
}
|
||||
return soses;
|
||||
}
|
||||
else if(board[y][x]== 'O'){
|
||||
for(dy=-1;dy<2;dy++){
|
||||
for(dx=-1;dx<2;dx++){
|
||||
for(dy=-1;dy<2;++dy){
|
||||
for(dx=-1;dx<2;++dx){
|
||||
if(rd(board,y+dy,x+dx)=='S' && rd(board,y-dy,x-dx) =='S')
|
||||
soses++;
|
||||
++soses;
|
||||
}
|
||||
}
|
||||
return soses/2;
|
||||
@ -106,8 +104,8 @@ byte did_sos(char board[len][wid], int y , int x ){
|
||||
void color_sos(char board[len][wid],byte colored[len][wid], int y , int x ,bool side){
|
||||
byte dy,dx;
|
||||
if(board[y][x]== 'S'){
|
||||
for(dy=-1;dy<2;dy++){
|
||||
for(dx=-1;dx<2;dx++){
|
||||
for(dy=-1;dy<2;++dy){
|
||||
for(dx=-1;dx<2;++dx){
|
||||
if(rd(board,y+dy,x+dx)=='O' && rd(board,y+2*dy,x+2*dx) == 'S' ){
|
||||
color(colored,y,x,side);
|
||||
color(colored,y+dy,x+dx,side);
|
||||
@ -117,8 +115,8 @@ void color_sos(char board[len][wid],byte colored[len][wid], int y , int x ,bool
|
||||
}
|
||||
}
|
||||
else if(board[y][x]== 'O'){
|
||||
for(dy=-1;dy<2;dy++){
|
||||
for(dx=-1;dx<2;dx++){
|
||||
for(dy=-1;dy<2;++dy){
|
||||
for(dx=-1;dx<2;++dx){
|
||||
if(rd(board,y+dy,x+dx)=='S' && rd(board,y-dy,x-dx) =='S'){
|
||||
color(colored,y,x,side);
|
||||
color(colored,y+dy,x+dx,side);
|
||||
@ -146,10 +144,10 @@ int decide ( char board[len][wid],byte colored[len][wid], byte depth , byte side
|
||||
int ry,rx;
|
||||
byte rc;
|
||||
randmove(&ry,&rx,&rc);//provides efficient randomization
|
||||
for(y=0;y<len;y++){
|
||||
for(x=0;x<wid;x++){
|
||||
for(y=0;y<len;++y){
|
||||
for(x=0;x<wid;++x){
|
||||
if(!board[y][x]){
|
||||
for(c=0;c<2;c++){
|
||||
for(c=0;c<2;++c){
|
||||
board[y][x]=so[c];
|
||||
adv=did_sos(board,y,x);
|
||||
if(depth>0)
|
||||
@ -176,8 +174,8 @@ int decide ( char board[len][wid],byte colored[len][wid], byte depth , byte side
|
||||
}
|
||||
bool isfilled(char board[len][wid]){
|
||||
int y,x;
|
||||
for(y=0;y<len;y++)
|
||||
for(x=0;x<wid;x++)
|
||||
for(y=0;y<len;++y)
|
||||
for(x=0;x<wid;++x)
|
||||
if(!board[y][x])
|
||||
return 0;
|
||||
return 1;
|
||||
@ -245,6 +243,7 @@ void gameplay(void){
|
||||
int main(int argc, char** argv){
|
||||
int dpt=1;
|
||||
signal(SIGINT,sigint_handler);
|
||||
#ifndef Plan9
|
||||
if(argc>4 || (argc==2 && !strcmp("help",argv[1])) ){
|
||||
printf("Usage: %s [len wid [AIpower]]\n",argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
@ -254,11 +253,7 @@ int main(int argc, char** argv){
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if(argc>=3){
|
||||
#ifndef Plan9
|
||||
bool lool = sscanf(argv[1],"%d",&len) && sscanf(argv[2],"%d",&wid);
|
||||
#else
|
||||
bool lool = sscanf(argv[1],"%d",len) && sscanf(argv[2],"%d",wid);
|
||||
#endif
|
||||
if(!lool){
|
||||
puts("Invalid input.");
|
||||
return EXIT_FAILURE;
|
||||
@ -270,10 +265,8 @@ int main(int argc, char** argv){
|
||||
|
||||
}
|
||||
else{
|
||||
#ifndef Plan9
|
||||
len=5;
|
||||
wid=6;
|
||||
#endif
|
||||
}
|
||||
if(argc==4){
|
||||
if( !sscanf(argv[3],"%d",&dpt)){
|
||||
@ -285,6 +278,24 @@ int main(int argc, char** argv){
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if(argc>2 || (argc==2 && !strcmp("help",argv[1])) ){
|
||||
printf("Usage: %s [AIpower]\n",argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if(argc==2){
|
||||
if( !sscanf(argv[1],"%d",&dpt)){
|
||||
puts("Invalid input.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if( dpt<1 || dpt>= 127){
|
||||
puts("That should be between 1 and 127.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
srand(time(NULL)%UINT_MAX);
|
||||
int input;
|
||||
initscr();
|
||||
@ -322,7 +333,7 @@ int main(int argc, char** argv){
|
||||
init_pair(1,COLOR_BLUE,-1);
|
||||
init_pair(2,COLOR_YELLOW,-1);
|
||||
init_pair(3,COLOR_GREEN,-1);
|
||||
for(byte b= 0;b<6;b++){
|
||||
for(byte b= 0;b<6;++b){
|
||||
colors[b]=COLOR_PAIR(b+1);
|
||||
}
|
||||
|
||||
@ -389,13 +400,13 @@ int main(int argc, char** argv){
|
||||
if( input==KEY_MOUSE )
|
||||
mouseinput(sy,sx);
|
||||
if( (input=='k' || input==KEY_UP) && py>0)
|
||||
py--;
|
||||
--py;
|
||||
if( (input=='j' || input==KEY_DOWN) && py<len-1)
|
||||
py++;
|
||||
++py;
|
||||
if( (input=='h' || input==KEY_LEFT) && px>0)
|
||||
px--;
|
||||
--px;
|
||||
if( (input=='l' || input==KEY_RIGHT) && px<wid-1)
|
||||
px++;
|
||||
++px;
|
||||
if( input=='q')
|
||||
sigint_handler(0);
|
||||
if(!board[py][px] && (input=='s'||input=='S'||input=='o'||input=='O') ){
|
||||
|
136
sources/sudoku.c
136
sources/sudoku.c
@ -1,3 +1,15 @@
|
||||
/*
|
||||
_
|
||||
(_
|
||||
_)UDOKU
|
||||
|
||||
Authored by abakh <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lncurses -lm
|
||||
|
||||
NOTE: This program is only made for entertainment porpuses. The puzzles are generated by randomly clearing tiles on the table and are guaranteed to have a solution , but are not guaranteed to have only one unique solution.
|
||||
*/
|
||||
#include <curses.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -5,24 +17,19 @@
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
#include <math.h>
|
||||
/*
|
||||
_
|
||||
(_
|
||||
_)UDOKU
|
||||
typedef signed char byte;
|
||||
|
||||
Authored by Hossein Bakhtiarifar <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
byte _wait=0, waitcycles=0;//apparently 'wait' conflicts with a variable in a library macOS includes by default
|
||||
byte py,px;
|
||||
byte diff;
|
||||
unsigned int filled;
|
||||
chtype colors[6]={0};
|
||||
|
||||
compile with -lncurses
|
||||
|
||||
NOTE: This program is only made for entertainment porpuses. The puzzles are generated by randomly clearing tiles on the table and are guaranteed to have a solution , but are not guaranteed to have only one unique solution.
|
||||
*/
|
||||
|
||||
/* the Plan9 compiler can not handle VLAs */
|
||||
#if defined Plan9
|
||||
#if defined Plan9 //the Plan9 compiler can not handle VLAs
|
||||
#define size 3
|
||||
#define s 9
|
||||
/* I hope this is approximately right */
|
||||
// I hope this is approximately right
|
||||
int round(float x)
|
||||
{
|
||||
int y;
|
||||
@ -32,21 +39,13 @@ int round(float x)
|
||||
y = (int)(x - 0.5); // the same but opposite
|
||||
return y;
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef signed char byte;
|
||||
byte _wait=0, waitcycles=0;//apparently 'wait' conflicts with a variable in a library macOS includes by default
|
||||
#ifndef Plan9
|
||||
#else
|
||||
byte size,s;//s=size*size
|
||||
#endif
|
||||
byte py,px;
|
||||
byte diff;
|
||||
unsigned int filled;
|
||||
chtype colors[6]={0};
|
||||
void cross(byte sy,byte sx,chtype start,chtype middle,chtype end){ //to simplify drawing tables. doesn't draw a cross (why did I choose that name?)
|
||||
mvaddch(sy,sx,start);
|
||||
byte f = 2*size;
|
||||
for(char n=1;n<size;n++){
|
||||
for(char n=1;n<size;++n){
|
||||
mvaddch(sy,sx+f,middle);
|
||||
f+=2*size;
|
||||
}
|
||||
@ -55,14 +54,14 @@ void cross(byte sy,byte sx,chtype start,chtype middle,chtype end){ //to simplify
|
||||
|
||||
void table(byte sy,byte sx){ //empty table
|
||||
byte l;//line
|
||||
for(l=0;l<=size;l++){
|
||||
for(byte y=0;y<=s+size;y++)
|
||||
for(l=0;l<=size;++l){
|
||||
for(byte y=0;y<=s+size;++y)
|
||||
mvaddch(sy+y,sx+l*size*2,ACS_VLINE);
|
||||
for(byte x=0;x<=s*2;x++)
|
||||
for(byte x=0;x<=s*2;++x)
|
||||
mvaddch(sy+(size+1)*l,sx+x,ACS_HLINE);
|
||||
}
|
||||
cross(sy,sx,ACS_ULCORNER,ACS_TTEE,ACS_URCORNER);
|
||||
for(l=1;l<size;l++)
|
||||
for(l=1;l<size;++l)
|
||||
cross(sy+l*size+l,sx,ACS_LTEE,ACS_PLUS,ACS_RTEE);
|
||||
cross(sy+l*size+l,sx,ACS_LLCORNER,ACS_BTEE,ACS_LRCORNER);
|
||||
}
|
||||
@ -92,18 +91,18 @@ bool isvalid(byte ty,byte tx,char board[s][s]){ //is it allowed to place that ch
|
||||
if(!t)
|
||||
return 0;
|
||||
byte y,x;
|
||||
for(y=0;y<s;y++){
|
||||
for(y=0;y<s;++y){
|
||||
if(board[y][tx] == t && y!=ty)
|
||||
return 0;
|
||||
}
|
||||
for(x=0;x<s;x++){
|
||||
for(x=0;x<s;++x){
|
||||
if(board[ty][x] == t && x!= tx)
|
||||
return 0;
|
||||
}
|
||||
byte sy=size*(ty/size);//square
|
||||
byte sx=size*(tx/size);
|
||||
for(y=0;y<size;y++){
|
||||
for(x=0;x<size;x++){
|
||||
for(y=0;y<size;++y){
|
||||
for(x=0;x<size;++x){
|
||||
if(board[sy+y][sx+x]==t && sy+y != ty && sx+x != tx)
|
||||
return 0;
|
||||
}
|
||||
@ -112,18 +111,18 @@ bool isvalid(byte ty,byte tx,char board[s][s]){ //is it allowed to place that ch
|
||||
}
|
||||
|
||||
void genocide(char board[s][s],char victim){
|
||||
for(byte y=0;y<s;y++)
|
||||
for(byte x=0;x<s;x++)
|
||||
for(byte y=0;y<s;++y)
|
||||
for(byte x=0;x<s;++x)
|
||||
if(board[y][x]==victim)
|
||||
board[y][x]=0;
|
||||
}
|
||||
bool fill_with(char board[s][s],char fillwith){//returns 1 on failure
|
||||
byte firstx,x,tries=0;
|
||||
Again:
|
||||
tries++;
|
||||
++tries;
|
||||
if (tries>s)
|
||||
return 1;
|
||||
for(byte y=0;y<s;y++){//there should be only one occurence of a number in a row, and this function makes use of this fact to improve generation speed
|
||||
for(byte y=0;y<s;++y){//there should be only one occurence of a number in a row, and this function makes use of this fact to improve generation speed
|
||||
firstx=x=rand()%s;
|
||||
while(1){
|
||||
if(!board[y][x]){
|
||||
@ -138,7 +137,7 @@ bool fill_with(char board[s][s],char fillwith){//returns 1 on failure
|
||||
}
|
||||
else{
|
||||
Next:
|
||||
x++;
|
||||
++x;
|
||||
if(x==s)
|
||||
x=0;
|
||||
if(x==firstx){
|
||||
@ -152,11 +151,11 @@ bool fill_with(char board[s][s],char fillwith){//returns 1 on failure
|
||||
return 0;
|
||||
}
|
||||
void fill(char board[s][s]){
|
||||
for(byte num=1;num<=s;num++){//it fills random places in the board with 1s, then random places in the remaining space with 2s and so on...
|
||||
for(byte num=1;num<=s;++num){//it fills random places in the board with 1s, then random places in the remaining space with 2s and so on...
|
||||
if(num==4){//something that randomly happens
|
||||
_wait=(_wait+1)%60;
|
||||
if(!_wait && waitcycles<3)
|
||||
waitcycles++;
|
||||
++waitcycles;
|
||||
}
|
||||
if ( fill_with(board,int2sgn(num) ) ){
|
||||
memset(board,0,s*s);
|
||||
@ -172,8 +171,8 @@ void fill(char board[s][s]){
|
||||
}
|
||||
void swap(char board[s][s],char A,char B){
|
||||
byte y,x;
|
||||
for(y=0;y<s;y++){
|
||||
for(x=0;x<s;x++){
|
||||
for(y=0;y<s;++y){
|
||||
for(x=0;x<s;++x){
|
||||
if(board[y][x]==A)
|
||||
board[y][x]=B;
|
||||
else if(board[y][x]==B)
|
||||
@ -183,27 +182,27 @@ void swap(char board[s][s],char A,char B){
|
||||
}
|
||||
void justfill(char board[s][s]){//sometimes fill() gets too much , and you just want a 49x49 sudoku puzzle of any quality
|
||||
byte y,x,k;//k is here to minimize calls to isvalid()
|
||||
for(y=0;y<s;y++){//fill with 1,2,3,4...
|
||||
for(y=0;y<s;++y){//fill with 1,2,3,4...
|
||||
k=1;
|
||||
for(x=0;x<s;x++){
|
||||
for(x=0;x<s;++x){
|
||||
board[y][x]=int2sgn(k);
|
||||
while(!isvalid(y,x,board)){
|
||||
board[y][x]=int2sgn(k=k+1);
|
||||
if(k>s)
|
||||
board[y][x]=int2sgn(k=1);
|
||||
}
|
||||
k++;
|
||||
++k;
|
||||
if(k>s)
|
||||
k=1;
|
||||
}
|
||||
}
|
||||
for(byte n=0;n<s*2;n++)//randomize
|
||||
for(byte n=0;n<s*2;++n)//randomize
|
||||
swap(board,int2sgn(1+(rand()%s)),int2sgn(1+(rand()%s)) );
|
||||
}
|
||||
void mkpuzzle(char board[s][s],char empty[s][s],char game[s][s]){//makes a puzzle to solve
|
||||
byte y,x;
|
||||
for(y=0;y<s;y++){
|
||||
for(x=0;x<s;x++){
|
||||
for(y=0;y<s;++y){
|
||||
for(x=0;x<s;++x){
|
||||
if( !(rand()%diff) ){
|
||||
empty[y][x]=board[y][x];
|
||||
game[y][x]=board[y][x];
|
||||
@ -222,8 +221,8 @@ void draw(byte sy,byte sx,char empty[s][s],char game[s][s]){
|
||||
chtype attr;
|
||||
table(sy,sx);
|
||||
filled=0;
|
||||
for(byte y=0;y<s;y++){
|
||||
for(byte x=0;x<s;x++){
|
||||
for(byte y=0;y<s;++y){
|
||||
for(byte x=0;x<s;++x){
|
||||
attr=A_NORMAL;
|
||||
if(x==px && y==py)
|
||||
attr |= A_STANDOUT;
|
||||
@ -234,7 +233,7 @@ void draw(byte sy,byte sx,char empty[s][s],char game[s][s]){
|
||||
attr |= colors[5];
|
||||
else{
|
||||
attr |= colors[game[y][x]%5];
|
||||
filled++;
|
||||
++filled;
|
||||
}
|
||||
mvaddch(sy+y+y/size+1,sx+x*2+1,attr|game[y][x]);
|
||||
}
|
||||
@ -320,6 +319,7 @@ void gameplay(void){
|
||||
}
|
||||
int main(int argc,char** argv){
|
||||
signal(SIGINT,sigint_handler);
|
||||
#ifndef Plan9
|
||||
if(argc>4 || (argc==2 && !strcmp("help",argv[1])) ){
|
||||
printf("Usage: %s [size [ difficulty]] \n",argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
@ -329,15 +329,11 @@ int main(int argc,char** argv){
|
||||
printf("2 <= size <= 7\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
#ifndef Plan9
|
||||
else
|
||||
size = *argv[1]-'0';
|
||||
#endif
|
||||
}
|
||||
else
|
||||
#ifndef Plan9
|
||||
size=3;
|
||||
#endif
|
||||
if(argc>2){
|
||||
if (strlen(argv[2])>1 || argv[2][0]-'0'>4 || argv[2][0]-'0'<= 0 ){
|
||||
printf("1 <= diff <=4\n");
|
||||
@ -348,6 +344,22 @@ int main(int argc,char** argv){
|
||||
}
|
||||
else
|
||||
diff=2;
|
||||
#else //Plan9 doesn't take size
|
||||
if(argc>2 || (argc==2 && !strcmp("help",argv[1])) ){
|
||||
printf("Usage: %s [difficulty]\n",argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if(argc>1){
|
||||
if (strlen(argv[2])>1 || argv[2][0]-'0'>4 || argv[2][0]-'0'<= 0 ){
|
||||
printf("1 <= diff <=4\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else
|
||||
diff = *argv[2]-'0'+1;
|
||||
}
|
||||
else
|
||||
diff=2;
|
||||
#endif
|
||||
bool fastgen= !(!getenv("SUDOKU_FASTGEN"));
|
||||
initscr();
|
||||
mousemask(ALL_MOUSE_EVENTS,NULL);
|
||||
@ -364,7 +376,7 @@ int main(int argc,char** argv){
|
||||
init_pair(4,COLOR_CYAN,-1);
|
||||
init_pair(5,COLOR_MAGENTA,-1);
|
||||
init_pair(6,COLOR_RED,-1);
|
||||
for(byte b=0;b<6;b++){
|
||||
for(byte b=0;b<6;++b){
|
||||
colors[b]=COLOR_PAIR(b+1);
|
||||
}
|
||||
}
|
||||
@ -426,13 +438,13 @@ int main(int argc,char** argv){
|
||||
if(input == KEY_MOUSE)
|
||||
mouseinput(sy,sx);
|
||||
if(input == KEY_UP && py)
|
||||
py--;
|
||||
--py;
|
||||
if(input == KEY_DOWN && py<s-1)
|
||||
py++;
|
||||
++py;
|
||||
if(input == KEY_LEFT && px)
|
||||
px--;
|
||||
--px;
|
||||
if(input == KEY_RIGHT && px<s-1)
|
||||
px++;
|
||||
++px;
|
||||
if(!empty[py][px]){
|
||||
if(input == ' ' )
|
||||
game[py][px]=0;
|
||||
@ -445,8 +457,8 @@ int main(int argc,char** argv){
|
||||
goto Start;
|
||||
if(input=='r'&& size <= 5){
|
||||
byte y,x;
|
||||
for(y=0;y<s;y++)
|
||||
for(x=0;x<s;x++)
|
||||
for(y=0;y<s;++y)
|
||||
for(x=0;x<s;++x)
|
||||
game[y][x]=empty[y][x];
|
||||
}
|
||||
|
||||
@ -454,8 +466,8 @@ int main(int argc,char** argv){
|
||||
game[py][px]=board[py][px];
|
||||
if(input == 'X' && getch()=='Y' && getch()=='Z' && getch()=='Z' && getch()=='Y'){
|
||||
byte y,x;
|
||||
for(y=0;y<s;y++)
|
||||
for(x=0;x<s;x++)
|
||||
for(y=0;y<s;++y)
|
||||
for(x=0;x<s;++x)
|
||||
game[y][x]=board[y][x];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user