Пример #1
0
inline HexColor StoneBoard::WhoseTurn() const
{
    BenzeneAssert(IsStandardPosition());
    bitset_t mask = GetPlayed() & Const().GetCells();
    std::size_t first = (GetColor(FIRST_TO_PLAY) & mask).count();
    std::size_t second = (GetColor(!FIRST_TO_PLAY) & mask).count();
    return (first > second) ? !FIRST_TO_PLAY : FIRST_TO_PLAY;
}
Пример #2
0
NODE * Div( NODE *n1, NODE *n2 )
{
  if( n1 == 0 ) return BinaryOp( DIV, Const(1), n2 );
  if( n2 == 0 ) return n1;

  if( IsConst( n2, 1 ) ) {
    n2->sign *= n1->sign;
    FreeNode( n2 );
    return n1;
  }
                  
  return BinaryOp( DIV, n1, n2 );    
}
Пример #3
0
Файл: parse.c Проект: AAAJet/ooc
static void initConst (void)
{	static const struct {
		const char * name;
		double value;
	} constants [] = {
		{ "PI",		3.14159265358979323846 },
		{ "E",		2.71828182845904523536 },
		{ "GAMMA",	0.57721566490153286060 },	/* Euler */
		{ "DEG",	57.29577951308232087680 },	/* deg/radian */
		{ "PHI",	1.61803398874989484820 },	/* golden ratio */
	{ 0 }}, * cp = constants;

	while (cp -> name)
		install(table, new(Const(), cp -> name, CONST, cp -> value)),
		++ cp;
}
Пример #4
0
void initialize_resolve_macro() {
    g_resolve_macro_name = new name("resolve");
    g_resolve_opcode = new std::string("Res");
    g_or = new expr(Const(get_or_name()));
    g_not = new expr(Const(get_not_name()));
    g_false = new expr(Const(get_false_name()));
    g_or_elim = new expr(Const(get_or_elim_name()));
    g_or_intro_left = new expr(Const(get_or_intro_left_name()));
    g_or_intro_right = new expr(Const(get_or_intro_right_name()));
    g_absurd_elim = new expr(Const(get_absurd_name()));
    g_var_0 = new expr(mk_var(0));
    g_resolve_macro_definition = new macro_definition(new resolve_macro_definition_cell());
    register_macro_deserializer(*g_resolve_opcode,
                                [](deserializer &, unsigned num, expr const * args) {
                                    if (num != 3)
                                        throw corrupted_stream_exception();
                                    return mk_resolve_macro(args[0], args[1], args[2]);
                                });
}
Пример #5
0
void initialize_string() {
    g_string_macro    = new name("string_macro");
    g_string_opcode   = new std::string("Str");
    g_nat             = new expr(Const(get_nat_name()));
    g_char            = new expr(Const(get_char_name()));
    g_char_of_nat     = new expr(Const(get_char_of_nat_name()));
    g_string          = new expr(Const(get_string_name()));
    g_empty           = new expr(Const(get_string_empty_name()));
    g_str             = new expr(Const(get_string_str_name()));
    g_fin_mk          = new expr(Const(get_fin_mk_name()));
    g_list_char       = new expr(mk_app(mk_constant(get_list_name(), {mk_level_one()}), *g_char));
    g_list_cons       = new expr(mk_constant(get_list_cons_name(), {mk_level_one()}));
    g_list_nil_char   = new expr(mk_app(mk_constant(get_list_nil_name(), {mk_level_one()}), *g_char));
    register_macro_deserializer(*g_string_opcode,
    [](deserializer & d, unsigned num, expr const *) {
        if (num != 0)
            throw corrupted_stream_exception();
        std::string v = d.read_string();
        return mk_string_macro(v);
    });
}
Пример #6
0
inline bool StoneBoard::IsPlayed(HexPoint cell) const
{
    BenzeneAssert(Const().IsValid(cell));
    return m_played.test(cell);
}
Пример #7
0
inline bool StoneBoard::IsOccupied(HexPoint cell) const
{
    BenzeneAssert(Const().IsLocation(cell));
    return (IsBlack(cell) || IsWhite(cell));
}
Пример #8
0
inline bool StoneBoard::IsEmpty(HexPoint cell) const
{
    BenzeneAssert(Const().IsLocation(cell));
    return !IsOccupied(cell);
}
Пример #9
0
inline bool StoneBoard::IsColor(HexPoint cell, HexColor color) const
{
    BenzeneAssert(HexColorUtil::isBlackWhite(color));
    BenzeneAssert(Const().IsLocation(cell));
    return m_stones[color].test(cell);
}
Пример #10
0
inline bool StoneBoard::IsWhite(HexPoint cell) const    
{
    BenzeneAssert(Const().IsValid(cell));
    return m_stones[WHITE].test(cell);
}
Пример #11
0
inline bitset_t StoneBoard::GetEmpty() const
{
    return Const().GetLocations() - GetOccupied();
}
Пример #12
0
inline bitset_t StoneBoard::GetColor(HexColor color) const
{
    BenzeneAssert(HexColorUtil::isValidColor(color));
    if (color == EMPTY) return GetEmpty();
    return m_stones[color] & Const().GetLocations();
}
Пример #13
0
inline bitset_t StoneBoard::GetWhite() const
{
    return m_stones[WHITE] & Const().GetLocations();
}
Пример #14
0
inline bitset_t StoneBoard::GetBlack() const
{
    return m_stones[BLACK] & Const().GetLocations();
}
Пример #15
0
Types WhileLoop::allowedTypes(int _index) const
{
	if (_index == Condition)
		return Type(Bool).topWith(Const());
	return Super::allowedTypes(_index);
}
Пример #16
0
 int operator=(double a)         { return Const(a); };    // C = a (all entries equal a)
