Ejemplo n.º 1
0
void testplay() {
	int i,j,c;
	players=2;
	srand(time(0));
	generatenewgame();
	testprintnewgame();
	for(i=0;i<players;i++) {
		resetplayer(i);
		c=getcardid("copper");
		if(c<0) error("testplay: couldn't find copper.\n");
		for(j=0;j<7;j++) gaincard(i,c);
		c=getcardid("estate");
		if(c<0) error("testplay: couldn't find estate.\n");
		for(j=0;j<3;j++) gaincard(i,c);
	}
	currentplayer=0;
	playgame();
}
Ejemplo n.º 2
0
/*
 * This game written by Ken Arnold.
 */
int main(int argc, char* argv[])
{
    initscr(); 
    
    /* Install a new signal handler */
    signal(SIGINT, die); 

    /* Setup the game */
    setup();
    
    for (;;) 
    {
        Wordnum++;
	/* Play the game */
        playgame();
        Average = (Average * (Wordnum - 1) + Errors) / Wordnum;
    }
    
    /* NOTREACHED */
}
Ejemplo n.º 3
0
int main(int argc, const char * argv[])
{
    FILE * file;
    const char *inputfile;
    
    if(argc != 2){
        /*We print argv[0] for the program name */
        printf("usage: game2 <file>\n");
        exit(1);
    }
    
    inputfile = argv[1];
    /* Assuming filename is containedin argv[1]*/
    file = fopen(inputfile, "r");
    /*open returns 0 if file is unopened*/
    
    if(file == -1){
        printf("Could not open file\n");
        exit(1);
    }
    playgame(createlist(file));
}
Ejemplo n.º 4
0
/* main().
 */
