Exemple #1
0
bool Check2point(POINT p1,POINT p2)
{
	CChessPoint pa(p1) , pb(p2);
	CChessPoint pc(p1),  pb(p2);
	int x,y;
	POINT p3,p4;

	if(p1.y == p2.y)
	{
		if(CheckLine(pa.m_rightPoint ,pb.m_leftPoint))
		//	return true;
		p3 =p1;
		p4 =p2;
		for(y = 0; y<11;y++)
		{
			p3.y  = p4.y -y;
		}
	}

	if(p1.x == p2.x)
	{
		if(CheckLine(pa.m_downPoint ,pb.m_upPoint))
			return true;
	}

	return false;
}
void CLinearSystem::SubstractLine(int what, int from, double times)
{
    CheckLine(what);
    CheckLine(from);

    for(int m = 0 ; m < m_m; m++)
    {
        Set(from,m,Get(from,m)-times*Get(what,m));
    }
}
void CLinearSystem::Swap(int n1, int n2)
{
    CheckLine(n1);
    CheckLine(n2);
    for(int m = 0; m < m_m; m++)
    {
        double l2 = Set(n2,m,Get(n1,m));
        Set(n1,m,l2);
    }
}
Exemple #4
0
void CTetrisDlg::OnTimer(UINT_PTR nIDEvent)
{
    if(m_pBlock->canMoveDown())
    {
        m_pBlock->moveDown();
    }
    else
    {
        for(CHAR i = ROW - 1; i >= 0; --i)
        {
            if(CheckLine(i))
            {
                RemoveLine(i);
                ++i;
            }
        }
        MSG msg;
        while(::PeekMessage(&msg, m_hWnd, 0, 0, PM_REMOVE));
        if(IsGameOver(m_gameParam & 0xE0))
        {
            GameOver();
        }
        else
        {
            delete m_pBlock;
            m_pBlock = BlockFromIndex(m_gameParam & 0xE0);
            NextRandomBlock();
            m_nextColor = NextRandomColor();
        }
    }
    Invalidate(FALSE);
    CDialog::OnTimer(nIDEvent);
}
/**
 * Checks if the player have made some lines.
 */
