Esempio n. 1
0
bool ChessFieldModel::redo()
{
    auto res = m_chess_board.redo();
    if( !res ) {
        return false;
    }
    update_cells(res);
    return true;
}
Esempio n. 2
0
void ChessFieldModel::make_move(int src_cell, int dst_cell)
{
    if( m_chess_board.get_board_piece(7 - src_cell / 8, src_cell % 8) == ChessPiece::NONE ) {
        return;
    }
    auto src = make_vec2(7 - src_cell/8, src_cell%8);
    auto dst = make_vec2(7 - dst_cell/8, dst_cell%8);

    auto res = m_chess_board.make_move(src, dst);
    if( !res ) {
        return ;
    }
    update_cells(res);
}
Esempio n. 3
0
/*
 * delete the selected row
 */
void del_point_cb(Widget w, XtPointer client_data, XtPointer call_data)
{
	EditPoints *ep = (EditPoints *)client_data;
	int i,j;
	
	XbaeMatrixGetCurrentCell( ep->mw, &i, &j );
	if( i>=ep->nrows || j>=ep->ncols ){
		errwin( "Selected cell out of range" );
		return;
	}
	del_point( ep->gno, ep->setno, i+1 );
	update_set_status( ep->gno, ep->setno );
	if( isactive_set( ep->gno, ep->setno )  ){
		update_cells( NULL, (XtPointer)ep, 0 );
	}
}
Esempio n. 4
0
DeviceAppletState::DeviceAppletState(WM &wm,
                                     const style::Spec &style_spec,
                                     const WBar::InsertPosition &position)
  : wm(wm),
    style(wm.dc, style_spec)
{
  placeholder = wm.bar.placeholder(position);

  ignore_present.insert("cdrom");
  ignore_present.insert("winxp");
  ignore_present.insert("dell-utility");

  update_cells();
  // FIXME: make this support this applet being unloaded
  boost::thread(boost::bind(&DeviceAppletState::monitor_mounts, this));
}
Esempio n. 5
0
int main()
{
  int gen = 1;

  FILE *fp;

  if ((fp = fopen("cells.txt", "w")) == NULL) {
    fprintf(stderr, "error: cannot open a file.\n");
    return 1;
  }

  init_cells();
  print_cells(fp);

  while (1) {
    printf("generation = %d\n", gen++);
    update_cells();
    print_cells(fp);
  }

  fclose(fp);
}
Esempio n. 6
0
/*
 * add a point to a set by copying the selected cell and placing it after it
 */
void add_pt_cb(Widget w, XtPointer client_data, XtPointer call_data)
{
	EditPoints *ep = (EditPoints *)client_data;
	int i,j, k;
	double vals[MAX_SET_COLS];
	
	XbaeMatrixGetCurrentCell( ep->mw, &i, &j );
	if( i>=ep->nrows || j>=ep->ncols || i<0 || j<0 ){
		errwin( "Selected cell out of range" );
		return;
	}
	for( k=0; k<ep->ncols; k++ )
		vals[k] = *(getcol( ep->gno, ep->setno, k )+i );
	for( ;k<MAX_SET_COLS; k++ )
		vals[k] = 0.;
	add_point_at( ep->gno, ep->setno, i, 1, 
	    vals[0], vals[1], vals[2], vals[3], g[ep->gno].p[ep->setno].type );
	update_set_status( ep->gno, ep->setno );
	if( isactive_set( ep->gno, ep->setno )  ) {
		update_cells( NULL, (XtPointer)ep, 0 );
	}
}
Esempio n. 7
0
/*-----------------------------------------------------------
 * Programme principal
 *----------------------------------------------------------*/
