Beispiel #1
0
int main(int argc, char * argv[]){
    Board * board;
    int x, y;
    Pos pos;
    UCTNode * uct_tree = 0;
    UCTNode * ptr;

    board_initialize();
    uct_initialize();

    board = board_new();

    while(1) {
        board_print(board, stdout);
        printf("\nBlack: ");
        if(scanf("%d %d", &x, &y) == -1)
            break;
        board_play(board, to_pos(x, y), BLACK);

        board_print(board, stdout);
        pos = uct_search(board, WHITE);
        board_play(board, pos, WHITE);
    }

    //for(ptr = uct_tree->child; ptr; ptr = ptr->next)
    //    printf("%d ", ptr->move);

    puts("");

    board_destroy();
    uct_destroy();
    return 0;
}
Beispiel #2
0
int UavcanNode::start(uavcan::NodeID node_id, uint32_t bitrate)
{


	if (_instance != nullptr) {
		PX4_INFO("Already started");
		return -1;
	}

	/*
	 * CAN driver init
	 */
	static bool can_initialized = false;

	if (!can_initialized) {

	    // Confgure the HW IO

	    board_initialize();

	    const int can_init_res = can.init(bitrate);

		if (can_init_res < 0) {
		        PX4_ERR("CAN driver init failed %i", can_init_res);
			return can_init_res;
		}

		can_initialized = true;
	}

	/*
	 * Node init
	 */
	_instance = newNode();

	const int node_init_res = _instance->init(node_id);

	if (node_init_res < 0) {
		_instance = nullptr;
		PX4_ERR("Node init failed %i", node_init_res);
		return node_init_res;
	}


	/* Keep the bit rate for reboots on BenginFirmware updates */

	_instance->active_bitrate = bitrate;

	return PX4_OK;
}
Beispiel #3
0
int os_bringup(void)
{
  int taskid;

  /* Setup up the initial environment for the idle task.  At present, this
   * may consist of only the initial PATH variable.  The PATH variable is
   * (probably) not used by the IDLE task.  However, the environment
   * containing the PATH variable will be inherited by all of the threads
   * created by the IDLE task.
   */

#if !defined(CONFIG_DISABLE_ENVIRON) && defined(CONFIG_PATH_INITIAL)
  (void)setenv("PATH", CONFIG_PATH_INITIAL, 1);
#endif

  /* Start the page fill worker kernel thread that will resolve page faults.
   * This should always be the first thread started because it may have to
   * resolve page faults in other threads
   */

#ifdef CONFIG_PAGING
  svdbg("Starting paging thread\n");

  g_pgworker = KERNEL_THREAD("pgfill", CONFIG_PAGING_DEFPRIO,
                             CONFIG_PAGING_STACKSIZE,
                             (main_t)pg_worker, (FAR char * const *)NULL);
  DEBUGASSERT(g_pgworker > 0);
#endif

  /* Start the worker thread that will serve as the device driver "bottom-
   * half" and will perform misc garbage clean-up.
   */

#ifdef CONFIG_SCHED_WORKQUEUE
#ifdef CONFIG_SCHED_HPWORK

#ifdef CONFIG_SCHED_LPWORK
  svdbg("Starting high-priority kernel worker thread\n");
#else
  svdbg("Starting kernel worker thread\n");
#endif

  g_work[HPWORK].pid = KERNEL_THREAD(HPWORKNAME, CONFIG_SCHED_WORKPRIORITY,
                                     CONFIG_SCHED_WORKSTACKSIZE,
                                     (main_t)work_hpthread, (FAR char * const *)NULL);
  DEBUGASSERT(g_work[HPWORK].pid > 0);

  /* Start a lower priority worker thread for other, non-critical continuation
   * tasks
   */

#ifdef CONFIG_SCHED_LPWORK

  svdbg("Starting low-priority kernel worker thread\n");

  g_work[LPWORK].pid = KERNEL_THREAD(LPWORKNAME, CONFIG_SCHED_LPWORKPRIORITY,
                                     CONFIG_SCHED_LPWORKSTACKSIZE,
                                     (main_t)work_lpthread, (FAR char * const *)NULL);
  DEBUGASSERT(g_work[LPWORK].pid > 0);

#endif /* CONFIG_SCHED_LPWORK */
#endif /* CONFIG_SCHED_HPWORK */

#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_SCHED_USRWORK)
  /* Start the user-space work queue */

  DEBUGASSERT(USERSPACE->work_usrstart != NULL);
  taskid = USERSPACE->work_usrstart();
  DEBUGASSERT(taskid > 0);
#endif

#endif /* CONFIG_SCHED_WORKQUEUE */

  /* Once the operating system has been initialized, the system must be
   * started by spawning the user init thread of execution.  This is the
   * first user-mode thead.
   */

  svdbg("Starting init thread\n");

  /* Perform any last-minute, board-specific initialization, if so
   * configured.
   */

#ifdef CONFIG_BOARD_INITIALIZE
  board_initialize();
#endif

  /* Start the default application.  In a flat build, this is entrypoint
   * is given by the definitions, CONFIG_USER_ENTRYPOINT.  In the kernel
   * build, however, we must get the address of the entrypoint from the
   * header at the beginning of the user-space blob.
   */

#ifdef CONFIG_NUTTX_KERNEL
  DEBUGASSERT(USERSPACE->us_entrypoint != NULL);
  taskid = TASK_CREATE("init", SCHED_PRIORITY_DEFAULT,
                       CONFIG_USERMAIN_STACKSIZE, USERSPACE->us_entrypoint,
                       (FAR char * const *)NULL);
#else
  taskid = TASK_CREATE("init", SCHED_PRIORITY_DEFAULT,
                       CONFIG_USERMAIN_STACKSIZE,
                       (main_t)CONFIG_USER_ENTRYPOINT,
                       (FAR char * const *)NULL);
#endif
  ASSERT(taskid > 0);

  /* We an save a few bytes by discarding the IDLE thread's environment. */

#if !defined(CONFIG_DISABLE_ENVIRON) && defined(CONFIG_PATH_INITIAL)
  (void)clearenv();
#endif

  return OK;
}
Beispiel #4
0
int play_game( KalahPlayer top, KalahPlayer bottom, PlayerPosition first_player )
{
	Board b_data;
	Board *b = &b_data;  // as shorthand

	board_initialize( b, first_player );

	if ( first_player == TOP )
		printf( "Player %s begins.\n", top.get_name() );
	else
		printf( "Player %s begins.\n", bottom.get_name() );

	while ( !board_game_over( b ) )
	{
		int move;

		board_print( b );		
		printf( "\n" );

		if ( b->player_to_move == TOP )
		{			
			move = top.make_move( b );
			printf( "TOP (%s) chooses move %d.\n", top.get_name(), move );
		}
		else
		{
			move = bottom.make_move( b );
			printf( "BOTTOM (%s) chooses move %d.\n", bottom.get_name(), move );
		}

		board_make_move( b, move );

		if ( board_game_over( b ) )
		{
			if ( board_winner( b ) == TOP )
			{
				printf( "TOP (%s) wins, %d to %d.\n", 
						top.get_name(),
						board_top_score( b ),
						board_bottom_score( b ) );
			}
			else if ( board_winner( b ) == BOTTOM )
			{
				printf( "BOTTOM (%s) wins, %d to %d.\n", 
						bottom.get_name(),
						board_bottom_score( b ),
						board_top_score( b ) );
			}
			else
			{
				printf( "TIE!\n" );
			}
		}
		else
		{
			if ( b->player_to_move == TOP )
				printf( "TOP (%s) to move.\n", top.get_name() );
			else
				printf( "BOTTOM (%s) to move.\n", bottom.get_name() );
		}
	}

	return board_top_score( b );
}