int main(int argc, char *argv[])
{
    startupdata	start;

    initwithcmdline(argc, argv, &start);

    if (!getseriesfiles(start.filename, &serieslist, &seriescount))
	return EXIT_FAILURE;

    if (start.listseries) {
	displayserieslist();
	return EXIT_SUCCESS;
    }

    pickstartinggame(start.filename, start.level);

    if (start.writeanswer) {
	selectgame(serieslist[currentseries].games + currentgame, currentgame);
	initgamestate();
	if (!displaygamesolution())
	    die("No solution exists for \"%s\", puzzle %d.",
		serieslist[currentseries].name, currentgame);
	return EXIT_SUCCESS;
    }

    if (!ioinitialize(start.silence))
	die("Failed to initialize terminal.");

    for (;;) {
	selectgame(serieslist[currentseries].games + currentgame, currentgame);
	initgamestate();
	playgame();
	if (!readlevel())
	    break;
    }

    return EXIT_SUCCESS;
}
Ejemplo n.º 5
0
static void
on_game_hint (GtkMenuItem * m, gpointer data)
{
  gchar *s;
  gint c;

  if (timeout)
    return;
  if (gameover)
    return;

  gtk_action_set_sensitive (hint_action, FALSE);
  gtk_action_set_sensitive (undo_action, FALSE);

  set_status_message (_("Thinking..."));

  vstr[0] = vlevel[LEVEL_STRONG];
  c = playgame (vstr, vboard) - 1;

  column_moveto = c;
  if (p.do_animate) {
    while (timeout)
      gtk_main_iteration ();
    anim = ANIM_HINT;
    timeout = g_timeout_add (SPEED_MOVE, (GSourceFunc) on_animate, NULL);
  } else {
    move_cursor (column_moveto);
  }

  blink_tile (0, c, gboard[0][c], 6);

  s = g_strdup_printf (_("Hint: Column %d"), c + 1);
  set_status_message (s);
  g_free (s);

  gtk_action_set_sensitive (hint_action, TRUE);
  gtk_action_set_sensitive (undo_action, (moves > 0));
}
Ejemplo n.º 6
0
int
main(int argc, char *argv[])
{
	int ch, done;
	char *bspec, *p, *seed;

	batch = debug = reuse = selfuse;
	bspec = seed = NULL;
	minlength = -1;
	tlimit = 180;		/* 3 minutes is standard */

	while ((ch = getopt(argc, argv, "Bbcds:t:w:")) != -1)
		switch(ch) {
		case 'B':
			grid = 5;
			break;
		case 'b':
			batch = 1;
			break;
		case 'c':
			challenge = 1;
			break;
		case 'd':
			debug = 1;
			break;
		case 's':
			seed = optarg;
			break;
		case 't':
			if ((tlimit = atoi(optarg)) < 1)
				errx(1, "bad time limit");
			break;
		case 'w':
			if ((minlength = atoi(optarg)) < 3)
				errx(1, "min word length must be > 2");
			break;
		case '?':
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	/* process final arguments */
	if (argc > 0) {
		if (strcmp(argv[0], "+") == 0)
			reuse = 1;
		else if (strcmp(argv[0], "++") == 0)
			selfuse = 1;
	}

	if (reuse || selfuse) {
		argc -= 1;
		argv += 1;
	}

	if (argc > 0) {
		if (islower(argv[0][0])) {
			if (strlen(argv[0]) != ncubes) {
				usage();
			} else {
				/* This board is assumed to be valid... */
				bspec = argv[0];
			}
		} else {
		  	usage();
		}
	}

	if (batch && bspec == NULL)
		errx(1, "must give both -b and a board setup");

	init();
	if (batch) {
		newgame(bspec);
		while ((p = batchword(stdin)) != NULL)
			(void) printf("%s\n", p);
		exit(0);
	}
	setup(seed);
	prompt("Loading the dictionary...");
	if ((dictfp = opendict(DICT)) == NULL) {
		warn("%s", DICT);
		cleanup();
		exit(1);
	}
#ifdef LOADDICT
	if (loaddict(dictfp) < 0) {
		warnx("can't load %s", DICT);
		cleanup();
		exit(1);
	}
	(void)fclose(dictfp);
	dictfp = NULL;
#endif
	if (loadindex(DICTINDEX) < 0) {
		warnx("can't load %s", DICTINDEX);
		cleanup();
		exit(1);
	}

	prompt("Type <space> to begin...");
	while (inputch() != ' ');

	for (done = 0; !done;) {
		newgame(bspec);
		bspec = NULL;	/* reset for subsequent games */
		playgame();
		prompt("Type <space> to continue, any cap to quit...");
		delay(10);	/* wait for user to quit typing */
		flushin(stdin);
		for (;;) {
			ch = inputch();
			if (ch == '\033')
				findword();
			else if (ch == '\014' || ch == '\022')	/* ^l or ^r */
				redraw();
			else {
				if (isupper(ch)) {
					done = 1;
					break;
				}
				if (ch == ' ')
					break;
			}
		}
	}
	cleanup();
	exit(0);
}
Ejemplo n.º 7
0
void
net_replay(void)
{
    char buf[BUFSZ];
    struct nhnet_game *gamelist;
    struct nh_menulist menu;
    int pick[1];
    int i, gamecount, gameid, want_done, show_all;

    want_done = FALSE;
    show_all = TRUE;
    while (1) {
        gamelist = nhnet_list_games(want_done, show_all, &gamecount);

        init_menulist(&menu);

        if (!gamecount)
            add_menu_txt(&menu, "(No games in this list)",
                         MI_NORMAL);

        /* add all the files to the menu */
        for (i = 0; i < gamecount; i++) {
            describe_game(buf, gamelist[i].status, &gamelist[i].i);
            add_menu_item(&menu, gamelist[i].gameid, buf, 0,
                          FALSE);
        }

        add_menu_txt(&menu, "", MI_NORMAL);
        if (want_done)
            add_menu_item(&menu, -1, show_all ? "Watch current games" :
                          "Replay your unfinished games", '!', FALSE);
        else
            add_menu_item(&menu, -1,
                          "Replay a completed game", '!', FALSE);

        if (show_all)
            add_menu_item(&menu, -2, want_done ? "View your completed games" :
                          "View your saved games", '#', FALSE);
        else
            add_menu_item(&menu, -2, "View games from other players",
                          '#', FALSE);

        curses_display_menu(&menu, want_done ? show_all ?
                            "Completed games by other players" :
                            "Your completed games" : show_all ?
                            "Pick a current game to watch" :
                            "Replay your saved games", PICK_ONE,
                            PLHINT_ANYWHERE, pick, curses_menu_callback);
        if (pick[0] == CURSES_MENU_CANCELLED)
            return;

        if (pick[0] == -1) {
            want_done = !want_done;
            if (want_done)
                show_all = FALSE; /* will normally be intended */
            continue;
        } else if (pick[0] == -2) {
            show_all = !show_all;
            continue;
        } else
            gameid = pick[0];

        break;
    }

    create_game_windows();

    /* If the game is over, we want to replay (nothing to watch). If it's our
       game, we want to replay (not much point in watching yourself). Otherwise,
       we start in watch mode; the player can change to replay mode from the
       watch menu. */
    int ret = playgame(gameid, show_all && !want_done ? FM_WATCH : FM_REPLAY);

    destroy_game_windows();
    cleanup_messages();

    game_ended(ret, NULL, TRUE);
}
Ejemplo n.º 8
0
int main(){

	 int bets = 0, pot = 0;

	 Deck game_deck = get_new_Deck();
	 printf("\n\n");
	 hBorder();	 
	 printf("\n\n");
	 welcomeSign();
	 hBorder();	 
	 welcome();
	 printf("\n");
	 hBorder();
	 printf("\n");
	 printf("\n");

	 Player one = player_init(getName(), getRupies());
	 printf("Hi %s, you have %i rupies\n",one.name, one.rupies);
	 Player two = player_init("Link", one.rupies);
	 Player three = player_init("Mario", one.rupies);
	 Player four = player_init("Taloon", one.rupies);
	 getStatus(&two);
	 getStatus(&three);
	 getStatus(&four);
	 printf("\n\n");
	 hBorder();	 

	 Player *table[NUM_PLAYERS];
	 table[0] = &one;
	 table[1] = &two;
	 table[2] = &three;
	 table[3] = &four;

	 int gamenumber = 1;
	 int gamesplayed = 0;
	 int gameStatus = 1;
	 while(gamenumber == 1){

		  if(gameStatus == 1){ 
				if(gamesplayed != 0){
					 printf("\n\n");
					 welcomeSign();
					 hBorder();	 
				}
				gamesplayed++;
				printf("\n\nREADY -- Here we go...\n\n");
				shuffle(&game_deck, DECK_SIZE);
				first_Deal(&game_deck, table, NUM_PLAYERS);
				gamescene(3, table);

				print_Hand(table, 1);
				isHand(one.hand);
				bets = betAmount(&one);
				printf("%s, bets %i rupies\n",one.name, bets);
				pot += bets;
				/*	cpuBIGACTION(table, &bets, &game_deck);

#pragma omp parallel num_threads(4)
int z;
tid = omp_get_thread_number();
for(z=1;z<NUM_PLAYERS;z++){
if(tid == 1){
				 */		  pot += cpuActions(&game_deck, &two, &one, bets); 
				/*	 }
					 if(tid == 1){
				 */		  
				printf("...hmm...yea...\n");
				pot += cpuActions(&game_deck, &three, &one, bets); 
				/*	 }
					 if(tid == 1){
				 */		  
				printf("...uhhh...ok...\n");
				pot += cpuActions(&game_deck, &four, &one, bets); 
				/*	 }
					 }*/
				hBorder();
				banter(table);
				playersLeft(table, &gameStatus);
		  }
		  if(gameStatus ==1){
				print_Hand(table, 1);
				print_Options();
				isHand(one.hand);

				Deck MC_Deck = create_Monte(&one);
				monteSuggest(monte_Analysis(&MC_Deck, &one));
				printTextReco(&one);

				newCards(&game_deck,&one);
				print_Hand(table, 1);
				isHand(one.hand);
				printf("\n\n");
				bets = betAmount(&one);
				pot += bets;
				pot += cpuBets(&two, &one, bets);
				pot += cpuBets(&three, &one, bets);
				pot += cpuBets(&four, &one, bets);


				playersLeft(table, &gameStatus);
		  }
		  hBorder();
		  printResults(table);
		  evaluateHands(table); 
		  tableCompareTo(table);

		  winnerIs(table, pot);
		  hBorder();
		  printf("\n");
		  banter(table);
		  getTableStatus(table);

		  gamenumber = playgame();
		  printf("\n\n\n\n");
		  bets = 0;
		  pot = 0;
		  tableRefresh(table);
	 }
	 return 0;
}
Ejemplo n.º 9
0
int main(int argc, char **argv)
{
    char buffer[NET_BUF_LEN];  // for command-line input
    int servers_found = 0;
    int server_number = -1;
    Uint32 timer = 0;

    //Scan local network to find running server:
    servers_found = LAN_DetectServers();

    if(servers_found < 1)
    {
        fprintf(stderr, "No server could be found - exiting.\n");
        exit(EXIT_FAILURE);
    }
    else if(servers_found  == 1)  //One server - connect without player intervention
    {
        fprintf(stderr, "Single server found - connecting automatically...");

        if(!LAN_AutoSetup(0))  //i.e.first (and only) entry in list
        {
            fprintf(stderr, "setup_client() failed - exiting.\n");
            exit(EXIT_FAILURE);
        }

        fprintf(stderr, "connected\n");
    } 


    else  // More than one server - will have to get player selection:
    {
        while(server_number < 0 || server_number >= servers_found)
        {
            fprintf(stderr, "The following TuxMath servers were detected:\n");
            print_server_list();
            fprintf(stderr, "Enter the SERVER NUMBER you would like to connect to:\n");
            scanf("%d", &server_number);
            if(server_number < 0 || server_number >= servers_found)
                fprintf(stderr, "Illegal value - try again.\n");
        }
        if(!LAN_AutoSetup(server_number))  //i.e.first (and only) entry in list
        {
            fprintf(stderr, "setup_client() failed - exiting.\n");
            exit(EXIT_FAILURE);
        }

        fprintf(stderr, "connected\n");
    }


    /* Now we are connected - get nickname from player: */
    {
        char name[NAME_SIZE];
        char* p;

        fprintf(stderr, "Please enter your name:\n>\n");
        fgets(buffer, NAME_SIZE, stdin);
        p = strchr(buffer, '\n');  //get rid of newline character
        if(p)
            *p = '\0';
        strncpy(name, buffer, NAME_SIZE);
        /* If no nickname received, use default: */
        if(strlen(name) == 1)
            strcpy(name, "Anonymous Coward");

        snprintf(buffer, NET_BUF_LEN, "%s", name);
        LAN_SetName(name);
    }

    fprintf(stderr, "Welcome to the Tux Math Test Client!\n");
    fprintf(stderr, "Type:\n"
            "'game' to start math game;\n"
            "'exit' to end client leaving server running;\n"
            "'quit' to end both client and server\n>\n"); 


    /* Set stdin to be non-blocking: */
    fcntl(0, F_SETFL, fcntl(0, F_GETFL, 0) | O_NONBLOCK);


    quit = 0;
    while(!quit)
    { 
        // See if we have any messages from server:
        game_check_msgs();

        //Get user input from command line and send it to server: 
        /*now display the options*/
        if(read_stdin_nonblock(buffer, NET_BUF_LEN))
        { 
            //Figure out if we are trying to quit:
            if( (strncmp(buffer, "exit", 4) == 0)
                    ||(strncmp(buffer, "quit", 4) == 0))

            {
                quit = 1;
            }
            else if (strncmp(buffer, "game", 4) == 0)
            {
                // Begin the actual math game
                playgame();
                fprintf(stderr, "Math game finished.\n\n");
                fprintf(stderr, "Type:\n"
                        "'game' to start math game;\n"
                        "'exit' to end client leaving server running;\n"
                        "'quit' to end both client and server\n>\n"); 
            }
            else
            {
                fprintf(stderr, "Command not recognized. Type:\n"
                        "'game' to start math game;\n"
                        "'exit' to end client leaving server running;\n"
                        "'quit' to end both client and server\n\n>\n");
            }
        }
        //Limit loop to once per 10 msec so we don't eat all CPU
        Throttle(10, &timer);
    }

    LAN_Cleanup();

    return EXIT_SUCCESS;
}