Пример #17
0
inline std::size_t StoneBoard::NumStones() const
{
    return (GetOccupied() & GetPlayed() & Const().GetCells()).count();
}
Пример #18
0
int intraFont_init(lua_State *L)
{
	intraFontInit();
	
	UserdataRegister("intraFont", intraFont_methods, intraFont_metamethods)
	
	lua_pushstring(L, "intraFont");
	lua_gettable(L, LUA_GLOBALSINDEX);
	
	Const("CENTER", INTRAFONT_ALIGN_CENTER)
	Const("LEFT", INTRAFONT_ALIGN_LEFT)
	Const("RIGHT", INTRAFONT_ALIGN_RIGHT)
	
	Const("G_UP", GRAD_UP)
	Const("G_RIGHT", GRAD_RIGHT)
	Const("G_DOWN", GRAD_DOWN)
	Const("G_LEFT", GRAD_LEFT)
	Const("G_UP_LEFT", GRAD_UP_LEFT)
	Const("G_UP_RIGHT", GRAD_UP_RIGHT)
	Const("G_DOWN_LEFT", GRAD_DOWN_LEFT)
	Const("G_DOWN_RIGHT", GRAD_DOWN_RIGHT)
	
	return 1;
}
Пример #19
0
bool EllipseFitting(POINT* rgPoints, int nPoints, double &a, double &b, double &c, double &d, double &e, double &f)
{
	int		i, j;
	int		np = nPoints;
	int		nrot=0;

	Matrix<double>	D(np+1,7);	//Design matrix
	Matrix<double>	S(7,7);		//Scatter matrix
	Matrix<double>	Const(7,7);	//Constraint matrix
	Matrix<double>	temp(7,7);
	Matrix<double>	L(7,7);		//The lower triangular matrix L * L' = S
	Matrix<double>	C(7,7);
	Matrix<double>	invL(7,7);	//Inverse matrix of L
	Matrix<double>	V(7,7);		//The eigen vectors
	Matrix<double>	sol(7,7);	//The GVE solution

	double	ev[7];		//The eigen value
	double	pvec[7];

	if (np < 6)
	{
		return false;
	}

	//Build design matrix D
	for (i = 0; i < np; i++)
	{ 
		D[i][1]	= rgPoints[i].x * rgPoints[i].x;
		D[i][2] = rgPoints[i].x * rgPoints[i].y;
		D[i][3] = rgPoints[i].y * rgPoints[i].y;
		D[i][4] = rgPoints[i].x;
		D[i][5] = rgPoints[i].y;
		D[i][6] = 1.0;
	}

	//Build Scatter matrix S
	A_TperB(D, D, S, np, 6, np, 6);

	//Build 6*6 constraint matrix
	Const[1][3] = -2;
	Const[2][2] = 1;
	Const[3][1] = -2;

	//Sovle generalized eigen system
	choldc(S, 6, L);
	if (!inverse(L, invL, 6))
	{
		return false;
	}
	AperB_T(Const, invL, temp, 6, 6, 6, 6);
	AperB(invL, temp, C, 6, 6, 6, 6);
	jacobi(C, 6, ev, V, nrot);
	A_TperB(invL, V, sol, 6, 6, 6, 6);

	//Normalize the solution
	for (j = 1; j <= 6; j++)
	{
		double mod = 0.0;

		for (i = 1; i <= 6; i++)
		{
			mod += sol[i][j] * sol[i][j];
		}

		mod = sqrt(mod);

		for (i = 1 ; i <= 6; i++)
		{
		 	sol[i][j] /= mod;
		}
	}

	double	zero	= 10e-20;
	int		solind	= 0;

	//Find the only negative eigen value
	for (i = 1; i <= 6; i++)
	{
		if ((ev[i] < 0) && (fabs(ev[i]) > zero))
		{
			solind = i;
		}
	}

	//Get the fitted parameters
	for (j = 1; j <= 6; j++)
	{
		pvec[j] = sol[j][solind];
	}		

	a = pvec[1];
	b = pvec[2];
	c = pvec[3];
	d = pvec[4];
	e = pvec[5];
	f = pvec[6];

	return true;
}
Пример #20
0
inline bool StoneBoard::IsBlack(HexPoint cell) const    
{
    BenzeneAssert(Const().IsValid(cell));
    return m_stones[BLACK].test(cell);
}
Пример #21
0
inline bitset_t StoneBoard::GetOccupied() const
{
    return (GetBlack() | GetWhite()) & Const().GetLocations();
}
Пример #22
0
}

