예제 #1
0
파일: POS_INIT.C 프로젝트: ibarrar/clipper
/*  init_method2(): file method but check existing devices(s)  */
static int init_method2(int dev_no)
{
  FHANDLE dev_handle;           /* device handle */
  int gen_status;  /* generic error codes returned to the application */  
  int other_dev;   

  gen_status = NORMAL;          /* assume normal status */
  other_dev = dev_no;  
  
  if (pos_setup[dev_no].init_flag)
      gen_status = DEV_EXIST;

  if (gen_status == DEV_EXIST)  /* already initialized */
  {
    /* update the POS Device table */ 
    update_table(1, dev_no, pos_setup[other_dev].file_num, -1, -1, -1, -1);  
    gen_status = NORMAL;    
  }
  else  /* not yet initialized */
  {
    dev_handle = _fsOpen(pos_setup[dev_no].dev_type, OPEN_FLAGS );

    gen_status = error_map(_fsError());  /* get the generic error status */

    if (gen_status == NORMAL)
      update_table(1, dev_no, dev_handle, -1, -1, -1, -1);  /* update the POS Device table */        
  }

  return gen_status;  
}
예제 #2
0
static int update_modify_target(struct libmnt_update *upd, struct libmnt_lock *lc)
{
	struct libmnt_table *tb = NULL;
	int rc = 0;

	DBG(UPDATE, mnt_debug_h(upd, "%s: modify target", upd->filename));

	if (lc)
		rc = mnt_lock_file(lc);
	if (rc)
		return rc;

	tb = __mnt_new_table_from_file(upd->filename,
			upd->userspace_only ? MNT_FMT_UTAB : MNT_FMT_MTAB);
	if (tb) {
		struct libmnt_fs *cur = mnt_table_find_target(tb,
				mnt_fs_get_srcpath(upd->fs), MNT_ITER_BACKWARD);
		if (cur) {
			rc = mnt_fs_set_target(cur, mnt_fs_get_target(upd->fs));
			if (!rc)
				rc = update_table(upd, tb);
		}
	}

	if (lc)
		mnt_unlock_file(lc);

	mnt_free_table(tb);
	return rc;
}
static EVENT_HANDLER(physical_ready){
	//printf("PR called!\n");
	int link;
	FRAME f;
	size_t length = sizeof(FRAME);
	CHECK(CNET_read_physical(&link, (char*)&f, &length));
	printf("Packet received from %d, via %d\n", f.payload.source, f.payload.dest);
	//DATA LINK LAYER - check if checksum matches
	int cs = f.checksum;
	f.checksum = 0;
	if(CNET_ccitt((unsigned char*)&f, (int)length) != cs){
		printf("Bad Checksum - ignoring frame!\n");
		return;	
	}
	
	switch(f.payload.kind){
		case RT_DATA : 	update_table(link, f, length); 
			   	break;
		case DL_DATA :  handle_data(link, f, length); 
				break;
		case DL_ACK  :  handle_ack(link, f.payload); 
				break;
		default      :  printf("The world is not enough!\n"); 
				break;
	}
	//printf("Packet successfully processed!");	
}
예제 #4
0
static int update_add_entry(struct libmnt_update *upd, struct libmnt_lock *lc)
{
	struct libmnt_table *tb;
	int rc = 0;

	assert(upd);
	assert(upd->fs);

	DBG(UPDATE, mnt_debug_h(upd, "%s: add entry", upd->filename));

	if (lc)
		rc = mnt_lock_file(lc);
	if (rc)
		return rc;

	tb = __mnt_new_table_from_file(upd->filename,
			upd->userspace_only ? MNT_FMT_UTAB : MNT_FMT_MTAB);
	if (tb) {
		struct libmnt_fs *fs = mnt_copy_fs(NULL, upd->fs);
		if (!fs)
			rc = -ENOMEM;
		else {
			mnt_table_add_fs(tb, fs);
			rc = update_table(upd, tb);
		}
	}

	if (lc)
		mnt_unlock_file(lc);

	mnt_free_table(tb);
	return rc;
}
예제 #5
0
static int update_remove_entry(struct libmnt_update *upd, struct libmnt_lock *lc)
{
	struct libmnt_table *tb;
	int rc = 0;

	assert(upd);
	assert(upd->target);

	DBG(UPDATE, mnt_debug_h(upd, "%s: remove entry", upd->filename));

	if (lc)
		rc = mnt_lock_file(lc);
	if (rc)
		return rc;

	tb = __mnt_new_table_from_file(upd->filename,
			upd->userspace_only ? MNT_FMT_UTAB : MNT_FMT_MTAB);
	if (tb) {
		struct libmnt_fs *rem = mnt_table_find_target(tb, upd->target, MNT_ITER_BACKWARD);
		if (rem) {
			mnt_table_remove_fs(tb, rem);
			rc = update_table(upd, tb);
			mnt_free_fs(rem);
		}
	}

	if (lc)
		mnt_unlock_file(lc);

	mnt_free_table(tb);
	return rc;
}
예제 #6
0
void TopScores::loadTopScores()
{

    save_load_t.load(Topscores);
    update_table();

}
예제 #7
0
파일: scpu.cpp 프로젝트: ben401/OpenEmu
void sCPU::reset() {
  CPU::reset();

  //note: some registers are not fully reset by SNES
  regs.pc   = 0x000000;
  regs.x.h  = 0x00;
  regs.y.h  = 0x00;
  regs.s.h  = 0x01;
  regs.d    = 0x0000;
  regs.db   = 0x00;
  regs.p    = 0x34;
  regs.e    = 1;
  regs.mdr  = 0x00;
  regs.wai  = false;
  update_table();

  mmio_reset();
  dma_reset();
  timing_reset();

  apu_port[0] = 0x00;
  apu_port[1] = 0x00;
  apu_port[2] = 0x00;
  apu_port[3] = 0x00;
}
예제 #8
0
파일: neighbor.c 프로젝트: nesl/sos-2x
static int8_t nbr_msg_handler(void *state, Message *msg)
{
	nbr_state_t *s = (nbr_state_t*)state;
	
	/**
	* Switch to the correct message handler
	 */
	switch (msg->type){
		case MSG_INIT:
		{
		
			s->nb_list = NULL;
			s->nb_cnt = 0;
			s->est_ticks = 0;
			s->gCurrentSeqNo = 0;
			
			sys_shm_open( sys_shm_name(NBHOOD_PID, SHM_NBR_LIST), s->nb_list );
			
			sys_timer_start(BACKOFF_TIMER, sys_rand() % 1024L, TIMER_ONE_SHOT);
			break;
		}
			
		case MSG_FINAL:
		{
			break;
		}
			
		case MSG_TIMER_TIMEOUT:
		{
			if( timer_get_tid( msg ) == BACKOFF_TIMER ) {
				sys_timer_start(NEIGHBOR_DISCOVERY_TIMER, NEIGHBOR_TIMER_INTERVAL, TIMER_REPEAT);
			} else {
				//
				// Send beacon packets
				//
				update_table( s );
				sys_shm_update( sys_shm_name(NBHOOD_PID, SHM_NBR_LIST), s->nb_list );
				send_beacon( s );
				nb_debug(s);
			}
			break;
		}
		case MSG_BEACON_PKT:
		{
			//
			// Process beacon packets
			//
			recv_beacon( s, msg );
			break;
		}
			
		default:
			return -EINVAL;
	}
	
	/**
		* Return SOS_OK for those handlers that have successfully been handled.
	 */
	return SOS_OK;
}
예제 #9
0
void CPU::reset() {
  create(Enter, system.cpu_frequency());
  coprocessors.reset();
  PPUcounter::reset();

  regs.pc = 0x000000;
  regs.x.h = 0x00;
  regs.y.h = 0x00;
  regs.s.h = 0x01;
  regs.d = 0x0000;
  regs.db = 0x00;
  regs.p = 0x34;
  regs.e = 1;
  regs.mdr = 0x00;
  regs.wai = false;
  update_table();

  regs.pc.l = bus.read(0xfffc);
  regs.pc.h = bus.read(0xfffd);
  regs.pc.b = 0x00;

  status.nmi_valid = false;
  status.nmi_line = false;
  status.nmi_transition = false;
  status.nmi_pending = false;

  status.frame_event_performed = false;

  status.irq_valid = false;
  status.irq_line = false;
  status.irq_transition = false;
  status.irq_pending = false;

  status.irq_lock = false;
  status.hdma_pending = false;

  status.wram_addr = 0x000000;

  status.joypad_strobe_latch = 0;

  status.nmi_enabled = false;
  status.virq_enabled = false;
  status.hirq_enabled = false;
  status.auto_joypad_poll_enabled = false;

  status.pio = 0xff;

  status.htime = 0x0000;
  status.vtime = 0x0000;

  status.rom_speed = 8;

  status.joy1l = status.joy1h = 0x00;
  status.joy2l = status.joy2h = 0x00;
  status.joy3l = status.joy3h = 0x00;
  status.joy4l = status.joy4h = 0x00;

  dma_reset();
}
예제 #10
0
파일: POS_INIT.C 프로젝트: ibarrar/clipper
/*  close_method3(): direct or other method  */
static int close_method3(int dev_no)
{

  update_table(0, dev_no, -1, -1, -1, -1, -1);

  return NORMAL;  /* for the meantime */
		  /* up to this time rci 3-15-97 */
}
예제 #11
0
template<int mode> void R65816::op_pflag_n() {
  rd.l = op_readpc();
L op_io();
  regs.p = (mode ? regs.p | rd.l : regs.p & ~rd.l);
  if(regs.p.x) {
    regs.x.h = 0x00;
    regs.y.h = 0x00;
  }
  update_table();
}
예제 #12
0
void R65816::op_plp_n() {
  op_io();
  op_io();
L regs.p = op_readstack();
  if(regs.p.x) {
    regs.x.h = 0x00;
    regs.y.h = 0x00;
  }
  update_table();
}
예제 #13
0
void TopScores::on_Azzera_clicked()
{
    for (int i=0; i<10; i++)
    {
        qstrcpy(Topscores[i].Nome, "nDisp");
        Topscores[i].POINTS = 0;
    }
    update_table();
    save_load_t.save(Topscores);
}
예제 #14
0
void TableSet::update_database() {
  log( "TableSet::update_database" );
  for( TableSet::iterator it = begin(); it != end(); ++it ) {
    Table td = it->second;
    log( td.table_name() );
    if( td.connection()->table_exists( td.table_name() ) )
      update_table( td );
    else
      create_table( td );
  }
}
예제 #15
0
void *reciever(void *params)
{
  struct hb_entry* temp;
  char *message;
  while(1){
      message = (char *) recvudp(hb_table[host_no].IP,hb_table[host_no].port);
      clear_temp_entry_table(entry);
      temp = extract_message(message);
      update_table(temp); 
  }
}
예제 #16
0
파일: POS_INIT.C 프로젝트: ibarrar/clipper
/*  close_method2(): file method but check existing devices(s)  */
static int close_method2(int dev_no)
{
  int gen_status;  /* generic error codes returned to the application */
  int other_dev;

  other_dev = 0;
  gen_status = NORMAL;  /* assume normal status */

   
  switch (dev_no)
  {
     case POS_KEYBOARD: 
     case POS_CARD_READ:
     case POS_CKEYLOCK: /* check existing devices */
                        if (chk_init_flag(POS_CARD_READ))  /* card reader */
                          ++other_dev;  

                        if (chk_init_flag(POS_CKEYLOCK))  /* keylock */
                          ++other_dev;

                        if (chk_init_flag(POS_KEYBOARD))  /* POS keyboard */
                          ++other_dev;

                        break;
                    
  }  

  if (other_dev > 1)  /* link to other devices */
    update_table(0, dev_no, -1, -1, -1, -1, -1);  /* update the POS Device table */ 
  else  
  {
    _fsClose(pos_setup[dev_no].file_num);

    gen_status = error_map(_fsError());  /* get the generic error status */

    if (gen_status == NORMAL)
      update_table(0, dev_no, -1, -1, -1, -1, -1);  /* update the POS Device table */
  }

  return gen_status;
}
예제 #17
0
void CPUDebugger::setFlag(unsigned id, bool value) {
  switch (id) {
  case FlagE: regs.e   = value; return;
  case FlagN: regs.p.n = value; return;
  case FlagV: regs.p.v = value; return;
  case FlagD: regs.p.d = value; return;
  case FlagI: regs.p.i = value; return;
  case FlagZ: regs.p.z = value; return;
  case FlagC: regs.p.c = value; return;
  case FlagM: 
    regs.p.m = value; 
    update_table();
    return;
  case FlagX: 
    regs.p.x = value;
    if (value)
      regs.x.h = regs.y.h = 0; 
    update_table();
    return;
  }
}
예제 #18
0
파일: POS_INIT.C 프로젝트: ibarrar/clipper
/*  int close_method1(): file method  */
static int close_method1(int dev_no)
{
  int gen_status;  /* generic error codes returned to the application */

  _fsClose(pos_setup[dev_no].file_num);

  gen_status = error_map(_fsError());  /* get the generic error status */

  if (gen_status == NORMAL)
    update_table(0, dev_no, -1, -1, -1, -1, -1);  /* update the POS Device table */

  return gen_status;
}
예제 #19
0
파일: POS_INIT.C 프로젝트: ibarrar/clipper
/*  init_method1(): file method  */
static int init_method1(int dev_no)
{
  FHANDLE dev_handle;           /* device handle */
  int gen_status;               /* generic error codes returned to the application */  

  dev_handle = _fsOpen(pos_setup[dev_no].dev_type, OPEN_FLAGS );

  gen_status = error_map(_fsError());  /* get the generic error status */

  if (gen_status == NORMAL)
    update_table(1, dev_no, dev_handle, -1, -1, -1, -1);  /* update the POS Device table */    

  return gen_status;    
}
예제 #20
0
void R65816::op_rti_n() {
  op_io();
  op_io();
  regs.p = op_readstack();
  if(regs.p.x) {
    regs.x.h = 0x00;
    regs.y.h = 0x00;
  }
  rd.l = op_readstack();
  rd.h = op_readstack();
L rd.b = op_readstack();
  regs.pc.d = rd.d & 0xffffff;
  update_table();
}
예제 #21
0
void R65816::op_xce() {
L op_io_irq();
  bool carry = regs.p.c;
  regs.p.c = regs.e;
  regs.e = carry;
  if(regs.e) {
    regs.p |= 0x30;
    regs.s.h = 0x01;
  }
  if(regs.p.x) {
    regs.x.h = 0x00;
    regs.y.h = 0x00;
  }
  update_table();
}
예제 #22
0
void CPUcore::op_rti() {
  op_io();
  op_io();
  regs.p = op_readstack() | (regs.e ? 0x30 : 0);
  if(regs.p.x) {
    regs.x.h = 0x00;
    regs.y.h = 0x00;
  }
  regs.pc.l = op_readstack();
  if(regs.e) {
L   regs.pc.h = op_readstack();
  } else {
    regs.pc.h = op_readstack();
L   regs.pc.b = op_readstack();
  }
  update_table();
}
예제 #23
0
/* Create the initial path list for solution's finding*/
void create_initial_path_list(struct stack **initial_path_list){
  int tmp_table[SIZE][SIZE];
  struct around aro;
  int value=pro_num_pos[0].value;
  struct position current_position=pro_num_pos[0].pos;
  
  for(aro.left=0; aro.left<value; ++aro.left){
    for(aro.right=0; aro.right<value-aro.left; ++aro.right){
      for(aro.up=0; aro.up<value-aro.left-aro.right; ++aro.up){
	aro.down=value-1-aro.left-aro.right-aro.up;
	
	if(check(blank_table,current_position,aro)){
	  copy_table(tmp_table,blank_table);
	  update_table(tmp_table,current_position,aro);
	  push(initial_path_list,tmp_table,1);
	}
      }
    }
  }
}
예제 #24
0
/* Extend path_list, depth-first*/
struct stack* extend(struct stack **path_list,int table[][SIZE],int step){
  int tmp_table[SIZE][SIZE];
  struct around aro;
  int value=pro_num_pos[step].value;
  struct position current_position=pro_num_pos[step].pos;
  for(aro.left=0; aro.left<value; ++aro.left){
    for(aro.right=0; aro.right<value-aro.left; ++aro.right){
      for(aro.up=0; aro.up<value-aro.left-aro.right; ++aro.up){
	// assure the number of white mass is equal to value
	aro.down=value-1-aro.left-aro.right-aro.up;
	if(check(table,current_position,aro)){
	  copy_table(tmp_table,table);
	  update_table(tmp_table,current_position,aro);
	  push(path_list,tmp_table,step+1);
	}
      }
    }
  }
  return *path_list;
}
예제 #25
0
static int update_modify_options(struct libmnt_update *upd, struct libmnt_lock *lc)
{
	struct libmnt_table *tb = NULL;
	int rc = 0;
	struct libmnt_fs *fs;

	assert(upd);
	assert(upd->fs);

	DBG(UPDATE, mnt_debug_h(upd, "%s: modify options", upd->filename));

	fs = upd->fs;

	if (lc)
		rc = mnt_lock_file(lc);
	if (rc)
		return rc;

	tb = __mnt_new_table_from_file(upd->filename,
			upd->userspace_only ? MNT_FMT_UTAB : MNT_FMT_MTAB);
	if (tb) {
		struct libmnt_fs *cur = mnt_table_find_target(tb,
					mnt_fs_get_target(fs),
					MNT_ITER_BACKWARD);
		if (cur) {
			if (upd->userspace_only)
				rc = mnt_fs_set_attributes(cur,	mnt_fs_get_attributes(fs));
			if (!rc)
				rc = mnt_fs_set_options(cur, mnt_fs_get_options(fs));
			if (!rc)
				rc = update_table(upd, tb);
		}
	}

	if (lc)
		mnt_unlock_file(lc);

	mnt_free_table(tb);
	return rc;
}
예제 #26
0
void CPU::reset() {
  create(Enter, system.cpu_frequency());
  coprocessors.reset();
  PPUcounter::reset();

  //note: some registers are not fully reset by SNES
  regs.pc   = 0x000000;
  regs.x.h  = 0x00;
  regs.y.h  = 0x00;
  regs.s.h  = 0x01;
  regs.d    = 0x0000;
  regs.db   = 0x00;
  regs.p    = 0x34;
  regs.e    = 1;
  regs.mdr  = 0x00;
  regs.wai  = false;
  update_table();

  mmio_reset();
  dma_reset();
  timing_reset();
}
예제 #27
0
/* Extend path_list with all new possibilities, depth-first*/
struct stack* extend(struct stack **path_list,int *table,int step){
  int *tmp_table=NULL;
  struct around aro;
  int value=number_position[step].value;
  tmp_table=new_table();   // allocate memory for temporary table
  struct position current_position=number_position[step].pos;
  for(aro.left=0; aro.left<value; ++aro.left){
    for(aro.right=0; aro.right<value-aro.left; ++aro.right){
      for(aro.up=0; aro.up<value-aro.left-aro.right; ++aro.up){
	// assure the number of white grid is equal to value
	aro.down=value-1-aro.left-aro.right-aro.up;
	// if black grids can be placed around the grid in question
	// push the updated tatble to the path_list
	if(check(table,current_position,aro)){
	  copy_table(tmp_table,table);
	  update_table(tmp_table,current_position,aro);
	  push(path_list,tmp_table,step+1);
	}
      }
    }
  }
  free(tmp_table);
  return *path_list;
}
예제 #28
0
/****************************************************************
 * NAME: receiverFunc 
 *
 * DESCRIPTION: This is the function that takes care of servicing
 *              the first among the three threads spawned i.e.
 *              the receiver threads which does the following:
 *              i) If I am a LEADER approve join requests from 
 *                 member hosts
 *              ii) Receive heartbeats
 *              
 * PARAMETERS: NONE 
 *
 * RETURN:
 * (int) ZERO if success
 *       ERROR otherwise
 * 
 ****************************************************************/