int main (int argc, char **argv) {
  struct ctx_s ctx;
  int i;
  int *recopy;
  double timer_start, timer_end;
  double runtime;
  char output[256];

  /* Initialisation MPI */
  initalize_mpi(argc, argv, &ctx);

  /* Initialisation de la taille du domain (grille carree) */
  ctx.X = GRIDSZ / ctx.size;
  ctx.Y = GRIDSZ;
  ctx.grid = init_grid(&ctx);
  randomize_grid(&ctx, ctx.grid);
  ctx.grid_next = init_grid(&ctx);
  fprintf(stderr, "Starting task %d (%dx%d)\n", ctx.rank, ctx.X, ctx.Y);

  /* Initialisation affichage */
  sprintf(output, "output/Rank%d", ctx.rank);
  display_init(&ctx, output, GRIDSZ,GRIDSZ,0 ); // taille 0 pour la 3ieme dimension signifie une grille 2D

  /* Mettre la case au milieu du sous-domaine de la tache 0 en feu ! */
  if (ctx.rank == 0) {
    ctx.grid[(ctx.X+2)/2][(ctx.Y+2)/2] = burning;
  }

  recopy = recopy_grid(&ctx, ctx.grid);
  gather_grid(&ctx, recopy);

  timer_start = get_timer();
  for (i=0; i < MAX_STEPS; ++i) {
    int **swap;
    /* Nombre de cellules mises à jour depuis le pas
     * de temps precedent */
    int nb_updated_cells;
    /* Si la simulation est terminee */
    int leave;

    exchange_ghost_cells(&ctx);

    nb_updated_cells = update_cells(&ctx);

    leave = check_final_conditions(&ctx, nb_updated_cells);
    if (leave) break;

    swap = ctx.grid;
    ctx.grid = ctx.grid_next;
    ctx.grid_next = swap;

    recopy = recopy_grid(&ctx, ctx.grid);
    gather_grid(&ctx, recopy);
    if (ctx.rank == 0 && i%10 == 0) {
      fprintf(stderr, "..[%d]", i);
    }
  }
  timer_end = get_timer();

  if (ctx.rank == 0) {
    fprintf(stderr, "\n");
  }

  display_finalize(&ctx);
  runtime = diff_time(timer_end, timer_start);
  print_time (&ctx, runtime);

  /* Fin de la simulation */
  finalize_mpi(&ctx);
  exit(0);
}
Esempio n. 8
0
void app_timer_event()
{
	static int completionTimer = 0;
	
	if (game_state == GameState_RUNNING)
	{
		for (int i = 0 ; i < GrabType_NBR_ELT ; i++)
		{
			if (grabbers[i].tick >= 0)
			{
				grabbers[i].tick++;
				
				if (grabbers[i].tick > GRABBER_TICKS)
				{
					grabbers[i].tick = 0;
					
					switch (grabbers[i].state)
					{
						case GrabberState_STOPPED:
						{
							break;
						}
						case GrabberState_EXTENDING:
						{
							ProgressResult result = can_progress((GrabType)i);
							if (result == ProgressResult_OK)
							{
								grabbers[i].length++;
							}
							else if (result == ProgressResult_COMPLETE)
							{
								score(grabbers[i].type);
								
								if (((scores[GrabType_TOP] >= 8) ||
									  (scores[GrabType_BOTTOM] >= 8) ||
									  (scores[GrabType_LEFT] >= 8) ||
									  (scores[GrabType_RIGHT] >= 8)))
								{
									/* Nb. This -- a return function in the middle of a function -- is horrible.
									I'll refactor at some point in the future! */
									
									game_complete(grabbers[i].type);
									
									return;
								}
								
								setup_nugget();
								grabbers[i].state = GrabberState_RETRACTING;
								grabbers[i].tick = GRABBER_TICKS;
							}
							else
							{
								grabbers[i].state = GrabberState_RETRACTING;
								grabbers[i].tick = GRABBER_TICKS;
							}
							break;
						}
						case GrabberState_RETRACTING:
						{
							if (grabbers[i].length > 0)
							{
								grabbers[i].length--;
							}
							
							if (grabbers[i].length == 0)
							{
								grabbers[i].state = GrabberState_STOPPED;
								grabbers[i].tick = -1;
							}
							break;
						}
						case GrabberState_RETRACTING_RESTART:
						{
							if (grabbers[i].length > 0)
							{
								grabbers[i].length--;
							}
							
							if (grabbers[i].length == 0)
							{
								grabbers[i].index = grabbers[i].next_index;
								grabbers[i].state = GrabberState_EXTENDING;
							}
							break;
						}
					}
					
					update_cells();
					update_LEDs();
				}
			}
		}
	}
	else if (game_state == GameState_INIT)
	{
		reset_cells();
		setup_nugget();
	}
	else if (game_state == GameState_GAME_COMPLETE)
	{
		completionTimer ++;
		
		if (completionTimer > COMPLETION_TICKS)
		{
			reset_game();
			update_LEDs();
			update_score_LEDs();
			completionTimer = 0;
		}
	}
}