void TetraminoesManager::InnerData::CheckLines() {
    int numLinesErased = 0;
    int accumPoints = 0;

    for (int i = 0; i < WORLD_HEIGHT; i++) {
        if (CheckLine(i)) {
            EraseLine(i);
            numLinesErased++;
            accumPoints += LINE_POINTS[level - 1];
        }
    }

    if (numLinesErased >= 4) {
        accumPoints *= 2;
    }

    lines += numLinesErased;
    score += accumPoints;

    if (lines > target) {
        level++;
        maxInterval = MAX_INTERVALS[level - 1];
        target += MAX_LINES[level - 1];
    }

    if (accumPoints > 0) {
        lineSound.Play();
        UpdateHud();
    } else if (Keyboard::IsKeyUp(Keyboard::X)) {
        fallSound.Play();
    } else {
        hitSound.Play();
    }
}
Bool
XkbRF_LoadRules(FILE *file, XkbRF_RulesPtr rules)
{
InputLine	line;
RemapSpec	remap;
XkbRF_RuleRec	trule,*rule;
XkbRF_GroupRec  tgroup,*group;

    if (!(rules && file))
	return FALSE;
    bzero((char *)&remap,sizeof(RemapSpec));
    bzero((char *)&tgroup,sizeof(XkbRF_GroupRec));
    InitInputLine(&line);
    while (GetInputLine(file,&line,TRUE)) {
	if (CheckLine(&line,&remap,&trule,&tgroup)) {
            if (tgroup.number) {
	        if ((group= XkbRF_AddGroup(rules))!=NULL) {
		    *group= tgroup;
		    bzero((char *)&tgroup,sizeof(XkbRF_GroupRec));
	        }
	    } else {
	        if ((rule= XkbRF_AddRule(rules))!=NULL) {
		    *rule= trule;
		    bzero((char *)&trule,sizeof(XkbRF_RuleRec));
	        }
	    }
	}
	line.num_line= 0;
    }
    FreeInputLine(&line);
    return TRUE;
}
void CLinearSystem::MultiplyLine(int n, double val)
{
    CheckLine(n);
    for(int m = 0; m < m_m; m++)
    {
        Set(n,m,Get(n,m)*val);
    }
}
Exemple #8
0
bool ppInclude::Check(int token, const std::string &args)
{
    if (!current || !current->Check(token, args, current->GetErrorLine()))
        if (!CheckInclude(token, args))
            if (!CheckLine(token, args))
                return false;
    return true;
}
bool DialogSpellChecker::FindNext() {
	AssDialogue *real_active_line = context->selectionController->GetActiveLine();
	// User has changed the active line; restart search from this position
	if (real_active_line != active_line) {
		active_line = real_active_line;
		has_looped = false;
		start_line = active_line;
	}

	int start_pos = context->textSelectionController->GetInsertionPoint();
	int commit_id = -1;

	if (CheckLine(active_line, start_pos, &commit_id))
		return true;

	entryIter it = context->ass->Line.iterator_to(*active_line);

	// Note that it is deliberate that the start line is checked twice, as if
	// the cursor is past the first misspelled word in the current line, that
	// word should be hit last
	while(!has_looped || active_line != start_line) {
		do {
			// Wrap around to the beginning if we hit the end
			if (++it == context->ass->Line.end()) {
				it = context->ass->Line.begin();
				has_looped = true;
			}
		} while (!(active_line = dynamic_cast<AssDialogue*>(&*it)));

		if (CheckLine(active_line, 0, &commit_id))
			return true;
	}

	if (IsShown()) {
		wxMessageBox(_("Aegisub has finished checking spelling of this script."), _("Spell checking complete."));
		Close();
	}
	else {
		wxMessageBox(_("Aegisub has found no spelling mistakes in this script."), _("Spell checking complete."));
		throw agi::UserCancelException("No spelling mistakes");
	}

	return false;
}
Exemple #10
0
objtype* EnemyVisible(int *angle, int *distance)
{
	objtype* ob;
	int tx = (int)player->tilex, ty = (int)player->tiley;
	int i, j, k;
	static objtype* oldob;

	int distmin = INT_MAX;
	fixed dxmin, dymin;
	objtype* obmin = NULL;

	for(ob = player->next; ob; ob = ob->next)
	{
		k = abs(ob->tilex - tx);
		j = abs(ob->tiley - ty);
		i = k > j ? k : j;

		if(i > ENEMY_VISIBLE_RANGE)
			continue;
		if(!(ob->flags & FL_VISABLE)
		&& time(NULL) - ob->lastSoundTime > SOUND_HEAR_TIME_SECONDS)
			continue;
		if(!(ob->flags & FL_SHOOTABLE))
			continue;
		if(ob->hitpoints <= 0)
			continue;
		if(!CheckLine(ob))
			continue;
		if((abs(*distance - i) >= ENEMY_VISIBLE_CHANGE_DISTANCE &&
		    ob != oldob)
		   || ob == oldob
		   || (oldob && !(oldob->flags & FL_SHOOTABLE)))
		{
			if(i <= distmin)
			{
				distmin = i;
				obmin = ob;
			}
		}
	}

	if(obmin)
	{
		oldob = obmin;
		*angle = (short)(180.f / PI_F * atan2(-((float)obmin->y -
							      player->y),
							(float)obmin->x -
							      player->x));
		*distance = distmin;
	}

	return obmin;
}
Exemple #11
0
bool VLevel::CrossSubsector(linetrace_t& Trace, int num) const
{
	guard(VLevel::CrossSubsector);
	subsector_t*	sub;
	int				count;
	seg_t*			seg;
	int 			polyCount;
	seg_t**			polySeg;

	sub = &Subsectors[num];
	
	if (sub->poly)
	{
		// Check the polyobj in the subsector first
		polyCount = sub->poly->numsegs;
		polySeg = sub->poly->segs;
		while (polyCount--)
		{
			if (!CheckLine(Trace, *polySeg++))
			{
				return false;
			}
		}
	}

	// check lines
	count = sub->numlines;
	seg = &Segs[sub->firstline];

	for ( ; count ; seg++, count--)
	{
		if (!CheckLine(Trace, seg))
		{
			return false;
		}
	}
	// passed the subsector ok
	return true;
	unguard;
}
double CLinearSystem::NormalizeLine(int n)
{
    CheckLine(n);
    for(int m = 0; m < m_m;m++)
    {
        if(Get(n,m) != 0)
        {
            MultiplyLine(n,1/Get(n,m));
            return Get(n,m);
        }
    }
    return 0;
}
Exemple #13
0
int main(int argc, char **argv)
{

    if (argc != 2)
    {
        fprintf(stderr, "\nusage opf_check <input ASCII file in the LibOPF format>\nNote that the input file for opf_check must be a text file.\nUse opf2txt to convert your OPF binary file into a text file.\n");
        exit(-1);
    }
    FILE *fp = NULL;
    char header[HEADERSIZE], line[LINESIZE], OK = 1;
    int nsamples, nlabels, nfeats, i;
    char *result = NULL;

    fp = fopen(argv[1], "r");
    if (!fp)
    {
        fprintf(stderr, "\nunable to open file %s\n", argv[1]);
        exit(-1);
    }

    /* it checks the header */
    result = fgets(header, HEADERSIZE, fp);
    if (!CheckHeader(header, &nsamples, &nlabels, &nfeats))
    {
        fprintf(stderr, "\nAn error has been found at line 1 (HEADER).");
        fprintf(stderr, "\nThe header should contain only three integers:");
        fprintf(stderr, "\n<#samples> <#labels> <#features>\n");
        OK = 0;
    }

    /* it checks the remaining file */
    for (i = 1; i <= nsamples; i++)
    {
        result = fgets(line, LINESIZE, fp);
        if (!CheckLine(line, nlabels, nfeats, i))
        {
            fprintf(stderr, "\nAn error has been found at line %d\n", i + 1);
            OK = 0;
            break;
        }
    }
    fclose(fp);
    if (result)
        result++;

    if (OK)
        fprintf(stderr, "\nThis file is in the proper format. Enjoy.\n");

    return 1;
}
int32_t SelectTestLine (uint8_t* pY, int32_t iWidth, int32_t iHeight, int32_t iPicHeight,
                        int32_t iStride, int32_t iOffsetX, int32_t iOffsetY) {
  const int32_t kiHalfHeight	= iHeight >> 1;
  const int32_t kiMidPos		= iOffsetY + kiHalfHeight;
  int32_t TestPos			= kiMidPos;
  int32_t iOffsetAbs;
  uint8_t* pTmp;

  for (iOffsetAbs = 0; iOffsetAbs < kiHalfHeight; iOffsetAbs++) {
    TestPos = kiMidPos + iOffsetAbs;
    if (TestPos < iPicHeight) {
      pTmp = pY + TestPos * iStride + iOffsetX;
      if (CheckLine (pTmp, iWidth)) break;
    }
    TestPos = kiMidPos - iOffsetAbs;
    if (TestPos >= 0) {
      pTmp = pY + TestPos * iStride + iOffsetX;
      if (CheckLine (pTmp, iWidth)) break;
    }
  }
  if (iOffsetAbs == kiHalfHeight)
    TestPos = -1;
  return TestPos;
}
////////////////////////////////////////
// ControlLine                        //
int GameDataControl::ControlLine( void )
////////////////////////////////////////
{
    int cleared= 0;

    for( int y= 1 ; y < GAMEBOARD_HEIGHT - 1 ; y++ )
    {
        if( CheckLine( y ) )
        {
            cleared++;
            ClearLine( y );
            y--;
        }
    }
    
    return cleared;
}
Exemple #16
0
int main (int argc, char *argv[]) {
	int c;
	unsigned long hostaddr;
	FILE *cmdfile;
	char *cmdline = NULL;
	char *cmdtok = NULL;
	char *filename = NULL;
	char line[MAXLEN];
	char tmpcmd[MAXLEN];
	debug=0;verbose=0;errpause=0;skiperr=0;allocpty=0;envfl=0;
	timeout=5;
	enable_trace=0;
	tracelvl=0;
	errfile=NULL;
	envfilenm=NULL;
	appname = basename(argv[0]);
	while ((c = getopt (argc, argv, "dhpvP :c:f:t:s:e:T:")) != -1) {
		switch (c) {
			case 'c':
				cmdline = optarg;
				break;
				
			case 'd':
				debug++;
				break;
				
			case 'f':
				filename = optarg;
				break;
				
			case 'h':
				PrintUsage();
				break;
				
			case 'p':
				errpause++;
				break;
				
			case 'P':
				allocpty++;
				break;
				
			case 'e':
				envfl++;
				envfilenm = optarg;
				break;
				
			case 's':
				skiperr++;
				errfile = optarg;
				break;
				
			case 't':
				timeout = (int) strtol(optarg, (char **)NULL, 10);
				break;
				
			case 'T':
				enable_trace++;
				tracelvl = (int) strtol(optarg, (char **)NULL, 10);
				break;
				
			case 'v':
				verbose++;
				break;
				
			case '?':
				PrintUsage();
				break;
		}
	}
	
	ValidateOptions(cmdline,filename);
	
	if ((argc - optind) == 1) {
		hostaddr = GetHostInfo((char *)argv[optind]);
	} else {
        fprintf(stderr, "Hostname or IP is required\n\n");
        PrintUsage();
	}
	
	/* Get Username from effecive user id running the program */
	GetUserInfo();
	
	/* Initialize the Session */
	InitSession(hostaddr);
	
	if (cmdline != NULL) {
		RunCommand(cmdline);
	} else {
		if ((cmdfile = fopen(filename, "r")) == 0) {
			fprintf(stderr, "Could not open file %s:%s\n",
					filename ,strerror(errno));
			exit(-1);
		}
		
		strcpy(tmpcmd,"");
		while (fgets(line, sizeof(line), cmdfile) != NULL) {
			cmdtok = strdup(line);
			if (CheckLine(trim(cmdtok))) {
				sprintf(tmpcmd,"%s%s",tmpcmd,cmdtok);
			} else {
				if ( strcmp(tmpcmd,"") != 0 ) {
					sprintf(tmpcmd,"%s%s",tmpcmd,cmdtok);
					free(cmdtok);
					cmdtok = strdup(tmpcmd);
				}
				if (strlen(cmdtok) > 1 && SkipComments(cmdtok) ) {
					RunCommand(cmdtok);
				}
				strcpy(tmpcmd,"");
			}
			free(cmdtok);
		}
		if (strcmp(tmpcmd,"") != 0) {
			RunCommand(tmpcmd);
			strcpy(tmpcmd,"");
		}
	}
	CleanupSession(session,username);
	return 0;
}
RageSurface *RageSurface_Load_XPM( char * const *xpm, CString &error )
{
	int line = 0;

	int width, height, num_colors, color_length;

	CheckLine();
	if( sscanf( xpm[line++], "%i %i %i %i", &width, &height, &num_colors, &color_length ) != 4 )
	{
		error = "parse error reading specs";
		return NULL;
	}

	if( width > 2048 || height > 2048 || num_colors > 1024*16 || color_length > 4 )
	{
		error = "spec error";
		return NULL;
	}

	vector<RageSurfaceColor> colors;

	map<CString,int> name_to_color;
	for( int i = 0; i < num_colors; ++i )
	{
		CheckLine();

		/* "id c #AABBCC"; id is color_length long.  id may contain spaces. */
		CString color = xpm[line++];

		if( color_length+4 > (int) color.size() )
			continue;

		CString name;
		name = color.substr( 0, color_length );

		if( color.substr( color_length, 4 ) != " c #")
			continue;

		CString clr = color.substr( color_length+4 );
		int r, g, b;
		if( sscanf( clr, "%2x%2x%2x", &r, &g, &b ) != 3 )
			continue;
		RageSurfaceColor colorval;
		colorval.r = (uint8_t) r;
		colorval.g = (uint8_t) g;
		colorval.b = (uint8_t) b;
		colorval.a = 0xFF;

		colors.push_back( colorval );

		name_to_color[name] = colors.size()-1;
	}

	RageSurface *img;
	if( colors.size() <= 256 )
	{
		img = CreateSurface( width, height, 8, 0, 0, 0, 0 );
		memcpy( img->fmt.palette->colors, &colors[0], colors.size()*sizeof(RageSurfaceColor) );
	} else {
		img = CreateSurface( width, height, 32,
			0xFF000000, 0x00FF0000, 0x0000FF00, 0 );
	}

	for( int y = 0; y < height; ++y )
	{
		CheckLine();
		const CString row = xpm[line++];
		if( (int) row.size() != width*color_length )
		{
			error = ssprintf( "row %i is not expected length (%i != %i)", y, int(row.size()), width*color_length );
			delete img;
		    return NULL;
		}

		int8_t *p = (int8_t *) img->pixels;
		p += y * img->pitch;
		int32_t *p32 = (int32_t *) p;
		for( int x = 0; x < width; ++x )
		{
			CString color_name = row.substr( x*color_length, color_length );
			map<CString,int>::const_iterator it;
			it = name_to_color.find( color_name );
			if( it == name_to_color.end() )
			{
				error = ssprintf( "%ix%i is unknown color \"%s\"", x, y, color_name.c_str() );
				delete img;
				return NULL;
			}

			if( colors.size() <= 256 )
			{
				p[x] = (int8_t) it->second;
			} else {
				const RageSurfaceColor &color = colors[it->second];
				p32[x] = (color.r << 24) + (color.g << 16) + (color.b << 8);
			}
		}
	}

    return img;
}
Exemple #18
0
bool plug::LinkGameEraser::CheckTwoPoint(POINT first, POINT secode)
{
    plug::ChessPoint pLeft(first);
    plug::ChessPoint pRight(secode);
    POINT tempLeft = {};
    POINT tempRight = {};
    int left = 0;
    int right = 0;
    if ((first.x == secode.x) && (first.y == secode.y))
    {
        return false;
    }
    else if (buffer_[first.y][first.x] == 0 || buffer_[secode.y][secode.x] == 0)
    {
        return false;
    }
    else if (buffer_[first.y][first.x] != buffer_[secode.y][secode.x])
    {
        return false;
    }

    tempLeft = first;
    tempRight = secode;
    if (first.y == secode.y)
    {
        if ((pLeft.right_.x == pRight.p_.x) || (pLeft.left_.x == pRight.p_.x))
        {
            return true;
        }

        if (CheckLine(pLeft.right_, pRight.left_))
            return true;

        tempLeft = first;
        tempRight = secode;
        if ((pLeft.up_.y >= 0) && (pLeft.up_.y <= 10))
        {
            for (right = 0; right < pLeft.up_.y; ++right)
            {
                tempLeft.y = right;
                tempRight.y = right;
                if (CheckLine(tempLeft, pLeft.up_) &&
                    CheckLine(tempRight, pRight.up_) &&
                    CheckLine(tempLeft, tempRight))
                    return true;
            }
        }
        tempLeft = first;
        tempRight = secode;
        if (pLeft.down_.y >= 0 && (pLeft.down_.y <= 10))
        {
            for (right = pLeft.down_.y; right <= 10; ++right)
            {
                tempLeft.y = right;
                tempRight.y = right;
                if (CheckLine(tempLeft, pLeft.down_) &&
                    CheckLine(tempRight, pRight.down_) &&
                    CheckLine(tempLeft, tempRight))
                {
                    return true;
                }
            }
        }
    }
    else if (first.x == secode.x)
    {
        if ((pLeft.down_.y == pRight.p_.y) || (pLeft.up_.y == pRight.p_.y))
        {
            return true;
        }

        if (CheckLine(pLeft.down_, pRight.up_))
        {
            return true;
        }

        tempLeft = first;
        tempRight = secode;
        for (left = 0; left <= pLeft.left_.x; ++left)
        {
            tempLeft.x = left;
            tempRight.x = left;
            if (CheckLine(tempLeft, pLeft.left_) &&
                CheckLine(tempRight, pRight.left_) &&
                CheckLine(tempLeft, tempRight))
            {
                return true;
            }

            tempLeft = first;
            tempRight = secode;
            for (left = pLeft.right_.x; left <= 18; ++left)
            {
                tempLeft.x = left;
                tempRight.x = left;

                if (CheckLine(tempLeft, pLeft.right_) &&
                    CheckLine(tempRight, pRight.right_) &&
                    CheckLine(tempLeft, tempRight))
                {
                    return true;
                }
            }
        }
        if (CheckLine(pLeft.down_, pRight.up_))
            return true;
    }
    else
    {
        tempLeft = first;
        tempRight = secode;
        if (first.x > secode.x)
        {
            for (left = 0; left <= pRight.left_.x; ++left)
            {
                tempLeft.x = left;
                tempRight.x = left;
                if (CheckLine(tempLeft, pLeft.left_) &&
                    CheckLine(tempLeft, tempRight) &&
                    CheckLine(tempRight, pRight.left_))
                {
                    return true;
                }
            }

            for (left = pRight.right_.x; left <= pLeft.left_.x; ++left)
            {
                tempLeft.x = left;
                tempRight.x = left;
                if (CheckLine(pRight.right_, tempRight) &&
                    CheckLine(tempLeft, tempRight) &&
                    CheckLine(tempLeft, pLeft.left_))
                {
                    return true;
                }
            }

            for (left = pRight.right_.x; left <= 18; ++left)
            {
                tempLeft.x = left;
                tempRight.x = left;
                if (CheckLine(pLeft.right_, tempLeft) &&
                    CheckLine(pRight.right_, tempRight) &&
                    CheckLine(tempLeft, tempRight))
                {
                    return true;
                }
            }

            tempLeft.x = first.x;
            tempRight.x = secode.x;
            for (right = 0; right <= pLeft.up_.y; ++right)
            {
                tempLeft.y = right;
                tempRight.y = right;
                if (CheckLine(tempRight, tempLeft) &&
                    CheckLine(tempLeft, pLeft.up_) &&
                    CheckLine(tempRight, pRight.up_))
                {
                    return true;
                }
            }

            for (right = pLeft.down_.y; right <= pRight.up_.y; ++right)
            {
                tempRight.y = right;
                tempLeft.y = right;
                if (CheckLine(tempRight, tempLeft) &&
                    CheckLine(pLeft.down_, tempLeft) &&
                    CheckLine(tempRight, pRight.up_))
                {
                    return true;
                }
            }

            for (right = pRight.down_.y; right <= 10; ++right)
            {
                tempLeft.y = right;
                tempRight.y = right;
                if (CheckLine(tempRight, tempLeft) &&
                    CheckLine(pLeft.down_, tempLeft) &&
                    CheckLine(pRight.down_, tempRight))
                {

                    return true;
                }
            }
        }
        else
        {
            tempLeft.y = first.y;
            tempRight.y = secode.y;
            for (left = 0; left <= pLeft.left_.x; ++left)
            {
                tempLeft.x = left;
                tempRight.x = left;
                if (CheckLine(tempLeft, tempRight) &&
                    CheckLine(tempLeft, pLeft.left_) &&
                    CheckLine(tempRight, pRight.left_))
                {
                    return true;
                }
            }

            for (left = pLeft.right_.x; left < pRight.left_.x; ++left)
            {
                tempLeft.x = left;
                tempRight.x = left;
                if (CheckLine(tempLeft, tempRight) &&
                    CheckLine(pLeft.right_, tempLeft) &&
                    CheckLine(tempRight, pRight.left_))
                {
                    return true;
                }
            }

            for (left = pRight.right_.x; left <= 18; ++left)
            {
                tempLeft.x = 0;
                tempRight.x = left;
                if (CheckLine(tempLeft, tempRight) &&
                    CheckLine(pLeft.right_, tempLeft) &&
                    CheckLine(pRight.right_, tempRight))
                {
                    return true;
                }
            }

            tempLeft.x = first.x;
            tempRight.x = secode.x;
            if ((pLeft.up_.y >= 0) && (pLeft.up_.y <= 10))
            {
                for (right = 0; right <= pLeft.up_.y; ++right)
                {
                    tempLeft.y = right;
                    tempRight.y = right;
                    if (CheckLine(tempLeft, tempRight) &&
                        CheckLine(tempLeft, pLeft.up_) &&
                        CheckLine(tempRight, pRight.up_))
                    {
                        return true;
                    }
                }
            }

            tempLeft.x = first.x;
            tempRight.x = secode.x;
            if ((pLeft.down_.y <= 10) && (pRight.up_.y >= 0))
            {
                for (right = pLeft.down_.y; right <= pRight.up_.y; ++right)
                {
                    tempLeft.y = right;
                    tempRight.y = right;
                    if (CheckLine(tempLeft, tempRight) &&
                        CheckLine(pLeft.down_, tempLeft) &&
                        CheckLine(tempRight, pRight.up_))
                    {
                        return true;
                    }
                }
            }

            tempLeft.x = first.x;
            tempRight.x = secode.x;
            if (pRight.down_.y <= 10)
            {
                for (right = pRight.down_.y; right <= 10; ++right)
                {
                    tempLeft.y = right;
                    tempRight.y = right;
                    if (CheckLine(tempLeft, tempRight) &&
                        CheckLine(pLeft.down_, tempLeft) &&
                        CheckLine(pRight.down_, tempRight))
                    {
                        return true;
                    }
                }
            }
        }
    }

    return false;
}
Exemple #19
0
bool CheckChess(
	POINT a,
	POINT b
	)
{
	CChessPoint p1(a), p2(b);
	POINT  pa, pb;	//转角点
	int x, y;

	// 如果2点为同一点 则返回假
	if ((a.x == b.x) && (a.y == b.y ))  { 
		return false;
	} 
	else if ((chessdata[a.y][a.x]==0) || 
			(chessdata[b.y][b.x]==0)){ 
		return false;
	} 
	else if (chessdata[a.y][a.x] != 
			 chessdata[b.y][b.x]){ 
		return false;
	}
  
	pa = a; 
	pb = b;
	
	// 在横向一条线上 y坐标 相同
	if (a.y == b.y)  
	{     
		// 2点在y轴相邻
		if ((p1.right.x == p2.p.x) || 
			(p1.left.x == p2.p.x) ){ 
			return true;   
		}

		//检测 这条线是否有一条路径相通
        if (CheckLine(p1.right, p2.left)) {
			return true; 
		}

		//检测 上下 
		
		//y 上
		pa = a;
		pb = b;
		if ((p1.up.y >= 0) && 
			(p1.up.y <= 10)) {
			for ( y=0 ;y<=p1.up.y;y++)
			{
				pa.y=y;pb.y=y;
				if (CheckLine(pa,p1.up) && 
					CheckLine(pb,p2.up ) && 
					CheckLine(pa,pb))  { 
						return true; 
				}
			}
		}

		// y下
		pa = a; 
		pb = b;
		if ((p1.down.y >= 0) && 
			(p1.down.y <= 10) ){ 
			for ( y=p1.down.y;y<=10;y++)
			{
				pa.y=y;pb.y=y;
				if (CheckLine(pa,p1.down ) && 
					CheckLine(pb,p2.down ) && 
					CheckLine(pa,pb))  { 
						return true; 
				}                                                
			}
		}

		//检测 左右 因为 y轴相等,所以不存在左右路径
	} 
	else if (a.x==b.x){
		//x下上 相邻不
		if ((p1.down.y==p2.p.y ) || 
			(p1.up.y==p2.p.y))   { 
			return true;   
		}
		
		//检测 这条线是否有一条路径相通
		if (CheckLine(p1.down,p2.up) )  { 
			return true;    
		}
		
		//检测 上下   国为x 轴相等 所以不存在路径
		//检测 左右

		//x左
		pa=a;
		pb=b;
		for (x=0 ;x<=p1.left.x ;x++)
		{
			pa.x=x;
			pb.x=x;
			if (CheckLine(pa,p1.left) && 
				CheckLine(pb,p2.left ) && 
				CheckLine(pa,pb))  { 
				return true;  
			}
		}

		//x右
		pa = a;
		pb = b;
		for(x = p1.right.x; x <= 18; x++)
		{
			pa.x =x;
			pb.x = x;
			if (CheckLine(pa,p1.right ) && 
				CheckLine(pb,p2.right ) && 
				CheckLine(pa,pb))  { 
				return true;  
			}
		}
	} 
	else {
		pa = a;
		pb = b;
		if (a.x > b.x)  {   
			// p2点 在 左 left
			// 找x轴路径
			for (x=0;x<=p2.left.x;x++)
			{
				pa.x=x;
				pb.x=x;
				if (CheckLine(pa,p1.left) && 
					CheckLine(pa,pb) && 
					CheckLine(pb,p2.left)){
					return true; 
				}                               
			} // end for

			for (x=p2.right.x ;x<= p1.left.x;x++)
			{
				pa.x=x;
				pb.x=x;
				if (CheckLine(p2.right,pb) && 
					CheckLine(pa,pb)&& 
					CheckLine(pa,p1.left))  {
					return true; 
				}                                                
			}

			for (x=p2.right.x;x<=18;x++)
			{
				pa.x=x;
				pb.x=x;
				if (CheckLine(p1.right ,pa)&& 
					CheckLine(p2.right ,pb) && 
					CheckLine(pa,pb))  { 
					return true; 
				}
			}

			// 找y轴路径 由于是从上向下 搜索 所以p1.y>p2.y
			// 初始化坐标 y渐变
			pa.x=a.x;   
			pb.x=b.x; 
			for ( y=0 ;y<=p1.up.y; y++)    //1段
			{
				pa.y=y;
				pb.y=y;
				if (CheckLine(pb,pa) && 
					CheckLine(pa,p1.up) && 
					CheckLine(pb,p2.up)){ 
					return true;
				}                                                            
			}

			for (y=p1.down.y ;y<=p2.up.y;y++)//2段
			{
				pa.y=y;
				pb.y=y;
				if (CheckLine(pb,pa)&& 
					CheckLine(p1.down,pa) && 
					CheckLine(pb,p2.up))   {
					return true;
				}
			}

			for (y=p2.down.y ;y<=10 ;y++) //3段
			{
				pa.y=y;
				pb.y=y;
				if (CheckLine(pb,pa) && 
					CheckLine(p1.down,pa) && 
					CheckLine(p2.down,pb))   { 
					return true;   
				}
			}
		} 
		else{
			// p2点  在 右 right a.x>b.x
			// 初始化坐标
			pa.y=a.y;   
			pb.y=b.y; 
			for (x=0 ;x<= p1.left.x ;x++);
			{
				pa.x=x;
				pb.x=x;
				if (CheckLine(pa,pb)&& 
					CheckLine(pa,p1.left)&& 
					CheckLine(pb,p2.left))  {
					return true;
				}                                                       
			}

			for (x=p1.right.x ;x<=p2.left.x;x++)
			{
				pa.x=x;
				pb.x=x;
				if (CheckLine(pa,pb)&& 
					CheckLine(p1.right,pa)&& 
					CheckLine(pb,p2.left))  { 
					return true;
				}
			}

			for (x=p2.right.x ;x<=18;x++)
			{
				pa.x=0;pb.x=x;
				if (CheckLine(pa,pb) && 
					CheckLine(p1.right,pa)&& 
					CheckLine(p2.right,pb)) {
						return true; 
				}                                                               
			}

			// y轴渐变
			// 初始化坐标
			pa.x =a.x;   
			pb.x =b.x ; 
			if ((p1.up.y>=0) && 
				(p1.up.y<=10))
			{
				for (y=0 ;y<=p1.up.y ;y++)    //1段
				{
					pa.y=y;
					pb.y=y;
					if (CheckLine(pa,pb)&& 
						CheckLine(pa,p1.up) && 
						CheckLine(pb,p2.up))  { 
						return true; 
					}                                                                           
				}
			}

			//初始化坐标
			pa.x =a.x;   
			pb.x =b.x ; 
			if ((p1.down.y<=10) 
				&& (p2.up.y>=0)) 
			{
				for (y=p1.down.y ;y<=p2.up.y;y++)  //2段
				{
					pa.y=y;
					pb.y=y;
					if (CheckLine(pa,pb)&& 
						CheckLine(p1.down,pa) && 
						CheckLine(pb,p2.up))  { 
						return true;
					}                                                                          
				}
			}
	    
			pa.x =a.x;   
			pb.x =b.x ; //初始化坐标
			if (p2.down.y <=10) 
			{
				for ( y=p2.down.y;y<=10;y++)           //3段
				{
					pa.y=y;
					pb.y=y;
					if (CheckLine(pa,pb) && 
						CheckLine(p1.down,pa)&& 
						CheckLine(p2.down ,pb))  { 
						return true; 
					}
				}                                                                          
			}
		}
	}
	return false;
}
Exemple #20
0
///
//	TriCubeIntersection()
//
//		Triangle t is compared with a unit cube,  
//		centered on the origin.                    
//		It returns INSIDE (0) or OUTSIDE(1) if t   
//		Intersects or does not intersect the cube. 
static
int TriCubeIntersection(const TRI& t)
{
	int v1_test,v2_test,v3_test;
	number d;
	vector3 vect12,vect13,norm;
	vector3 hitpp,hitpn,hitnp,hitnn;

	///
	//	First compare all three vertexes with all six face-planes 
	//	If any vertex is inside the cube, return immediately!     
	//
	if ((v1_test = FacePlane(t.m_P[0])) == INSIDE) return(INSIDE);
	if ((v2_test = FacePlane(t.m_P[1])) == INSIDE) return(INSIDE);
	if ((v3_test = FacePlane(t.m_P[2])) == INSIDE) return(INSIDE);

	///
	//	If all three vertexes were outside of one or more face-planes,
	//	return immediately with a trivial rejection!              
	//
	if ((v1_test & v2_test & v3_test) != 0) return(OUTSIDE);

	///
	//	Now do the same trivial rejection test for the 12 edge planes 
	//
	v1_test |= Bevel2d(t.m_P[0]) << 8; 
	v2_test |= Bevel2d(t.m_P[1]) << 8; 
	v3_test |= Bevel2d(t.m_P[2]) << 8;
	if ((v1_test & v2_test & v3_test) != 0) return(OUTSIDE);  

	///
	//	Now do the same trivial rejection test for the 8 corner planes
	//
	v1_test |= Bevel3d(t.m_P[0]) << 24; 
	v2_test |= Bevel3d(t.m_P[1]) << 24; 
	v3_test |= Bevel3d(t.m_P[2]) << 24; 
	if ((v1_test & v2_test & v3_test) != 0) return(OUTSIDE);   

	///
	//	If vertex 1 and 2, as a pair, cannot be trivially rejected 
	//  by the above tests, then see if the v1-->v2 triangle edge  
	//	intersects the cube.  Do the same for v1-->v3 and v2-->v3. 
	//  Pass to the intersection algorithm the "OR" of the outcode 
	//  bits, so that only those cube faces which are spanned by   
	//  each triangle edge need be tested.                         
	//
	if ((v1_test & v2_test) == 0)
		if (CheckLine(t.m_P[0],t.m_P[1],v1_test|v2_test) == INSIDE) return(INSIDE);
	if ((v1_test & v3_test) == 0)
		if (CheckLine(t.m_P[0],t.m_P[2],v1_test|v3_test) == INSIDE) return(INSIDE);
	if ((v2_test & v3_test) == 0)
		if (CheckLine(t.m_P[1],t.m_P[2],v2_test|v3_test) == INSIDE) return(INSIDE);

	///
	//	By now, we know that the triangle is not off to any side,     
	//	 and that its sides do not penetrate the cube.  We must now   
	//	 test for the cube intersecting the interior of the triangle. 
	//	 We do this by looking for intersections between the cube     
	//	 diagonals and the triangle...first finding the intersection  
	//	 of the four diagonals with the plane of the triangle, and    
	//	 then if that intersection is inside the cube, pursuing       
	//	 whether the intersection point is inside the triangle itself. 

	//	 To find plane of the triangle, first perform crossproduct on  
	//	 two triangle side vectors to compute the normal vector.                                       
	SUB(t.m_P[0],t.m_P[1],vect12);
	SUB(t.m_P[0],t.m_P[2],vect13);
	CROSS(vect12,vect13,norm)

	///
	//	 The normal vector "norm" X,Y,Z components are the coefficients 
	//		 of the triangles AX + BY + CZ + D = 0 plane equation.  If we   
	//	 solve the plane equation for X=Y=Z (a diagonal), we get        
	//	 -D/(A+B+C) as a metric of the distance from cube center to the 
	//	 diagonal/plane intersection.  If this is between -0.5 and 0.5, 
	//	 the intersection is inside the cube.  If so, we continue by    
	//	 doing a point/triangle intersection.                           
	//	 Do this for all four diagonals.                                
	d = norm.x() * t.m_P[0].x() + norm.y() * t.m_P[0].y() + norm.z() * t.m_P[0].z();
	hitpp.x() = hitpp.y() = hitpp.z() = d / (norm.x() + norm.y() + norm.z());
	if (fabs(hitpp.x()) <= 0.5)
		if (PointTriangleIntersection(hitpp,t) == INSIDE) return(INSIDE);
	hitpn.z() = -(hitpn.x() = hitpn.y() = d / (norm.x() + norm.y() - norm.z()));
	if (fabs(hitpn.x()) <= 0.5)
		if (PointTriangleIntersection(hitpn,t) == INSIDE) return(INSIDE);
	hitnp.y() = -(hitnp.x() = hitnp.z() = d / (norm.x() - norm.y() + norm.z()));
	if (fabs(hitnp.x()) <= 0.5)
		if (PointTriangleIntersection(hitnp,t) == INSIDE) return(INSIDE);
	hitnn.y() = hitnn.z() = -(hitnn.x() = d / (norm.x() - norm.y() - norm.z()));
	if (fabs(hitnn.x()) <= 0.5)
		if (PointTriangleIntersection(hitnn,t) == INSIDE) return(INSIDE);

	///
	//	No edge touched the cube; no cube diagonal touched the triangle. 
	//  We're done...there was no intersection.                          
	//
	return(OUTSIDE);
}
Exemple #21
0
int Read_a_Email(unsigned int Num)
{
    char        *p = NULL, *fn, *charset = NULL, *charsin = NULL;
    lastread    LR;
    unsigned int	mycrc;

    LastNum = Num;
    iLineCount = 7;
    WhosDoingWhat(READ_POST, NULL);

    /*
     * The area data is already set, so we can do the next things
     */
    if (EmailBase.Total == 0) {
	Enter(1);
	/* There are no messages in this area */
	pout(WHITE, BLACK, (char *) Language(205));
	Enter(2);
	sleep(3);
	return FALSE;
    }

    if (!Msg_Open(sMailpath)) {
	WriteError("Error open JAM base %s", sMailpath);
	return FALSE;
    }

    if (!Msg_ReadHeader(Num)) {
	Enter(1);
	pout(WHITE, BLACK, (char *)Language(77));
	Enter(2);
	Msg_Close();
	sleep(3);
	return FALSE;
    }

    /*
     * Fill Quote file in case the user wants to reply. Note that line
     * wrapping is set lower then normal message read, to create room
     * for the Quote> strings at the start of each line.
     */
    fn = calloc(PATH_MAX, sizeof(char));
    snprintf(fn, PATH_MAX, "%s/%s/.quote", CFG.bbs_usersdir, exitinfo.Name);
    if ((qf = fopen(fn, "w")) != NULL) {
	if (Msg_Read(Num, 75)) {
	    if ((p = (char *)MsgText_First()) != NULL)
		do {
		    if (p[0] == '\001') {
			/*
			 * Check CHRS kludge
			 */
			if (strncmp(p, "\001CHRS: ", 7) == 0) {
			    charset = xstrcpy(p + 7);
			}
			/*
			 * While doing this, store the original Message-id in case
			 * a reply will be made.
			 */
			if (strncasecmp(p, "\001Message-id: ", 13) == 0) {
			    snprintf(Msg.Msgid, sizeof(Msg.Msgid), "%s", p+13);
			    Syslog('m', "Stored Msgid \"%s\"", Msg.Msgid);
			}
			if (Kludges) {
			    p[0] = 'a';
			    fprintf(qf, "^%s\n", p);
			}
		    } else
			fprintf(qf, "%s\n", p);
		} while ((p = (char *)MsgText_Next()) != NULL);
	}
	fclose(qf);
    } else {
	WriteError("$Can't open %s", p);
    }
    free(fn);

    if (charset == NULL) {
	charsin = xstrcpy((char *)"CP437");
    } else {
    	charsin = xstrcpy(get_ic_ftn(find_ftn_charset(charset)));
    }

    /*
     * Setup character translation
     */
    chartran_init(charsin, get_ic_ftn(exitinfo.Charset), 'b');

    ShowEmailHdr();

    /*
     * Show message text
     */
    colour(CFG.TextColourF, CFG.TextColourB);
    if (Msg_Read(Num, 79)) {
	if ((p = (char *)MsgText_First()) != NULL) {
	    do {
		if (p[0] == '\001') {
		    if (Kludges) {
			colour(LIGHTGRAY, BLACK);
			if (p[0] == '\001')
			    p[0] = 'a';
			PUTSTR(chartran(p));
			Enter(1);
			if (CheckLine(CFG.TextColourF, CFG.TextColourB, TRUE))
			    break;
		    }
		} else {
		    colour(CFG.TextColourF, CFG.TextColourB);
		    if (strchr(p, '>') != NULL)
			if ((strlen(p) - strlen(strchr(p, '>'))) < 10)
			    colour(CFG.HiliteF, CFG.HiliteB);
		    PUTSTR(chartran(p));
		    Enter(1);
		    if (CheckLine(CFG.TextColourF, CFG.TextColourB, TRUE))
			break;
		}
	    } while ((p = (char *)MsgText_Next()) != NULL);
	}
    }

    if (charset)
    	free(charset);
    if (charsin)
    	free(charsin);
    chartran_close();

    /*
     * Set the Received status on this message.
     */
    if (!Msg.Received) {
	Syslog('m', "Marking message received");
	Msg.Received = TRUE;
	Msg.Read = time(NULL) - (gmt_offset((time_t)0) * 60);
	if (Msg_Lock(30L)) {
	    Msg_WriteHeader(Num);
	    Msg_UnLock();
	}
    }

    /*
     * Update lastread pointer.
     */
    p = xstrcpy(exitinfo.sUserName);
    mycrc = StringCRC32(tl(p));
    free(p);
    if (Msg_Lock(30L)) {
        LR.UserID = grecno;
	LR.UserCRC = mycrc;
        if (Msg_GetLastRead(&LR) == TRUE) {
            LR.LastReadMsg = Num;
            if (Num > LR.HighReadMsg)
                LR.HighReadMsg = Num;
            if (LR.HighReadMsg > EmailBase.Highest)
                LR.HighReadMsg = EmailBase.Highest;
            LR.UserCRC = mycrc;
	    if (!Msg_SetLastRead(LR))
                WriteError("Error update lastread");
	} else {
            /*
             * Append new lastread pointer
             */
            LR.UserCRC = mycrc;
            LR.UserID  = grecno;
            LR.LastReadMsg = Num;
            LR.HighReadMsg = Num;
            if (!Msg_NewLastRead(LR))
                WriteError("Can't append lastread");
        }
        Msg_UnLock();
    }

    Msg_Close();
    return TRUE;
}