示例#1
0
void get_coord(struct coord *coord, const struct map *map) {
    printf("Enter x : ");
    scanf("%d", &coord->y);
    printf("Enter y : ");
    scanf("%d", &coord->x);
    if(coord->x > map->rows - 1)
        get_coord(coord, map);
    if(coord->y > map->columns - 1)
        get_coord(coord, map);
}
示例#2
0
static	void	get_object_from_file(char *path,
				     t_object **o, t_object *parent)
{
  t_face		*f;
  t_vertice       	*v;
  t_vertice_n     	*vn;
  double		pt[3][3];
  double		n[3];

  f = NULL;
  v = NULL;
  vn = NULL;
  get_coord(path, &v, &vn, &f);
  my_rev_list(&v);
  my_rev_n(&vn);
  my_rev_f(&f);
  while (f)
    {
      if (copy_tab(pt[0], get_itm(v, vn, 1, f->pos[0])) &&
	  copy_tab(pt[1], get_itm(v, vn, 1, f->pos[1])) &&
	  copy_tab(pt[2], get_itm(v, vn, 1, f->pos[2])) &&
	  copy_tab(n, get_itm(v, vn, 0, f->n)))
	add_triangle(o, pt, n, parent);
      f = f->next;
    }
}
示例#3
0
void unflag(struct map *map) {
    struct coord coord;
    get_coord(&coord, map);

    map->Map[coord.x][coord.y].flagged = false;
    if(map->Map[coord.x][coord.y].value == MINE)
        --map->flags;
}
示例#4
0
void flag(struct map *map) {
    struct coord coord;
    get_coord(&coord, map);
    if(!map->Map[coord.x][coord.y].visible)
        map->Map[coord.x][coord.y].flagged = true;
    if(map->Map[coord.x][coord.y].value == MINE)
        ++map->flags;

}
// find min/max in one dimension
void find_min_max(data_type_short *points, uint *idx , uint dim, uint n, coord_type *ret_min, coord_type *ret_max)
{    
    coord_type min = get_coord(points,idx,0,dim);
    coord_type max = get_coord(points,idx,0,dim);
    coord_type tmp;
    // inefficient way of searching the min/max
    for (int i=0; i<n; i++) {
        tmp = get_coord(points,idx,i,dim);        
        if (tmp < min) {
            min = tmp;
        }        
        if (tmp >= max) {
            max = tmp;
        }
    }

    *ret_min = min;
    *ret_max = max;
}
示例#6
0
文件: events.c 项目: sebastiencs/FDF
void	put_blackout(t_infos_mlx *infos_mlx)
{
  int	i;

  i = 0;
  while (i <= HEIGHT)
  {
    print_line(get_coord(0, i, WIDTH, i), infos_mlx, 1);
    i = i + 1;
  }
}
示例#7
0
int find_char_pos(CHAR_DATA *ch, char *arg, int coord)
{
CHAR_DATA *victim;
if(strlen(arg) > 2)
{
    if ((victim = get_char_room (ch, arg)) == NULL)
    {
        return -2;
    }
    if(coord == 0)
    return victim->mposx;
    else
    return victim->mposy;
}
else
{
if(coord == 0)
return get_coord(arg[0]);
else
return get_coord(arg[1]);
}
}
示例#8
0
void explore(struct map *map) {
    struct coord coord;
    get_coord(&coord, map);

    if(map->Map[coord.x][coord.y].flagged == true)
        printf("This cell has a flag...\n");
    else if(map->Map[coord.x][coord.y].value == MINE) {
            printf("\n\tThis cell is mined... Too bad...\n\n");
            display_map_debug(map);
            getchar();
            exit(EXIT_SUCCESS);
    } else
        explore_cell(map, coord.x, coord.y);
}
示例#9
0
int				main(int ac, char **av)
{
	t_env		e;
	t_map		*map;

	if (ac < 2 || ac > 5)
		ft_usage();
	else if ((map = get_map(av[1])))
	{
		ft_init_env(&e, av);
		ft_putendl("Getting your maps' coordonates...");
		if ((e.coord = get_coord(map, &e, NULL)))
		{
			ft_free_map(&map);
			fdf(&e);
			ft_free_all(&e);
		}
	}
	return (EXIT_FAILURE);
}
示例#10
0
/** 
 * IUP canvas callback for mouse press/unpress. 
 */
