int main()
{
    char ch[100];
    struct music songs[7]={{"Walking with a ghost", "Kadebostany", 2.30, 2013}, {"Burn", "Ellie Goulding", 2.48, 2013}, {"Oblivion", "30 seconds to Mars", 1.59, 2002}, {"Stronger", "Kanye West", 4.46, 2007}, {"Eagle", "Kadebostany", 1.46, 2013}, {"It`s my life", "Bon Jovi", 2.50, 2000}, {"Skyfall", "Adele", 4.46, 2012}};
    const char* newsong;
    int i, amount;
    size_t size = sizeof(songs)/sizeof(struct music);
    printst(size, songs);

    printf("Enter number of song [1 ... %i], you want to change ", size);
    scanf("%i", &i);
    fflush(stdin);
    printf("Enter a new name of song\n");
    newsong = gets(ch);
    puts("");
    struct music* p = &songs[i-1];
    change(p, newsong);

    amount = count(size, songs);
    printf("amount = %i\n\n", amount);

    print(p);

    return 0;
}
Beispiel #2
0
int main(int argc, char *argv[])
{
	int x, y, en, side, depth, score; 

	// true reversi starts with empty board, but that is not implemented yet!
	// therefore, here is the othello starting arrangement.
	int board[100] =
	{
		2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
		2, 0, 0, 0, 0, 0, 0, 0, 0, 2,
		2, 0, 0, 0, 0, 0, 0, 0, 0, 2,
		2, 0, 0, 0, 0, 0, 0, 0, 0, 2,
		2, 0, 0, 0,-1, 1, 0, 0, 0, 2,
		2, 0, 0, 0, 1,-1, 0, 0, 0, 2,
		2, 0, 0, 0, 0, 0, 0, 0, 0, 2,
		2, 0, 0, 0, 0, 0, 0, 0, 0, 2,
		2, 0, 0, 0, 0, 0, 0, 0, 0, 2,
		2, 2, 2, 2, 2, 2, 2, 2, 2, 2
	};

	if (argc > 1)
	{
		side  = atoi(argv[1]); 
	}
	else
	{
		printf("Insufficient arguments\n\n");
		printf("Syntax: %s {computer's side} [difficulty]\n", argv[0]);
		return 0;
	}
	if (argc == 3)
	{
		// side is the color that the computer plays
		// '1' is black, '-1' white
		// depth is the difficulty, the number of plies.
		depth = atoi(argv[2]);
	}
	else
	{
		depth = 4;
	}
	if (depth % 2 == 0) parity = 1; else parity = -1;

	printf("Computer playing as %c\n", pchar(side));
	printf("Difficulty %i\n", depth);
	printf("Right-click to quit\n");

	if (allegro_init() != 0) return 1;

	install_keyboard();
	install_mouse();
	install_timer();
	if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 440, 440 + 20, 0, 0))
	{
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Unable to enter graphics mode\n%s\n", allegro_error);
		return 1;
	}
	
	set_palette(desktop_palette);
	clear_to_color(screen, makecol(0, 200, 0)); // green background

	textout_centre_ex(screen, font, "REVERSI", SCREEN_W/2, 10, 
						makecol(0, 0, 0), -1);

	printbd(board);
	printst(board, 0);
	show_mouse(screen);

	if (side == 1)
	{
		// make first move
		findmv(side, board, &en, depth);
		move(board, en, side);
		highlight(en, side);

		printbd(board);
		printst(board, 0);
	}
	// game loop
	while (1)
	{
		if (mouse_b & 1)
		{
			// the user has clicked to place a move
			x = mouse_pos >> 16;
			y = mouse_pos & 0x0000ffff;

			readmv(x, y, &en);
			
			// perform user move
			if (move(board, en, -side))
			{
				// highlight user move
				highlight(en, -side);
				printbd(board);
				printst(board, 0);
				
				// find reply
				score = findmv(side, board, &en, depth);
				if (move(board, en, side))
				{
					highlight(en, side);

					printbd(board);
					printst(board, 0);
				}
			}
			else
			{
				// check and see if user CAN move at all
				en = -1;
				score = findmv(-side, board, &en, depth);
				if (en == -1)
				{
					// computer move instead
					score = findmv(side, board, &en, depth);
					if (move(board, en, side))
					{
						highlight(en, side);

						printbd(board);
						printst(board, 0);
					}
					else
					{
						// Game over
						printst(board, 1);
					}
				}
			}
		}

		if (mouse_b & 2) return 0; // exit on right-click
	}