コード例 #1
0
ファイル: sudoku-solver.cpp プロジェクト: elsucai/LC
    void solveSudoku(vector<vector<char> > &board) {
	
		// false means vacancy
		vector<vector<bool> > rows(9, vector<bool>(10, false));
		vector<vector<bool> > cols(9, vector<bool>(10, false));
		vector<vector<bool> > squares(9, vector<bool>(10, false));
		vector<int> empty;
		unordered_map<int, int> hm;

		int i, j, si, sj, index;
		char c;
		for(i = 0, index = 0; i < 9; i++){
			for(int j = 0; j < 9; j++){
				c = board[i][j];
				if(c == '.'){
					empty.push_back(i*9+j);
					hm[i*9+j] = index;
					index++;
				}
				else{
					rows[i][c-'0'] = true;
					cols[j][c-'0'] = true;
					si = i/3;
					sj = j/3;
					squares[si*3+sj][c-'0'] = true;
				}
			}
		}

		if(empty.empty())
			return;
		helper(board, rows, cols, squares, empty, hm, empty[0]);
    }
int main() 
{ 
    int i, j, cnt; 
    while(scanf("%d", &n) != EOF && n)
    {
		for(i = 0;i < PRIME;i++) hash[i].next = -1;
		hashl = PRIME;
		int x1, y1, x2, y2;
		for (i = 0; i < n; i++){
			scanf("%d%d", &p[i].x, &p[i].y); 
			Hash((p[i].x + 100000) * 100000 + p[i].y + 100000);
		}   
		cnt = 0; 
		for (i = 0; i < n; i++){ 
			for (j = i + 1; j < n; j++) 
			{ 
				point a, b; 
				if(squares(p[i], p[j], a, b) == 0) continue; 
				if(Hash2((a.x + 100000) * 100000 + a.y + 100000) == 0) continue;
				if(Hash2((b.x + 100000) * 100000 + b.y + 100000) == 0) continue;
				cnt++; 
			} 
		}
		printf("%d\n", cnt / 2); 
	}
    return 0; 
} 
コード例 #3
0
ファイル: SAMER08F.c プロジェクト: feliposz/spoj-solutions
int squares(int n)
{
    if (n == 0)
        return 0;
    else
        return n*n + squares(n-1);
}
コード例 #4
0
ファイル: ii.c プロジェクト: Awia00/BPRD-Projects
void main(int n) {
    int arr[100];
    squares(n, arr);
    int x;
    int *sum;
    sum = &x;
    *sum = 0;
    arrsum(n, arr, sum);
}
コード例 #5
0
int main()
{
	
	cout << "The chessboard starts with one grain of rice on the first\n"
		<< "square, two grains on the second, four on the third, doubling\n"
		<< "the amount of rice on each square." << endl << endl;

	cout << "A thousand grains of rice are on " << squares(1000)
		<< " squares." << endl;
	cout << "A million grains of rice are on " << squares(1000000)
		<< " squares." << endl;
	cout << "A billion grains of rice are on " << squares(1000000000)
		<< " squares." << endl;
	cout << "I can barely imagine how much rice would be on the whole\n"
		<< "chessboard..." << endl;

	return 0;
}
コード例 #6
0
void display(void)
{
  glClear( GL_COLOR_BUFFER_BIT);

  squares(-1.6, 5.0, 1.6, 5.0, 1.0); //call he recursive function

  printf("DONE\n");
  glFlush();
}
コード例 #7
0
void main(int n) {
	int arr[20];
	
	squares(n, arr);
	
	int sum;
	arrsum(n, arr, &sum);
	
	print sum;
	println;
}
コード例 #8
0
ファイル: SAMER08F.c プロジェクト: feliposz/spoj-solutions
int main()
{
    int n;
    while (1) {
        scanf("%d", &n);
        if (n == 0)
            break;
        printf("%d\n", squares(n));
    }
    return 0;
}
コード例 #9
0
ファイル: main.c プロジェクト: bsuir250502/sudoku_prilutskiy
int checkCells(int **cells)
{
    if (rows(cells) == 0) {
        if (coloumns(cells) == 0) {
            if (squares(cells) == 0)
                return 0;
            else
                return 1;
        }
        return 1;
    }
    return 1;
}
コード例 #10
0
int main(int argc, char* argv[]){

    int n;
    while (1){
        scanf("%d",&n);
        if (n==0){
            break;
        }
        printf("%d\n",squares(n) );
    }

    //Worked!  Just some simple C code! 
    return 0;
}
コード例 #11
0
//return how many numbers are square number
i64 squares(int level, int max_level, i64 product, int prime_pos){
    if(level >  max_level) {
        return  0;
    }
    i64 num = 0;
    int max_prime = limit/product;
    for(unsigned int i = prime_pos; i < primes.size(); ++i){
        if(primes[i] > max_prime) break;
        i64 p1 = product * primes[i];
        num += limit2/(p1*p1);
        num -= squares(level+1, max_level, p1, i+1);
    }
    return num;
}
コード例 #12
0
ファイル: stream1.cpp プロジェクト: bingmann/stxxl
int main()
{
    {
        counter_object counter;

        while (!counter.empty())
        {
            std::cout << *counter << " ";
            ++counter;
        }
        std::cout << std::endl;
    }

    {
        for (counter_object cnt; !cnt.empty(); ++cnt)
        {
            std::cout << *cnt << " ";
        }
        std::cout << std::endl;
    }

    {
        counter_object counter;
        squaring_object<counter_object> squares(counter);

        while (!squares.empty())
        {
            std::cout << *squares << " ";
            ++squares;
        }
        std::cout << std::endl;
    }

    {
        std::vector<int> intvector;
        // (fill intvector)

        // define stream class iterating over an integer vector
        using intstream_type = stxxl::stream::iterator2stream<std::vector<int>::const_iterator>;

        // instantiate the stream object, iterate from begin to end of intvector.
        intstream_type intstream(intvector.begin(), intvector.end());

        // plug in squaring object after vector iterator stream.
        squaring_object<intstream_type> squares(intstream);
    }

    {
        stxxl::vector<int> intvector;
        // (fill intvector)

        // define stream class iterating over an integer vector
        using intstream_type = stxxl::stream::vector_iterator2stream<stxxl::vector<int>::const_iterator>;

        // instantiate the stream object, iterate from begin to end of intvector.
        intstream_type intstream(intvector.begin(), intvector.end());

        // plug in squaring object after vector iterator stream.
        squaring_object<intstream_type> squares(intstream);
    }

    {
        // construct the squared counter stream
        counter_object counter;
        squaring_object<counter_object> squares(counter);

        // allocate vector of 100 integers
        std::vector<int> intvector(100);

        // materialize 100 integers from stream and put into vector
        stxxl::stream::materialize(squares, intvector.begin(), intvector.end());
    }

    {
        // construct the squared counter stream
        counter_object counter;
        squaring_object<counter_object> squares(counter);

        // allocate STXXL vector of 100 integers
        stxxl::vector<int> intvector(100);

        // materialize 100 integers from stream and put into STXXL vector
        stxxl::stream::materialize(squares, intvector.begin(), intvector.end());
    }

    {
        static const int ram_use = 10 * 1024 * 1024; // amount of memory to use in runs creation

        counter_object counter;                      // the counter stream from first examples

        // define a runs sorter for the counter stream which order by CompareMod10 object.
        using rc_counter_type = stxxl::stream::runs_creator<counter_object, CompareMod10>;

        // instance of CompareMod10 comparator class
        CompareMod10 comparemod10;

        // instance of runs_creator which reads the counter stream.
        rc_counter_type rc_counter(counter, comparemod10, ram_use);

        // define a runs merger for the sorted runs from rc_counter.
        using rm_counter_type = stxxl::stream::runs_merger<rc_counter_type::sorted_runs_type, CompareMod10>;

        // instance of runs_merger which merges sorted runs from rc_counter.
        rm_counter_type rm_counter(rc_counter.result(), comparemod10, ram_use);

        // read sorted stream: runs_merger also conforms to the stream interface.
        while (!rm_counter.empty())
        {
            std::cout << *rm_counter << " ";
            ++rm_counter;
        }
        std::cout << std::endl;
    }

    {
        static const int ram_use = 10 * 1024 * 1024;   // amount of memory to use in runs creation

        // define a runs sorter which accepts imperative push()s and orders by CompareMod10 object.
        using rc_counter_type = stxxl::stream::runs_creator<stxxl::stream::use_push<int>, CompareMod10>;

        // instance of CompareMod10 comparator class.
        CompareMod10 comparemod10;

        // instance of runs_creator which waits for input.
        rc_counter_type rc_counter(comparemod10, ram_use);

        // write sequence of integers into runs
        for (int i = 1; i <= 1000; ++i)
            rc_counter.push(i);

        // define a runs merger for the sorted runs from rc_counter.
        using rm_counter_type = stxxl::stream::runs_merger<rc_counter_type::sorted_runs_type, CompareMod10>;

        // instance of runs_merger which merges sorted runs from rc_counter.
        rm_counter_type rm_counter(rc_counter.result(), comparemod10, ram_use);

        // read sorted stream: runs_merger also conforms to the stream interface.
        while (!rm_counter.empty())
        {
            std::cout << *rm_counter << " ";
            ++rm_counter;
        }
        std::cout << std::endl;
    }

    {
        static const int ram_use = 10 * 1024 * 1024;   // amount of memory to use in runs creation

        // define a runs sorter which accepts imperative push()s and orders by CompareMod10 object.
        using sr_counter_type = stxxl::sorter<int, CompareMod10>;

        // instance of CompareMod10 comparator class.
        CompareMod10 comparemod10;

        // instance of sorter which waits for input.
        sr_counter_type sr_counter(comparemod10, ram_use);

        // write sequence of integers into sorter, which creates sorted runs
        for (int i = 1; i <= 1000; ++i)
            sr_counter.push(i);

        // signal sorter that the input stream is finished and switch to output mode.
        sr_counter.sort();

        // read sorted stream: sorter also conforms to the stream interface.
        while (!sr_counter.empty())
        {
            std::cout << *sr_counter << " ";
            ++sr_counter;
        }
        std::cout << std::endl;
    }
}
コード例 #13
0
void squares(float topLeftx,  float topLefty,   //top left corner
			 float topRightx, float topRighty,  //top right corner
			 float n)							//
{
	//1st point						top left corner
	float Q1x = topLeftx;
	float Q1y = topLefty;

	//2nd point						top right corner
	float Q2x = topRightx;
	float Q2y = topRighty;

	//3rd point						bottom right corner
	float Q3x = Q2x - (Q1y - Q2y);
	float Q3y = Q2y + (Q1x - Q2x);

	//4th point						bottom left corner
	float Q4x = (Q1x-Q2x) + Q3x;
	float Q4y = (Q1y-Q2y) + Q3y;

	//display filled square
	glBegin(GL_POLYGON);
	glColor3f(n*n*n*n*n-0.3, n*n*n*n-0.3, n*n*n-0.3);
	glVertex3f(Q1x, Q1y, 0.0);
	glVertex3f(Q2x, Q2y, 0.0);
	glVertex3f(Q3x, Q3y, 0.0);
	glVertex3f(Q4x, Q4y, 0.0);
	glEnd();

	//display square outline
	glColor3f(n, n, n);
	glBegin(GL_LINES);
	glVertex3f(Q1x, Q1y, 0.0);
	glVertex3f(Q2x, Q2y, 0.0);
	glVertex3f(Q2x, Q2y, 0.0);
	glVertex3f(Q3x, Q3y, 0.0);
	glVertex3f(Q3x, Q3y, 0.0);
	glVertex3f(Q4x, Q4y, 0.0);
	glVertex3f(Q4x, Q4y, 0.0);
	glVertex3f(Q1x, Q1y, 0.0);
	glEnd();


	//calculate begining of next square
	float ACx = (Q3x - Q1x)/2;	//half of the diagonal
	float ACy = (Q3y - Q1y)/2;
	float newx = ACx + Q4x;		// point of iscoceles right triangle
	float newy = ACy + Q4y;		// off of the bottom of the square


	//length of a side of the square
	float dist = sqrt(((Q1x-Q2x)*(Q1x-Q2x)) + ((Q1y-Q2y)*(Q1y-Q2y)));

				// 1/700 = x/20
				//20/700 = 1 px?
	if( dist > (20.0/WINDOW_SIZE)) { //if the square is larger than 1 pixel
		squares(Q4x, Q4y, newx, newy, n-0.1); //left recursion
		squares(newx, newy, Q3x, Q3y, n-0.1); //right recursion
	}


}
コード例 #14
0
ファイル: Board.cpp プロジェクト: Mohammedbie/TIM-Engine
void Board::Get_Possible_Moves_By_Piece_Type(Possible_Moves* Moves,pieces pc) const
{
    U64 And_Result;

    //If the side with this piece under check , DO NOTHING , in MakeMove we will check the king is still under check.
    if(GET_PIECE_COLOUR(pc) == WHITE && Is_Square_Attacked(KingSquare[WHITE],BLACK));
    else if(GET_PIECE_COLOUR(pc) == BLACK && Is_Square_Attacked(KingSquare[BLACK],WHITE));

    //White Pawn moves
    else if(pc == wP)
    {

        for(unsigned sq=0;sq<64;++sq)
        {
            if(Piece_Type_By_Square[sq] == wP)
            {
                //Direct Captures
                And_Result = White_Pawn_Direct_Attacks[sq] & Black_Pieces;


                if(And_Result != 0)
                 {
                     std::vector<unsigned int> TO_sqs;
                     Get_SetBits_Indecies(TO_sqs,And_Result);

                     for(unsigned i=0;i<TO_sqs.size();++i)
                     {
                         //Promotion Moves
                         if(GET_RANK_FROM_SQUARE(sq) == Rank_7)
                         {
                             Set_Move_Info((Moves->moves)+(Moves->Count++),sq,TO_sqs[i],wN,Piece_Type_By_Square[TO_sqs[i]],0,0,Game_Phase,false,Side_To_Move,false);
                             Set_Move_Info((Moves->moves)+(Moves->Count++),sq,TO_sqs[i],wB,Piece_Type_By_Square[TO_sqs[i]],0,0,Game_Phase,false,Side_To_Move,false);
                             Set_Move_Info((Moves->moves)+(Moves->Count++),sq,TO_sqs[i],wR,Piece_Type_By_Square[TO_sqs[i]],0,0,Game_Phase,false,Side_To_Move,false);
                             Set_Move_Info((Moves->moves)+(Moves->Count),sq,TO_sqs[i],wQ,Piece_Type_By_Square[TO_sqs[i]],0,0,Game_Phase,false,Side_To_Move,false);

                         }

                         else
                         Set_Move_Info((Moves->moves)+(Moves->Count),sq,TO_sqs[i],EMPTY,Piece_Type_By_Square[TO_sqs[i]],0,0,Game_Phase,false,Side_To_Move,false);

                         Moves->Count++;

                     }
                 }

                 //EnPassent Capture
                 And_Result = (U64(1)<<Enpassent) & White_Pawn_Direct_Attacks[sq];
                 if(GET_RANK_FROM_SQUARE(sq) == Rank_5 && And_Result!= 0)
                 {
                     Set_Move_Info((Moves->moves)+(Moves->Count),sq,Enpassent,EMPTY,bP,0,0,Game_Phase,true,Side_To_Move,false);
                     Moves->Count++;
                 }

                 //Quiet Moves
                 if(Piece_Type_By_Square[sq+8] == EMPTY)
                 {
                     //Pawn Start
                     if(GET_RANK_FROM_SQUARE(sq) == Rank_2  && Piece_Type_By_Square[sq+16] == EMPTY )
                     {
                         Set_Move_Info((Moves->moves)+(Moves->Count),sq,sq+16,EMPTY,EMPTY,0,0,Game_Phase,false,Side_To_Move,true);
                         Moves->Count++;
                     }


                         Set_Move_Info((Moves->moves)+(Moves->Count),sq,sq+8,EMPTY,EMPTY,0,0,Game_Phase,false,Side_To_Move,false);
                         Moves->Count++;
                 }



            }
        }
    }

    //Black Pawn moves
    else if(pc == bP)
    {
        for(unsigned sq=0;sq<64;++sq)
        {
            if(Piece_Type_By_Square[sq] == bP)
            {
                //Direct Captures
                U64 And_Result = Black_Pawn_Direct_Attacks[sq] & White_Pieces;


                if(And_Result != 0)
                 {
                     std::vector<unsigned int> TO_sqs;
                     Get_SetBits_Indecies(TO_sqs,And_Result);

                     for(unsigned i=0;i<TO_sqs.size();++i)
                     {
                         if(GET_RANK_FROM_SQUARE(sq) == Rank_2)
                         {
                             //Promotion Moves
                             Set_Move_Info((Moves->moves)+(Moves->Count++),sq,TO_sqs[i],bN,Piece_Type_By_Square[TO_sqs[i]],0,0,Game_Phase,false,Side_To_Move,false);
                             Set_Move_Info((Moves->moves)+(Moves->Count++),sq,TO_sqs[i],bB,Piece_Type_By_Square[TO_sqs[i]],0,0,Game_Phase,false,Side_To_Move,false);
                             Set_Move_Info((Moves->moves)+(Moves->Count++),sq,TO_sqs[i],bR,Piece_Type_By_Square[TO_sqs[i]],0,0,Game_Phase,false,Side_To_Move,false);
                             Set_Move_Info((Moves->moves)+(Moves->Count),sq,TO_sqs[i],bQ,Piece_Type_By_Square[TO_sqs[i]],0,0,Game_Phase,false,Side_To_Move,false);

                         }

                         else
                         Set_Move_Info((Moves->moves)+(Moves->Count),sq,TO_sqs[i],EMPTY,Piece_Type_By_Square[TO_sqs[i]],0,0,Game_Phase,false,Side_To_Move,false);

                         Moves->Count++;

                     }
                 }

                 //EnPassent Capture
                 And_Result = (U64(1)<<Enpassent) & Black_Pawn_Direct_Attacks[sq];
                 if(GET_RANK_FROM_SQUARE(sq) == Rank_4 && And_Result!= 0)
                 {
                     Set_Move_Info((Moves->moves)+(Moves->Count),sq,Enpassent,EMPTY,wP,0,0,Game_Phase,true,Side_To_Move,false);
                     Moves->Count++;
                 }

                 //Quiet Moves
                 if(Piece_Type_By_Square[sq-8] == EMPTY)
                 {
                     //Pawn Start
                     if(GET_RANK_FROM_SQUARE(sq) == Rank_7  && Piece_Type_By_Square[sq-16] == EMPTY )
                     {
                         Set_Move_Info((Moves->moves)+(Moves->Count),sq,sq-16,EMPTY,EMPTY,0,0,Game_Phase,false,Side_To_Move,true);
                         Moves->Count++;
                     }


                         Set_Move_Info((Moves->moves)+(Moves->Count),sq,sq-8,EMPTY,EMPTY,0,0,Game_Phase,false,Side_To_Move,false);
                         Moves->Count++;
                 }



            }
        }
    }

    //Knights moves
    else if(pc == wN || pc == bN)
    {
        for(unsigned sq=0;sq<64;++sq)
        {
            if(Piece_Type_By_Square[sq] == pc)
            {
                if(pc == wN)
                And_Result = (Knight_Moves[sq] | White_Pieces) ^ White_Pieces;
                else
                And_Result = (Knight_Moves[sq] | Black_Pieces) ^ Black_Pieces;

                if(And_Result != 0)
                {
                    std::vector<unsigned int> TO_sqs;
                    Get_SetBits_Indecies(TO_sqs,And_Result);

                    for(unsigned i=0;i<TO_sqs.size();++i)
                    {
                        Set_Move_Info((Moves->moves)+(Moves->Count),sq,TO_sqs[i],EMPTY,Piece_Type_By_Square[TO_sqs[i]],0,0,Game_Phase,false,Side_To_Move,false);
                        Moves->Count++;
                    }

                }
            }
        }

    }

    //Bishops moves
    else if(pc == wB || pc == bB)
    {
        for(squares sq=a1;sq<OFF_BOARD;sq = squares(sq+b1))
        {
            if(Piece_Type_By_Square[sq] == pc)
            {
                And_Result = Bishop_Moves[sq] & All_Pieces;

                if(And_Result != 0)
                {
                    std::vector<unsigned int> TO_sqs;
                    std::vector<unsigned int> Blockers_sqs;
                    Get_SetBits_Indecies(Blockers_sqs,And_Result);

                    U64 Slider_Moves = FULL_BOARD;
                    for(unsigned i=0;i<Blockers_sqs.size();++i)
                    {
                        Slider_Moves = Get_Slider_Moves_Blocked_AtSq(pc,Piece_Type_By_Square[Blockers_sqs[i]],sq,squares(Blockers_sqs[i]),Slider_Moves);
                    }

                    Get_SetBits_Indecies(TO_sqs,Slider_Moves);

                    for(unsigned i=0;i<TO_sqs.size();++i)
                    {
                        Set_Move_Info((Moves->moves)+(Moves->Count),sq,TO_sqs[i],EMPTY,Piece_Type_By_Square[TO_sqs[i]],0,0,Game_Phase,false,Side_To_Move,false);
                        Moves->Count++;
                    }

                }
            }
        }
    }

    else if(pc == wR || pc == bR)
    {
        for(squares sq=a1;sq<OFF_BOARD;sq = squares(sq+b1))
        {
            if(Piece_Type_By_Square[sq] == pc)
            {
                And_Result = Rook_Moves[sq] & All_Pieces;

                if(And_Result != 0)
                {
                    std::vector<unsigned int> TO_sqs;
                    std::vector<unsigned int> Blockers_sqs;
                    Get_SetBits_Indecies(Blockers_sqs,And_Result);

                    U64 Slider_Moves = FULL_BOARD;
                    for(unsigned i=0;i<Blockers_sqs.size();++i)
                    {
                        Slider_Moves = Get_Slider_Moves_Blocked_AtSq(pc,Piece_Type_By_Square[Blockers_sqs[i]],sq,squares(Blockers_sqs[i]),Slider_Moves);
                    }

                    Get_SetBits_Indecies(TO_sqs,Slider_Moves);

                    for(unsigned i=0;i<TO_sqs.size();++i)
                    {
                        Set_Move_Info((Moves->moves)+(Moves->Count),sq,TO_sqs[i],EMPTY,Piece_Type_By_Square[TO_sqs[i]],0,0,Game_Phase,false,Side_To_Move,false);
                        Moves->Count++;
                    }

                }
            }
        }
    }

    else if(pc == wQ || pc == bQ)
    {
        for(squares sq=a1;sq<OFF_BOARD;sq = squares(sq+b1))
        {
            if(Piece_Type_By_Square[sq] == pc)
            {
                And_Result = Queen_Moves[sq] & All_Pieces;

                if(And_Result != 0)
                {
                    std::vector<unsigned int> TO_sqs;
                    std::vector<unsigned int> Blockers_sqs;
                    Get_SetBits_Indecies(Blockers_sqs,And_Result);

                    U64 Slider_Moves = FULL_BOARD;
                    for(unsigned i=0;i<Blockers_sqs.size();++i)
                    {
                        Slider_Moves = Get_Slider_Moves_Blocked_AtSq(pc,Piece_Type_By_Square[Blockers_sqs[i]],sq,squares(Blockers_sqs[i]),Slider_Moves);
                    }

                    Get_SetBits_Indecies(TO_sqs,Slider_Moves);

                    for(unsigned i=0;i<TO_sqs.size();++i)
                    {
                        Set_Move_Info((Moves->moves)+(Moves->Count),sq,TO_sqs[i],EMPTY,Piece_Type_By_Square[TO_sqs[i]],0,0,Game_Phase,false,Side_To_Move,false);
                        Moves->Count++;
                    }

                }
            }
        }
    }

    else if(pc == wK || pc == bK)
    {
        //Castling Moves
        if(pc == wK && KingSquare[0] == e1)
        {
            if(Castling_Permissions & CastleWhiteKside != 0 )
                if(Get_Piece_onSquare(f1) == EMPTY && Get_Piece_onSquare(g1) == EMPTY)
                     if(!Is_Square_Attacked(f1,BLACK) && !Is_Square_Attacked(g1,BLACK))
                     {
                         Set_Move_Info((Moves->moves)+(Moves->Count),e1,g1,EMPTY,EMPTY,CastleWhiteKside,0,MID_GAME,0,Side_To_Move,false);
                         Moves->Count++;
                         Set_Move_Info((Moves->moves)+(Moves->Count),h1,f1,EMPTY,EMPTY,0,0,MID_GAME,0,Side_To_Move,false);
                         Moves->Count++;
                     }

            if(Castling_Permissions & CastleWhiteQside != 0 )
                if(Get_Piece_onSquare(d1) == EMPTY && Get_Piece_onSquare(c1) == EMPTY && Get_Piece_onSquare(b1) == EMPTY)
                     if(!Is_Square_Attacked(d1,BLACK) && !Is_Square_Attacked(c1,BLACK))
                     {
                         Set_Move_Info((Moves->moves)+(Moves->Count),e1,c1,EMPTY,EMPTY,CastleWhiteQside,0,MID_GAME,0,Side_To_Move,false);
                         Moves->Count++;
                         Set_Move_Info((Moves->moves)+(Moves->Count),a1,d1,EMPTY,EMPTY,0,0,MID_GAME,0,Side_To_Move,false);
                         Moves->Count++;
                     }
        }

        else if(pc == bK && KingSquare[1] == e8)
        {
            if(Castling_Permissions & CastleBlackKside != 0 )
                if(Get_Piece_onSquare(f8) == EMPTY && Get_Piece_onSquare(g8) == EMPTY)
                     if(!Is_Square_Attacked(f8,WHITE) || !Is_Square_Attacked(g8,WHITE))
                     {
                         Set_Move_Info((Moves->moves)+(Moves->Count),e8,g8,EMPTY,EMPTY,CastleBlackKside,0,MID_GAME,0,Side_To_Move,false);
                         Moves->Count++;
                         Set_Move_Info((Moves->moves)+(Moves->Count),h8,f8,EMPTY,EMPTY,0,0,MID_GAME,0,Side_To_Move,false);
                         Moves->Count++;
                     }

            if(Castling_Permissions & CastleBlackQside != 0 )
                if(Get_Piece_onSquare(d8) == EMPTY && Get_Piece_onSquare(c8) == EMPTY && Get_Piece_onSquare(b8) == EMPTY)
                     if(!Is_Square_Attacked(d8,WHITE) || !Is_Square_Attacked(c8,WHITE))
                     {
                         Set_Move_Info((Moves->moves)+(Moves->Count),e8,c8,EMPTY,EMPTY,CastleBlackQside,0,MID_GAME,0,Side_To_Move,false);
                         Moves->Count++;
                         Set_Move_Info((Moves->moves)+(Moves->Count),a8,d8,EMPTY,EMPTY,0,0,MID_GAME,0,Side_To_Move,false);
                         Moves->Count++;
                     }
        }


            unsigned sq;

            if(pc == wK)
            {
                sq = KingSquare[WHITE];
                And_Result = (King_Moves[sq] | White_Pieces) ^ White_Pieces;
            }

            else
            {
                sq = KingSquare[BLACK];
                And_Result = (King_Moves[sq] | Black_Pieces) ^ Black_Pieces;
            }

             if(And_Result != 0)
                {
                    std::vector<unsigned int> TO_sqs;
                    Get_SetBits_Indecies(TO_sqs,And_Result);

                    for(unsigned i=0;i<TO_sqs.size();++i)
                    {
                        if(!Is_Square_Attacked(squares(TO_sqs[i]),pc==wK?BLACK:WHITE))
                        {
                            Set_Move_Info((Moves->moves)+(Moves->Count),sq,TO_sqs[i],EMPTY,Piece_Type_By_Square[TO_sqs[i]],0,0,Game_Phase,false,Side_To_Move,false);
                            Moves->Count++;
                        }
                    }

                }

    }
}
コード例 #15
0
bool GraphGen_notSorted::GenerateGraph(
		const unsigned long long nEdges,
		const unsigned long long nVertices,
		const double RMAT_a, const double RMAT_b, const double RMAT_c,
		const unsigned int nCPUWorkerThreads,
		std::ofstream& outFile,
		const unsigned long long standardCapacity,
		const bool allowEdgeToSelf,
		const bool allowDuplicateEdges,
		const bool directedGraph
		) {

	std::vector<Square> squares ( 1, Square( 0, nVertices, 0, nVertices, nEdges, 0, 0, 0 ) );

	bool allRecsAreInRange;
	do {
		allRecsAreInRange = true;
		unsigned int recIdx = 0;
		for( auto& rec: squares ) {
			if( Eligible_RNG_Rec(rec, standardCapacity) ) {
				continue;
			} else {
				ShatterSquare(squares, RMAT_a, RMAT_b, RMAT_c, recIdx, directedGraph);
				allRecsAreInRange = false;
				break;
			}
			++recIdx;
		}
	} while( !allRecsAreInRange );

	// Making sure there are enough squares to utilize all threads.
	while( squares.size() < nCPUWorkerThreads && !edgeOverflow(squares) ) {
		// Shattering the biggest rectangle.
		unsigned long long biggest_size = 0;
		unsigned int biggest_index = 0;
		for( unsigned int x = 0; x < squares.size(); ++x )
			if( squares.at(x).getnEdges() > biggest_size ) {
				biggest_size = squares.at(x).getnEdges();
				biggest_index = x;
			}
		ShatterSquare(squares, RMAT_a, RMAT_b, RMAT_c, biggest_index, directedGraph);
	}

	if( SHOW_SQUARES_DETAILS )
		for( unsigned int x = 0; x < squares.size(); ++x )
			std::cout << squares.at(x);

	std::cout << squares.size() << " partition(s) specified." << "\n";
	std::cout << "Generating the graph ..." << "\n";

	std::vector<std::thread> threads;

	if( USE_A_MUTEX_TO_CONTROL_WRITE_TO_FILE_INSTEAD_OF_CONCURRENT_QUEUES ) {

		/*******************************************
		 * Control writes to file using a mutex
		 *******************************************/

		std::mutex writeMutex;
		unsigned int nWorkerThreads = nCPUWorkerThreads <squares.size() ? nCPUWorkerThreads : squares.size();

		auto eachThreadGenEdgesUsingMutexFunc = [&] ( unsigned int puId ) {
			std::vector<Edge> edgeVector;

			std::random_device rd;
			std::mt19937_64 gen(rd());
			std::uniform_int_distribution<> dis;

			for( unsigned int recIdx = puId; recIdx < squares.size(); recIdx += nWorkerThreads ) {
				auto& rec = squares.at( recIdx );
				fill_up_edge_vector( std::ref(rec), std::ref(edgeVector), std::ref(dis), std::ref(gen), RMAT_a, RMAT_b, RMAT_c, allowEdgeToSelf, allowDuplicateEdges, directedGraph );
				{
					std::lock_guard<std::mutex> guard( writeMutex );
					printEdgeGroup( std::ref(edgeVector), outFile );
					progressBar();
				}	// guard gets out-of-scope, unlocking the mutex upon destruction.
				edgeVector.clear();	// clean the edge vector for the next round
			}
		};

		for( unsigned int puIdx = 0; puIdx < nWorkerThreads; ++puIdx )
			threads.push_back( std::thread( eachThreadGenEdgesUsingMutexFunc, puIdx ) );

		std::for_each( threads.begin(), threads.end(), std::mem_fn(&std::thread::join) );

	} else {

		/*****************************************************
		 * Control writes to file using concurrent queues
		 *****************************************************/

		threadsafe_queue<Square> rec_queue;
		threadsafe_queue< std::vector<Edge> > EV_queue;
		capacity_controller<long long> capacityGate(static_cast<long long>(standardCapacity), 0);

		for( auto& rec: squares )
			rec_queue.push(rec);

		auto eachThreadGenEdgesUsingQueuesFunc = [&] {
			std::random_device rd;
			std::mt19937_64 gen(rd());
			std::uniform_int_distribution<> dis;
			Square rec;
			while( rec_queue.try_pop(std::ref(rec)) != 0 ) {
				capacityGate.accumulate( rec.getnEdges() );
				std::vector<Edge> edgeVector;
				fill_up_edge_vector( std::ref(rec), std::ref(edgeVector), std::ref(dis), std::ref(gen), RMAT_a, RMAT_b, RMAT_c, allowEdgeToSelf, allowDuplicateEdges, directedGraph );
				EV_queue.push(std::move(edgeVector));
			}
		};

		for( unsigned int puIdx = 0; puIdx < nCPUWorkerThreads; ++puIdx )
			threads.push_back( std::thread( eachThreadGenEdgesUsingQueuesFunc ) );

		std::vector<Edge> poppedEV;
		for( unsigned nWrittenEV = 0; nWrittenEV < squares.size(); ++nWrittenEV ) {
			EV_queue.wait_and_pop( std::ref(poppedEV) );
			printEdgeGroupNoFlush( poppedEV, outFile );
			capacityGate.dissipate( poppedEV.size() );
			progressBar();
		}

		std::for_each( threads.begin(), threads.end(), std::mem_fn(&std::thread::join) );

	}

	progressBarNewLine();

	return( EXIT_SUCCESS );

}
コード例 #16
0
ファイル: display_loop.c プロジェクト: stefanctdo/borgware-2d
void display_loop(){
//	mcuf_serial_mode();

	mode = setjmp(newmode_jmpbuf);

#ifdef JOYSTICK_SUPPORT
	// in case we get here via mode jump, we (re)enable joystick queries
	waitForFire = 1;
#endif

	oldOldmode = oldMode;

#ifdef JOYSTICK_SUPPORT
	waitForFire = 1;
#endif

	for(;;){
#ifndef MENU_SUPPORT
		clear_screen(0);
#endif
		oldMode = mode;

		switch(mode++) {

#ifdef ANIMATION_SCROLLTEXT
		case 1:
			scrolltext(scrolltext_text);

	#ifdef RANDOM_SUPPORT
			{
				char a[28];
				sprintf(a,"</# counter == %lu  ",
					(unsigned long)percnt_get(&g_reset_counter, &g_reset_counter_idx));
				scrolltext(a);
			}
	#endif
#endif
#ifdef ANIMATION_TIME
#ifndef ANIMATION_SCROLLTEXT
		case 1:
#endif
			time_anim();
			break;
#else
#ifdef ANIMATION_SCROLLTEXT
			break;
#endif
#endif

#ifdef ANIMATION_SPIRAL
#		ifndef SPIRAL_DELAY
#			define SPIRAL_DELAY 5
#		endif

		case 2:
			spiral(SPIRAL_DELAY);
			break;
#endif

#ifdef ANIMATION_JOERN1
		case 3:
			joern1();
			break;
#endif

#ifdef ANIMATION_SNAKE
		case 4:
			snake_animation();
			break;
#endif

#ifdef ANIMATION_CHECKERBOARD
		case 5:
			checkerboard(20);
			break;
#endif

#ifdef ANIMATION_FIRE
		case 6:
			fire();
			break;
#endif

#ifdef ANIMATION_TIME
		case 7:
			time_anim();
			break;
#endif

#ifdef ANIMATION_MATRIX
		case 8:
			matrix();
			break;
#endif

#ifdef ANIMATION_RANDOM_BRIGHT
		case 9:
			random_bright(30);
			break;
#endif

#ifdef ANIMATION_STONEFLY
		case 10:
			stonefly();
			break;
#endif

#ifdef ANIMATION_GAMEOFLIFE
		case 11:
			gameoflife();
			break;
#endif

#ifdef ANIMATION_FLYINGDOTS
		case 12:
			flyingdots();
			break;
#endif

#ifdef ANIMATION_BREAKOUT
		case 13:
			breakout_demo();
			break;
#endif

#ifdef ANIMATION_MHERWEG
		case 14:
			mherweg();
			break;
#endif

#ifdef ANIMATION_MOIRE
		case 15:
			moire();
			break;
#endif

#ifdef ANIMATION_TIME
		case 16:
			time_anim();
			break;
#endif

#ifdef ANIMATION_LTN_ANT
		case 17:
			ltn_ant();
			break;
#endif

#ifdef ANIMATION_LABORLOGO
		case 18:
			laborlogo();
			break;
#endif

#ifdef ANIMATION_AMPHIBIAN
		case 19:
			amphibian();
			break;
#endif

#ifdef ANIMATION_LOGO_OOS
		case 20:
			logo_OutOfSpec();
			break;
#endif

#ifdef ANIMATION_FAIRYDUST
		case 21:
			fairydust();
			break;
#endif

#ifdef ANIMATION_PLASMA
		case 22:
			plasma();
			break;
#endif

#ifdef ANIMATION_PSYCHEDELIC
		case 23:
			psychedelic();
			break;
#endif

#ifdef ANIMATION_BLACKHOLE
		case 24:
			blackhole();
			break;
#endif

#ifdef ANIMATION_SQUARES
		case 25:
			squares();
			break;
#endif

#ifdef ANIMATION_DNA
		case 26:
			dna();
			break;
#endif

#ifdef ANIMATION_TESTS
		case 31:
			test_level(1, false);
			break;

		case 32:
			test_level(2, false);
			break;

		case 33:
			test_level(3, false);
			break;

		case 35:
			test_palette(false);
			test_palette2(false);
			break;
#endif

#ifdef SMALLANIMATION_ROWWALK
		case 36:
		  rowwalk(SMALLANIMATION_ROWWALK_COUNT,SMALLANIMATION_ROWWALK_SPEED);
		  break;
#endif

#ifdef SMALLANIMATION_COLWALK
		case 37:
		  colwalk(SMALLANIMATION_COLWALK_COUNT,SMALLANIMATION_COLWALK_SPEED);
		  break;
#endif
#ifdef SMALLANIMATION_COLBOUNCE
		case 38:
		  colbounce(SMALLANIMATION_COLBOUNCE_COUNT,SMALLANIMATION_COLBOUNCE_SPEED);
		  break;
#endif
#ifdef SMALLANIMATION_ROWBOUNCE
		case 39:
		  rowbounce(SMALLANIMATION_ROWBOUNCE_COUNT,SMALLANIMATION_ROWBOUNCE_SPEED);
		  break;
#endif

#ifdef MENU_SUPPORT
		case 0xFDu:
			mode = 1;
			break;

		case 0xFEu:
			menu();
			mode = oldOldmode;
			break;
#else

		case 0xFDu:
#ifdef JOYSTICK_SUPPORT
			if (JOYISFIRE)
				mode = 0xFEu;
			else
#endif
				mode = 1;
			break;

		case 0xFEu:
#ifdef JOYSTICK_SUPPORT
			waitForFire = 0;   // avoid circular jumps
			while (JOYISFIRE); // wait until user released the fire button
#endif
			wait(25);          // wait for button to settle

#  ifdef GAME_TETRIS
			tetris();
#  endif

#  ifdef GAME_BASTET
			tetris_bastet();
#  endif

#  ifdef GAME_TETRIS_FP
			tetris_fp();
#  endif

#  ifdef GAME_SPACE_INVADERS
			borg_invaders();
#  endif

#  ifdef GAME_SNAKE
			snake_game();
#  endif

#  ifdef GAME_BREAKOUT
			borg_breakout(0);
#  endif

#ifdef JOYSTICK_SUPPORT
			while (JOYISFIRE); // avoid an unwanted restart of the game loop
#endif
			wait(25);          // wait for button to settle
			mode = oldOldmode; // restore old animation mode
#ifdef JOYSTICK_SUPPORT
			waitForFire = 1;   // reenable joystick query of the wait() function
#endif
			break;
#endif

#ifdef ANIMATION_OFF
		case 0xFFu:
			off();
			break;
#endif
		default:
			if (reverseMode) {
				if (reverseMode-- == (mode - 1)) {
					mode -= 2;
				} else {
					reverseMode = 0;
				}
			}
			break;
		}
	}
}
コード例 #17
0
std::vector<int> fill_with_squares() {
	std::vector<int> squares(10, 1);
	//TODO: Calculate "squares" using standard functors
	
	return squares;
}
コード例 #18
0
int main(){
    i64 total = limit2;
    primeWithin(primes, limit + 200);
    total -= squares(0, 8, 1, 0);
    printf("%lld\n", total);
}