int main(void)
{
    TicTacToe game;
    int size;

    printf("This is the game of Tic Tac Toe.\n");
    printf("You will be playing against the computer.\n");

    printf("Enter the size of the board: ");
    scanf("%d", &size);
    printf("The game board is %d by %d.\n", size, size);

    init_game(&game, size); // initialise the board

    int done;
    do {
        print_game(game);
        do {
            done = player_move(&game);
        } while (!done); // loop until valid move
        if(check(&game) != FALSE) break; // was a winner or a draw
        computer_move(&game);
        if(check(&game) != FALSE) break; // was a winner or a draw
    } while (TRUE);

    print_result(game);
    print_game(game); // show final positions

    free_game(&game);

    return 0;
}
Пример #2
0
int main() {
	HANDLE c2s, s2c;
	DWORD x, cbMessage, cMessage, cbRead, dwRet;
	int status = 0,row,column;
	int m[3][3];
	start_game(m);
	printf("Waiting for a client to connect...\n");

	// creating mailslots
	// msg2 = CreateMailslot(TEXT("\\\\.\\mailslot\\c2s"), 0, MAILSLOT_WAIT_FOREVER, NULL);
	c2s = CreateMaleSlut(TEXT("\\\\.\\mailslot\\c2s"));
	// msg2 = CreateFile(TEXT("\\\\.\\PIPE\\c2s"), GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NMPWAIT_WAIT_FOREVER, NULL);
	s2c = ConnectMaleSlut(TEXT("\\\\.\\mailslot\\s2c"));

	printf("I am the server, marked with '1'\n");

	while (1) {
		//reads from client
		printf("Waiting for client's move...\n");
		if (ReadFile(c2s, m, sizeof(m), &x, NULL)==0) {
			printf("reading error.. %d\n", x);
		}
		print_game(m);
		// chekcs for win
		status = win(m);
		if (status) break;
		// make the move
		printf("Give the row:");
		scanf("%d",&row);
		printf("Give the column: ");
		scanf("%d",&column);
		mark(m,row,column,1);
		// writes to client
		if (WriteFile(s2c, m, sizeof(m), &x, NULL)==0) {
			printf("writing error..%d\n", x);
		}
		print_game(m);
		// checks again for win
		status = win(m);
		if (status) break;
	}

	if (status == 1) printf("\nCongratulions! You won! \n");
		else if (status == 2) printf("\nThe client won! \n");
			else printf("It's a tie!\n");

	// closing connections
	// DisconnectNamedPipe(c2s);
	// DisconnectNamedPipe(s2c);
	// closing pipes
	CloseHandle(c2s);
	CloseHandle(s2c);

}
Пример #3
0
int main(int argc, char *argv[]){
  if(argc != 2)
    usage(argv[0]);
  int level = atoi(argv[1]);
  if(level <= 0)
    usage(argv[0]);
  game g = init_game(level);
  char buf[3][100];
  int piece_num;
  dir d;
  int distance;
  int back_code;
  while(!game_over_hr(g)){
    bool good = false;
    while(!good){
      //Loop for the break of cancel instruction
      while(!good){
	system("clear");
	print_game(g);
	printf("Move the pieces for free the piece 0 to the exit:\n");
	printf("Write exit for quit the game or cancel for restart the current move.\n");
	printf("Total move: %d\n",game_nb_moves(g));
	//First loop to take the number piece that you want to move
	back_code = take_piece_num(g, buf[0], &(piece_num));
	if(back_code == 0)
	  break;
	if(back_code == -1)
	  return EXIT_SUCCESS;
	//Second loop to take the direction where you want to move
	back_code = take_direction(g, piece_num, buf[1], &(d));
	if(back_code == 0)
	  break;
	if(back_code == -1)
	  return EXIT_SUCCESS;
	//Third loop to take the number of case that need for the move
	back_code = take_number_case(g, piece_num, d, buf[2], &(distance));
	if(back_code == 0)
	  break;
	if(back_code == -1)
	  return EXIT_SUCCESS;
	good = true;
      }
    }
  }
  system("clear");
  print_game(g);
  printf("CONGRATULATION\nYou won in %d moves\n", game_nb_moves(g));
  delete_game(g);
  return EXIT_SUCCESS;
}
Пример #4
0
void	stat_game(t_game *g)
{
	int		press;

	print_game(g);
	press = getch();
	if (press == 'm')
	{
		if (g->end == 1)
		{
			ft_restart(g);
			g->start = 0;
		}
		g->stat = 0;
	}
	else if (press == KEY_UP && g->end != 1)
		ft_move_up(g);
	else if (press == KEY_DOWN && g->end != 1)
		ft_move_down(g);
	else if (press == KEY_RIGHT && g->end != 1)
		ft_move_right(g);
	else if (press == KEY_LEFT && g->end != 1)
		ft_move_left(g);
	else if (press == 'r')
		ft_restart(g);
	else if (press == 27)
		ft_del_game(&g);
}
Пример #5
0
int main(int argc, char *argv[])
{
    Echiquier B = E;
    double end_game;
    do{//loop to start a new game
    do{//loop to change player until mat

		term_clear(); // un peu mieux ;)

        print_game(&B);
        if(hunt_chess(&B)){
        printf("Vous etes en echec !\n");
        }
        move_piece(&B);
       /* printf("\n----------blacks_positions------------\n");
        print_binary_chess_table(B.blacks_position);
        printf("\n---------whites_position----------\n");
        print_binary_chess_table(B.whites_position);
        printf("\n");
        printf("a6 : %d, %d, (%d,%d), %d\n", B.t[2][0].t, B.t[2][0].c,B.t[2][0].p.posx,B.t[2][0].p.posy,B.t[2][0].m);
        getchar();*/
       //print_game(&B);

    }while(!mat(&B));
    char *player;
    switch (B.joueur){
        case JOUEUR_BLANC : player = "blanc";
        break;
        case JOUEUR_NOIR : player = "noir";
    }
	term_clear();

    print_game(&B);
    printf("\nJoueur %s, vous etes echec et mat !\n",player);
    getchar();
    B = E;
    do{
        printf("Souhaitez-vous refaire une partie ?\n1. Oui\n2. Non\n\n");
        scanf("%lf",&end_game);
        if(end_game != 1 && end_game != 2){
            printf("taper 1 ou 2.\n");
        }
    }while(end_game != 1 && end_game != 2);
    }while(end_game==1);
    return 0;
}
Пример #6
0
// implement a very simple client that sends and receives
// all other logic, just send and receive strings
// extension is to add extra clients
int main(void)
{
    // define our variables related to pipes
    int clientfd, serverfd;
    char *clientpipe = "clientpipe";
    char *serverpipe = "serverpipe";
    char buf[MAX_BUF];
    int size;

    // create the FIFO (named pipe) and open for reading
    mkfifo(clientpipe, 0666);
    mkfifo(serverpipe, 0666);
    serverfd = open(serverpipe, O_WRONLY);
    clientfd = open(clientpipe, O_RDONLY);

    printf("This is the game of Tic Tac Toe.\n");
    printf("You will be playing against the computer\n");

    read(clientfd, buf, MAX_BUF);
    printf("%s", buf);

    size = init_game(serverfd);

    int done;  // used to check validity of move
    int game_over; // used to check if game has completed

    // client must send commands and wait for responses
    // client exits loop if game is over
    // client should continue if receives continue message
    do {
        print_game(clientfd, size);
        do {
            done = player_move(clientfd, serverfd);
        } while (!done); // loop until valid move
        if (check(clientfd) != FALSE) break;
    } while (TRUE);

    print_game(clientfd, size);
    print_winner(clientfd);

    // tidy up
    close(clientfd);
    unlink(clientpipe);

    return 0;
}
Пример #7
0
int main()
{
	init_curses();

	const char *exit_msg = "";
	srandom(time(NULL));

	struct game_t game = {0};
	int last_turn = game.turns;

	get_highscore_filepath(&game);
	load_highscore(&game);

	place_tile(&game);
	place_tile(&game);

	while (1) {
		print_game(&game);

		if (lose_game(game)) {
			exit_msg = "lost";
			goto lose;
		}

		last_turn = game.turns;

		switch (getch()) {
    case 'h': case KEY_LEFT:  case 'a': move_left(&game); break;
    case 'j': case KEY_DOWN:  case 's': move_down(&game); break;
    case 'k': case KEY_UP:    case 'w': move_up(&game);   break;
    case 'l': case KEY_RIGHT: case 'd': move_right(&game);break;
		case 'q':
			exit_msg = "quit";
			goto end;
		}

		if (last_turn != game.turns)
			place_tile(&game);
	}

lose:
	move(7, 0);
	printw("You lose! Press q to quit.");
	while (getch() != 'q');
end:
	endwin();
	if(game.score > game.highscore)
	{
		game.highscore = game.score;
		save_highscore(&game);
	}
	printf("You %s after scoring %d points in %d turns, "
		"with largest tile %d. The local highscore is %d points.\n",
		exit_msg, game.score, game.turns,
		1 << max_tile((tile_t *)game.board), game.highscore);
	free(game.highscorefile);
	return 0;
}
Пример #8
0
int	print_all(t_tetris *tetris)
{
  mvprintw(tetris->map->pos_y, tetris->game->x, NAME_GAME);
  mvprintw(tetris->map->pos_y + 2, tetris->game->x, COPYRIGHT);
  print_game(tetris->game);
  if (tetris->next->valid)
    print_next(tetris->next);
  print_map(tetris->map);
  return (0);
}
Пример #9
0
int		*tab_line()
{
  int		*tab;

  if ((tab = malloc(sizeof(int) * 4)) == NULL)
    return (NULL);
  tab[0] = 1;
  tab[1] = 3;
  tab[2] = 5;
  tab[3] = 7;
  print_game(tab);
  return (tab);
}
Пример #10
0
int main()
{
	init_curses();

	const char *exit_msg = "";
	srand(time(NULL));

	struct game_t game = {0};
	int last_turn = game.turns;

	place_tile(&game);
	place_tile(&game);

	while (1) {
		print_game(&game);

		if (lose_game(game)) {
			exit_msg = "lost";
			goto lose;
		}

		last_turn = game.turns;

		switch (getch()) {
		case 'h': case KEY_LEFT: move_left(&game); break;
		case 'j': case KEY_DOWN: move_down(&game); break;
		case 'k': case KEY_UP: move_up(&game); break;
		case 'l': case KEY_RIGHT: move_right(&game); break;
		case 'q':
			exit_msg = "quit";
			goto end;
		}

		if (last_turn != game.turns)
			place_tile(&game);
	}

lose:
	move(7, 0);
	printw("You lose! Press q to quit.");
	while (getch() != 'q');
end:
	endwin();
	printf("You %s after scoring %d points in %d turns, "
		"with largest tile %d\n",
		exit_msg, game.score, game.turns,
		1 << max_tile((tile_t *)game.board));
	return 0;
}
Пример #11
0
void	stat_save(t_game *g)
{
	int		press;

	print_game(g);
	press = getch();
	if (ft_isalnum(press))
		ft_pseudo_add_char(g, press);
	else if (press == 127)
		ft_pseudo_del_char(g);
	else if (press == 10)
		ft_save_pseudo(g);
	else if (press == 27)
		ft_del_game(&g);
}
Пример #12
0
void	stat_continue(t_game *g)
{
	int		press;

	print_game(g);
	press = getch();
	if (press == 'n' || press == 'N')
	{
		ft_restart(g);
		g->start = 0;
		g->stat = 0;
	}
	else if (press == 'y' || press == 'Y')
		g->stat = 1;
	else if (press == 27)
		ft_del_game(&g);
}
Пример #13
0
void	play(int *lines, int *ia_goal, int num_line)
{
	int		player;
	int		num;

	player = ((int)&lines / 10000000) % 2;
	while (lines[0] != 0)
	{
		print_game(lines, num_line);
		num = turn(player, lines, ia_goal, num_line);
		lines[num_line] -= num;
		if (lines[num_line] == 0)
			num_line--;
		player = (player + 1) % 2;
		ft_putstr("Answer: ");
		ft_putnbr(num);
	}
	(player == 1) ? ft_putstranim("\nI won, noob !\n\n", 1) :
		ft_putstranim("\nYou win but that's only luck.\n\n", 0);
}
Пример #14
0
int main()
{
	try
	{
		std::string server="skynet.cs.uaf.edu";
		std::cout<<"Listing games on server "<<server<<":"<<std::endl;

		for(auto game:skynet::checkers::list_games(server))
			print_game(game.first,game.second);
	}
	catch(std::exception& error)
	{
		std::cout<<"Error - "<<error.what()<<std::endl;
	}
	catch(...)
	{
		std::cout<<"Error - Unknown."<<std::endl;
	}

	return 0;
}
Пример #15
0
int main(void)
{
	int state;
	char c;

	sleep_time = 1000 * 300; //1s = 1000ms  1ms = 1000us
	state = 0;
	len = 3;
	score = 0;
	init_game();

	while(0 <= state)
	{
		print_game();
		usleep(sleep_time);
		state = move();
		
		system("stty raw -echo");
		if(kbhit())
		{
			c = getchar();
			if('a' == c && 'd' != direc)
				direc = 'a';
			else
			if('s' == c && 'w' != direc)
				direc = 's';
			else
			if('d' == c && 'a' != direc)
				direc = 'd';
			else
			if('w' == c && 's' != direc)
				direc = 'w';
			
		}
		system("stty cooked echo");
	}
	free_node();
	
	return 0;
}
Пример #16
0
bool run(struct grid *grid)
{
  char entree[50];
  char **tmp;
  char *ent;
  int i;

  print_game(grid);
  my_memreset(entree, 50);
  ent = readLine();
  if (my_strcmp(my_strcpy(entree, ent), "") != 0) {
    free(ent);
    tmp = my_str_to_wordtab(entree);
    if (choise(grid, tmp) == true)
      return (true);
    for (i = 0; tmp[i][0] != '\0'; i++)
        free(tmp[i]);
    free(tmp);
  }
  else
    my_putstr("Wrong command \n");
  return (is_won(grid));
}
Пример #17
0
int main()
{
	init_curses();

	const char *exit_msg = "";

	struct game_t game = { 0 };
	int last_turn = game.turns;

	place_tile(&game);
	place_tile(&game);

	gotoxy(0, 7);
	printf("Press ENTER to quit.");

	int cur_key;

	while (1)
	{
		print_game(&game);

		if (lose_game(game))
		{
			exit_msg = "lost";
			goto lose;
		}

		last_turn = game.turns;

		switch (cur_key = keyb_getkey(1))
		{

		case 22:
			move_left(&game);
			break;
		case 38:
			move_down(&game);
			break;
		case 6:
			move_up(&game);
			break;
		case 54:
			move_right(&game);
			break;
		case 96:
			exit_msg = "quit";
			goto end;

		}

		if (last_turn != game.turns)
			place_tile(&game);
	}

lose:
	gotoxy(0, 7);
	printf("You lose! Press ENTER to quit.");
	while (keyb_getkey(1) != 96);
end:
	gotoxy(0, 7);
	printf("You %s after scoring %d points in %d turns, "
		"with largest tile %d\n",
		exit_msg, game.score, game.turns,
		1 << max_tile((tile_t *)game.board));
	sys_sleep(3000);
	return 0;
}
Пример #18
0
void start_match(int tid, char* cmd, int argc) {
    char id[USERID_LENGTH] = "";
    char type[2] = "";
    double time1 = 0.0, time2 = 0.0;
    //Break the command down
    if(argc == 2) {
        //If you're invited, you better follow commands
        if(client[tid].game_on)
            return;
        sscanf(cmd, "%*s %s", id);
        strcpy(type, "b");
        time1 = time2 = 300.0;
    } else if(argc == 3) {
        //If you're invited, you better follow commands
        if(client[tid].game_on)
            return;
        sscanf(cmd, "%*s %s %s", id, type);
        time1 = time2 = 300.0;
    } else if(argc == 5) {
        char time1_str[5], time2_str[5];
        sscanf(cmd, "%*s %s %s %s %s", id, type, time1_str, time2_str);
        time1 = atof(time1_str);
        time2 = atof(time2_str);
    }
    //Check if the user is trying to start a match with himself
    if(strcmp(id, client[tid].user_id) == 0) {
        char message[MSG_LENGTH];
        strcpy(message, "You cannot have a match with yourself.");
        my_write(client[tid].cli_sock, message, strlen(message));
        return;
    } else {
        //If not, check if the user is online
        bool user_is_online = false;
        for(int i = 0; i < CLIENT_SIZE; ++i) {      
            if(client[i].cli_sock != -1) {
                if(strcmp(id, client[i].user_id) == 0) {
                    user_is_online = true;
                    //If online, first check if i'm the inviter/invitee
                    if(!client[tid].game_on) {
                        //I'm the inviter, waiting..
                        client[i].game_on = true;
                        char p_type = (type[0] == 'w') ? 'b' : 'w';
                        char message[MSG_LENGTH];
                        sprintf(message, "%s invites you for a game <Please type -> match %s %c %0.f %0.f>."
                                , client[tid].user_id, client[tid].user_id, p_type, time1, time2);
                        my_write(client[i].cli_sock, message, strlen(message));
                    } else {
                        //I'm the invitee, so game on!
                        game_count++;
                        for(int i = 0;i < 3; i++)
                            for(int j = 0;j < 3;j++)
                                instances[game_count].game_grid[i][j] = '.';
                        instances[game_count].no_of_moves = 0;
                        instances[game_count].winner_tid = -1;
                        for(int i = 0; i < 20; i++)
                            instances[game_count].observers[i] = -1;
                        client[i].game_on = true;
                        //Setting player type
                        client[tid].player_type = type[0];
                        client[i].player_type = (type[0] == 'b') ? 'w' : 'b';
                        //Setting the game instance
                        client[i].game_id = client[tid].game_id = game_count;
                        //Hardcoding time limit for now
                        client[i].game_time_limit = time2;
                        client[tid].game_time_limit = time1;
                        //Black gets to go first
                        if(client[tid].player_type == 'b')
                            client[tid].game_turn = true;
                        else
                            client[i].game_turn = true;
                        //Setting user ids to game instance
                        instances[game_count].player1_tid = tid;
                        instances[game_count].player2_tid = i;
                        //Print game board
                        print_game(i, tid, YES, NO, NO, -1);
                        //Timer starts for Black
                        instances[game_count].game_start = microtime();
                    }
                    break; 
                }
            }
        }
        if(!user_is_online) {
            char message[MSG_LENGTH];
            strcpy(message, "User is not online.");
            my_write(client[tid].cli_sock, message, strlen(message));
        }
    }
}
Пример #19
0
Файл: ai.c Проект: ejrh/ejrh
void test(void)
{
    GAME game;
    MOVE moves[MAX_MOVES];
    int vector[MAX_PLAYERS];
    int num_moves;
    int i;
    MOVE chosen_move;
    clock_t start_time, end_time;
    int centiseconds, rate;

    printf("Rankoids AI test\n");

    clear_transposition_table();
    init_stack(&game_stack, 100*sizeof(GAME));

    initialise_game(&game);
    game.num_players = 3;
    game.players[0].hand[0] = 1;
    game.players[0].hand[1] = 3;
    game.players[0].hand[3] = 2;
    game.players[1].hand[4] = 1;
    game.players[0].hand[6] = 4;
    game.players[0].hand[7] = 3;
    game.players[0].hand[10] = 2;
    game.players[0].hand[JOKER_VALUE] = 1;
    game.players[1].hand[1] = 1;
    game.players[1].hand[2] = 3;
    game.players[1].hand[3] = 1;
    game.players[1].hand[4] = 1;
    game.players[1].hand[5] = 1;
    game.players[1].hand[9] = 3;
    game.players[1].hand[12] = 1;
    game.players[1].hand[5] = 2;
    game.players[2].hand[0] = 3;
    game.players[2].hand[2] = 1;
    game.players[2].hand[3] = 1;
    game.players[1].hand[4] = 2;
    game.players[2].hand[5] = 2;
    game.players[2].hand[9] = 1;
    game.players[2].hand[11] = 4;
    game.current_player = 0;
    game.pile_owner = 0;

    printf("Current game:\n");
    print_game(&game);

    printf("All moves for player 1:\n");
    num_moves = generate_all_moves(game.players[0].hand, moves);
    for (i = 0; i < num_moves; i++)
        print_move(moves[i]);
    printf("\n");

    evaluate_game_immediate(&game, vector);
    printf("Game vector is: [%d,%d,%d]\n", vector[0], vector[1], vector[2]);

    printf("All valid moves for player 1:\n");
    num_moves = generate_valid_moves(&game, moves);
    for (i = 0; i < num_moves; i++)
        print_move(moves[i]);
    printf("\n");

    chosen_move = MAKE_MOVE(3, 2);
    printf("Apply move ");
    print_move(chosen_move);
    printf(", game is:\n");
    apply_move(&game, chosen_move);
    print_game(&game);

    evaluate_game_immediate(&game, vector);
    printf("Game vector is: [%d,%d,%d]\n", vector[0], vector[1], vector[2]);

    printf("All valid moves for player 2:\n");
    num_moves = generate_valid_moves(&game, moves);
    for (i = 0; i < num_moves; i++)
    {
        print_move(moves[i]);
        clear_transposition_table();
        evaluate_move(&game, moves[i], vector, parameters.depth);
        printf(", with vector [%d,%d,%d]\n", vector[0], vector[1], vector[2]);
    }

    node_count = 0;
    clear_transposition_table();

    start_time = clock();
    chosen_move = choose_move(&game, vector, parameters.depth+5);
    end_time = clock();
    centiseconds = (end_time - start_time)*100 / CLOCKS_PER_SEC;
    if (centiseconds != 0)
    {
        rate = (int) (100.0*node_count/centiseconds);
    }
    else
    {
        rate = 0;
    }
    printf("%d nodes examined (%d hits), time was: %0.2f seconds, rate is: %d nodes/sec\n", node_count, hit_count, centiseconds/100.0, rate);
    printf("Chosen move was:");
    print_move(chosen_move);
    printf(", with vector [%d,%d,%d]\n", vector[0], vector[1], vector[2]);

    free_stack(&game_stack);
}
Пример #20
0
int Amazons::play_game() {
    int row, col;

    // Reset the board in case mutliple games are played
    for (int i = 0; i < mImpl->board_size * mImpl->board_size; i++) {
        mImpl->board[i] = 0;
    }
    // Randomize player positions initially
    for (int p = 0; p < mImpl->p_count; p++) {
        row = rand() % mImpl->board_size;
        col = rand() % mImpl->board_size;
        if ( mImpl->board[mImpl->board_size * row + col] == 0){
            mImpl->board[mImpl->board_size * row + col] = (p+1);
        }
        else {
            p--;
        }
    }
    lock_game();
    int player = 0;
    int winner = 0;
    int p_with_move = mImpl->p_count;
    bool *has_move = (bool*) malloc(mImpl->p_count * sizeof(bool));
    for (int i = 0; i < mImpl->p_count; i++)
        has_move[i] = true;
    int move = 0;
    int r_to, c_to, r_arrow, c_arrow;
    while (p_with_move > 1) {
        player = move % mImpl->p_count;
        print_game(mImpl->p[player]->get_out_stream());
        if (!mImpl->can_move(player)) {
            if ((mImpl->p[player]->get_out_stream()) != NULL) {
                fprintf(mImpl->p[player]->get_out_stream(), "Player %i has no valid "
                            "move. Their turn will be skipped.\n", player+1);
            }
            p_with_move--;
            has_move[player] = false;
            move++;
        }
        else {
            if (!has_move[player]) {
                has_move[player] = true;
                p_with_move++;
            }
            char* s = mImpl->p[player]->get_move();
            char* tok = strtok(s, " (),");
            if(tok == NULL || !sscanf(tok, "%i", &r_to)) {
                fprintf(stderr, "Invalid input format.\n");
                print_instructions(mImpl->p[player]->get_out_stream());
            }
            tok = strtok(NULL, " (),");
            if(tok == NULL || !sscanf(tok, "%i", &c_to)) {
                fprintf(stderr, "Invalid input format.\n");
                print_instructions(mImpl->p[player]->get_out_stream());
            }
            tok = strtok(NULL, " (),");
            if(tok == NULL || !sscanf(tok, "%i", &r_arrow)) {
                fprintf(stderr, "Invalid input format.\n");
                print_instructions(mImpl->p[player]->get_out_stream());
            }
            tok = strtok(NULL, " (),");
            if(tok == NULL || !sscanf(tok, "%i", &c_arrow)) {
                fprintf(stderr, "Invalid input format.\n");
                print_instructions(mImpl->p[player]->get_out_stream());
            }
            free(s);
            if (!mImpl->make_move(player, r_to, c_to, r_arrow, c_arrow)) {
                fprintf(stderr, "Try again, must be a valid move.\n");
                print_instructions(mImpl->p[player]->get_out_stream());
            }
            else {
                move++;
            }
        }
    }
    winner = 0;
    free(has_move);
    while(!mImpl->can_move(winner))  {
        winner++;
    }
    if (mImpl->p_count == 2) {
        winner = move % 2;
    }
    winner++; // Adjust from index to count
    unlock_game();
    return winner;
}
Пример #21
0
int main(){
	
	/*If you wish to make your own test cases against the gold code, all of the functions
	that you need to implement can be called with an underscore before the function. For example
	to call the gold version of make_game(), use the function _make_game(). See game_test.h */
	
	game * game1 = make_game(14,32);
	if( game1 == NULL){
		printf("test 1: fail - make_game() does not return a pointer correctly\n");
		exit(0);
	}
	else{
		printf("test 1: pass - make_game() returns pointer to game structure\n");
	}
	
	cell * cell_ptr1;
	cell_ptr1 = game1->cells;
	int i;
	
	
	
	if( cell_ptr1 == NULL){
		printf("test 2: fail - make_game() cell pointer is not initialized\n");
		exit(0);
	}
	else{
		printf("test 2: pass - make_game() returns pointer to game structure\n");
	}
	
	

	int flag = 0;
	for(i = 0; i < 14*32;i++){
		if(*cell_ptr1 != -1){
			flag = 1;
			printf("test 3: fail - cells are not initialized\n");
			break;
		}
		cell_ptr1++;
	}
	
	if( flag == 0){
		printf("test 3: pass - cells are initialized to -1\n");
	}
	
	if(( game1->rows == 14 )&&	(game1->cols == 32 )){
		printf("test 4: pass - number of rows and cols stored correctly\n");
	}
	else{
		printf("test 4: fail - number of rows and cols stored incorrectly\n");
	}
	
	game * game_orig;
	cell * cell_ptr_orig;
	cell * ptr1;
	cell * ptr2;
	
	game_orig = _make_game(4,3);
	game * game_cpy1 = _make_game(4,3);
	game * game_cpy2 = _make_game(4,3);
	
	cell_ptr_orig = game_orig->cells;
	
	ptr1 = game_cpy1->cells;
	ptr2 = game_cpy2->cells;
	
	cell temparray[12] = {2, 4, 4, 8, 4, -1, -1, 4, -1, 2, 4, 8};
	for( i =0; i<12;i++){
		*cell_ptr_orig = temparray[i];
		*ptr1 = temparray[i];
		*ptr2 = temparray[i];
		cell_ptr_orig++;
		ptr1++;
		ptr2++;
	}
	
	//print_game(game_cpy2);
	
	if( move_w(game_cpy1) == _move_w(game_cpy2))
		printf("test 5: pass - move_w returns the correct value\n");
	else
		printf("test 5: fail - move_w returns the incorrect value\n");
	
	
	ptr1 = game_cpy1->cells;
	ptr2 = game_cpy2->cells;
	
	for( i = 0; i < 12; i ++){
		if (*ptr1 != *ptr2){
			printf("test 6: fail - move_w does not move tiles correctly\n");
			//exit(0);
			printf("Your output:");
			print_game(game_cpy1);
			printf("Correct output:");
			print_game(game_cpy2);
			exit(0);
		}
		ptr1++;
		ptr2++;
	}
	printf("test 6: pass - move_w moves the tiles around correctly\n");
		
	
	if( move_a(game_cpy1) == _move_a(game_cpy2))
		printf("test 7: pass - move_a returns the correct value\n");
	else
		printf("test 7: fail - move_a returns the incorrect value\n");
	
			
	ptr1 = game_cpy1->cells;
	ptr2 = game_cpy2->cells;
	
	for( i = 0; i < 12; i ++){
		if (*ptr1 != *ptr2){
			printf("test 8: fail - move_a does not move tiles correctly\n");
			printf("Your output:");
			print_game(game_cpy1);
			printf("Correct output:");
			print_game(game_cpy2);
			exit(0);
		}
		ptr1++;
		ptr2++;
	}
	printf("test 8: pass - move_a moves the tiles around correctly\n");
	
	
	if( move_a(game_cpy1) == _move_a(game_cpy2))
		printf("test 9: pass - move_a returns the correct value\n");
	else
		printf("test 9: fail - move_a returns the incorrect value\n");
	

	
	
	if( move_d(game_cpy1) == _move_d(game_cpy2))
		printf("test 10: pass - move_d returns the correct value\n");
	else
		printf("test 10: fail - move_d returns the incorrect value\n");
	
			
	ptr1 = game_cpy1->cells;
	ptr2 = game_cpy2->cells;
	
	for( i = 0; i < 12; i ++){
		if (*ptr1 != *ptr2){
			printf("test 11: fail - move_d does not move tiles correctly\n");
			printf("Your output:");
			print_game(game_cpy1);
			printf("Correct output:");
			print_game(game_cpy2);
			exit(0);
		}
		ptr1++;
		ptr2++;
	}
	printf("test 11: pass - move_a moves the tiles around correctly\n");
	
	remake_game(&game_cpy1,12,8);
	
	if(game_cpy1 == NULL){
		printf("1test 12: fail - remake game does not work correctly.\n");
		exit(0);
	}
	if(game_cpy1->cells == NULL){
		printf("2test 12: fail - remake game causes cells to point to NULL.\n");
		exit(0);
	}
	
	ptr1 = game_cpy1->cells;
	
	if(!(game_cpy1->rows == 12 && game_cpy1->cols==8)){
		printf("3test 12: fail - remake game does not set rows / cols correctly.\n");
		exit(0);
	}
	
	for(i = 0; i < 12*8 ; i++){
		if(*ptr1 != -1){
			printf("test 12: fail - remake game does not initialize cells.\n");
			exit(0);
		}
		ptr1++;
	}
	printf("test 12: pass - remake game works correctly.\n");
	
	
	
	
	//print_game(game_cpy2);
	//print_game(game_cpy1);
	
	return 0;
}
Пример #22
0
int main(int argc, char *argv[]){
  set_up_pieces();
  game g = new_game_hr(NB_PIECES, pieces);
  char buf[3][100];
  int piece_num;
  dir d;
  int distance;
  while(!game_over_hr(g)){
    bool good = false;
    while(!good){
      while(!good){
	set_up_board(g);
	print_game(g);
	printf("Move the pieces for free the piece 0 to the exit:\n");
	printf("Total move: %d\n",game_nb_moves(g));
	while(!good){
	  printf("What piece do you want to move?\n");
	  read(0, buf[0], sizeof(char)*100);
	  if(strcmp(buf[0], "cancel") == 10)
	    break;
	  if(strcmp(buf[0], "exit") == 10)
	    return EXIT_SUCCESS;
	  if(buf[0][0]<48 || buf[0][0]>=48+NB_PIECES || buf[0][1] != 10)
	    printf("Write a number between 0 and %d\tor write cancel or exit.\n",NB_PIECES-1);
	  else{
	    piece_num = atoi(buf[0]);
	    good = true;
	  }
	}
	if(!good)
	  break;
	good = false;
	while(!good){
	  printf("In what direction?\n");
	  read(0, buf[1],  sizeof(char)*100);
	  if(strcmp(buf[1], "cancel") == 10)
	    break;
	  if(strcmp(buf[1], "exit") == 10)
	    return EXIT_SUCCESS;
	  if(!is_dir_option(buf[1]))
	    printf("Write one of those direction: up, down, right, left\tor write cancel or exit.\n");
	  else{
	    for(int i=0; i<4; ++i){
	      if(strcmp(buf[1], direction[i].dir_name) == 10)
		d = direction[i].dir_option;
	    }
	    if(!good_direction(g, piece_num, d)){
	      if(is_horizontal(game_piece(g, piece_num)))
		printf("The piece %d cannot move vertycaly\n", piece_num);
	      else
		printf("The piece %d cannot move horizontaly\n", piece_num);
	    }else
	      good = true;
	  }
	}
	if(!good)
	  break;
	good = false;
	while(!good){
	  printf("How many case?\n");
	  read(0, buf[2],  sizeof(char)*100);
	  if(strcmp(buf[2], "cancel") == 10)
	    break;
	  if(strcmp(buf[2], "exit") == 10)
	    return EXIT_SUCCESS;
	  if(buf[2][0]<48 || buf[2][0]>=48+SIZE_ARRAY || buf[2][1] != 10)
	    printf("Write a number between 0 and %d\tor write cancel or exit.\n",SIZE_ARRAY-1);
	  else{
	    distance = atoi(buf[2]);
	    good = play_move(g, piece_num, d, distance);
	    if(!good)
	      printf("The piece %d cannot move to that case.\n", piece_num);
	  }
	}
      }
    }
  }
  set_up_board(g);
  print_game(g);
  printf("CONGRETULATION\nYou won in %d moves\n", game_nb_moves(g));
  return EXIT_SUCCESS;
}
Пример #23
0
void human_game() {
    printf("Welcome to 2048!\n");
    print_commands();


    //char buf[MAXLINE];
    Game g = init_game(squaresum_heuristic);
    print_game(g);

    char in;
    int playing = 1;
    while (playing) {
        in = getc(stdin);
        if (in == '\033') {
            getc(stdin);
            switch (getc(stdin)) {
                case 'A':
                    in = 'u';
                    break;
                case 'B':
                    in = 'd';
                    break;
                case 'C':
                    in = 'r';
                    break;
                case 'D':
                    in = 'l';
                    break;
                default:
                    break;
            }
        }
        switch (in) {
            case 'q':
                playing = 0;
                break;
            case 'u':
                make_move(g, Up);
                print_game(g);
                break;
            case 'd':
                make_move(g, Down);
                print_game(g);
                break;
            case 'l':
                make_move(g, Left);
                print_game(g);
                break;
            case 'r':
                make_move(g, Right);
                print_game(g);
                break;
            case 'h':
                print_commands();
                break;
            default:
                break;
        }
        PointList pl = open_spaces(g->board);
        if (pl_empty(pl)) {
            playing = 0;
        }
        pl_free(pl);
    }
    print_game(g);
    printf("Game Over! Final Score: %d\n", g->score);
}
Пример #24
0
int main(int argc, char* argv[])
{
	struct game *game = create_game();

	apply_sc(0, &zero_value, game); switch_turn(game);

	apply_sc(100, &help_value, game); switch_turn(game);
	apply_cs(&K_value, 100, game); switch_turn(game);
	apply_cs(&S_value, 100, game); switch_turn(game);
	apply_sc(100, &get_value, game); switch_turn(game);
	apply_sc(100, &zero_value, game); switch_turn(game);

	apply_cs(&put_value, 0, game); switch_turn(game);
	apply_sc(0, &zero_value, game); switch_turn(game);
	apply_cs(&succ_value, 0, game); switch_turn(game);

	apply_cs(&K_value, 100, game); switch_turn(game);
	apply_cs(&S_value, 100, game); switch_turn(game);
	apply_sc(100, &get_value, game); switch_turn(game);
	apply_sc(100, &zero_value, game); switch_turn(game);

	apply_cs(&put_value, 0, game); switch_turn(game);
	apply_sc(0, &zero_value, game); switch_turn(game);
	apply_cs(&succ_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game);  switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game); // 8192

	apply_cs(&K_value, 100, game); switch_turn(game);
	apply_cs(&S_value, 100, game); switch_turn(game);
	apply_sc(100, &get_value, game); switch_turn(game);
	apply_sc(100, &zero_value, game); switch_turn(game);

	print_game(game);

	apply_cs(&put_value, 0, game); switch_turn(game);
	apply_sc(0, &zero_value, game); switch_turn(game);
	apply_cs(&succ_value, 0, game); switch_turn(game);

	apply_sc(100, &attack_value, game); switch_turn(game);
	apply_cs(&K_value, 100, game); switch_turn(game);
	apply_cs(&S_value, 100, game); switch_turn(game);
	apply_sc(100, &get_value, game); switch_turn(game);
	apply_sc(100, &zero_value, game); switch_turn(game);

	apply_cs(&put_value, 0, game); switch_turn(game);
	apply_sc(0, &zero_value, game); switch_turn(game);

	apply_cs(&K_value, 100, game); switch_turn(game);
	apply_cs(&S_value, 100, game); switch_turn(game);
	apply_sc(100, &get_value, game); switch_turn(game);
	apply_sc(100, &zero_value, game); switch_turn(game);

	apply_cs(&put_value, 0, game); switch_turn(game);
	apply_sc(0, &zero_value, game); switch_turn(game);
	apply_cs(&succ_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game);  switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game); // 16384

	apply_cs(&K_value, 100, game); switch_turn(game);
	apply_cs(&S_value, 100, game); switch_turn(game);
	apply_sc(100, &get_value, game); switch_turn(game);
	apply_sc(100, &zero_value, game);

	print_game(game);

	apply_cs(&put_value, 0, game); switch_turn(game);
	apply_sc(0, &zero_value, game); switch_turn(game);
	apply_cs(&copy_value, 0, game); switch_turn(game);

	print_game(game);

	apply_cs(&put_value, 0, game); switch_turn(game);
	apply_sc(0, &zero_value, game); switch_turn(game);
	apply_cs(&succ_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&succ_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&succ_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&succ_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&succ_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&succ_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&succ_value, 0, game); switch_turn(game);
	apply_cs(&dbl_value, 0, game); switch_turn(game);
	apply_cs(&succ_value, 0, game); switch_turn(game);
	apply_cs(&revive_value, 0, game); switch_turn(game);

	print_game(game);

	destroy_game(game);

	return 0;
}
Пример #25
0
int             wait_event(SDL_Renderer *renderer)
{
  bool          quit;
  int           y_p1;
  int           y_p2;
  SDL_Event     event;
  SDL_Rect      raq_p1;
  SDL_Rect      raq_p2;
  SDL_Rect      ball;
  SDL_Rect      bold;

  quit = false;
  init_ball(&ball, &bold);
  y_p1 = 240;
  y_p2 = 240;
  while (!quit)
    {
      printf("x");
      SDL_Delay(2);
      SDL_PollEvent(&event);
      switch (event.type)
        {
        case SDL_KEYDOWN:
          switch(event.key.keysym.sym)
            {
            case SDLK_ESCAPE: 
              {
                quit = true; 
                return (0); 
              }
            case SDLK_UP: 
              {
                if (y_p1 > 0)
                  y_p1--; 
                else 
                  break; 
                break;
              }
            case SDLK_DOWN:
              {
                if (y_p1 < 480 - 64) 
                  y_p1++; 
                else 
                  break; 
                break;
              }
            case SDLK_LEFT:
              {
                if (y_p2 < 480 - 64) 
                  y_p2++; 
                else 
                  break; 
                break;
              }
            case SDLK_RIGHT:
              {
                if (y_p2 > 0) 
                  y_p2--; else 
                  break; 
                break;
              }
            }
          break;
        }
      pos_raq_p1(&raq_p1, &y_p1);
      pos_raq_p2(&raq_p2, &y_p2);
      ball_move(&ball, &bold, &raq_p1, &raq_p2);
      print_game(renderer, &raq_p1, &raq_p2, &ball);
    }
}
Пример #26
0
int main(int argn, char** argv) {
	
	int xsize, ysize;
	char c, c2;
	int i, i2;
	int x, y;

	WINDOW* wnd;
	char buf[50];
	tile* temp_tile; 

	/* Inicjalizacja generatora liczb losowych */
	srand(time(0));

	wnd = initscr();
	start_color();
	
	if(has_colors()) {

		enable_tile_colors();
		use_default_colors();

		/* Przyporządkuj każdej płytce kolor */
		init_pair(1, COLOR_YELLOW, -1);
		init_pair(2, COLOR_GREEN, -1);
		init_pair(3, COLOR_RED, -1);
		init_pair(4, COLOR_YELLOW, -1);
		init_pair(5, COLOR_WHITE, -1);
		init_pair(6, COLOR_RED, -1);
		init_pair(7, COLOR_GREEN, -1);
		init_pair(8, COLOR_BLUE, -1);
		init_pair(9, COLOR_CYAN, -1);
		init_pair(10, COLOR_MAGENTA, -1);

	}
	else {

		disable_tile_colors();

	}

	cbreak();
	echo();
	nonl();
	intrflush(stdscr, FALSE);
	keypad(stdscr, TRUE);

	getmaxyx(wnd, ysize, xsize);

	/* Pobierz docelowy rozmiar */
	while(1) {

		werase(wnd);

		draw_frame(wnd);

		wmove(wnd, ysize/2-(MAX_SIZE-MIN_SIZE+2), 20);	

		wprintw(wnd, "Available pool size:");

		for(i=MIN_SIZE;i<=MAX_SIZE;i++) {

			wmove(wnd, ysize/2-(MAX_SIZE-MIN_SIZE+2)+(i-MIN_SIZE+1), 20);
			attron(COLOR_PAIR(5) | A_BOLD);
			wprintw(wnd, "%d", i);
			attroff(COLOR_PAIR(5) | A_BOLD);
			wprintw(wnd, " for %dx%d", i, i);
			
		}

		wmove(wnd, ysize-2, 2);
		wprintw(wnd, "Saephir (c), 2010");

		wmove(wnd, ysize/2+1, 20);
		wprintw(wnd, "Type the desired number: ");

		c = getch();

		buf[0] = c;
		buf[1] = 0;

		i2 = atoi(buf);

		if(i2 >= MIN_SIZE && i2 <= MAX_SIZE) {
			TILES_COUNT = i2;
			init();
			break;
		}

	}

	while(1) {

		werase(wnd);

		draw_frame(wnd);

		/* Wygrana gra */
		if(verify()) {

			print_game(wnd);

			wmove(wnd, ysize/2, 40);
			wprintw(wnd, "Well done!");
			wmove(wnd, ysize/2+1, 40);
			wprintw(wnd, "Press ENTER to exit...");
			getch();
			break;

		}

		print_game(wnd);
		print_pool(wnd);

		wmove(wnd, ysize-2, 1);

		wgetnstr(wnd, buf, 49);
		buf[49] = 0;

		if(strcmp(buf, "exit") == 0 || strcmp(buf, "quit") == 0 || strcmp(buf, "q") == 0) {

			break;

		}
		else if(strcmp(buf, "help") == 0 || strcmp(buf, "?") == 0) {

			wmove(wnd, ysize-2, 1);
			wclrtoeol(wnd);
			draw_frame(wnd);
			wmove(wnd, ysize-2, 1);
			wprintw(wnd, HELP_LINE);
			getch();
			wmove(wnd, ysize-2, 1);
			wclrtoeol(wnd);
			draw_frame(wnd);
			wmove(wnd, ysize-2, 1);
			wprintw(wnd, HELP_LINE2);
			getch();

		}

		else if(strcmp(buf, "<<") == 0) {

			push_left();

		}

		else if(strcmp(buf, ">>") == 0) {

			push_right();

		}

		else if(strcmp(buf, "^^") == 0) {

			push_top();

		}

		else if(strcmp(buf, "vv") == 0) {

			push_bottom();

		}
		else if(sscanf(buf, "%c%d<%c%d", &c, &i, &c2, &i2) == 4) {

			i--;
			i2--;

			if(c == c2 && i == i2)
				continue;

			if(c-'a' < 0 || c-'a' >= 2*TILES_COUNT)
				continue;

			if(c2-'a' < 0 || c2-'a' >= 2*TILES_COUNT)
				continue;

			if(i < 0 || i >= TILES_COUNT)
				continue;

			if(i2 < 0 || i2 >= TILES_COUNT)
				continue;

			/* Przesuwamy na pole gry */
			if(c-'a' < TILES_COUNT) {

				temp_tile = &game[i][c-'a'];

				/* Miejsce musi być puste */
				if(!is_empty(temp_tile))
					continue;

				/* przesuwamy z puli do gry */
				if(c2-'a' >= TILES_COUNT)
					temp_tile = &pool[i2][c2-'a'-TILES_COUNT];
				/* przesuwamy z gry do gry */
				else
					temp_tile = &game[i2][c2-'a'];

				/* Żródło nie może być puste */
				if(is_empty(temp_tile))
					continue;

				move_tile(&game[i][c-'a'], temp_tile);

			}
			/* Przesuwamy do puli */
			else {

				temp_tile = &pool[i][c-'a'-TILES_COUNT];

				/* Miejsce musi być puste */
				if(!is_empty(temp_tile))
					continue;

				/* Przesuwamy z pola gry do puli */
				if(c2-'a' < TILES_COUNT)
					temp_tile = &game[i2][c2-'a'];
				/* Przesuwamy z puli do puli */
				else
					temp_tile = &pool[i2][c2-'a'-TILES_COUNT];
				
				/* Żródło nie może być puste */
				if(is_empty(temp_tile))
					continue;

				move_tile(&pool[i][c-'a'-TILES_COUNT], temp_tile);

			}
			


		}
		else if(sscanf(buf, "%c%d>%c%d", &c, &i, &c2, &i2) == 4) {

			i--;
			i2--;

			if(c == c2 && i == i2)
				continue;

			if(c-'a' < 0 || c-'a' >= 2*TILES_COUNT)
				continue;

			if(c2-'a' < 0 || c2-'a' >= 2*TILES_COUNT)
				continue;

			if(i < 0 || i >= TILES_COUNT)
				continue;

			if(i2 < 0 || i2 >= TILES_COUNT)
				continue;

			/* Przesuwamy do puli */
			if(c2-'a' >= TILES_COUNT) {

				temp_tile = &pool[i2][c2-'a'-TILES_COUNT];

				/* Miejsce musi być puste */
				if(!is_empty(temp_tile))
					continue;

				/* Przesuwamy z pola gry */
				if(c-'a' < TILES_COUNT)
					temp_tile = &game[i][c-'a'];
				/* Przesuwamy z puli */
				else
					temp_tile = &pool[i][c-'a'-TILES_COUNT];
				
				/* Żródło nie może być puste */
				if(is_empty(temp_tile))
					continue;

				move_tile(&pool[i2][c2-'a'-TILES_COUNT], temp_tile);

			}
			/* Przesuwamy na pole gry */
			else {

				temp_tile = &game[i2][c2-'a'];

				/* Miejsce musi być puste */
				if(!is_empty(temp_tile))
					continue;

				/* Przesuwamy z puli na pole gry */
				if(c-'a' >= TILES_COUNT)
					temp_tile = &pool[i][c-'a'-TILES_COUNT];
				/* Przesuwamy z pola gry na pole gry */
				else
					temp_tile = &game[i][c-'a'];
				
				/* Żródło nie może być puste */
				if(is_empty(temp_tile))
					continue;

				move_tile(&game[i2][c2-'a'], temp_tile);

			}

		}
		else if(sscanf(buf, "%c%d>pool", &c, &i) == 2 || sscanf(buf, "pool<%c%d", &c, &i) == 2) {

			i--;

			if(strcmp(&buf[2], ">pool") != 0) {
				buf[5] = 0;
				if(strcmp(buf, "pool<") != 0)
					continue;
			}

			if(c-'a' < 0 || c-'a' >= TILES_COUNT)
				continue;

			if(i < 0 || i >= TILES_COUNT)
				continue;

			/* Żródło nie może być puste */
			if(is_empty(&game[i][c-'a']))
				continue;

			/* Jeżeli źródło nie jest puste, to istnieją wolne miejsca w puli */
			/* znajdujemy więc pierwsze wolne miejsce */
			for(y=0;y<TILES_COUNT;y++) {
				for(x=0;x<TILES_COUNT;x++) {
					
					if(is_empty(&pool[x][y])) {
						
						move_tile(&pool[x][y], &game[i][c-'a']);
						break;
					}

				}
			}
			

		}

	}

	endwin();

	return 0;
}