Exemplo n.º 1
0
void game_loop(void)
{
	bool redraw = true;
	al_start_timer(timer);
	int frame = 0;

	while (!done) {
		ALLEGRO_EVENT event;
		al_wait_for_event(event_queue, &event);

		if (event.type == ALLEGRO_EVENT_TIMER) {
			redraw = true;
			//update_logic();
		}
		else if (event.type == ALLEGRO_EVENT_KEY_DOWN) {
			if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
				done = true;
			}
			get_user_input(event.keyboard.keycode);
		}
		if (redraw && al_is_event_queue_empty(event_queue)) {
			redraw = false;
			al_clear_to_color(al_map_rgb(0,0,0));
			update_graphics();
			al_flip_display();
		}
		frame++;
	}
}
Exemplo n.º 2
0
int main(int argc, char* argv[])
{
	/* Unused arguments */
	(void)argc;
	(void)argv;

	/* Initialize SDL */
	if (SDL_Init(SDL_INIT_VIDEO) != 0){
		SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
		                         "SDL_Init Failure",
		                         SDL_GetError(),
		                         NULL);
		return EXIT_FAILURE;
	}

	/* Initialize game state */
	init_game();
	/* Initialize graphics */
	if (init_graphics() != 0){
		return EXIT_FAILURE;
	}

	/* Start game logic thread */
	SDL_CreateThread(game_thread, "GameLogic", NULL);

	/* Main Loop */
	while (!quit){
		/* Handle events*/
		handle_event();
		/* Render graphics */
		update_graphics();
	}

	return EXIT_SUCCESS;
}
Exemplo n.º 3
0
 void MainThread ()
 {

     FILE *Fp_in;
     FILE *Fp_out;

	 Fp_in   = fopen("in.dat","r");
     Fp_out  = fopen("out.dat","w");             

     //-----Initialization of graphics----------------------
     graphics_init();

     //---optimization--------------------------------------
	 devol(Fp_in,Fp_out);

	 fclose(Fp_in);
	 fclose(Fp_out);

	 //-----enable zooming in and out even when optimization is finished----
	 while(1)
	 {
        update_graphics(gt_best.fa_vector, gi_D, gfa_bound, gl_nfeval, gi_gen, gt_best.fa_cost[0],gi_strategy,gi_genmax);
		Sleep(50); // provide some time (50ms) for the eye to see the graphics
        if (gi_exit_flag == 1)
		{
           gi_exit_flag = 0;
		}
	 }
 }