static int cells_motion(Ihandle *h, int x, int y, char* r) {
  int returned_value = IUP_DEFAULT;

  /* Getting cell struct pointer saved in iup handle */
  TCells* obj = (TCells*) iupGetEnv(h, "_IUPCELLS_DATA");
  if (obj == NULL) return IUP_IGNORE;

  /* Checking the existence of a motion bar callback. If the application
   * has set one, it will be called now. However, before calling the
   * callback, we need to find out which cell is under the mouse
   * position. */
  
  { int i, j; 
    TMotionCb func = (TMotionCb)IupGetCallback(h, "MOUSEMOTION_CB");
    if (func == NULL) return IUP_DEFAULT;
    get_coord(obj, x, y, &i, &j); 
    returned_value = (*(func))(h, i, j, x, y, r);
  }
  return returned_value;
}
示例#11
0
/** 
 * IUP canvas callback for mouse press/unpress. 
 */
static int cells_button(Ihandle *h, int b, int m, int x, int y, char* r) {
  int i, j;
    
  /* Getting cell struct pointer saved in iup handle */
  TCells* obj = (TCells*) iupGetEnv(h, "_IUPCELLS_DATA");
  if (obj == NULL) return IUP_DEFAULT;

  cdCanvasUpdateYAxis(obj->cdcanvas, &y);  

  /* Treating the button event. The application will receive
   * a button press callback. */
    
  /* Checking if there is a callback and calling it. */
  { 
     TButtonCb func = (TButtonCb)IupGetCallback(h, "MOUSECLICK_CB");
     if (func == NULL) return IUP_DEFAULT;
     get_coord(obj, x, y, &i, &j);       /* Getting cells coordinates. */
     (*(func))(h, b, m, i, j, x, y, r);  /* Calling the callback */
  }

  return IUP_DEFAULT;
}
示例#12
0
void		parse_file(const int sfd, const char *filename, t_img_buff *cl)
{
  int		fd;
  t_file	*file;
  t_scene	scene;
  char		*buff;
  int		len;

  if ((fd = open(filename, O_RDONLY)) < 0)
    exit(EXIT_FAILURE);
  file = fd_open_file(fd, FILE_R);
  init_scene_client(&scene);
  if (!parse_scene(&scene, file))
    exit(0);
  cl->img = NULL;
  buff = xmalloc_and_set(NULL, sizeof(*buff) * 10);
  fprintf(stdout, "Parsing done.\nWaiting for server...\n");
  if ((len = read(sfd, buff, 9)) < 0)
    return;
  buff[len] = 0;
  cl->cli_max = atoi(buff);
  get_coord(&scene, cl);
}
示例#13
0
t_coord			*ft_str_to_coord(char *str)
{
	double		x;
	double		y;
	double		z;
	int			i;

	i = 0;
	while (ft_isdigit(str[i]) == 0 && str[i] != '-')
		i++;
	x = (double)ft_atoi(str + i) / 100;
	while (ft_isdigit(str[i]) == 1 || str[i] == '-')
		i++;
	while (ft_isdigit(str[i]) == 0 && str[i] != '-')
		i++;
	y = (double)ft_atoi(str + i) / 100;
	while (ft_isdigit(str[i]) == 1 || str[i] == '-')
		i++;
	while (ft_isdigit(str[i]) == 0 && str[i] != '-')
		i++;
	z = (double)ft_atoi(str + i) / 100;
	return (get_coord(x, y, z));
}
示例#14
0
void nl_meson_prop (int t,double *nlpiprop,double *nlpi2prop,
		    double *ckpiprop,double *ckpi2prop,
		    field_offset temp1, field_offset temp2)
     /* Calculates non-local pion propagator pi_3 and pi_3 tilde */
     /* and local pion propagators for a check */
     /* temp1 and temp2 are scratch space */
{
  int x,y,z,i,icol;
  int coord;
  register su3_matrix *tmp1, *tmp2;

  complex cc;
  /* Sum over all x,y z              */
  for(x=0;x<nx;x++)for(y=0;y<ny;y++)for(z=0;z<nz;z++) {
    if( node_number(x,y,z,t) != mynode() )continue;
    i=node_index(x,y,z,t);
    
    coord = get_coord(i,NL_PI_DIR);
    if(coord%2 == 0)accum_nl_meson_prop(i,NL_PI_DIR,temp1,temp2);
    
    for(icol=0;icol<3;icol++) {
      
      /* Calculate non-local propagator only on even coordinate */
      
      if(coord%2 ==0) {
	/* propmat contains "q" and temp1 contains "Dq" */
	/* q^adj D q  */
	tmp1 = (su3_matrix *)F_PT(&lattice[i],temp1);
	cc = su3_dot( &lattice[i].propmat[icol],
		      (su3_vector *)(tmp1->e[icol]) );
	*nlpiprop += cc.real;
	
	/* propmat2 contains "o" and temp2 contains "Do" */
	/* q^adj D q - o^adj D o  */
	tmp2 = (su3_matrix *)F_PT(&lattice[i],temp2);
	cc = su3_dot( &(lattice[i].propmat2[icol]),
		      (su3_vector *)(tmp2->e[icol]) );
	*nlpiprop -= cc.real;
	
	/* o^adj D q          */
	cc = su3_dot( &lattice[i].propmat2[icol],
		      (su3_vector *)(tmp1->e[icol]) );
	
	if((x+y+z)%2 == 0)*nlpi2prop += cc.real;
	else              *nlpi2prop -= cc.real;
	
	/* o^adj D q - q^adj D o          */
	cc = su3_dot( &(lattice[i].propmat[icol]),
		      (su3_vector *)(tmp2 ->e[icol]) );
	
	if((x+y+z)%2 == 0)*nlpi2prop -= cc.real;
	else              *nlpi2prop += cc.real;
	
      }
      
      /* Calculate local check for all z */
      
      /* q^adj q  */
      cc = su3_dot( &lattice[i].propmat[icol],
		    &lattice[i].propmat[icol] );
      *ckpiprop += cc.real;
      
      /* q^adj q + o^adj o          */
      cc = su3_dot( &lattice[i].propmat2[icol],
		    &lattice[i].propmat2[icol] );
      *ckpiprop += cc.real;
      
      
      /* q^adj o  */
      cc = su3_dot( &lattice[i].propmat[icol],
		    &lattice[i].propmat2[icol] );
      
      if( (x+y+z)%2==0)*ckpi2prop += cc.real;
      else	           *ckpi2prop -= cc.real;
      
    }
  }
}
示例#15
0
文件: torvol.c 项目: kashif/evolver
void torvol()
{
  facet_id f_id;    /* main facet iterator */
  body_id b_id;
  body_id b0_id,b1_id;    /* facet adjacent bodies */

#ifdef NEWTORVOL
struct qinfo f_info; /* for calling q_facet_torus_volume */
q_info_init(&f_info,METHOD_VALUE);
#endif

  /* adjust body volumes to the invariant constant for each */
  FOR_ALL_BODIES(b_id)
    set_body_volume(b_id,get_body_volconst(b_id),NOSETSTAMP);
  if ( web.representation == STRING )
    FOR_ALL_FACETS(f_id)
      set_facet_area(f_id,0.0);

  FOR_ALL_FACETS(f_id)
  {
    REAL t;     /* accumulator for this facet */

    if ( get_fattr(f_id) & NONCONTENT ) continue;

    /* find adjacent bodies */
    b0_id = get_facet_body(f_id);
    b1_id = get_facet_body(facet_inverse(f_id));
    if ( !valid_id(b0_id) && !valid_id(b1_id) ) continue;

#ifdef NEWTORVOL
    f_info.id = f_id;
    q_facet_setup(NULL,&f_info,NEED_SIDE|TORUS_MODULO_MUNGE|ORIENTABLE_METHOD);
    t = q_facet_torus_volume(&f_info);
    if ( valid_id(b0_id) )
        add_body_volume(b0_id,t);
    if ( valid_id(b1_id) )
        add_body_volume(b1_id,-t);
#else
    REAL *v[FACET_VERTS];  /* pointers to three vertex coordinates */
    facetedge_id fe;
    int i;
    REAL adj[FACET_EDGES][MAXCOORD];  /* torus wrap adjustments for edge */
    /* get basic info */
    fe = get_facet_fe(f_id);
    for ( i = 0 ; i < FACET_EDGES ; i ++ )
    {
      v[i] = get_coord(get_fe_tailv(fe));
      get_edge_adjust(get_fe_edge(fe),adj[i]); 
      fe = get_next_edge(fe);
    }

    /* basic tetrahedron */
    t = triple_prod(v[0],v[1],v[2]);

    /* torus wrap corrections */
    for ( i = 0 ; i < FACET_EDGES ; i++ )
    {
      /* two-vertex term */
      t += triple_prod(adj[(i+1)%FACET_EDGES],v[i],v[(i+1)%FACET_EDGES])/2;
      t -= triple_prod(adj[(i+2)%FACET_EDGES],v[i],v[(i+1)%FACET_EDGES])/2;

      /* one-vertex term */
      t += triple_prod(v[i],adj[(i+2)%FACET_EDGES],adj[i]);
    }

    if ( valid_id(b0_id) )
       add_body_volume(b0_id,t/6);
    if ( valid_id(b1_id) )
       add_body_volume(b1_id,-t/6);
#endif
        }
#ifdef NEWTORVOL
q_info_free(&f_info);
#endif
}
示例#16
0
/*
 * The splitting routine is essentially a median search,
 * i.e. finding the median and split the array about it.
 * There are several algorithms for the median search
 * (an overview is given at http://ndevilla.free.fr/median/median/index.html):
 * - AHU (1)
 * - WIRTH (2)
 * - QUICKSELECT (3)
 * - TORBEN (4)
 * (1) and (2) are essentially the same in recursive and non recursive versions.
 * (2) is among the fastest in sequential programs.
 * (3) is similar to what quicksort uses and is as fast as (2).
 * Both (2) and (3) require permuting array elements.
 * (4) is significantly slower but only reads the array without modifying it.
 * The implementation below is a simplified version of (2).
 
*/
void split_bounding_box(data_type_short *points, uint *idx, uint n, data_type_short *bnd_lo, data_type_short *bnd_hi, uint *n_lo, uint *cdim, coord_type *cval)
{
    // search for dimension with longest egde
    coord_type longest_egde = bnd_hi->value[0] - bnd_lo->value[0];    
    uint dim = 0;
    
    for (uint d=0; d<D; d++) {        
        coord_type tmp = bnd_hi->value[d] - bnd_lo->value[d];
        if (longest_egde < tmp) {
            longest_egde = tmp;
            dim = d;
        }            
    }

    *cdim = dim;
    
    coord_type ideal_threshold = (bnd_hi->value[dim] + bnd_lo->value[dim]) / 2;    
    coord_type min,max;
    
    find_min_max(points,(idx+0),dim,n,&min,&max);
    
    coord_type threshold = ideal_threshold;
    
    if (ideal_threshold < min) {
        threshold = min;
    } else if (ideal_threshold > max) {
        threshold = max;
    }
    
    *cval = threshold;
    
    // Wirth's method
    int l = 0;
    int r = n-1;
       
    for(;;) {               // partition points[0..n-1]
    while (l < n && get_coord(points,idx+0,l,dim) < threshold) {
            l++;
        }
    while (r >= 0 && get_coord(points,idx+0,r,dim) >= threshold) {
            r--;
        }
    if (l > r) break; // avoid this
    coord_swap(idx+0,l,r);
    l++; r--;
    }
    
    uint br1 = l;           // now: data_points[0..br1-1] < threshold <= data_points[br1..n-1]
    r = n-1;
    for(;;) {               // partition pa[br1..n-1] about threshold
    while (l < n && get_coord(points,idx+0,l,dim) <= threshold) {
            l++;
        }
    while (r >= br1 && get_coord(points,idx+0,r,dim) > threshold) {
            r--;
        }
    if (l > r) break; // avoid this
    coord_swap(idx+0,l,r);
    l++; r--;
    }
    uint br2 = l;           // now: points[br1..br2-1] == threshold < points[br2..n-1]
    if (ideal_threshold < min) *n_lo = 0+1;
    else if (ideal_threshold > max) *n_lo = n-1;
    else if (br1 > n/2) *n_lo = br1;
    else if (br2 < n/2) *n_lo = br2;
    else *n_lo = n/2;
}
示例#17
0
t_coord				*ft_div_vector(t_coord *v, double k)
{
    return (get_coord(v->x / k, v->y / k, v->z / k));
}
示例#18
0
t_coord				*ft_mult_vector(t_coord *v, double k)
{
    return (get_coord(v->x * k, v->y * k, v->z * k));
}
示例#19
0
	void step_create_widget()
	{
		MyGUI::Widget* widget = get_random(all_widgets);
		if (widget)
		{
			int select = random(3);
			if (select == 0)
			{
				MyGUI::Widget* child = widget->createWidget<MyGUI::Widget>(MyGUI::WidgetStyle::Child, get_skin(), get_coord(), MyGUI::Align::Default);
				MYGUI_ASSERT(child, "child nullptr");
				all_widgets.push_back(child);
			}
			else if (select == 1)
			{
				MyGUI::Widget* child = widget->createWidget<MyGUI::Widget>(MyGUI::WidgetStyle::Popup, get_skin(), get_coord(), MyGUI::Align::Default, get_layer());
				MYGUI_ASSERT(child, "child nullptr");
				all_widgets.push_back(child);
			}
			else if (select == 2)
			{
				MyGUI::Widget* child = widget->createWidget<MyGUI::Widget>(MyGUI::WidgetStyle::Overlapped, get_skin(), get_coord(), MyGUI::Align::Default);
				MYGUI_ASSERT(child, "child nullptr");
				all_widgets.push_back(child);
			}
		}
		else
		{
			MyGUI::Widget* child = MyGUI::Gui::getInstance().createWidget<MyGUI::Widget>(get_skin(), get_coord(), MyGUI::Align::Default, get_layer());
			MYGUI_ASSERT(child, "child nullptr");
			all_widgets.push_back(child);
		}
		test_widgets();
	}
