void note_remove( BOARD_DATA * board, NOTE_DATA * pnote ) { if( !board ) { bug( "note remove: null board", 0 ); return; } if( !pnote ) { bug( "note remove: null pnote", 0 ); return; } /* * Remove note from linked list. */ UNLINK( pnote, board->first_note, board->last_note, next, prev ); --board->num_posts; free_note( pnote ); write_board( board ); }
int main(int argc, char *argv[]) { vector<board> all_state; deque<board> q; set<board> h; unsigned int MAX_BOARD_NUM; vector<board> next_boards; unsigned int i, j, n; board b; set<board>::iterator iter; if (argc == 2) { MAX_BOARD_NUM = atoi(argv[1]); } else{ MAX_BOARD_NUM = 10; } b = get_init_board(); write_board(b); b = regulate(b); write_board(b); i = 0; q.push_back(b); while(!q.empty()) { if (i>=MAX_BOARD_NUM) { break; } b = q.front(); q.pop_front(); iter = h.find(b); if (iter == h.end()) { all_state.push_back(b); h.insert(b); i++; // 終わった盤面からは解析しない if (!is_win_state(b) && !is_lose_state(b)) { next_boards.clear(); get_next_board(next_boards, b); n = next_boards.size(); for (j=0; j<n; j++) { // ちゃんと正規化して,手番を合わせて保存 b = get_reverse(next_boards[j]); b = regulate(b); q.push_back(b); } } } } // ソート sort(all_state.begin(), all_state.end()); fprintf(stderr, "num of all-state = %ld\n", all_state.size()); ofstream ofs("all-state.dat"); ofs.write((char *)&all_state[0],all_state.size()*sizeof(board)); return 0; }
void do_note( CHAR_DATA * ch, char *arg_passed, bool IS_MAIL ) { char buf[MAX_STRING_LENGTH]; char arg[MAX_INPUT_LENGTH]; NOTE_DATA *pnote = NULL; BOARD_DATA *board = NULL; int vnum = 0; int anum = 0; int first_list = 0; OBJ_DATA *paper = NULL, *tmpobj = NULL; EXTRA_DESCR_DATA *ed = NULL; char notebuf[MAX_STRING_LENGTH]; char short_desc_buf[MAX_STRING_LENGTH]; char long_desc_buf[MAX_STRING_LENGTH]; char keyword_buf[MAX_STRING_LENGTH]; bool mfound = FALSE; bool wasfound = FALSE; if( IS_NPC( ch ) ) return; if( !ch->desc ) { bug( "do_note: no descriptor", 0 ); return; } switch ( ch->substate ) { default: break; case SUB_WRITING_NOTE: if( ( paper = get_eq_char( ch, WEAR_HOLD ) ) == NULL || paper->item_type != ITEM_PAPER ) { bug( "do_note: player not holding paper", 0 ); stop_editing( ch ); return; } ed = ( EXTRA_DESCR_DATA * ) ch->dest_buf; STRFREE( ed->description ); ed->description = copy_buffer( ch ); stop_editing( ch ); return; } set_char_color( AT_NOTE, ch ); arg_passed = one_argument( arg_passed, arg ); smash_tilde( arg_passed ); if( !str_cmp( arg, "list" ) ) { board = find_board( ch ); if( !board ) { send_to_char( "There is no board here to look at.\r\n", ch ); return; } if( !can_read( ch, board ) ) { send_to_char ( "You cannot make any sense of the cryptic scrawl on this board...\r\n", ch ); return; } first_list = atoi( arg_passed ); if( first_list ) { if( IS_MAIL ) { send_to_char ( "You cannot use a list number (at this time) with mail.\r\n", ch ); return; } if( first_list < 1 ) { send_to_char( "You can't read a message before 1!\r\n", ch ); return; } } if( !IS_MAIL ) { vnum = 0; set_pager_color( AT_NOTE, ch ); for( pnote = board->first_note; pnote; pnote = pnote->next ) { vnum++; if( ( first_list && vnum >= first_list ) || !first_list ) pager_printf( ch, "%2d%c %-12s%c %-12s %s\r\n", vnum, is_note_to( ch, pnote ) ? ')' : '}', pnote->sender, ( pnote->voting != VOTE_NONE ) ? ( pnote->voting == VOTE_OPEN ? 'V' : 'C' ) : ':', pnote->to_list, pnote->subject ); } act( AT_ACTION, "$n glances over the messages.", ch, NULL, NULL, TO_ROOM ); return; } else { vnum = 0; if( IS_MAIL ) /* SB Mail check for Brit */ { for( pnote = board->first_note; pnote; pnote = pnote->next ) if( is_note_to( ch, pnote ) ) mfound = TRUE; if( !mfound && !IS_IMMORTAL( ch ) ) { ch_printf( ch, "You have no mail.\r\n" ); return; } } for( pnote = board->first_note; pnote; pnote = pnote->next ) if( is_note_to( ch, pnote ) || IS_IMMORTAL( ch ) ) ch_printf( ch, "%2d%c %s: %s\r\n", ++vnum, is_note_to( ch, pnote ) ? '-' : '}', pnote->sender, pnote->subject ); return; } } if( !str_cmp( arg, "read" ) ) { bool fAll = FALSE; board = find_board( ch ); if( !board ) { send_to_char( "There is no board here to look at.\r\n", ch ); return; } if( !can_read( ch, board ) ) { send_to_char ( "You cannot make any sense of the cryptic scrawl on this board...\r\n", ch ); return; } if( !str_cmp( arg_passed, "all" ) ) { fAll = TRUE; anum = 0; } else if( is_number( arg_passed ) ) { fAll = FALSE; anum = atoi( arg_passed ); } else { send_to_char( "Note read which number?\r\n", ch ); return; } set_pager_color( AT_NOTE, ch ); if( !IS_MAIL ) { vnum = 0; for( pnote = board->first_note; pnote; pnote = pnote->next ) { vnum++; if( vnum == anum || fAll ) { wasfound = TRUE; pager_printf( ch, "[%3d] %s: %s\r\n%s\r\nTo: %s\r\n%s", vnum, pnote->sender, pnote->subject, pnote->date, pnote->to_list, pnote->text ); if( pnote->yesvotes[0] != '\0' || pnote->novotes[0] != '\0' || pnote->abstentions[0] != '\0' ) { send_to_pager ( "------------------------------------------------------------\r\n", ch ); pager_printf( ch, "Votes:\r\nYes: %s\r\nNo: %s\r\nAbstain: %s\r\n", pnote->yesvotes, pnote->novotes, pnote->abstentions ); } act( AT_ACTION, "$n reads a message.", ch, NULL, NULL, TO_ROOM ); } } if( !wasfound ) ch_printf( ch, "No such message: %d\r\n", anum ); return; } else { vnum = 0; for( pnote = board->first_note; pnote; pnote = pnote->next ) { if( is_note_to( ch, pnote ) || IS_IMMORTAL( ch ) ) { vnum++; if( vnum == anum || fAll ) { wasfound = TRUE; pager_printf( ch, "[%3d] %s: %s\r\n%s\r\nTo: %s\r\n%s", vnum, pnote->sender, pnote->subject, pnote->date, pnote->to_list, pnote->text ); } } } if( !wasfound ) ch_printf( ch, "No such message: %d\r\n", anum ); return; } } /* Voting added by Narn, June '96 */ if( !str_cmp( arg, "vote" ) ) { char arg2[MAX_INPUT_LENGTH]; arg_passed = one_argument( arg_passed, arg2 ); board = find_board( ch ); if( !board ) { send_to_char( "There is no bulletin board here.\r\n", ch ); return; } if( !can_read( ch, board ) ) { send_to_char( "You cannot vote on this board.\r\n", ch ); return; } if( is_number( arg2 ) ) anum = atoi( arg2 ); else { send_to_char( "Note vote which number?\r\n", ch ); return; } vnum = 1; for( pnote = board->first_note; pnote && vnum < anum; pnote = pnote->next ) vnum++; if( !pnote ) { send_to_char( "No such note.\r\n", ch ); return; } /* Options: open close yes no abstain */ /* If you're the author of the note and can read the board you can open and close voting, if you can read it and voting is open you can vote. */ if( !str_cmp( arg_passed, "open" ) ) { if( str_cmp( ch->name, pnote->sender ) ) { send_to_char( "You are not the author of this message.\r\n", ch ); return; } pnote->voting = VOTE_OPEN; act( AT_ACTION, "$n opens voting on a note.", ch, NULL, NULL, TO_ROOM ); send_to_char( "Voting opened.\r\n", ch ); write_board( board ); return; } if( !str_cmp( arg_passed, "close" ) ) { if( str_cmp( ch->name, pnote->sender ) ) { send_to_char( "You are not the author of this message.\r\n", ch ); return; } pnote->voting = VOTE_CLOSED; act( AT_ACTION, "$n closes voting on a note.", ch, NULL, NULL, TO_ROOM ); send_to_char( "Voting closed.\r\n", ch ); write_board( board ); return; } /* Make sure the note is open for voting before going on. */ if( pnote->voting != VOTE_OPEN ) { send_to_char( "Voting is not open on this note.\r\n", ch ); return; } /* Can only vote once on a note. */ sprintf( buf, "%s %s %s", pnote->yesvotes, pnote->novotes, pnote->abstentions ); if( is_name( ch->name, buf ) ) { send_to_char( "You have already voted on this note.\r\n", ch ); return; } if( !str_cmp( arg_passed, "yes" ) ) { sprintf( buf, "%s %s", pnote->yesvotes, ch->name ); DISPOSE( pnote->yesvotes ); pnote->yesvotes = str_dup( buf ); act( AT_ACTION, "$n votes on a note.", ch, NULL, NULL, TO_ROOM ); send_to_char( "Ok.\r\n", ch ); write_board( board ); return; } if( !str_cmp( arg_passed, "no" ) ) { sprintf( buf, "%s %s", pnote->novotes, ch->name ); DISPOSE( pnote->novotes ); pnote->novotes = str_dup( buf ); act( AT_ACTION, "$n votes on a note.", ch, NULL, NULL, TO_ROOM ); send_to_char( "Ok.\r\n", ch ); write_board( board ); return; } if( !str_cmp( arg_passed, "abstain" ) ) { sprintf( buf, "%s %s", pnote->abstentions, ch->name ); DISPOSE( pnote->abstentions ); pnote->abstentions = str_dup( buf ); act( AT_ACTION, "$n votes on a note.", ch, NULL, NULL, TO_ROOM ); send_to_char( "Ok.\r\n", ch ); write_board( board ); return; } do_note( ch, STRLIT_EMPTY, FALSE ); } if( !str_cmp( arg, "write" ) ) { if( ch->substate == SUB_RESTRICTED ) { send_to_char ( "You cannot write a note from within another command.\r\n", ch ); return; } if( ( paper = get_eq_char( ch, WEAR_HOLD ) ) == NULL || paper->item_type != ITEM_PAPER ) { paper = create_object( get_obj_index( OBJ_VNUM_NOTE ) ); if( ( tmpobj = get_eq_char( ch, WEAR_HOLD ) ) != NULL ) unequip_char( ch, tmpobj ); paper = obj_to_char( paper, ch ); equip_char( ch, paper, WEAR_HOLD ); act( AT_MAGIC, "$n grabs a message disk to record a note.", ch, NULL, NULL, TO_ROOM ); act( AT_MAGIC, "You get a message disk to record your note.", ch, NULL, NULL, TO_CHAR ); } if( paper->value[0] < 2 ) { paper->value[0] = 1; ed = SetOExtra( paper, "_text_" ); ch->substate = SUB_WRITING_NOTE; ch->dest_buf = ed; start_editing( ch, ed->description ); return; } else { send_to_char( "You cannot modify this message.\r\n", ch ); return; } } if( !str_cmp( arg, "subject" ) ) { if( !arg_passed || arg_passed[0] == '\0' ) { send_to_char( "What do you wish the subject to be?\r\n", ch ); return; } if( ( paper = get_eq_char( ch, WEAR_HOLD ) ) == NULL || paper->item_type != ITEM_PAPER ) { paper = create_object( get_obj_index( OBJ_VNUM_NOTE ) ); if( ( tmpobj = get_eq_char( ch, WEAR_HOLD ) ) != NULL ) unequip_char( ch, tmpobj ); paper = obj_to_char( paper, ch ); equip_char( ch, paper, WEAR_HOLD ); act( AT_MAGIC, "$n grabs a message disk.", ch, NULL, NULL, TO_ROOM ); act( AT_MAGIC, "You get a message disk to record your note.", ch, NULL, NULL, TO_CHAR ); } if( paper->value[1] > 1 ) { send_to_char( "You cannot modify this message.\r\n", ch ); return; } else { paper->value[1] = 1; ed = SetOExtra( paper, "_subject_" ); STRFREE( ed->description ); ed->description = STRALLOC( arg_passed ); send_to_char( "Ok.\r\n", ch ); return; } } if( !str_cmp( arg, "to" ) ) { struct stat fst; char fname[1024]; if( !arg_passed || arg_passed[0] == '\0' ) { send_to_char( "Please specify an addressee.\r\n", ch ); return; } if( ( paper = get_eq_char( ch, WEAR_HOLD ) ) == NULL || paper->item_type != ITEM_PAPER ) { paper = create_object( get_obj_index( OBJ_VNUM_NOTE ) ); if( ( tmpobj = get_eq_char( ch, WEAR_HOLD ) ) != NULL ) unequip_char( ch, tmpobj ); paper = obj_to_char( paper, ch ); equip_char( ch, paper, WEAR_HOLD ); act( AT_MAGIC, "$n gets a message disk to record a note.", ch, NULL, NULL, TO_ROOM ); act( AT_MAGIC, "You grab a message disk to record your note.", ch, NULL, NULL, TO_CHAR ); } if( paper->value[2] > 1 ) { send_to_char( "You cannot modify this message.\r\n", ch ); return; } arg_passed[0] = UPPER( arg_passed[0] ); sprintf( fname, "%s%c/%s", PLAYER_DIR, tolower( ( int ) arg_passed[0] ), capitalize( arg_passed ) ); if( !IS_MAIL || stat( fname, &fst ) != -1 || !str_cmp( arg_passed, "all" ) ) { paper->value[2] = 1; ed = SetOExtra( paper, "_to_" ); STRFREE( ed->description ); ed->description = STRALLOC( arg_passed ); send_to_char( "Ok.\r\n", ch ); return; } else { send_to_char( "No player exists by that name.\r\n", ch ); return; } } if( !str_cmp( arg, "show" ) ) { const char *subject = ""; const char *to_list = ""; const char *text = ""; if( ( paper = get_eq_char( ch, WEAR_HOLD ) ) == NULL || paper->item_type != ITEM_PAPER ) { send_to_char( "You are not holding a message disk.\r\n", ch ); return; } if( ( subject = get_extra_descr( "_subject_", paper->first_extradesc ) ) == NULL ) subject = "(no subject)"; if( ( to_list = get_extra_descr( "_to_", paper->first_extradesc ) ) == NULL ) to_list = "(nobody)"; sprintf( buf, "%s: %s\r\nTo: %s\r\n", ch->name, subject, to_list ); send_to_char( buf, ch ); if( ( text = get_extra_descr( "_text_", paper->first_extradesc ) ) == NULL ) text = "The disk is blank.\r\n"; send_to_char( text, ch ); return; } if( !str_cmp( arg, "post" ) ) { char *strtime = NULL; const char *text = NULL; if( ( paper = get_eq_char( ch, WEAR_HOLD ) ) == NULL || paper->item_type != ITEM_PAPER ) { send_to_char( "You are not holding a message disk.\r\n", ch ); return; } if( paper->value[0] == 0 ) { send_to_char( "There is nothing written on this disk.\r\n", ch ); return; } if( paper->value[1] == 0 ) { send_to_char( "This message has no subject... using 'none'.\r\n", ch ); paper->value[1] = 1; ed = SetOExtra( paper, "_subject_" ); STRFREE( ed->description ); ed->description = STRALLOC( "none" ); } if( paper->value[2] == 0 ) { if( IS_MAIL ) { send_to_char( "This message is addressed to no one!\r\n", ch ); return; } else { send_to_char ( "This message is addressed to no one... sending to 'all'!\r\n", ch ); paper->value[2] = 1; ed = SetOExtra( paper, "_to_" ); STRFREE( ed->description ); ed->description = STRALLOC( "All" ); } } board = find_board( ch ); if( !board ) { send_to_char ( "There is no terminal here to upload your message to.\r\n", ch ); return; } if( !can_post( ch, board ) ) { send_to_char ( "You cannot use this terminal. It is encrypted...\r\n", ch ); return; } if( board->num_posts >= board->max_posts ) { send_to_char ( "This terminal is full. There is no room for your message.\r\n", ch ); return; } act( AT_ACTION, "$n uploads a message.", ch, NULL, NULL, TO_ROOM ); strtime = ctime( ¤t_time ); strtime[strlen( strtime ) - 1] = '\0'; CREATE( pnote, NOTE_DATA, 1 ); pnote->date = STRALLOC( strtime ); text = get_extra_descr( "_text_", paper->first_extradesc ); pnote->text = text ? STRALLOC( text ) : STRALLOC( "" ); text = get_extra_descr( "_to_", paper->first_extradesc ); pnote->to_list = text ? STRALLOC( text ) : STRALLOC( "all" ); text = get_extra_descr( "_subject_", paper->first_extradesc ); pnote->subject = text ? STRALLOC( text ) : STRALLOC( "" ); pnote->sender = QUICKLINK( ch->name ); pnote->voting = 0; pnote->yesvotes = str_dup( "" ); pnote->novotes = str_dup( "" ); pnote->abstentions = str_dup( "" ); LINK( pnote, board->first_note, board->last_note, next, prev ); board->num_posts++; write_board( board ); send_to_char( "You upload your message to the terminal.\r\n", ch ); extract_obj( paper ); return; } if( !str_cmp( arg, "remove" ) || !str_cmp( arg, "take" ) || !str_cmp( arg, "copy" ) ) { char take = 0; board = find_board( ch ); if( !board ) { send_to_char ( "There is no terminal here to download a note from!\r\n", ch ); return; } if( !str_cmp( arg, "take" ) ) take = 1; else if( !str_cmp( arg, "copy" ) ) { if( !IS_IMMORTAL( ch ) ) { send_to_char( "Huh? Type 'help note' for usage.\r\n", ch ); return; } take = 2; } else take = 0; if( !is_number( arg_passed ) ) { send_to_char( "Note remove which number?\r\n", ch ); return; } if( !can_read( ch, board ) ) { send_to_char ( "You can't make any sense of what's posted here, let alone remove anything!\r\n", ch ); return; } anum = atoi( arg_passed ); vnum = 0; for( pnote = board->first_note; pnote; pnote = pnote->next ) { if( IS_MAIL && ( ( is_note_to( ch, pnote ) ) || IS_IMMORTAL( ch ) ) ) vnum++; else if( !IS_MAIL ) vnum++; if( ( !str_cmp( ch->name, pnote->sender ) || can_remove( ch, board ) ) && ( vnum == anum ) ) { if( ( is_name( "all", pnote->to_list ) ) && ( !IS_IMMORTAL( ch ) ) && ( take == 1 ) ) { send_to_char ( "Notes addressed to 'all' can not be taken.\r\n", ch ); return; } if( take != 0 ) { paper = create_object( get_obj_index( OBJ_VNUM_NOTE ) ); ed = SetOExtra( paper, "_sender_" ); STRFREE( ed->description ); ed->description = QUICKLINK( pnote->sender ); ed = SetOExtra( paper, "_text_" ); STRFREE( ed->description ); ed->description = QUICKLINK( pnote->text ); ed = SetOExtra( paper, "_to_" ); STRFREE( ed->description ); ed->description = QUICKLINK( pnote->to_list ); ed = SetOExtra( paper, "_subject_" ); STRFREE( ed->description ); ed->description = QUICKLINK( pnote->subject ); ed = SetOExtra( paper, "_date_" ); STRFREE( ed->description ); ed->description = QUICKLINK( pnote->date ); ed = SetOExtra( paper, "note" ); STRFREE( ed->description ); sprintf( notebuf, "From: " ); strcat( notebuf, pnote->sender ); strcat( notebuf, "\r\nTo: " ); strcat( notebuf, pnote->to_list ); strcat( notebuf, "\r\nSubject: " ); strcat( notebuf, pnote->subject ); strcat( notebuf, "\r\n\r\n" ); strcat( notebuf, pnote->text ); strcat( notebuf, "\r\n" ); ed->description = STRALLOC( notebuf ); paper->value[0] = 2; paper->value[1] = 2; paper->value[2] = 2; sprintf( short_desc_buf, "a note from %s to %s", pnote->sender, pnote->to_list ); STRFREE( paper->short_descr ); paper->short_descr = STRALLOC( short_desc_buf ); sprintf( long_desc_buf, "A note from %s to %s lies on the ground.", pnote->sender, pnote->to_list ); STRFREE( paper->description ); paper->description = STRALLOC( long_desc_buf ); sprintf( keyword_buf, "note parchment paper %s", pnote->to_list ); STRFREE( paper->name ); paper->name = STRALLOC( keyword_buf ); } if( take != 2 ) note_remove( board, pnote ); send_to_char( "Ok.\r\n", ch ); if( take == 1 ) { act( AT_ACTION, "$n downloads a message.", ch, NULL, NULL, TO_ROOM ); obj_to_char( paper, ch ); } else if( take == 2 ) { act( AT_ACTION, "$n copies a message.", ch, NULL, NULL, TO_ROOM ); obj_to_char( paper, ch ); } else act( AT_ACTION, "$n removes a message.", ch, NULL, NULL, TO_ROOM ); return; } } send_to_char( "No such message.\r\n", ch ); return; } send_to_char( "Huh? Type 'help note' for usage.\r\n", ch ); }