void initialize_with_options_tactic() {
    g_options_name     = new name("options");
    g_options_opcode   = new std::string("OPTM");
    register_macro_deserializer(*g_options_opcode,
                                [](deserializer & d, unsigned num, expr const *) {
                                    if (num > 0)
                                        throw corrupted_stream_exception();
                                    options info;
                                    d >> info;
                                    return mk_options_expr(info);
                                });

    name with_options_tac_name{"tactic", "with_options_tac"};
    g_with_options_tac = new expr(Const(with_options_tac_name));
    register_tac(with_options_tac_name,
                 [=](type_checker & tc, elaborate_fn const & fn, expr const & e, pos_info_provider const * p) {
                     buffer<expr> args;
                     get_app_args(e, args);
                     if (args.size() != 2)
                         throw expr_to_tactic_exception(e, "invalid 'with_options' tactical, it must have two arguments");
                     check_tactic_expr(args[0], "invalid 'with_options' tactical, invalid argument");
                     expr opts = get_tactic_expr_expr(args[0]);
                     if (!is_options_expr(opts))
                         throw expr_to_tactic_exception(args[0], "invalid 'with_options' tactical, invalid argument");
                     tactic t  = expr_to_tactic(tc, fn, args[1], p);
                     return with_options(get_options_expr_options(opts), t);
                 });
}