示例#20
0
t_coord				*ft_add_vectors(t_coord *v1, t_coord *v2)
{
    return (get_coord(v1->x + v2->x, v1->y + v2->y, v1->z + v2->z));
}
示例#21
0
/*
 * Comando per gestire il gioco degli scacchi
 */
void do_chess( CHAR_DATA *ch, char *argument )
{
	CHESSBOARD_DATA *board;
	char			 arg[MIL];

	if ( !ch )
	{
		send_log( NULL, LOG_BUG, "do_chess: ch è NULL" );
		return;
	}

	if ( IS_MOB(ch) )
	{
		send_to_char( ch, "I mob non possono giocare a scacchi.\r\n" );
		return;
	}

	board = get_chessboard( ch );

	if ( !VALID_STR(argument) || is_name(argument, "sintassi aiuto syntax help ?") )
	{
		char	*cmd;

		cmd = translate_command( ch, "chess" );
		ch_printf( ch, "&YSintassi gioco&w:  %s inizio|smetto|partecipo|forfeit\r\n", cmd );
		ch_printf( ch, "&YSintassi info&w:   %s pezzi\r\n", cmd );
		ch_printf( ch, "&YSintassi mosse&w:  %s muovo <sorgente> <destinazione> [comandi opzionali]\r\n", cmd );
		ch_printf( ch, "&YSintassi extra&w:  %s arrocco|promuovo\r\n", cmd );

		if ( !VALID_STR(argument) && board )
		{
			send_to_char( ch, "\r\n" );
			show_status( ch, board );
			send_to_char( ch, "\r\n" );
			show_board( ch, board );
		}

		return;
	}

	argument = one_argument( argument, arg );

	if ( is_name_prefix(arg, "inizio inizia comincio comincia cominciare start") )
	{
		CHESSBOARD_DATA *newboard;

		if ( board )
		{
			send_to_char( ch, "Sto già partecipando ad una partita di scacchi.\r\n" );
			return;
		}

		CREATE( newboard, CHESSBOARD_DATA, 1 );
		init_board( newboard );
		newboard->player1	= ch;
		newboard->turn		= ch;

		LINK( newboard, first_chessboard, last_chessboard, next, prev );
		top_chessboard++;

		send_to_char( ch, "Inizio una nuova partita di scacchi.\r\n" );
		return;
	}

	if ( is_name_prefix(arg, "partecipa partecipo join") )
	{
		CHESSBOARD_DATA *vboard = NULL;
		CHAR_DATA		*vch;
		char			 arg2[MIL];

		if ( board )
		{
			send_to_char( ch, "Sto già partecipando ad una partita di scacchi.\r\n" );
			return;
		}

		argument = one_argument( argument, arg2 );
		if ( !VALID_STR(arg2) )
		{
			send_to_char( ch, "Con chi devo partecipare ad una partita di scacchi?\r\n" );
			return;
		}

		vch = get_player_room( ch, arg2, TRUE );
		if ( !vch )
		{
			ch_printf( ch, "Non vedo nessun %s nella stanza.\r\n", arg2 );
			return;
		}

		vboard = get_chessboard( vch );
		if ( !vboard )
		{
			send_to_char( ch, "Non sta giocando a scacchi.\r\n" );
			return;
		}

		if ( vboard->player2 )
		{
			send_to_char( ch, "Questa scacchiera ha già due giocatori.\r\n" );
			return;
		}

		vboard->player2 = ch;
		vboard->turn	= vboard->player2;

		send_to_char( ch, "Mi unisco alla partita, è il mio turno.\r\n" );
		ch_printf( vboard->player1, "%s si unisce alla tua partita.\r\n", ch->name );
		return;
	}

	if ( is_name_prefix(arg, "pezzi pieces") )
	{
		int		x;	/* contatore dei colori */
		int		y;	/* contatore dei pezzi */

		for ( x = 0;  x < COLOR_NONE;  x++ )
		{
			if ( x == COLOR_BLACK )
				send_to_char( ch, "\r\n\r\nPezzi neri:\r\n" );
			else
				send_to_char( ch, "Pezzi bianchi:\r\n" );

			for ( y = PIECE_PAWN;  y < PIECE_NONE;  y++ )
				ch_printf( ch, "%-7s", table_pieces[y].name );

			send_to_char( ch, "\r\n" );
			for ( y = PIECE_PAWN;  y < PIECE_NONE;  y++ )
				send_to_char( ch, (x == COLOR_WHITE) ? table_pieces[y].wgraph1 : table_pieces[y].bgraph1 );

			send_to_char( ch, "\r\n" );
			for ( y = PIECE_PAWN;  y < PIECE_NONE;  y++ )
				send_to_char( ch, (x == COLOR_WHITE) ? table_pieces[y].wgraph2 : table_pieces[y].bgraph2 );
		}
		send_to_char( ch, "\r\n" );
		return;
	}

	if ( !board )
	{
		send_to_char( ch, "Non ho iniziato o non sto partecipando a nessuna partita di scacchi.\r\n" );
		return;
	}

	if ( is_name_prefix(arg, "smetto fermo stop") )
	{
		free_chessboard( board );
		return;
	}

	if ( is_name_prefix(arg, "forfeit") )
	{
		send_to_char( ch, "Dò forfeit così perdendo.\r\n" );
		free_chessboard( board );
		return;
	}

	if ( !board->player1 || !board->player2 )
	{
		send_to_char( ch, "C'è solo un giocatore.\r\n" );
		return;
	}

	if ( board->moves < 0 )
	{
		send_to_char( ch, "Il gioco non è ancora iniziato.\r\n" );
		return;
	}

	if ( is_name_prefix(arg, "promuovo promuovi promote") )
	{
		int		piece = board->piece[board->lastx][board->lasty];
		char	extra[MIL];

		if ( !((piece == PIECE_PAWN && board->player1 == ch)
		  ||   (piece == PIECE_PAWN && board->player2 == ch)) )
		{
			send_to_char( ch, "Non posso promuovere questo pezzo.\r\n" );
			return;
		}

		if ( (piece == PIECE_PAWN && board->lastx != 0)
		  || (piece == PIECE_PAWN && board->lastx != 7) )
		{
			send_to_char( ch, "Puoi promuovere solamente i pedoni che hanno raggiunto l'altro lato della scacchiera.\r\n" );
			return;
		}

		if ( !VALID_STR(argument) )
		{
			send_to_char( ch, "Vorrei promuovere il pedone in che cosa?\r\n" );
			return;
		}

		if		( is_name_prefix(argument, "regina queen"  ) )	piece = PIECE_QUEEN;
		else if ( is_name_prefix(argument, "alfiere bishop") )	piece = PIECE_BISHOP;
		else if ( is_name_prefix(argument, "cavallo knight") )	piece = PIECE_KNIGHT;
		else if ( is_name_prefix(argument, "torre rook"	   ) )	piece = PIECE_ROOK;
		else
		{
			ch_printf( ch, "Non posso promuoverlo a %s.\r\n", argument );
			return;
		}

		board->piece[board->lastx][board->lasty] = piece;
		sprintf( extra, "%s (%c%d)", table_pieces[piece].name, board->lastx+'a', board->lasty+1 );
		board_move_messages( ch, MOVE_PROMOTE, extra );
		return;
	}

	if ( board->turn != ch )
	{
		send_to_char( ch, "Non è il mio turno.\r\n" );
		return;
	}

	if ( is_name_prefix(arg, "arrocco") )
	{
		int 	myx;
		int 	rooky;
		int 	kdy;
		int		rdy;
		bool	fRookShort;

		if ( king_in_check(board, PIECE_KING, (board->player1 == ch) ? COLOR_BLACK : COLOR_WHITE) > 0 )
		{
			send_to_char( ch, "Non posso eseguire un arrocco mentre sono sotto scacco.\r\n" );
			return;
		}

		if ( (board->player1 == ch && HAS_BIT(board->flags1, CHESSFLAG_MOVEDKING))
		  || (board->player2 == ch && HAS_BIT(board->flags2, CHESSFLAG_MOVEDKING)) )
		{
			send_to_char( ch, "Non posso effettuare un arrocco quando ho già mosso il mio re.\r\n" );
			return;
		}
		myx = (board->player1 == ch) ? 7 : 0;

		if ( !VALID_STR(argument) )
		{
			ch_printf( ch, "Utilizzo: %s arrocco corto|lungo\r\n", translate_command(ch, "chess") );
			return;
		}

		if ( is_name_prefix(argument, "corto short") )
			fRookShort = TRUE;
		else if ( is_name_prefix(argument, "lungo long") )
			fRookShort = FALSE;
		else
		{
			send_command( ch, "chess arrocco", CO );
			return;
		}

		if ( (board->player1 == ch && HAS_BIT(board->flags1, fRookShort ? CHESSFLAG_MOVEDKROOK : CHESSFLAG_MOVEDQROOK))
		  || (board->player2 == ch && HAS_BIT(board->flags2, fRookShort ? CHESSFLAG_MOVEDKROOK : CHESSFLAG_MOVEDQROOK)) )
		{
			ch_printf( ch, "Non posso effettuare l'arrocco %s perchè ho già mosso la torre prima.\r\n",
				fRookShort ? "corto" : "lungo" );
			return;
		}
		rooky = fRookShort ? 7 : 0;

		if ( ( fRookShort && (board->piece[myx][6] != PIECE_NONE || board->piece[myx][5] != PIECE_NONE))
		  || (!fRookShort && (board->piece[myx][1] != PIECE_NONE || board->piece[myx][2] != PIECE_NONE || board->piece[myx][3] != PIECE_NONE)) )
		{
			send_to_char( ch, "L'arrocco è bloccato dalla presenza di pezzi tra il re e la torre.\r\n" );
			return;
		}

		/* castling succeeded */
		if ( fRookShort )
		{
			kdy = 6;
			rdy = 5;
		}
		else
		{
			kdy = 2;
			rdy = 3;
		}

/* (FF) (TT) (RR) (bb) ricordo che una qualsiasi delle caselle, in cui avveniva l'arrocco
 *	non dovevano essere sotto scacco, mi sa che qui non è così, o forse ricordo sbagliato */

		/* check for 'move across check' rule */
		board->piece[myx][rdy] = board->piece[myx][4];
		board->piece[myx][4] = PIECE_NONE;

		if ( king_in_check(board, board->piece[myx][rdy], board->color[myx][rdy]) > 0 )
		{
			send_to_char( ch, "Il mio re si troverebbe sotto scacco dopo l'arrocco.\r\n" );

			board->piece[myx][4] = board->piece[myx][rdy];
			board->piece[myx][rdy] = PIECE_NONE;
			return;
		}

		board->piece[myx][kdy] = board->piece[myx][rdy];
		board->piece[myx][rdy] = board->piece[myx][rooky];
		board->piece[myx][rooky] = PIECE_NONE;

		/* check for 'check' after castled */
		if ( king_in_check(board, board->piece[myx][kdy], board->color[myx][kdy]) > 0 )
		{
			send_to_char( ch, "Il mio re si troverebbe sotto scacco dopo l'arrocco.\r\n" );

			board->piece[myx][4] = board->piece[myx][kdy];
			board->piece[myx][kdy] = PIECE_NONE;
			board->piece[myx][rooky] = board->piece[myx][rdy];
			board->piece[myx][rdy] = PIECE_NONE;
			return;
		}

		/* Basta indicare che è stato mosso il re per evitare un altro arrocco */
		if ( board->player1 == ch )
			SET_BIT( board->flags1, CHESSFLAG_MOVEDKING );
		else
			SET_BIT( board->flags2, CHESSFLAG_MOVEDKING );

		board_move_stuff( board );
		board_move_messages( ch, MOVE_CASTLE, rooky == 7 ? "corto" : "lungo" );
	}

	if ( is_name_prefix(arg, "muovo move") )
	{
		char	coord1[MIL];
		char	coord2[MIL];
		char	extra[MIL];
		int		x, y, dx, dy;
		int		ret;

		if ( !VALID_STR(argument) )
		{
			ch_printf( ch, "Utilizzo: %s muovo <sorgente> <destinazione>\r\n", translate_command(ch, "chess") );
			return;
		}

		argument = one_argument( argument, coord1 );
		argument = one_argument( argument, coord2 );

		if ( !VALID_STR(coord1) || !VALID_STR(coord2) )
		{
			ch_printf( ch, "Utilizzo: %s muovo <sorgente> <destinazione>\r\n", translate_command(ch, "chess") );
			return;
		}

		get_coord( coord1, &x, &y );
		get_coord( coord2, &dx, &dy );

		if ( x < 0 || x >= 8 || dx < 0 || dx >= 8
		  || y < 0 || y >= 8 || dy < 0 || dy >= 8 )
		{
			send_to_char( ch, "Mossa non valida, utilizza a-h e 1-8 (esempio: a4 b4).\r\n" );
			return;
		}

		extra[0] = '\0';

		ret = is_valid_move( ch, board, x, y, dx, dy );
		if ( ret == MOVE_OK || ret == MOVE_TAKEN )
		{
			int	piece;
			int	color;
			int	destpiece;
			int	destcolor;

			piece	  = board->piece[x][y];
			color	  = board->color[x][y];
			destpiece = board->piece[dx][dy];
			destcolor = board->color[dx][dy];

			board->piece[dx][dy] = piece;
			board->color[dx][dy] = color;
			board->piece[x][y] = PIECE_NONE;
			board->color[x][y] = COLOR_NONE;

			if ( king_in_check(board, PIECE_KING, board->color[dx][dy]) > 0 )
			{
				board->piece[dx][dy] = destpiece;
				board->color[dx][dy] = destcolor;
				board->piece[x][y]	 = piece;
				board->color[x][y]	 = color;
				ret = MOVE_INCHECK;
			}
			else
			{
				if ( destpiece == PIECE_NONE )
					sprintf( extra, "%c%d (%s) alle coordinate %c%d", x+'a', y+1, table_pieces[piece].name, y+'a', dy+1 );
				else
					sprintf( extra, "%c%d (%s) alle coordinate %c%d (%s)", x+'a', y+1, table_pieces[piece].name, y+'a', dy+1, table_pieces[destpiece].name );

				board_move_stuff( board );
				board->lastx = dx;
				board->lasty = dy;

				/* Imposta le flag per evitare gli arrocchi */
				if ( piece == PIECE_ROOK )
				{
					if ( color == COLOR_WHITE )
					{
						if ( y == 0 && x == 0 )
							SET_BIT( board->flags1, CHESSFLAG_MOVEDKROOK );
						else if ( y == 0 && x == 7 )
							SET_BIT( board->flags1, CHESSFLAG_MOVEDQROOK );
					}
					else
					{
						if ( y == 7 && x == 0 )
							SET_BIT( board->flags2, CHESSFLAG_MOVEDKROOK );
						else if ( y == 7 && x == 7 )
							SET_BIT( board->flags2, CHESSFLAG_MOVEDQROOK );
					}
				}
				else if ( piece == PIECE_KING )
				{
					if ( color == COLOR_WHITE )
						SET_BIT( board->flags1, CHESSFLAG_MOVEDKING );
					else
						SET_BIT( board->flags2, CHESSFLAG_MOVEDKING );
				}
			}

			board_move_messages( ch, ret, extra );
		}

		/* Così qui gestisce i comandi opzionali, come il promote */
		if ( VALID_STR(argument) )
		{
			do_chess( ch, argument );
			return;
		}
		return;
	}

	send_command( ch, "chess aiuto", CO );
}
示例#22
0
t_coord				*ft_sub_vectors(t_coord *v1, t_coord *v2)
{
    return (get_coord(v1->x - v2->x, v1->y - v2->y, v1->z - v2->z));
}
示例#23
0
文件: game.c 项目: fmalazemi/chess
///////////////////////////////////
// MAIN (only for internal test) //
///////////////////////////////////
int
main ()
{
  // Valgrind run
  init_chess_library ();
  int i, from, to;

  for (i = 0; i < 1000; i++)
    {
      Game *g = init_game ();
      Board *board;
      char *fen;

      // 1. e4 a6 2. Bc4 a5 3. Qh5 a4 4. Qxf7#
      board = current_board (g);
      get_coord (board, 'P', "e", "e4", 0, &from, &to);
      pseudo_legal_move (board, from, to);
      apply_move (g, from, to, 0);
      fen = to_fen (board);
      free (fen);

      board = current_board (g);
      get_coord (board, 'P', "a", "a6", 0, &from, &to);
      pseudo_legal_move (board, from, to);
      apply_move (g, from, to, 0);
      fen = to_fen (current_board (g));
      free (fen);

      board = current_board (g);
      get_coord (board, 'B', "", "c4", 0, &from, &to);
      pseudo_legal_move (board, from, to);
      apply_move (g, from, to, 0);
      fen = to_fen (current_board (g));
      free (fen);

      board = current_board (g);
      get_coord (board, 'P', "a", "a5", 0, &from, &to);
      pseudo_legal_move (board, from, to);
      apply_move (g, from, to, 0);
      fen = to_fen (current_board (g));
      free (fen);

      board = current_board (g);
      get_coord (board, 'Q', "", "h5", 0, &from, &to);
      pseudo_legal_move (board, from, to);
      apply_move (g, from, to, 0);
      fen = to_fen (current_board (g));
      free (fen);

      board = current_board (g);
      get_coord (board, 'P', "a", "a4", 0, &from, &to);
      pseudo_legal_move (board, from, to);
      apply_move (g, from, to, 0);
      fen = to_fen (current_board (g));
      free (fen);

      board = current_board (g);
      get_coord (board, 'Q', "", "f7", 0, &from, &to);
      pseudo_legal_move (board, from, to);
      apply_move (g, from, to, 0);
      fen = to_fen (current_board (g));
      free (fen);

      free_game (g);
    }
  return 0;
}