static void
network_message_cb (int opcode)
{
  /* message and associated data arrived safely */

  switch (opcode) {
  case msgseat:
    if (variables.num == 0) {
      set_status_message (_("Waiting for an opponent to join the game."));
    } else {
      prompt_player ();
    }

    break;
  case msgplayers:
    /* Not implemented. */
    break;
  case reqmove:
    player_active = TRUE;
    prompt_player ();
    break;
  case rspmove:
    if (!variables.status) {
      process_move (variables.column);
      player_active = FALSE;
    }

    break;
  case msgmove:
    process_move (variables.column2);
    break;
  case sndsync:
    /* Not implemented yet. */
    break;
  case msggameover:
    player_active = FALSE;
    break;
  case reqoptions:
    variables.boardheight2 = BOARDY;
    variables.boardwidth2 = BOARDX;
    variables.connectlength2 = TILES;
    ggzcomm_sndoptions ();
    break;
  case msgoptions:
    /* Not supported yet. */
    break;

  default:
    printf ("Unknown opcode.\n");
    break;
  }

}
Beispiel #2
0
void	run_processes(void)
{
	t_proc	*process;
	int		opcode;
	int		offset;
	int		i;

	i = g_corewar.process_count;
	while (--i >= 0)
	{
		process = &g_corewar.process[i];
		if (process->wait < 0)
		{
			opcode = (int)read_byte(process->pc) - 1;
			if (opcode < OP_COUNT && opcode >= 0)
			{
				process->op = &g_op_tab[opcode];
				process->wait = g_op_tab[opcode].cycles;
			}
		}
		if (--process->wait <= 0)
		{
			offset = process_op(process);
			process_move(&g_corewar.process[i], offset);
		}
	}
}
Beispiel #3
0
int main(void) {
	num[0][0] = 1;

	while (num[N1 - 1][N2 - 1] <= 1) {
		print();
		move=getche();
		printf("\n");
		process_move();
		num_reset = reset(num_reset);
		if (num_reset == 0) {
			return 0;
		}
	}
}
void LIR_OopMapGenerator::iterate_one(BlockBegin* block) {
#ifndef PRODUCT
  if (TraceLIROopMaps) {
    tty->print_cr("Iterating through block %d", block->block_id());
  }
#endif

  set_block(block);
  block->set(BlockBegin::lir_oop_map_gen_reachable_flag);

  int i;

  if (!is_caching_change_block(block)) {
    LIR_OpVisitState state;
    LIR_OpList* inst = block->lir()->instructions_list();
    int length = inst->length();
    for (i = 0; i < length; i++) {
      LIR_Op* op = inst->at(i);
      LIR_Code code = op->code();

      state.visit(op);
      for (int j = 0; j < state.info_count(); j++) {
        process_info(state.info_at(j));
      }

      if (code == lir_volatile_move ||
          code == lir_move) {
        process_move(op);
      }
    }
  }

  // Process successors
  if (block->end() != _base) {
    for (i = 0; i < block->end()->number_of_sux(); i++) {
      merge_state(block->end()->sux_at(i));
    }
  } else {
    // Do not traverse OSR entry point of the base
    merge_state(_base->std_entry());
  }

  set_block(NULL);
}
Beispiel #5
0
void GameDriver::run() {
    int toggle = 0;
    int cant_move_counter=0;
    Player* current = p1;
    Player* opponent = p2;

    display();
    std::cout << "Player 1 (" << p1->get_symbol() << ") move:\n";
    while (1) {
	if( board->has_legal_moves_remaining(current->get_symbol())) {
	    cant_move_counter = 0;
	    process_move(current, opponent);
	    display();
	} else {
	    std::cout << "Can't move\n";
	    if( cant_move_counter == 1 ) {
		// Both players can't move, game over                       
		break;
	    } else {
		cant_move_counter++;
	    }
	}
	toggle = (toggle + 1) % 2;
	if (toggle == 0) {
	    current = p1;
	    opponent = p2;
	    std::cout << "Player 1 (" << p1->get_symbol() << ") move:\n";
	} else {
	    current = p2;
	    opponent = p1;
	    std::cout << "Player 2 (" << p2->get_symbol() << ") move:\n";
	}
    }

    if ( board->count_score(p1->get_symbol()) == board->count_score(p2->get_symbol())) {
	std::cout << "Tie game" << std::endl;
    } else if ( board->count_score(p1->get_symbol()) > board->count_score(p2->get_symbol())) {
	std::cout << "Player 1 wins" << std::endl;
    } else {
	std::cout << "Player 2 wins" << std::endl;
    }
}
Beispiel #6
0
/*
 * Try to read and process a move from stdin. 
 *
 * Returns 1 if a move was successfully made, otherwise 0. Success means an
 * actual move - saving a file is reported as failure to allow re-prompting.
 */
int
try_move(struct game *g)
{
    char input[11] = { 0 };
    int n = 0, c;

    printf("%c> ", g->current_player + 'A');
    fflush(stdout);

    while (n < 10) {
        c = fgetc(stdin);
        
        if (c == EOF || c == '\n') {
            break;
        } else if (n == 1 && c == ' ' && *input == 'w') {
            read_path_and_save(g);
            return 1;
        } else {
            input[n++] = c;
        }
    }

    while (c != EOF && c != '\n') {
        c = fgetc(stdin);
    }

    if (c == EOF && n == 0) {
        fprintf(stderr, "End of user input\n");
        exit(6);
    }

    if (n == 10) {
        return 1;
    } 

    return process_move(input, g);
}
Beispiel #7
0
static void
game_process_move (gint c)
{
  process_move (c);
}
Beispiel #8
0
static gint
next_move (gint c)
{
  process_move (c);
  return FALSE;
}