Example #1
0
/**
 * From Gordon's paper, the gen function.
 * @param pos  The offset from an anchor square.
 * @param word The word generated so far.
 * @param rack The player's current rack.
 * @param arc  An Arc to the initial state of the GADDAG.
 */
void gen(int pos, char* word, uint8_t* rack, ARC* arc, int spaces) {
    // If a letter L is on this square, go_on
    // What square am I on?
    #ifdef DEBUG_
    print_spaces(spaces);
    printf("in gen, %d, Word: %s,", pos, word);
    print_rack(rack);
    #endif
    uint8_t blank_position = game_state.num_distinct_letters - 1;
    uint8_t i, k;
    char letter = is_letter(
        game_state.game_board[game_state.current_anchor_row]
        [game_state.current_anchor_col]);
    if (letter) {
        go_on(pos, letter, word, rack, next_arc(arc, letter), arc, spaces);
    } else if (letters_remain(rack)) {
        /*
         * TODO: for each letter ALLOWED ON THIS SQUARE, not just all
         * letters.
         */
        // For all letters, except the blank.
        for (i = 0; i < game_state.num_distinct_letters - 1; i++) {
            if (rack[i] > 0) {
                #ifdef DEBUG_
                print_spaces(spaces);
                printf("%d %cs\n", rack[i], i + 'A');
                #endif
                // Letter (i + 'A') is on this rack. Temporarily remove it.
                rack[i]--;
                go_on(pos, i + 'A', word, rack, next_arc(arc, i + 'A'),
                      arc, spaces + 1);
                // Re-add letter.
                rack[i]++;
            }
        }
        // Check if there is a blank.
        if (rack[blank_position] > 0) {
            // For each blank
            for (k = 0; k < game_state.num_distinct_letters; k++) {
                /**
                 * TODO: For each letter the blank could be ALLOWED
                 * ON THIS SQUARE.
                 */
                rack[blank_position]--;
                go_on(pos, k + 'A', word, rack, next_arc(arc, k + 'A'),
                      arc, spaces + 1);
                rack[blank_position]++;
            }
        }
    }
}
Example #2
0
MINDY_NORETURN
void mindy_pause(enum pause_reason reason)
{
    clear_interrupt_handler();
    if (reason != pause_NoReason)
        PauseReason = reason;
    go_on();
}
Example #3
0
MINDY_NORETURN
static obj_t dylan_getc(void)
{
    getc_or_wait(thread_current());
    go_on();
    /* go_on never returns. */
    lose("go_on actually returned?");
}
void client()
{
    int ret;
    int s = socket(AF_INET, SOCK_STREAM, 0);
    assert(s >= 0);

    client_end go_on(s);

    sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htons(g_port);
    addr.sin_addr.s_addr = inet_addr(g_ip);
    ret = ::connect(s, (sockaddr*)&addr, sizeof(addr));
    if (ret < 0) {
        printf("connect error %d:%s\n", errno, strerror(errno));
        return ;
    }
    boost::shared_ptr<int> __cp(conn_count_p);

    for (;;)
    {
        co_sleep(180 * 1000);
        //co_sleep(180);
        ssize_t wpos = 0;
retry_write:
        ssize_t wn = ::write(s, (char*)&sping + wpos, sizeof(sping) - wpos);
        if (wn < 0) {
            if (errno == EINTR)
                goto retry_write;
            else
                return ;
        }
        wpos += wn;
        if (wpos < sizeof(sping))
            goto retry_write;
        printf("ping\n");

        Pong pong;
        ssize_t rpos = 0;
retry_read:
        ssize_t rn = ::read(s, (char*)&pong + rpos, sizeof(pong) - rpos);
        if (rn < 0) {
            if (errno == EINTR)
                goto retry_read;
            else
                return ;
        }
        if (rn == 0) {
            return ;
        }
        rpos += rn;
        if (rpos < sizeof(pong))
            goto retry_read;
        printf("pong\n");
    }
}
Example #5
0
void type_error(obj_t value, obj_t type)
{
    if (error_system_enabled) {
	struct thread *thread = thread_current();
	*thread->sp++ = type_error_var->value;
	*thread->sp++ = value;
	*thread->sp++ = type;
	invoke(thread, 2);
	go_on();
    }
    else
	error("%= is not an instance of type %=", value, type);
}
Example #6
0
int main()
{
	void control();
	void print();
	void seed();
	void map();
	void find();
	void judge_1();
	void follow();
	void food();
	void go_on();
	void add();
loop1:
	tail = NULL;
	head = &b[0];
	for (i = 0; i <= N; i++)
	{
		b[i].next = &b[i + 1];
		b[i + 1].previous = &b[i];
	}
	b[N].next = tail;
	b[0].x = 10;
	b[0].y = 11;
	b[1].x = 10;
	b[1].y = 10;
	b[2].x = 10;
	b[2].y = 9;
	for (i = 0; i <= N; i++)
		a[b[i].x][b[i].y] = 'O';
loop2: seed();
	while (1)
	{
		map();
		food();
		find();
		system("cls");
		print();
		Sleep(300);
		if (_kbhit())
		{
			control();
			follow();
		}
		else go_on();
		judge_1();
	}
	return 0;
}
Example #7
0
static void verror(char *msg, va_list ap)
{
    int nargs = count_format_args(msg);
    int i;
    struct thread *thread = thread_current();
    
    if (error_system_enabled) {
	*thread->sp++ = error_var->value;
	*thread->sp++ = make_byte_string(msg);
	for (i = 0; i < nargs; i++)
	    *thread->sp++ = va_arg(ap, obj_t);

	invoke(thread, nargs+1);
	go_on();
    }
    else if (thread) {
	obj_t cond = make_vector(nargs+1, NULL);

	SOVEC(cond)->contents[0] = make_byte_string(msg);
	for (i = 1; i <= nargs; i++)
	    SOVEC(cond)->contents[i] = va_arg(ap, obj_t);

	thread_debuggered(thread, cond);
    }
    else {
	obj_t cond = make_vector(nargs, NULL);

	for (i = 0; i < nargs; i++)
	    SOVEC(cond)->contents[i] = va_arg(ap, obj_t);
	
	printf("error: ");
	vformat(msg, SOVEC(cond)->contents, nargs);
	putchar('\n');
	exit(1);
    }
}
Example #8
0
main() {
   int x, y, loop = 1, fact = 0;
   char instring[200], outstring[200], sub[200], vrb[200], rst[200], qwd[200];
   char osub[200], ovrb[200], orst[200];
   fam = 0;
   printf("Hello there.  My name is Eliza and I was written by Mohan Embar.\n");
   printf("Please type \"END\" to end this session.\n");
   printf("I'm here to help you if I can.  What seems to be the trouble?\n");
   while (loop) {
      printf("\n");
      gets(instring);
      printf("\n");
      parse(instring);
      if (numwords == 0) {
         switch (x = randnum(2)) {
            case 1 : printf("Don't you have anything to say?\n");
               break;
            case 2 : printf("Cat got your tongue?\n");
               break;
         }
         continue;
      }
      if (!strcmp(s[1],"END")) {
         printf("Goodbye.  Please come again.\n");
         break;
      }
      agree();
      if (bad_word())
         printf(b_word_resp());
      else if (naughty_word())
         printf(n_word_resp());
      else if (x = family()) {
         fam = x;
         printf(fam_resp());
         strcpy(fam_member,s[fam]);
      }
      else if (sword("ALIKE",1))
         printf(alike_resp());
      else if (sword("ALWAYS",1))
         printf(always_resp());
      else if (sword("BECAUSE",1))
         printf(because_resp());
      else if (sword("YES",1))
         printf(yes_resp());
      else if (sword("NO",1) || sword("NOT",1))
         printf(neg_resp());
      else if (x = i_am()) { /* If occurrence of I AM x.. */
         get_til_stop(x,outstring);    /* Get I AM x .. into outstring */
         printf(i_am_resp(),outstring); /* Print reponse for this */
      }
      else if (real_quest() ||
              (is_helper(s[1]) && is_sub_pronoun(s[2])) ||
              sub_and_helper()) {
         if (real_quest()) {
            strcpy(qwd,s[1]);
            strcpy(vrb,s[2]);
            strcpy(sub,s[3]);
            get_til_stop(4,rst);
         }
         else if (is_helper(s[1]) && is_sub_pronoun(s[2])) {
            strcpy(vrb,s[1]);
            strcpy(sub,s[2]);
            get_til_stop(3,rst);
            strcpy(qwd,"YES");
         }
         else if (sub_and_helper()) {
            x = find_helper();
            y = search_back_sub(x);
            strcpy(vrb,s[x]);
            get_til_stop(x+1,rst);
            getrange(y,x-1,sub);
            strcpy(qwd,"NO");
         }
         make_lower(qwd);
         if (strcmp(sub,"I")) make_lower(sub);
         make_lower(vrb);
         make_lower(rst);
         /* First do x verb y responses */

         /*
	 printf("\n*** %s\n",sub);
         */
	 
	 if (!strcmp(sub," I") || !strcmp(sub,"I")) {
            printf(you_resp());
         }
         else if (!strcmp(qwd,"no")) {
            /* Record this statement for later use. */
            fact = 1;
            strcpy(osub,sub); strcpy(ovrb,vrb); strcpy(orst,rst);
            if (is_be(vrb) && !strcmp(sub," you") && (y = sad_word())) {
               getrange(y,y,outstring);
               x = randnum(5)+6;
            }
            else if (is_be(vrb) && (y = sad_word())) {
               getrange(y,y,outstring);
               x = randnum(2)+11;
            }
            else if (is_be(vrb))
               x = randnum(6);
            else x = randnum(4);
            switch (x) {
               case 1 : printf("How do you feel about%s?\n",cnnv(sub));
                  break;
               case 2 : printf("Why %s%s%s?\n",vrb,sub,rst);
                  break;
               case 3 : for (y=1;sub[y]=sub[y--];y=y+2);
                  sub[0] = toupper(sub[0]);
                  printf("%s %s%s?\n",sub,vrb,rst);
                  break;
               case 4 : printf("Could you describe%s for me?\n",cnnv(sub));
                  break;
               case 5 : printf("What if%s were not%s?\n",sub,rst);
                  break;
               case 6 : printf("Would you be happy if%s were not%s?\n",sub,
                                rst);
                  break;
               case 7 : printf("I'm sorry to hear that you are%s.\n",outstring);
                  break;
               case 8 : printf("Do you think that coming here will help you not to be%s?\n",outstring);
                  break;
               case 9 : printf("Let's talk about why you feel%s.\n",outstring);
                  break;
               case 10 : printf("What happened that made you feel%s?\n",outstring);
                  break;
               case 11 : printf("What could be the reason for your feeling%s?\n",outstring);
                  break;
               case 12 : printf("What could cause%s to be%s?\n",cnnv(sub),outstring);
                  break;
               case 13 : printf("If%s came here, would it help%s not to be%s?\n",sub,cnnv(sub),outstring);
                  break;
            }
         }
         else if (!strcmp(sub,"you"))
            printf(you_know());
         else if (!strcmp(qwd,"yes")) {
            x = randnum(8);
            switch (x) {
               case 1 : printf("You want to know if %s %s%s.\n",sub,vrb,rst);
                  break;
               case 2 : printf("If %s %s%s, does that concern you?\n",sub,vrb,rst);
                  break;
               case 3 : printf("What are the consequences if %s %s%s?\n",sub,vrb,rst);
                  break;
               case 4 : printf("Why does %s concern you?\n",sub);
                  break;
               case 5 : printf("Why are you thinking of %s?\n",cnnv(sub));
                  break;
               case 6 : printf("Tell me more about %s.\n",cnnv(sub));
                  break;
               case 7 : printf("To answer that, I'd need to know more about %s.\n",cnnv(sub));
                  break;
               case 8 : printf("What is the relationship between you and %s?\n",cnnv(sub));
                  break;
               case 9 : printf("Why don't you ask %s?\n",cnnv(sub));
                  break;
            }
         }
         else {
            x = randnum(8);
            switch (x) {
               case 1 : printf("You want to know %s %s %s%s.\n",qwd,sub,vrb,rst);
                  break;
               case 2 : printf("If %s %s%s, does that concern you?\n",sub,vrb,rst);
                  break;
               case 3 : printf("What are the consequences if %s %s%s?\n",sub,vrb,rst);
                  break;
               case 4 : printf("Why does %s concern you?\n",sub);
                  break;
               case 5 : printf("Why are you thinking of %s?\n",cnnv(sub));
                  break;
               case 6 : printf("Tell me more about %s.\n",cnnv(sub));
                  break;
               case 7 : printf("To answer that, I'd need to know more about %s.\n",cnnv(sub));
                  break;
               case 8 : printf("What is the relationship between you and %s?\n",cnnv(sub));
                  break;
               case 9 : printf("Why don't you ask %s?\n",cnnv(sub));
                  break;
            }
         }
      }
      else if (is_command())
         printf(command_resp());
      else if (vague_quest())
         printf(question());
      else if ((s[numwords][0] == '?') && !real_quest())
         printf(question());
      else if (x = sad_word()) {
         getrange(x,x,outstring);
         for (y=1;outstring[y]=outstring[y--];y=y+2);
         outstring[0] = toupper(outstring[0]);
         printf("%s?\n",outstring);
      }
      else if (x = can_spit_out()) {
         if (x<=(numwords-2) && is_sub_pronoun(s[x])
                             && (matches("NEED",s[x+1]) ||
                                 matches("WANT",s[x+1]))) {
            get_til_stop(x+2,outstring);
            strcpy(sub,s[x]);
            if (strcmp(sub,"I")) make_lower(sub);
            if (strcmp(s[x],"I")) make_lower(s[x]);
            x = randnum(6);
            switch (x) {
               case 1 : printf("What would it mean to %s if %s got%s?\n",cnnv2(s[x]),sub,outstring);
                  break;
               case 2 : printf("Would %s really be happy if %s got%s?\n",sub,sub,outstring);
                  break;
               case 3 : printf("Why is getting%s so desirable?\n",outstring);
                  break;
               case 4 : printf("Okay.  Suppose %s got%s.  Then what?\n",sub,outstring);
                  break;
               case 5 : printf("Why is this important to %s?\n",cnnv2(sub));
                  break;
               case 6 : printf("What price would %s pay to achieve this?\n",sub);
                  break;
            }
         }
         else {
            get_til_stop(x,outstring);
            outstring[1]=toupper(outstring[1]);
            printf("%s.\n",outstring+1);
         }
      }
      else if (fam) {
         make_lower(fam_member);
         printf(family_resp(),fam_member);
         fam = 0;
      }
      else if (fact && (randnum(5)==3)) {
         printf(old_fact(),osub,ovrb,orst);
         fact = 0;
      }
      else {
         printf(go_on());
      }
   }
}