コード例 #1
0
ファイル: tttnew.c プロジェクト: shubhamchaudhary/uiet
int score(char **board, char piece1, char piece2) {
   char winner = checkwin(board, piece1);
   if (winner == piece1)
      return WIN;
   else if (winner == ' ')
      return TIE;
   else if (checkwin(board, piece2) == piece2)
      return LOSS;
   else
      return CONTINUE;
}
コード例 #2
0
int terminal_test(char **board) {
  //if player 1 wins
  if (checkwin(board, PLAYER1) == PLAYER1) {	
    return -1;
  } //if player 2 wins
  else if (checkwin(board, PLAYER2) == PLAYER2) {
    return 1;
  } //if tie
  else if ((checkwin(board, PLAYER1) == ' ') && (checkwin(board, PLAYER2) == ' ')) {
    return 0;
  } //if game not yet over
  else {
    return INCOMPLETE; 
  }
}
コード例 #3
0
ファイル: moc_awari.cpp プロジェクト: varshashastri/varsha
bool awari::qt_invoke( int _id, QUObject* _o )
{
    switch ( _id - staticMetaObject()->slotOffset() ) {
    case 0: reset(); break;
    case 1: takeopp((QValueList<int>::iterator)(*((QValueList<int>::iterator*)static_QUType_ptr.get(_o+1))),(int)static_QUType_int.get(_o+2)); break;
    case 2: display(); break;
    case 3: p1_clicked(); break;
    case 4: p2_clicked(); break;
    case 5: p3_clicked(); break;
    case 6: p4_clicked(); break;
    case 7: p5_clicked(); break;
    case 8: movec5(); break;
    case 9: movec4(); break;
    case 10: movec3(); break;
    case 11: movec2(); break;
    case 12: movec1(); break;
    case 13: movecomp(); break;
    case 14: movecomp((QValueList<int>::iterator)(*((QValueList<int>::iterator*)static_QUType_ptr.get(_o+1)))); break;
    case 15: checkwin(); break;
    case 16: comp1st_clicked(); break;
    case 17: spinBox_valueChanged((int)static_QUType_int.get(_o+1)); break;
    case 18: ok_clicked(); break;
    case 19: languageChange(); break;
    default:
	return QWizard::qt_invoke( _id, _o );
    }
    return TRUE;
}
コード例 #4
0
ファイル: loto.c プロジェクト: denrusio/vak-opensource
int main ()
{
	int i;

	srand ((int) time ((long *) 0));

	for (i=0; i<NPLAY; i++) {
		printf ("Введите имя %s игрока: ", z1[i]);
		gets (name[i]);
		if (! name[i][0]) break;
		name[i][7] = '\0';
	}
	if (! (num = i)) exit (0);

	for (nround=1; ; nround++) {
		for (player=0; player<num; player++) {
			printround ();
			delta = step ();
			if (delta) {
				changes ();
				checkwin ();
			}
		}
	}
}
コード例 #5
0
int main() {
  int i,j;
  char again[2],winner,**board;
   
  board=(char**)malloc(sizeof(char*)*3);
  for (i=0; i<3; i++) {
    board[i]=(char*)malloc(sizeof(char)*3);
  }
  
  printf("\nWelcome to a game of Tic-Tac-Toe!\n");   
  do {
    board=initboard(board);
    displayboard(board);
    do {
      board=human_move(board,PLAYER1);
  	  displayboard(board);
	    winner=checkwin(board,PLAYER1);
    	if (winner!=PLAYER1 && winner!=' ') {
	      if (computer_move(board,PLAYER2,PLAYER1)) {
	        winner=checkwin(board,PLAYER2);
	      } else {
          printf("\nComputer passed\n");
	      }
	      displayboard(board);
	    }
	  } while (winner==BLANK);
	  
  	if (winner!=' ') {
  	  printf("THE WINNER IS %c!\n",winner);
  	} else {
	    printf("IT'S A TIE.\n");
	  }	 
	  
  	printf("\nPlay again (y)?: ");
	  scanf("%s",again);
  } while(again[0]=='y');

  for (i=0; i<3; i++) {
    free(board[i]);
  }
  free(board);
   
  printf("\nThank you for playing.\n\n");
  return 0;
}
コード例 #6
0
int computer_ai(int board[3][3], int level, int moves) {
    int wincheck, x, y, placesuccess, noderootmax, bestnodex, bestnodey, bestnoderootmax, numvalues=0, p, q;
    int boardcopy[3][3] = { { 0 } };
    int values[3][9] = { { 0 } };

    for (x = 0; x < 3; x++) {
        for (y = 0; y < 3; y++) {
            for (p = 0; p < 3; p++) {
                for (q = 0; q < 3; q++) {
                    boardcopy[p][q] = board[p][q];
                }
            }
            placesuccess = placeitem(1, x, y, boardcopy, 1, 0);
            if (placesuccess == 0) {
                wincheck = checkwin(boardcopy);
                if (wincheck == 1 && level == 1) {
                    placeitem(1, x, y, board, 1, 1);
                    return 0;
                } else if (wincheck == 1 && level > 1) {
                    return 1;
                } else if (wincheck == -1) {
                    noderootmax = 0;
                    if (moves + 1 < 9) {
                        noderootmax = human_predictor(boardcopy, level + 1, moves + 1);
                    }
                    if (moves + 1 == 9) {
                        return 0;
                    }
                    if (noderootmax > -100) {
                        values[0][numvalues] = noderootmax;
                        values[1][numvalues] = x;
                        values[2][numvalues] = y;
                        numvalues++;
                    }
                }
            }
        }
    }

    bestnoderootmax = values[0][0];
    bestnodex = values[1][0];
    bestnodey = values[2][0];
    for (x = 0; x < numvalues-1; x++) {
        if (values[0][x+1] > values[0][x]) {
            bestnoderootmax = values[0][x+1];
            bestnodex = values[1][x+1];
            bestnodey = values[2][x+1];
        }
    }
    if (level == 1) {
        return placeitem(1, bestnodex, bestnodey, board, 1, 1);
    } else {
        return bestnoderootmax;
    }
}
コード例 #7
0
ファイル: TIC-TAC~TOE.CPP プロジェクト: RajanAghera/TicTacToe
int main()
{
	int player = 1,i,choice;
	char mark;
	clrscr();
	do
	{
		board();
		player = ( player % 2 ) ? 1 : 2 ;
		cout << "Player " << player << ", enter a number:  ";
		cin >> choice;
		mark=(player == 1) ? 'X' : 'O';
		if (choice == 1 && square[1] == '1')
			square[1] = mark;
		else if (choice == 2 && square[2] == '2')
			square[2] = mark;
		else if (choice == 3 && square[3] == '3')
			square[3] = mark;
		else if (choice == 4 && square[4] == '4')
			square[4] = mark;
		else if (choice == 5 && square[5] == '5')
			square[5] = mark;
		else if (choice == 6 && square[6] == '6')
			square[6] = mark;
		else if (choice == 7 && square[7] == '7')
			square[7] = mark;
		else if (choice == 8 && square[8] == '8')
			square[8] = mark;
		else if (choice == 9 && square[9] == '9')
			square[9] = mark;
		else
		{
			cout<<"Invalid move ";
			player--;
			getch();
		}
		i=checkwin();
		player++;
	}while(i==-1);
	board();
	if(i==1)
		cout<<"==>\aPlayer "<<--player<<" win ";
	else
		cout<<"==>\aGame draw";
	getch();
	return 0;
}
コード例 #8
0
int human_predictor(int board[3][3], int level, int moves) {
    int wincheck, x, y, placesuccess, noderootmin, bestnoderootmin, numvalues=0, p, q;
    int boardcopy[3][3] = { { 0 } };
    int values[3][9] = { { 0 } };

    for (x = 0; x < 3; x++) {
        for (y = 0; y < 3; y++) {
            for (p = 0; p < 3; p++) {
                for (q = 0; q < 3; q++) {
                    boardcopy[p][q] = board[p][q];
                }
            }

            placesuccess = placeitem(0, x, y, boardcopy, 1, 0);

            if (placesuccess == 0) {
                wincheck = checkwin(boardcopy);
                if (wincheck == 0) {
                    return -1;
                } else if (wincheck == -1) {
                    if (moves + 1 == 9) {
                        return 0;
                    }
                    noderootmin = 0;
                    noderootmin = computer_ai(boardcopy, level + 1, moves + 1);
                    if (noderootmin < 100) {
                        values[0][numvalues] = noderootmin;
                        values[1][numvalues] = x;
                        values[2][numvalues] = y;
                        numvalues++;
                    }
                }
            }
        }
    }

    bestnoderootmin = values[0][0];
    for (x = 0; x < numvalues-1; x++) {
        if (values[0][x+1] < values[0][x]) {
            bestnoderootmin = values[0][x+1];
        }
    }
    return bestnoderootmin;
}
コード例 #9
0
ファイル: mc.c プロジェクト: order-and-chaos/client
static int playthrough(Board board,int player){
	(void)player;
	int win;
	Move poss[2*N*N];
	int nposs;
	while(true){
		win=checkwin(&board);
		if(win!=-1)return 1-2*win;

		nposs=0;
		for(int p=0;p<N*N;p++){
			for(int stone=0;stone<2;stone++){
				if(!ISEMPTY(board.b[0]|board.b[1],p))continue;
				poss[nposs].pos=p;
				poss[nposs++].stone=stone;
			}
		}
		assert(nposs>0); //else Chaos would've won

		int i=random()%nposs;
		APPLY(board.b[poss[i].stone],poss[i].pos);
	}
}
コード例 #10
0
int main() {
    int player = 0, moves = 0, end = -1, x, y, successplace;
    int board[3][3] = { { 0 } };

    do {
        successplace = 1;
        printf("Player %d's turn\n", player + 1);

        if (player == 1) {
            x = computer_ai(board, 1, moves);
        } else {
            do {
                x = getcoord(0); /* input and checks bounds */
                y = getcoord(1);
                successplace = placeitem(player, x-1, y-1, board, 0, 1);
            } while (successplace == 1);
        }

        printmap(board);

        if (moves > 3) {
            end = checkwin(board);
        }

        moves++;
        player = (player + 1) % 2;
    } while (end == -1 && moves < 9);

    if (end == -1) {
        printf("Draw\n");
    } else {
        printf("Player %d wins!\n", end + 1);
    }

    return EXIT_SUCCESS;
}
コード例 #11
0
ファイル: XO.c プロジェクト: miwtoo/XO-C-Project
int main(){
    int count = 1, num, player;
    char mark;


    printf("\n\n\t   XO by Miwtoo\n\n\n");
    printf("\t              \n");
    printf("\t\n");
    printf("\t     %c | %c | %c  \n", '1', '2', '3');
    printf("\t    ---+---+---\n");
    printf("\t     %c | %c | %c  \n", '4', '5', '6');
    printf("\t    ---+---+---\n");
    printf("\t     %c | %c | %c  \n", '7', '8', '9');
    printf("\t\n\n\n");

    printf("Press any key to continue...\n");
    getch();
    system("cls");

    do{
        player = (count%2 == 1) ? 1:2;
        mark = (player == 1) ? 'X':'O';
        board();

        printf("Round %d\n\n", count);

        if(player == 1){
            printf("Player %d(%c) : ",player,mark);
            scanf("%d", &num);
        }
        else{
            num = ai(num);
        }

        if(num == 1 && square[1] == '1'){
            square[1] = mark;
        }
        else if(num == 2 && square[2] == '2'){
            square[2] = mark;
        }
        else if(num == 3 && square[3] == '3'){
            square[3] = mark;
        }
        else if(num == 4 && square[4] == '4'){
            square[4] = mark;
        }
        else if(num == 5 && square[5] == '5'){
            square[5] = mark;
        }
        else if(num == 6 && square[6] == '6'){
            square[6] = mark;
        }
        else if(num == 7 && square[7] == '7'){
            square[7] = mark;
        }
        else if(num == 8 && square[8] == '8'){
            square[8] = mark;
        }
        else if(num == 9 && square[9] == '9'){
            square[9] = mark;
        }
        else{
            while(num >= 9){
                printf("Please Enter number 1-9!!\n");
                printf("Player %d : ",player);
                scanf("%d", &num);
            }
        }

        count++;
        system("cls");
    }while(checkwin() != 1);

    board();
    printf("Player %d Win!!!\n",player);
    getch();

    return 0;
}
コード例 #12
0
ファイル: tttnew.c プロジェクト: shubhamchaudhary/uiet
int main()
{
   srand((time(0)));

   int i,j;
   char again[2],winner,**board,agin='y';

   board=(char**)malloc(sizeof(char*)*3);
   for (i=0; i<3; i++)
      board[i]=(char*)malloc(sizeof(char)*3);

    do {
        board=initboard(board);
        char first = 'y';
        printf("Play first? ");
        scanf("%c",&first);
        displayboard(board);
        if (first == 'y'){
            do {
                board=human_move(board,PLAYER1);
                displayboard(board);
                winner=checkwin(board,PLAYER1);
                if (winner!=PLAYER1 && winner!=' ') {
                   if (computer_move(board,PLAYER2,PLAYER1))
                       winner=checkwin(board,PLAYER2);
                   else
                       printf("\nComputer passed\n");
                   displayboard(board);
                }
            } while (winner==BLANK);
        }else{
            do{
                if (computer_move(board,PLAYER2,PLAYER1))
                   winner=checkwin(board,PLAYER2);
               else
                   printf("\nComputer passed\n");
               displayboard(board);
               if (winner!=PLAYER2 && winner!=' ') {
                    board=human_move(board,PLAYER1);
                    winner=checkwin(board,PLAYER1);
                    displayboard(board);
               }
            }while (winner == BLANK);
        }

        if (winner!=' ')
            printf("THE WINNER IS %c!\n",winner);
        else
            printf("IT'S A TIE.\n");

        printf("\nPlay again (y)?: ");
        scanf("%s",again);
        getchar();
    } while(again[0]=='y');
//         getchar();
//         scanf("%c",&agin);
//     } while(agin=='y');

    //Free Allocated Space
    for (i=0; i<3; i++)
        free(board[i]);
    free(board);

   printf("\nThank you for playing.\n\n");
   return 0;
}
コード例 #13
0
ファイル: fifteen.cpp プロジェクト: opieproject/opie
void PiecesTable::mousePressEvent(QMouseEvent* e)
{
  QTableView::mousePressEvent(e);

  if (e->button() == RightButton) {

    // setup RMB pupup menu
    if(!_menu) {
      _menu = new QPopupMenu(this);
      _menu->insertItem(tr("R&andomize Pieces"), mRandomize);
      _menu->insertItem(tr("&Reset Pieces"), mReset);
      _menu->adjustSize();
    }

    // execute RMB popup and check result
    switch(_menu->exec(mapToGlobal(e->pos()))) {
    case mRandomize:
      randomizeMap();
      break;
    case mReset:
      initMap();
      repaint();
      break;
    default:
      break;
    }
  }
  else {
    // GAME LOGIC
    int cols = numCols();
    int rows = numRows();
    int item = cols*rows -1;

    // find the free position
    int pos = _map.find(item);
    if(pos < 0) return;

    int frow = pos / cols;
    int fcol = pos - frow * cols;

    // find click position
    int row = findRow(e->y());
    int col = findCol(e->x());

    // sanity check
    if (row < 0 || row >= rows) return;
    if (col < 0 || col >= cols) return;
    if ( row != frow && col != fcol ) return;

    // valid move?
    if(row != frow && col != fcol) return;

    // rows match -> shift pieces
    if(row == frow) {

      if (col < fcol) {
	for(int c = fcol; c > col; c--) {
	  _map[c + row * cols] = _map[ c-1 + row *cols];
	  updateCell(row, c, false);
	}
      }
      else if (col > fcol) {
	for(int c = fcol; c < col; c++) {
	  _map[c + row * cols] = _map[ c+1 + row *cols];
	  updateCell(row, c, false);
	}
      }
    }
    // cols match -> shift pieces
    else if (col == fcol) {

      if (row < frow) {
	for(int r = frow; r > row; r--) {
	  _map[col + r * cols] = _map[ col + (r-1) *cols];
	  updateCell(r, col, false);
	}
      }
      else if (row > frow) {
	for(int r = frow; r < row; r++) {
	  _map[col + r * cols] = _map[ col + (r+1) *cols];
	  updateCell(r, col, false);
	}
      }
    }
    // move free cell to click position
    _map[col + row * cols] = item;
    updateCell(row, col, false);

    // check if the player wins with this move
    checkwin();
  }
}
コード例 #14
0
ファイル: tic.c プロジェクト: IcaroKeller/TicTacToe-1
//Startmethod
int main(int argc, char** argv) {
int xx = 0;
    printf("Welcome to TicTacToe_CLI Version %i.%i!\n", version, subversion);

    do { //mainloop
    
            //Draw the fields
            draw(fields);
            
            //Choose Player
            if (player == 2) {
                player--;
                xro = 'x';
            }else{
                player++;
                xro = 'o';
            }
            do {
                //Scan input
                printf("\nEscolha um número, Jogador%i: ", player);
                scanf("%i", &userinput);
                getchar();
		
		if (userinput < 1 || userinput > 9){
                printf("\nNumero digitado foi: >%i<! Este numero é inválido!\n", userinput);
		}
		switch (userinput) {
		case 1:		
		if (fields[7] == 'x' || fields[7] == 'o') {
			printf("\nNumero digitado foi: >%i<! Este numero é inválido!\n", userinput);
			userinput = 0;
		}else{
		fields[7] = xro;
		}
		break;
		case 2:		
            	if (fields[8] == 'x' || fields[8] == 'o') {
			printf("\nNumero digitado foi: >%i<! Este numero é inválido!\n", userinput);
			userinput = 0;
		}else{
		fields[8] = xro;
		}
		break;
		case 3:		
            	if (fields[9] == 'x' || fields[9] == 'o') {
			printf("\nNumero digitado foi: >%i<! Este numero é inválido!\n", userinput);
			userinput = 0;
		}else{
		fields[9] = xro;
		}
		break;
		case 4:		
            	if (fields[4] == 'x' || fields[4] == 'o') {
			printf("\nNumero digitado foi: >%i<! Este numero é inválido!\n", userinput);
			userinput = 0;
		}else{
		fields[4] = xro;
		}
		break;
		case 5:		
            	if (fields[5] == 'x' || fields[5] == 'o') {
			printf("\nNumero digitado foi: >%i<! Este numero é inválido!\n", userinput);
			userinput = 0;
		}else{
		fields[5] = xro;
		}
		break;
		case 6:		
            	if (fields[6] == 'x' || fields[6] == 'o') {
			printf("\nNumero digitado foi: >%i<! Este numero é inválido!\n", userinput);
			userinput = 0;
		}else{
		fields[6] = xro;
		}
		break;
		case 7:		
            	if (fields[1] == 'x' || fields[1] == 'o') {
			printf("\nNumero digitado foi: >%i<! Este numero é inválido!\n", userinput);
			userinput = 0;
		}else{
		fields[1] = xro;
		}
		break;
		case 8:		
            	if (fields[2] == 'x' || fields[2] == 'o') {
			printf("\nNumero digitado foi: >%i<! Este numero é inválido!\n", userinput);
			userinput = 0;
		}else{
		fields[2] = xro;
		}
		break;
		case 9:		
            	if (fields[3] == 'x' || fields[3] == 'o') {
			printf("\nNumero digitado foi: >%i<! Este numero é inválido!\n", userinput);
			userinput = 0;
		}else{
		fields[3] = xro;
		}
		break;
		}

            }while(userinput < 1 || userinput > 9);
            
            //set input9


	    
            //Clear
            system("clear");
            
            //Check if someone has won
            checkwin();
            
            //Check if the Game is over and nobody wins
            checkloose();
    
        }while(loop == 0);
    
    return 0;
}
コード例 #15
0
ファイル: winmine.c プロジェクト: lytsing/ytht
void
winloop()
{
	int x, y, c, marked, t0, inited;
	char buf[100];
	x = 10;
	y = 8;
	inited = 0;
	marked = 0;
	clearbuf();
	t0 = time(0);
	while (1) {
		c = egetch();
		if (c == 257 && y > 1)
			y--;
		if (c == 258 && y < 16)
			y++;
		if (c == 260 && x > 1)
			x--;
		if (c == 259 && x < 30)
			x++;
		move(0, 20);
		sprintf(buf, "ʱ¼ä: %d ", (int) (time(0) - t0));
		prints(buf);
		move(40, 20);
		sprintf(buf, "񈬀: %d ", marked);
		prints(buf);
		move(0, 22);
		sprintf(buf, "×ø±ê: %3d, %3d", x, y);
		prints(buf);
		move(x * 2 - 2, y - 1);
		if (c == 'h' || c == 'H')
			winhelp();
		if (c == 'd' || c == 'D')
			winrefresh();
		if (c == 'a' || c == 'A') {
			if (!inited) {
				wininit(x, y);
				inited = 1;
			}
			dig(x, y);
		}
		if ((c == 83 || c == 115) && !o[x][y]) {
			if (m[x][y]) {
				m[x][y] = 0;
				marked--;
			} else {
				m[x][y] = 1;
				marked++;
			}
			winsh(x, y);
		}
		if (checkwin() == 1) {
			move(0, 22);
			prints("×£ºØÄ㣡Äã³É¹¦ÁË£¡                    ");
			{
				char buf[100];
				sprintf(buf, "finished in %d s.",
					(int) (time(0) - t0));
				win_checkrec(time(0) - t0);
				winminelog(buf);
			}
			gameover = 0;
			return;
		}
		if (gameover) {
			move(0, 22);
			prints("ºÜÒź¶£¬Äãʧ°ÜÁË... ÔÙÀ´Ò»´Î°É£¡    ");
			{
				char buf[100];
				sprintf(buf, "failed in %d s.",
					(int) (time(0) - t0));
				winminelog(buf);
			}
			gameover = 0;
			return;
		}
		move(x * 2 - 2, y - 1);
		refresh();
	}
}
コード例 #16
0
ファイル: singleplayer.c プロジェクト: order-and-chaos/client
void startsingleplayer(){
	const int player=ORDER;

	clearscreen();
	moveto(0,0);
	setbold(true);
	tprintf("Order & Chaos -- Single player");
	setbold(false);

	Board *board=makeboard();

	int curx=0,cury=0;
	bool aiturn=false;
	Move mv;
	int win=-1;
	while(true){
		moveto(2,2);
		tprintboard(board);
		redraw();

		if(win!=-1)break;

		if(aiturn){
			aiturn=false;
			moveto(0,N+3);
			tprintf("Calculating...");
			redraw();
			mv=calcmove(board,!player);
			applymove(board,mv);
			win=checkwin(board);
			if(win!=-1)break;
			moveto(0,N+3);
			tprintf("              ");
			continue;
		}

		moveto(2+2*curx,2+cury);
		redraw();
		int key=tgetkey();
		int stone;
		switch(key){
			case 'q':
				moveto(0,N+3);
				setbold(true);
				tprintf("Really quit? [y/N] ");
				setbold(false);
				redraw();
				key=tgetkey();
				if(key=='y'||key=='Y')return;
				moveto(0,N+3);
				tprintf("                  ");
				break;

			case 'h': case KEY_LEFT:
				if(curx>0)curx--; else bel();
				break;

			case 'j': case KEY_DOWN:
				if(cury<N-1)cury++; else bel();
				break;

			case 'k': case KEY_UP:
				if(cury>0)cury--; else bel();
				break;

			case 'l': case KEY_RIGHT:
				if(curx<N-1)curx++; else bel();
				break;

			case 'x':
				stone=XX;
				if(false){
			case 'o':
					stone=OO;
				}
				if(!isempty(board,N*cury+curx)){
					bel();
					break;
				}
				mv.pos=N*cury+curx;
				mv.stone=stone;
				applymove(board,mv);
				win=checkwin(board);
				if(win!=-1)break;
				aiturn=true;
				break;


			default:
				bel();
				break;
		}
	}

	moveto(0,N+3);
	setbold(true);
	const char *plstr=win==ORDER?"Order":"Chaos";
	if(win==player)tprintf("You (%s) won! Congratulations!",plstr);
	else tprintf("The AI (%s) won! Better next time...",plstr);
	setbold(false);
	redraw();
	tgetkey();
}
コード例 #17
0
ファイル: k2.cpp プロジェクト: Mityai/nncworkspaces
int main() {
  freopen("tictactoe.in", "r", stdin);
  freopen("tictactoe.out", "w", stdout);
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i <= n + 12; i++)  
    for (int j = 0; j <= m + 12; j++)
      s[i][j] = '.';
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int c = getchar();
      while (c <= 32) c = getchar();
      s[i + 6][j + 6] = c;
    }
  }   
  n += 12;
  m += 12;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] != '0') continue;
      for (int dx = -1; dx <= 1; dx++) {
        for (int dy = -1; dy <= 1; dy++) {
          if (dx == 0 && dy == 0) continue;
          bool allhas = true;
          int x = i;
          int y = j;
          for (int f = 0; f < 4; f++) {
            allhas &= s[x][y] == '0';
            x += dx;
            y += dy;
          }
          allhas &= s[x][y] == '.';
          if (allhas) {
            bad[x][y] = true;
          }
        }
      }
    }
  }
  int cnbad = 0;
  int ibad = -1;
  int jbad = -1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) if (bad[i][j]) {
      ++cnbad;
      ibad = i;
      jbad = j;
    }
  V = 10;
  if (cnbad > 1) {
    puts("0");
    return 0;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] != '.') continue;
      s[i][j] = 'X';
      if (checkwin1(std::max(0, i - 7), std::min(n - 1, i + 7), 
                   std::max(0, j - 7), std::min(m - 1, j + 7)) || 
                   (!(ibad >= 0 && (i != ibad || j != jbad)) && 
                   checkwin(std::max(0, i - 7), std::min(n - 1, i + 7), 
                   std::max(0, j - 7), std::min(m - 1, j + 7)))) {
        ++ans;
      }
      s[i][j] = '.';
    }
  }
  printf("%d\n", ans);
}
コード例 #18
0
ファイル: winmine.c プロジェクト: marvelliu/lilacsrc
int winloop()
{
    int x, y, c, marked, t0, inited;
    x= 10;
    y= 8;
    inited= 0; 
    marked= 0; 
    t0=time(0);
    steps=0;
    while(1) {
        c= igetkey();
			//system("echo start_winloop_igetkey >> /home/bbs/stiger.test");
		steps++;
		if(c=='q' || c==Ctrl('C')) return 0;
        if((c==KEY_UP||c=='k')&&y>1) y--;
        if((c==KEY_DOWN||c=='j')&&y<16) y++;
        if((c==KEY_LEFT||c=='h')&&x>1) x--;
        if((c==KEY_RIGHT||c=='l')&&x<30) x++;
        move(20,0);
        prints("й╠╪Д: %d ", time(0)-t0);
        move(21,0);
        prints("вЬ╠Й: %3d, %3d", x, y);
        move(y-1,x*2-2);
//modified by stiger,2001,6,12,╦дуЩmarkedмЁ╪ф╣д╢МнС
        if(ganyingshi)
        {
        	marknum=o[x-1][y-1]+o[x-1][y]+o[x-1][y+1]+o[x][y-1]+o[x][y+1]+o[x+1][y-1]+o[x+1][y]+o[x+1][y+1];
        	if((m[x][y]!=1)&&(num_mine_beside(x, y)==8-marknum)) {
        	    	if(o[x-1][y-1]!=1) { if(!m[x-1][y-1]) {m[x-1][y-1]=1;   marked++; }  winsh(x-1,y-1);}     	
        		if(o[x-1][y]!=1) { if(!m[x-1][y]) {m[x-1][y]=1;   marked++; } winsh(x-1,y);}     	
        		if(o[x-1][y+1]!=1) { if(!m[x-1][y+1]) {m[x-1][y+1]=1;   marked++;}  winsh(x-1,y+1);}     	
        		if(o[x][y-1]!=1) { if(!m[x][y-1]) {m[x][y-1]=1;   marked++; } winsh(x,y-1);}     	
        		if(o[x][y+1]!=1) { if(!m[x][y+1]) {m[x][y+1]=1;   marked++;}  winsh(x,y+1);}
        		if(o[x+1][y-1]!=1) { if(!m[x+1][y-1]) {m[x+1][y-1]=1;   marked++;}  winsh(x+1,y-1);}     	
        		if(o[x+1][y]!=1) { if(!m[x+1][y]) {m[x+1][y]=1;   marked++;}  winsh(x+1,y);}     	
         		if(o[x+1][y+1]!=1) { if(!m[x+1][y+1]) {m[x+1][y+1]=1;   marked++;}  winsh(x+1,y+1);}     	
        	}
        	if(num_mine_beside(x, y)==num_mark_beside(x, y)) dblclick(x,y); 
        }
//add by stiger,2001,6,12,╦дуЩmarkedотй╬╣днйлБ
        move(20,30);
        prints("╠Й╪г: %d ", marked);
//add end
        if(c=='H') winhelp();
        if(c=='d'|| c=='D') winrefresh();
        if(c=='f'|| c=='F'){
             if(!inited) {
                  wininit(x, y);
                  inited= 1;
             } 
             dig(x, y);      
        } 
        if((c==83|| c==115)&&!o[x][y]) {
             if(m[x][y]){
                  m[x][y]=0;
                  marked--;
             } else {
                  m[x][y]=1;
                  marked++;
             }
             winsh(x, y);
//add by stiger,2001,6,12
        	move(20,30);
        	prints("╠Й╪г: %d ", marked);
//add end
        }
        if(checkwin()==1) {
            /*add by stiger*/
            stiger=steps*1.0/(time(0)-t0);
            move(22,0);
            prints("вё╨ьдЦё║дЦЁи╧╕акё║ф╫╬Ыц©цК%lf╡╫",stiger);
            gameover= 0;
 	    	win_checkrec(time(0)-t0);/* added by soff ╫Ьппеепп╪Л╡И */
            return 1;
        }
        if(gameover) {
            move(22,0);
            prints("╨эре╨╤ё╛дЦй╖╟эак... тыю╢р╩╢н╟иё║                                 ");
            gameover= 0;
            return 1;
        }
        move(y-1,x*2-2);
        refresh();
    }
	return 1;
}
コード例 #19
0
ファイル: winmine.c プロジェクト: caidongyun/fbbs
int winloop()
{
    int x, y, c, marked, t0, inited;
    char buf[100];
    x= 10;
    y= 8;
    inited= 0; 
    marked= 0; 
    clearbuf();
    t0= time(0);
    while(1) {
        c= egetch();
        if((c==257||c=='k')&&y>1) y--;
        if((c==258||c=='j')&&y<16) y++;
        if((c==260||c=='h')&&x>1) x--;
        if((c==259||c=='l')&&x<30) x++;
        move(0, 20);
        //% sprintf(buf, "时间: %ld ", time(0)-t0);
        sprintf(buf, "\xca\xb1\xbc\xe4: %ld ", time(0)-t0);
        prints(buf);
        move(40, 20);
        //% sprintf(buf, "标记: %d ", marked);
        sprintf(buf, "\xb1\xea\xbc\xc7: %d ", marked);
        prints(buf);
        move(0, 21);
        //% sprintf(buf, "坐标: %3d, %3d", x, y);
        sprintf(buf, "\xd7\xf8\xb1\xea: %3d, %3d", x, y);
        prints(buf);
        move(x*2-2, y-1);
        if(c=='H') winhelp();
        if(c=='d'|| c=='D') winrefresh();
        if(c=='f'|| c=='F'){
             if(!inited) {
                  wininit(x, y);
                  inited= 1;
             } 
             dig(x, y);      
        } 
        if((c==83|| c==115)&&!o[x][y]) {
             if(m[x][y]){
                  m[x][y]=0;
                  marked--;
             } else {
                  m[x][y]=1;
                  marked++;
             }
             winsh(x, y);
        }
        if(checkwin()==1) {
            move(0, 22);
            //% prints("祝贺你!你成功了!                    ");
            prints("\xd7\xa3\xba\xd8\xc4\xe3\xa3\xa1\xc4\xe3\xb3\xc9\xb9\xa6\xc1\xcb\xa3\xa1                    ");
            {  char buf[100];
               sprintf(buf, "finished in %ld s.", time(0)-t0);
               syslog(buf);
            }
            gameover= 0;
 	    win_checkrec(time(0)-t0);/* added by soff 进行排行检查 */
            return;
        }
        if(gameover) {
            move(0, 22);
            //% prints("很遗憾,你失败了... 再来一次吧!                                 ");
            prints("\xba\xdc\xd2\xc5\xba\xb6\xa3\xac\xc4\xe3\xca\xa7\xb0\xdc\xc1\xcb... \xd4\xd9\xc0\xb4\xd2\xbb\xb4\xce\xb0\xc9\xa3\xa1                                 ");
            {  char buf[100];
               sprintf(buf, "failed in %ld s.", time(0)-t0);
               syslog(buf);
            }
            gameover= 0;
            return;
        }
        move(x*2-2, y-1);
        refresh();
    }
}