int receiverFunc()
{

    funcEntry(logF, ipAddress, "receiverFunc");

    int rc = SUCCESS,                    // Return code
        numOfBytesRec,                   // Number of bytes received
        i_rc,                            // Temp RC
        op_code;                         // Operation code

    char recMsg[LONG_BUF_SZ],            // Received message
         tokenRecMsg[LONG_BUF_SZ],       // Received message without join op code 
         buffer[SMALL_BUF_SZ];           // Temp buffer

    struct sockaddr_in memberAddress;    // Address of host 
 
    struct hb_entry * recMsgStruct;      // Heart beat table that holds received message

    recMsgStruct = (struct hb_entry *) malloc(4*sizeof(struct hb_entry));

    /*
     * 1) Receive UDP packet
     * 2) Check operation code
     * 3) If JOIN message: 
     *    i) Extract message
     *    ii) Update heartbeat table
     * 4) Else
     *    i) Extract message 
     *    ii) Update heartbeat table
     */

    for(;;)
    {
        /////////
        // Step 1
        /////////
        memset(recMsg, '\0', LONG_BUF_SZ);
        
        // Debug
        printToLog(logF, "recMsg before recvUDP", recMsg);

        numOfBytesRec = recvUDP(recMsg, LONG_BUF_SZ, memberAddress);
        // Check if 0 bytes is received 
        if ( SUCCESS == numOfBytesRec )
        {
             sprintf(logMsg, "Number of bytes received is ZERO = %d", numOfBytesRec);
             printf("\n%s\n", logMsg);
             printToLog(logF, ipAddress, logMsg);
             continue;
        }

        // Debug
        printToLog(logF, "recMsg after recvUDP", recMsg);

        /////////
        // Step 2
        /////////
        i_rc = checkOperationCode(recMsg, &op_code, tokenRecMsg);
        if ( i_rc != SUCCESS ) 
        {
            printToLog(logF, ipAddress, "Unable to retrieve opcode");
            continue;
        }
        /////////
        // Step 3
        /////////
        if ( JOIN_OP_CODE == op_code )
        {
            sprintf(logMsg, "JOIN msg from %s", inet_ntop(AF_INET, &memberAddress.sin_addr, buffer, sizeof(buffer)));
            printToLog(logF, ipAddress, logMsg);
            ///////////
            // Step 3i
            ///////////
            
            // Debug. uncomment if req
            printToLog(logF, ipAddress, "\nBefore clear_temp_entry_table\n"); 

            clear_temp_entry_table(recMsgStruct);

            printToLog(logF, ipAddress, "\nAfter c_t_e_t\n");

            printToLog(logF, ipAddress, "\nbefore extract_msg\n");

            sprintf(logMsg, "Token received message before e_m: %s", tokenRecMsg);
            printToLog(logF, ipAddress, logMsg);

            recMsgStruct = extract_message(tokenRecMsg);

            printToLog(logF, ipAddress, "\nafter e_m\n");

            //printToLog(logF, ipAddress, "\nToken Received Message: %s", tokenRecMsg);

            sprintf(logMsg, "Token received message: %s", tokenRecMsg);
            printToLog(logF, ipAddress, logMsg);

            if ( NULL == recMsgStruct )
            {
                printToLog(logF, ipAddress, "Unable to extract message");
                continue;
            }
            ////////////
            // Step 3ii
            ////////////
            i_rc = update_table(recMsgStruct);
            if ( i_rc != SUCCESS )
            {
                 printToLog(logF, ipAddress, "Unable to update heart beat table");
                 continue;
            }

        } // End of if ( JOIN_OP_CODE == op_code )
        /////////
        // Step 4
        /////////
        else
        {
            //////////
            // Step 4i
            //////////
            clear_temp_entry_table(recMsgStruct);
            recMsgStruct = extract_message(recMsg);
            if ( NULL == recMsgStruct )
            {
                printToLog(logF, ipAddress, "Unable to extract message");
                continue;
            }
            ///////////
            // Step 4ii
            ///////////
            i_rc = update_table(recMsgStruct);
            if ( i_rc != SUCCESS )
            {
                 printToLog(logF, ipAddress, "Unable to update heart beat table");
                 continue;
            }
        } // End of else
    } // End of for(;;)

  rtn:
    funcExit(logF, ipAddress, "receiverFunc", rc);
    return rc;

} // End of receiverFunc()
예제 #29
0
int main() {

	// Make a matrix for the board
	int board[LENGTH];

	// Tracker of current player, 0 for P1, 1 for P2
	int whoseTurn;

	// Stores user's last inputted x and y, variable to store output of check_table_full
	int x, y, fullTable;

	// User input of whether they want to play again or not. 
	char again;

	// Prompts user with explanatory but kind of unhelpful text.
	printf("This program plays the game of tic-tac-toe");


	for(;;) {
		whoseTurn = 0;

		// Clear matrix
		create_clear_table(board, LENGTH);

		fullTable = check_table_full(board, LENGTH);

		while( !check_three_in_a_row(board, LENGTH, whoseTurn) && !fullTable ) { // Not three in a row, not full
			// Display table
			display_table(board, LENGTH);

			// Ask appropriate user for x and y coordinates
			printf("Enter the section of %c for Player %d [row,col]:", (whoseTurn == 0)?'O':'X', (whoseTurn == 0)?1:2);
			scanf("%d,%d", &y, &x);
			while(check_legal_option(board, LENGTH, x, y)) { // Ask user while they have not inputted a legal option
				printf("Invalid selection\nEnter the section of %c for Player %d [row,col]: ", (whoseTurn == 0)?'O':'X', (whoseTurn == 0)?1:2);
				scanf("%d,%d", &y, &x);
			}

			update_table(board, LENGTH, x, y, whoseTurn);

			// Change whoseTurn
			whoseTurn = !whoseTurn;

			// Check again for looping back; just so I don't have to do an extra function call for the win/lose/tie case at the end
			fullTable = check_table_full(board, LENGTH);

		}

		// Win case or lose case or tie case
		display_table(board, LENGTH);
		if(fullTable) { // Tie case
			printf("Game over, no player wins.\n");
		}
		else { // Win case
			printf("Congratulations, Player %d wins! \n", whoseTurn + 1);
		}

		printf("Would you like to play again?\n"); 
		scanf(" %c", &again);

		if(again == 'n' || again == 'N') { // Will by default play again; this catches all plausible variations of "no", including "nah", "neh", "nahhhh" etc.
			return 0;
		}
	}
}
예제 #30
0
void
Power2NodesMPIRandomAccessUpdate(u64Int logTableSize,
                                 u64Int TableSize,
                                 s64Int LocalTableSize,
                                 u64Int MinLocalTableSize,
                                 u64Int GlobalStartMyProc,
                                 u64Int Top,
                                 int logNumProcs,
                                 int NumProcs,
                                 int Remainder,
                                 int MyProc,
                                 s64Int ProcNumUpdates,
                                 MPI_Datatype INT64_DT,
                                 MPI_Status *finish_statuses,
                                 MPI_Request *finish_req)
{
  int i,j,k;
  int logTableLocal,ipartner,iterate,niterate,iter_mod;
  int ndata,nkeep,nsend,nrecv,nlocalm1, nkept;
  u64Int ran,datum,procmask;
  u64Int *data,*send,*send1,*send2;
  u64Int *recv[PITER][MAXLOGPROCS];
  MPI_Status status;
  MPI_Request request[PITER][MAXLOGPROCS];
  MPI_Request srequest;

  /* setup: should not really be part of this timed routine */

  data = (u64Int *) malloc(CHUNKBIG*sizeof(u64Int));
  send1 = (u64Int *) malloc(CHUNKBIG*sizeof(u64Int));
  send2 = (u64Int *) malloc(CHUNKBIG*sizeof(u64Int));
  send = send1;

  for (j = 0; j < PITER; j++)
    for (i = 0; i < logNumProcs; i++)
      recv[j][i] = (u64Int *) malloc(sizeof(u64Int)*RCHUNK);

  ran = HPCC_starts(4*GlobalStartMyProc);

  niterate = ProcNumUpdates / CHUNK;
  logTableLocal = logTableSize - logNumProcs;
  nlocalm1 = LocalTableSize - 1;

  /* actual update loop: this is only section that should be timed */

  for (iterate = 0; iterate < niterate; iterate++) {
    iter_mod = iterate % PITER;
    for (i = 0; i < CHUNK; i++) {
      ran = (ran << 1) ^ ((s64Int) ran < ZERO64B ? POLY : ZERO64B);
      data[i] = ran;
    }
    nkept = CHUNK;
    nrecv = 0;

    if (iter_mod == 0)
      for (k = 0; k < PITER; k++)
        for (j = 0; j < logNumProcs; j++) {
          ipartner = (1 << j) ^ MyProc;
          MPI_Irecv(recv[k][j],RCHUNK,INT64_DT,ipartner,0,MPI_COMM_WORLD,
                    &request[k][j]);
        }

    for (j = 0; j < logNumProcs; j++) {
      nkeep = nsend = 0;
      send = (send == send1) ? send2 : send1;
      ipartner = (1 << j) ^ MyProc;
      procmask = ((u64Int) 1) << (logTableLocal + j);
      if (ipartner > MyProc) {
      	sort_data(data,data,send,nkept,&nkeep,&nsend,logTableLocal+j);
        if (j > 0) {
          MPI_Wait(&request[iter_mod][j-1],&status);
          MPI_Get_count(&status,INT64_DT,&nrecv);
      	  sort_data(recv[iter_mod][j-1],data,send,nrecv,&nkeep,
                    &nsend,logTableLocal+j);
        }
      } else {
        sort_data(data,send,data,nkept,&nsend,&nkeep,logTableLocal+j);
        if (j > 0) {
          MPI_Wait(&request[iter_mod][j-1],&status);
          MPI_Get_count(&status,INT64_DT,&nrecv);
          sort_data(recv[iter_mod][j-1],send,data,nrecv,&nsend,
                    &nkeep,logTableLocal+j);
        }
      }
      if (j > 0) MPI_Wait(&srequest,&status);
      MPI_Isend(send,nsend,INT64_DT,ipartner,0,MPI_COMM_WORLD,&srequest);
      if (j == (logNumProcs - 1)) update_table(data,HPCC_Table,nkeep,nlocalm1);
      nkept = nkeep;
    }

    if (logNumProcs == 0) update_table(data,HPCC_Table,nkept,nlocalm1);
    else {
      MPI_Wait(&request[iter_mod][j-1],&status);
      MPI_Get_count(&status,INT64_DT,&nrecv);
      update_table(recv[iter_mod][j-1],HPCC_Table,nrecv,nlocalm1);
      MPI_Wait(&srequest,&status);
    }

    ndata = nkept + nrecv;
  }

  /* clean up: should not really be part of this timed routine */

  for (j = 0; j < PITER; j++)
    for (i = 0; i < logNumProcs; i++) free(recv[j][i]);

  free(data);
  free(send1);
  free(send2);
}