Exemplo n.º 4
0
Arquivo: main.c Projeto: GalaxyUser/C
int main(void)
{

    /* Initialization players */
    srand(time(0));
    int playerNumber = ( rand() % 2 ) + 1;;
    int *p_playerNumber = &playerNumber;

    /* Initilization MAP */

    double posX = marginWidth + circleSize * 2 + 57;
    double posY = 420 + marginHight;

    double *p_posX = &posX;
    double *p_posY = &posY;

    int map[45], i, j = 3, posMap = 1, keyPressed;
    int *p_posMap = &posMap;

    for (i = 1 ; i <= 42 ; i++){
            map[i] = j;
            j++;
    }

    /* Draw the grid */
    createGrid();
    update_graphics();

    /* Take deplacement with key until ESCAPE is pressed*/

    while (gameStat(map) == 0) {
        if (keyPressed == key_ESCAPE) exit(1);
        keyPressed = get_key();
        moveCase(p_posX, p_posY, p_posMap, map, p_playerNumber, keyPressed);
        update_graphics();
    }

    set_drawing_color(color_BLUE);

    if (gameStat(map) == 100) draw_printf(5, 5, "Result: match nul");
        else draw_printf(5, 1, "Winner: player %d", gameStat(map));
        update_graphics();

    get_key();

    return EXIT_SUCCESS;
}
Exemplo n.º 5
0
void MainMenu::loop()
{
    while (!end_menu() &	 !end_game() )
    {
        Keyboard::GetInstance()->update_events();
        update();
        update_graphics();
    }
}
Exemplo n.º 6
0
UINT32 sed1330_device::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	if (m_d)
	{
		if (m_dm)
		{
			update_graphics(bitmap, cliprect);
		}
		else
		{
			update_text(bitmap, cliprect);
		}
	}
	return 0;
}
Exemplo n.º 7
0
UINT32 msm6255_device::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	if (m_mor & MOR_DISPLAY_ON)
	{
		if (m_mor & MOR_GRAPHICS)
		{
			update_graphics(bitmap, cliprect);
		}
		else
		{
			update_text(bitmap, cliprect);
		}
	}
	else
	{
		bitmap.fill(get_black_pen(machine()), cliprect);
	}
	return 0;
}
Exemplo n.º 8
0
void Physics::step( real_t dt )
{
    // step the world forward by dt. Need to detect collisions, apply
    // forces, and integrate positions and orientations.
    //
    // Note: put RK4 here, not in any of the physics bodies
    //
    // Must use the functions that you implemented
    //
    // Note, when you change the position/orientation of a physics object,
    // change the position/orientation of the graphical object that represents
    // it
      
    detect_collisions();
    save_initial_states();
    //save initial state after changing it in collisions
    RK4(dt);
    update_graphics();

}
Exemplo n.º 9
0
int main(void) {
  /* setup controller */
  sys_init();
	
  /* setup u8g and m2 libraries */
  setup();

  /* application main loop */
  for(;;) {  
    m2_CheckKey();
    if ( m2_HandleKey() || update_graphics() ) {
      /* picture loop */
      u8g_FirstPage(&u8g);
      do {
	draw();
        m2_CheckKey();
      } while( u8g_NextPage(&u8g) );
    }
  }  
}
Exemplo n.º 10
0
/**C*F****************************************************************
**                                                                  
** Function       :void devol(FILE *Fp_in, FILE *Fp_out)                                        
**                                                                  
** Author         :Rainer Storn, Kenneth Price                                     
**                                                                  
** Description    :Performs Differential Evolution optimization.                 
**                                                                  
** Functions      :-                                                
**                                                                  
** Globals        :
**                 gi_strategy  (I) 1 --> DE/rand/1:
**                                        the classical version of DE.             
**                                  2 --> DE/local-to-best/1:
**                                        a version which has been used by quite a number
**                                        of scientists. Attempts a balance between robustness
**                                        and fast convergence.
**                                  3 --> DE/best/1 with jitter:
**                                        taylored for small population sizes and fast convergence.
**                                        Dimensionality should not be too high.           
**                                  4 --> DE/rand/1 with per-vector-dither:
**                                        classical DE with dither to become even more robust.
**                                  5 --> DE/rand/1 with per-generation-dither:
**                                        classical DE with dither to become even more robust.
**                                        Choosing f_weight = 0.3 is a good start here.
**                                  6 --> DE/rand/1 either-or-algorithm:
**                                        Alternates between differential mutation and three-point-
**                                        recombination.           
**
**                 gi_D         (I)    number of parameters 
**                 gl_nfeval   (I/O)   counter for function evaluations                                               
**                 gi_gen      (I/O)   number of generations  
**                 gt_best     (I/O)   best vector
**                                               
** Parameters     :Fp_in    (I)     pointer to input file
**                 Fp_out   (I)     pointer to output file   
**                                                                  
** Preconditions  :-                     
**                                                                  
** Postconditions :- 
**
** Return Value   :-                                            
**                                                                  
***C*F*E*************************************************************/
void devol(FILE *Fp_in, FILE *Fp_out)
{
#define URN_DEPTH   5   //4 + one index to avoid

//-----Variable declarations-----------------------------------------

   int   i, j, k;                 // counting variables                 
   int   i_r1, i_r2, i_r3, i_r4;  // placeholders for random indexes    
   int   i_refresh;               // refresh rate of screen output      
   int   i_genmax, i_seed, i_bs_flag;
   int   ia_urn2[URN_DEPTH];

   float fa_minbound[MAXDIM];
   float fa_maxbound[MAXDIM];
   t_pop t_tmp, t_bestit;
#ifdef BOUND_CONSTR
   t_pop t_origin;
#endif//BOUND_CONSTR
   float f_weight, f_jitter, f_dither;
   float f_cross;


//-----Initialization of annealing parameters-------------------------

 fscanf(Fp_in,"%d",&gi_strategy);      //---choice of strategy-----------------
 fscanf(Fp_in,"%d",&i_genmax);         //---maximum number of generations------
 fscanf(Fp_in,"%d",&i_refresh);        //---output refresh cycle---------------
 gi_genmax = i_genmax;
 fscanf(Fp_in,"%d",&gi_D);             //---number of parameters---------------
 if (gi_D > MAXDIM)
 {
	 printf("Error! too many parameters\n");
	 return;
 }
 fscanf(Fp_in,"%d",&gi_NP);             //---population size.-------------------
 if (gi_NP > MAXPOP)
 {
	 printf("Error! too many points\n");
	 return;
 }
 fscanf(Fp_in,"%f",&f_weight);         //---weight factor----------------------
 fscanf(Fp_in,"%f",&f_cross);          //---crossing over factor---------------
 fscanf(Fp_in,"%d",&i_seed);           //---random seed------------------------
 fscanf(Fp_in,"%d",&i_bs_flag);        //---if TRUE: best of parent+child selection--------
                                       //---if FALSE: DE standard tournament selection-----
 for (i=0; i<gi_D; i++)
 {
	 fscanf(Fp_in,"%f",&fa_minbound[i]);
 }
 for (i=0; i<gi_D; i++)
 {
	 fscanf(Fp_in,"%f",&fa_maxbound[i]);
 }


//-----Initialize random number generator-----------------------------

 if(i_seed == 0) sgenrand((unsigned long) time(NULL));// Generates a random seed
 else sgenrand((unsigned long)i_seed);// for Mersenne Twister
 gl_nfeval    =  0;              // reset number of function evaluations 

//------Initialization-----------------------------
   for (j=0; j<gi_D; j++)
   {
	 gta_pop[0].fa_vector[j] = fa_minbound[j]+genrand()*(fa_maxbound[j] - fa_minbound[j]);
   }
   gta_pop[0]      = evaluate(gi_D,gta_pop[0],&gl_nfeval,&gta_pop[0],gi_NP);
   gt_best  = gta_pop[0];

   for (i=1; i<gi_NP; i++)
   {
      for (j=0; j<gi_D; j++)
      {
	     gta_pop[i].fa_vector[j] = fa_minbound[j]+genrand()*(fa_maxbound[j] - fa_minbound[j]);
      }
      gta_pop[i] = evaluate(gi_D,gta_pop[i],&gl_nfeval,&gta_pop[0],gi_NP);

	  if (left_vector_wins(gta_pop[i],gt_best) == TRUE)
	  {
         gt_best = gta_pop[i];
	  }
   }

   t_bestit  = gt_best;

   //---assign pointers to current ("old") and new population---

   gpta_old = &gta_pop[0];
   gpta_new = &gta_pop[gi_NP];


//------Iteration loop--------------------------------------------
   gi_gen = 0;
#ifdef DO_PLOTTING
   while ((gi_gen < i_genmax) && (gi_exit_flag == 0))// && (gt_best.fa_cost[0] > VTR))
#else
   //Note that kbhit() needs conio.h which is not always available under Unix.
   while ((gi_gen < i_genmax))// && (kbhit() == 0))// && (gt_best.fa_cost[0] > VTR))
#endif//DO_PLOTTING
   {
      gi_gen++;

	  //----computer dithering factor (if needed)-----------------
	  f_dither = f_weight + genrand()*(1.0 - f_weight);

      //----start of loop through ensemble------------------------
      for (i=0; i<gi_NP; i++)           
      {
		permute(ia_urn2,URN_DEPTH,gi_NP,i); //Pick 4 random and distinct
		i_r1 = ia_urn2[1];                 //population members
		i_r2 = ia_urn2[2];
		i_r3 = ia_urn2[3];
		i_r4 = ia_urn2[4];

/*
        //---this is an alternative way to pick population members---
	    do                        // Pick a random population member 
		{
	       i_r1 = (int)(genrand()*gi_NP);
		}while(i_r1==i);

	    do                        // Pick a random population member 
		{
	       i_r2 = (int)(genrand()*gi_NP);
		}while((i_r2==i) || (i_r2==i_r1));

	    do                        // Pick a random population member 
		{
	       i_r3 = (int)(genrand()*gi_NP);
		}while((i_r3==i) || (i_r3==i_r1) || (i_r3==i_r2));

	    do                        // Pick a random population member 
		{
	       i_r4 = (int)(genrand()*gi_NP);
		}while((i_r4==i) || (i_r4==i_r1) || (i_r4==i_r2) || (i_r4==i_r3));
*/

        //========Choice of strategy=======================================================
		//---classical strategy DE/rand/1/bin-----------------------------------------
		if (gi_strategy == 1)
		{
           assigna2b(gi_D,gpta_old[i].fa_vector,t_tmp.fa_vector);
	       j = (int)(genrand()*gi_D); // random parameter         
	       k = 0;
	       do
		   {                            // add fluctuation to random target 
	          t_tmp.fa_vector[j] = gpta_old[i_r1].fa_vector[j] + f_weight*(gpta_old[i_r2].fa_vector[j]-gpta_old[i_r3].fa_vector[j]);

	          j = (j+1)%gi_D;
	          k++;
		   }while((genrand() < f_cross) && (k < gi_D));
#ifdef BOUND_CONSTR
		   assigna2b(gi_D,gpta_old[i_r1].fa_vector,t_origin.fa_vector);
#endif//BOUND_CONSTR
		}
		//---DE/local-to-best/1/bin---------------------------------------------------
	    else if (gi_strategy == 2)
		{
           assigna2b(gi_D,gpta_old[i].fa_vector,t_tmp.fa_vector);
	       j = (int)(genrand()*gi_D); // random parameter         
	       k = 0;
	       do
		   {                            // add fluctuation to random target 
	          t_tmp.fa_vector[j] = t_tmp.fa_vector[j] + f_weight*(t_bestit.fa_vector[j] - t_tmp.fa_vector[j]) + 
				                                        f_weight*(gpta_old[i_r2].fa_vector[j]-gpta_old[i_r3].fa_vector[j]);

	          j = (j+1)%gi_D;
	          k++;
		   }while((genrand() < f_cross) && (k < gi_D));
#ifdef BOUND_CONSTR
		   assigna2b(gi_D,t_tmp.fa_vector,t_origin.fa_vector);
#endif//BOUND_CONSTR
		}
		//---DE/best/1/bin with jitter------------------------------------------------
	    else if (gi_strategy == 3)
		{
           assigna2b(gi_D,gpta_old[i].fa_vector,t_tmp.fa_vector);
	       j = (int)(genrand()*gi_D); // random parameter         
	       k = 0;
	       do
		   {                            // add fluctuation to random target 
			  f_jitter = (0.0001*genrand()+f_weight);
	          t_tmp.fa_vector[j] = t_bestit.fa_vector[j] + f_jitter*(gpta_old[i_r1].fa_vector[j]-gpta_old[i_r2].fa_vector[j]);

	          j = (j+1)%gi_D;
	          k++;
		   }while((genrand() < f_cross) && (k < gi_D));
#ifdef BOUND_CONSTR
		   assigna2b(gi_D,t_tmp.fa_vector,t_origin.fa_vector);
#endif//BOUND_CONSTR
		}
		//---DE/rand/1/bin with per-vector-dither-------------------------------------
	    else if (gi_strategy == 4)
		{
           assigna2b(gi_D,gpta_old[i].fa_vector,t_tmp.fa_vector);
	       j = (int)(genrand()*gi_D); // random parameter         
	       k = 0;
	       do
		   {                            // add fluctuation to random target 
	          t_tmp.fa_vector[j] = gpta_old[i_r1].fa_vector[j] + 
			                       (f_weight + genrand()*(1.0 - f_weight))*
								   (gpta_old[i_r2].fa_vector[j]-gpta_old[i_r3].fa_vector[j]);

	          j = (j+1)%gi_D;
	          k++;
		   }while((genrand() < f_cross) && (k < gi_D));
#ifdef BOUND_CONSTR
		   assigna2b(gi_D,t_tmp.fa_vector,t_origin.fa_vector);
#endif//BOUND_CONSTR
		}
		//---DE/rand/1/bin with per-generation-dither---------------------------------
	    else if (gi_strategy == 5)
		{
           assigna2b(gi_D,gpta_old[i].fa_vector,t_tmp.fa_vector);
	       j = (int)(genrand()*gi_D); // random parameter         
	       k = 0;
	       do
		   {                            // add fluctuation to random target 
	          t_tmp.fa_vector[j] = gpta_old[i_r1].fa_vector[j] + f_dither*(gpta_old[i_r2].fa_vector[j]-gpta_old[i_r3].fa_vector[j]);

	          j = (j+1)%gi_D;
	          k++;
		   }while((genrand() < f_cross) && (k < gi_D));
#ifdef BOUND_CONSTR
		   assigna2b(gi_D,t_tmp.fa_vector,t_origin.fa_vector);
#endif//BOUND_CONSTR
		}
		//---variation to DE/rand/1/bin: either-or-algorithm--------------------------
	    else
		{
           assigna2b(gi_D,gpta_old[i].fa_vector,t_tmp.fa_vector);
	       j = (int)(genrand()*gi_D); // random parameter         
	       k = 0;
		   if (genrand() < 0.5) //Pmu = 0.5
		   {//differential mutation
	          do
			  {                            // add fluctuation to random target 
	             t_tmp.fa_vector[j] = gpta_old[i_r1].fa_vector[j] + f_weight*(gpta_old[i_r2].fa_vector[j]-gpta_old[i_r3].fa_vector[j]);

	             j = (j+1)%gi_D;
	             k++;
			  }while((genrand() < f_cross) && (k < gi_D));
		   }
		   else
		   {//recombination with K = 0.5*(F+1) --> F-K-Rule
	          do
			  {                            // add fluctuation to random target 
	             t_tmp.fa_vector[j] = gpta_old[i_r1].fa_vector[j] + 0.5*(f_weight+1.0)*
					                 (gpta_old[i_r2].fa_vector[j]+gpta_old[i_r3].fa_vector[j] -
									2*gpta_old[i_r1].fa_vector[j]);

	             j = (j+1)%gi_D;
	             k++;
			  }while((genrand() < f_cross) && (k < gi_D));
		   }
#ifdef BOUND_CONSTR
		   assigna2b(gi_D,gpta_old[i_r1].fa_vector,t_origin.fa_vector);
#endif//BOUND_CONSTR		
		}//end if (gi_strategy ...

#ifdef BOUND_CONSTR
      for (j=0; j<gi_D; j++) //----boundary constraints via random reinitialization-------
      {                      //----and bounce back----------------------------------------
         if (t_tmp.fa_vector[j] < fa_minbound[j])
		 {
            t_tmp.fa_vector[j] = fa_minbound[j]+genrand()*(t_origin.fa_vector[j] - fa_minbound[j]);
		 }
         if (t_tmp.fa_vector[j] > fa_maxbound[j])
		 {
            t_tmp.fa_vector[j] = fa_maxbound[j]+genrand()*(t_origin.fa_vector[j] - fa_maxbound[j]);
		 }
      }
#endif//BOUND_CONSTR


        //------Trial mutation now in t_tmp-----------------

	    t_tmp = evaluate(gi_D,t_tmp,&gl_nfeval,&gpta_old[0],gi_NP);  // Evaluate mutant in t_tmp[] 

if (i_bs_flag == TRUE)
{
        gpta_new[i]=t_tmp; //save new vector, selection will come later
}
else
{
		if (left_vector_wins(t_tmp,gpta_old[i]) == TRUE)
		{
	       gpta_new[i]=t_tmp;              // replace target with mutant 

		   if (left_vector_wins(t_tmp,gt_best) == TRUE)// Was this a new minimum? 
		   {                               // if so...
		      gt_best = t_tmp;             // store best member so far  
		   }                               // If mutant fails the test...
		}                                  // go to next the configuration 
	    else
		{
	       gpta_new[i]=gpta_old[i];              // replace target with old value 
		}
}//if (i_bs_flag == TRUE)
      }//end for (i=0; i<gi_NP; i++)
					    // End mutation loop through pop. 

if (i_bs_flag == TRUE)
{
      sort (gpta_old, 2*gi_NP); //sort array of parents + children
	  gt_best = gpta_old[0];
}
else
{
      gpta_swap = gpta_old;
      gpta_old  = gpta_new;
      gpta_new  = gpta_swap;
}//if (i_bs_flag == TRUE)

	  t_bestit = gt_best;


//    }//if ....
//======Output Part=====================================================

	if (gi_gen%i_refresh == 0) //refresh control
	{
       #ifdef DO_PLOTTING
          update_graphics(gt_best.fa_vector, gi_D, gfa_bound, gl_nfeval, gi_gen, gt_best.fa_cost[0], gi_strategy,gi_genmax);
       #else
	/* DIOGO
	   printf("%6li   %12.6f   %12.6f\n",gl_nfeval, gt_best.fa_cost[0], gt_best.fa_constraint[0]);
	   OGOID */
       #endif//DO_PLOTTING
	/* DIOGO
	   fprintf(Fp_out,"%6li   %12.6f\n",gl_nfeval, gt_best.fa_cost[0]);
	   OGOID */


	}//end if (gi_gen%10 == 0)

   }//end while ((gi_gen < i_genmax) && (gf_emin > MINI))

   /* DIOGO
   fprintf(Fp_out,"\n******** best vector ********\n");
      OGOID */
   for (i=0; i<gi_D; i++)
   {
	   #ifndef DO_PLOTTING
	      printf("%f\n", gt_best.fa_vector[i]);
	   #endif//DO_PLOTTING
	/* DIOGO
	   fprintf(Fp_out,"best_vector[%d]=%12.6f\n", i, gt_best.fa_vector[i]);
	   OGOID */
   }
   /* DIOGO */
   /* Saída */
   fprintf(stderr, "custo,total_gerado"); if(gi_D == 6) fprintf(stderr, ",perdas");
   fprintf(stderr, "\n%f,%f", gt_best.fa_cost[0], gt_best.fa_constraint[0]);
   if(gi_D == 6) fprintf(stderr, ",%f", gt_best.fa_constraint[1]);
   fprintf(stderr, "\n");
   /* OGOID */
   #ifdef DO_PLOTTING 
      if (gi_exit_flag == 1)
	  {
         gi_exit_flag = 0;
	  }
   #endif//DO_PLOTTING
}
Exemplo n.º 11
0
// Draws one frame then returns
void run_one_frame() {
    frame_drawn = 0;

    while (!frame_drawn) {
        if (halted || stopped) {
            long current_cycles = cgb_speed ? 2 : 4;
            update_timers(current_cycles);
            sound_add_cycles(current_cycles);
            inc_serial_cycles(current_cycles);

            // If Key pressed in "stop" mode, then gameboy is "unstopped"
            if (stopped) {
                if(key_pressed()) {
                    stopped = 0;
                }
            }
            if (halted) {
                update_graphics(current_cycles);
            }
        }
        else if (!(halted || stopped)) {
            current_cycles = 0;
            current_cycles += exec_opcode(skip_bug);

        }

        cycles += current_cycles;
      
		#ifdef EFIAPI
        if (cycles > 3000) {
		#else
		if (cycles > 15000) {
		#endif
            quit |= update_keys();
            cycles = 0;
        }
        skip_bug = handle_interrupts();

        if (debug && step_count > 0 && --step_count == 0) {
            int flags = get_command();
            step_count = (flags & STEPS_SET) ? get_steps() : STEPS_OFF;
        }
    }

}

void setup_debug() {
    if (debug) {
        int flags = get_command();
        step_count = (flags & STEPS_SET) ?  get_steps() : STEPS_OFF;

        breakpoint =  (flags & BREAKPOINT_SET) ?
                      get_breakpoint() : BREAKPOINT_OFF;
    }


}

void run() {
    log_message(LOG_INFO, "About to setup debug\n");
    setup_debug();
    log_message(LOG_INFO, "About to run\n");
    while(!quit) {
        run_one_frame();
    }
}
Exemplo n.º 12
0
void game::movePiece(int relative_piece){
    int fixed_piece = rel_to_fixed(relative_piece);     //index of the piece in player_positions
    int modifier = color * 13;
    int relative_pos = player_positions[fixed_piece];
    int target_pos = 0;
    if(player_positions[fixed_piece] == -1){        //if the selected piece is in the safe house, try to move it to start
        move_start(fixed_piece);
    } else {
        //convert to relative position
        if(relative_pos == 99){
            std::cout << "I tought this would be it ";
        }else if(relative_pos == 51 && color != 0){
            int tmp_abs = relative_pos - 52;
            relative_pos = (tmp_abs - modifier); //Alien attack prevention
        }else if(relative_pos < modifier) {
            relative_pos = relative_pos + 52 - modifier;
        } else if( relative_pos > 50) {
            relative_pos = relative_pos - color * 5 - 1;
        } else {//if(relative >= modifier)
            relative_pos = relative_pos - modifier;
        }
        if(DEBUG) std::cout << "color: " << color << " pos: " << relative_pos << " + " << dice_result << " = " << relative_pos + dice_result;
        //add dice roll
        relative_pos += dice_result;    //this is relative position of the selected token + the dice number

        int jump = isStar(relative_pos); //return 0 | 6 | 7
        if(jump){
            if(jump + relative_pos == 57){
                relative_pos = 56;
            } else {
                relative_pos += jump;
            }
        }
        //special case checks
        if(relative_pos > 56 && relative_pos < 72){ // go back
            target_pos = 56-(relative_pos-56) + color * 5 + 1; //If the player moves over the goal, it should move backwards
        }else if(relative_pos == 56 || relative_pos >= 99){
            target_pos = 99;
        }else if(relative_pos > 50){ // goal stretch
            target_pos = relative_pos + color * 5 + 1;
        } else {
            int new_pos = relative_pos + color * 13;
            if(new_pos < 52){
                target_pos = new_pos;
            } else { //wrap around
                target_pos = new_pos - 52;  //this is the global position wrap around at the green entry point
            }
        }

        //check for game stuff

        if(isOccupied(target_pos)){
            if(isGlobe(target_pos)){
                target_pos = -1; //send me home
            } else {
                send_them_home(target_pos);
            }
        }
        if(DEBUG) std::cout << " => " << target_pos << std::endl;
        player_positions[fixed_piece] = target_pos;
    }
    std::vector<int> new_relative = relativePosition();
    switch(color){
    case 0:
        emit player1_end(new_relative);
        break;
    case 1:
        emit player2_end(new_relative);
        break;
    case 2:
        emit player3_end(new_relative);
        break;
    case 3:
        emit player4_end(new_relative);
    default:
        break;
    }
    emit update_graphics(player_positions);
}
void CPhantomContextView::UpdateGraphics()
{
    update_graphics();
}