예제 #1
0
파일: chess.c 프로젝트: pkova/noobchess
		bool linelooper(int tox, int toy, int xory, bool direction) {

			if (direction == 0) {

				while(xory != tox+1){
					tox = tox+1;

					if (checksquare(map[tox][toy]) == 1) {
						return 1;
						}
					
					}
				return 0;
				}

			if (direction == 1) {
	
				while (xory != toy-1) {
					toy = toy-1;

					if (checksquare(map[tox][toy]) == 1) 
						return 1;
						
					}
				return 0;
			}
		}	
예제 #2
0
파일: chess.c 프로젝트: pkova/noobchess
		bool diaglooper(int tox, int toy, int fromx, bool reverse) {

			if (reverse == 0) {

				while(tox+1 != fromx) {
					tox = tox+1;
					toy = toy+1;

					if (checksquare(map[tox][toy]) == 1) 
						return 1;
						
					 }
				return 0;
				}

			if (reverse == 1) {

				while (tox-1 != fromx) {
					tox = tox-1;
					toy = toy+1;

					if (checksquare(map[tox][toy]) == 1) 
						return 1;
						
					}
				return 0;

			}
		}
예제 #3
0
bool gt_linspace_management_checksquare(GtLinspaceManagement *spacemanager,
                                        GtUword ulen,
                                        GtUword vlen,
                                        size_t valuesize,
                                        size_t rsize)
{
  return checksquare(spacemanager, ulen, vlen, valuesize, rsize,false);
}
예제 #4
0
파일: chess.c 프로젝트: pkova/noobchess
    void turn (char* move) {

        int len = strlen(move);

        char square[3];
        strncpy(square, &move[len-2], 2);
        square[2] = '\0';
        memcpy(prevsquare, square, sizeof(square));
        

        int x = squarexfinder(square);
		int y = squareyfinder(square);

        if (strncmp(move, "0-0-0", 5) == 0) {

            if (cancastlelong() == 0)
                printf("Illegal move\n");

            else if (cancastlelong() == 1 && wturn == 1) {
                movepiece("e1", "c1");
                movepiece("a1", "d1");
            }

            else if (cancastlelong() == 1 && wturn == 0) {
                movepiece("e8", "c8");
                movepiece("a8", "d8");
            }

        }
       
        else if (strncmp(move, "0-0", 3) == 0) {

            if (cancastleshort() == 0)
                printf("Illegal move\n");

            else if (cancastleshort() == 1 && wturn == 1) {
                movepiece("e1", "g1");
                movepiece("h1", "f1");
            }
            
            else if (cancastleshort() == 1 && wturn == 0) {
                movepiece("e8", "g8");
                movepiece("h8", "f8");
            }

        }


        else if ((worb(map[x][y]) == 'w' && wturn == 1) || (worb(map[x][y]) == 'b' && wturn == 0))
			printf("Illegal move");
			
			
        else if (strlen(move) == 2 && move[1] == '4' && wturn == 1 && checksquare(move) == 0
                 && (board[x+1][y] == "pw" || board[x+2][y] == "pw")) {
			
            char* sqtocheck = map[x+1][y];
			bool check = checksquare(sqtocheck);

			if (check == 1) 
				movepiece(sqtocheck, move);
				
			
            else if (check == 0) {
				char* sqtocheck = map[x+2][y];
				bool check = checksquare(sqtocheck);
				
				if (check == 1) 
					movepiece(sqtocheck, move);
					

                else if (check == 0) 
					printf("Illegal move");
					
				}
			}

        else if (strlen(move) == 2 && wturn == 1 && board[x+1][y] == "pw" && board[x][y] == ". ") {
			char* from = map[x+1][y];
			movepiece(from, move);
			}

        else if (strlen(move) == 2 && move[1] == '5' && wturn == 0 && checksquare(move) == 0
                 && (board[x-1][y] == "pb" || board[x-2][y] == "pb")) {
			
            char* sqtocheck = map[x-1][y];
			bool check = checksquare(sqtocheck);

			if (check == 1) 
				movepiece(sqtocheck, move);
				
			
            else if (check == 0) {
				char* sqtocheck = map[x-2][y];
				bool check = checksquare(sqtocheck);
				
				if (check == 1) 
					movepiece(sqtocheck, move);
					

                else if (check == 0) 
					printf("Illegal move");
					
				}
			}

        else if (strlen(move) == 2 && wturn == 0 && board[x-1][y] == "pb" && board[x][y] == ". ") {
            char* from = map[x-1][y];
			movepiece(from, move);
			}


        else if (strlen(move) == 3 && move[0] == 'N' && wturn == 1)
            knightmover(square, "Nw");    

        else if (strlen(move) == 3 && move[0] == 'N' && wturn == 0) 
            knightmover(square, "Nb");

        else if (strlen(move) == 4 && move[0] == 'N' && wturn == 1 && move[1] == 'x' &&
                 board[x][y] != ". ") {

            char* status = board[x][y];

            if (status[1] == 'b')
                knightmover(square, "Nw");
            
            else
                printf("Illegal move\n");
        }

        else if (strlen(move) == 4 && move[0] == 'N' && wturn == 0 && move[1] == 'x' &&
                 board[x][y] != ". ") {

            char* status = board[x][y];

            if (status[1] == 'w')
                knightmover(square, "Nb");
            
            else
                printf("Illegal move\n");
        }

        else if (strlen(move) == 3 && move[0] == 'B' && board[x][y] == ". ")
            bishopmover(square);            

        else if (strlen(move) == 4 && move[0] == 'B' && move[1] == 'x' && board[x][y] != ". ") {

            char* status = board[x][y];

            if (wturn == 1 && status[1] == 'b')
                bishopmover(square);

            else if (wturn == 0 && status[1] == 'w')
                bishopmover(square);

            else
                printf("Illegal move\n");
        }

        else if (strlen(move) == 3 && move[0] == 'R' && board[x][y] == ". ")
            rookmover(square);

        else if (strlen(move) == 4 && move[0] == 'R' && move[1] == 'x' && board[x][y] != ". ") {

            char* status = board[x][y];

            if (wturn == 1 && status[1] == 'b')
                rookmover(square);

            else if (wturn == 0 && status[1] == 'w')
                rookmover(square);

            else
                printf("Illegal move\n");

        }
            

        else if (strlen(move) == 3 && move[0] == 'Q')
            queenmover(square);

        else if (strlen(move) == 4 && move[0] == 'Q' && move[1] == 'x' && board[x][y] != ". ") {

            char* status = board[x][y];

            if (wturn == 1 && status[1] == 'b')
                queenmover(square);

            else if (wturn == 0 && status[1] == 'w')
                queenmover(square);

            else
                printf("Illegal move\n");
        }

        else if (strlen(move) == 3 && move[0] == 'K')
            kingmover(square);

        else if (strlen(move) == 4 && move[0] == 'K' && move[1] == 'x' && board[x][y] != ". ") {

            char* status = board[x][y];

            if (wturn == 1 && status[1] == 'b')
                kingmover(square);

            else if (wturn == 0 && status[1] == 'w')
                kingmover(square);

            else
                printf("Illegal move\n");
        }

        else if (strlen(move) == 4 && wturn == 1 && move[1] == 'x' && worb(square) == 'b') {
           
            
            char str[3] = "\0";
            char m = move[0];
            str[0] = m;
            str[1] = '1';

            int column = squareyfinder(str);
            int row = x+1;


            if (row < 8 && board[row][column] == "pw")
                movepiece(map[row][column], map[x][y]);

            else
                printf("Illegal move \n");

        }
            
        else if (strlen(move) == 4 && wturn == 0 && move[1] == 'x' && worb(square) == 'w') {

            char str[3] = "\0";
            char m = move[0];
            str[0] = m;
            str[1] = '1';

            int column = squareyfinder(str);
            int row = x-1;

            if (row >= 0 && board[row][column] == "pb")
                movepiece(map[row][column], map[x][y]);

            else
                printf("Illegal move \n");

        }



        else
            printf("error");

		}
예제 #5
0
Matrix operator * (const Matrix& A, const Matrix& B)
{
    if (A.Clo() != B.Rlo() || A.Chi() != B.Rhi()) 
      Matpack.Error("Matrix operator * (const Matrix&, const Matrix&): "
                    "non conformant arguments\n");

    // allocate return matrix
    Matrix C(A.Rlo(),A.Rhi(),B.Clo(),B.Chi());
    
    //------------------------------------------------------------------------//
    // the BLAS version
    //------------------------------------------------------------------------//

#if defined ( _MATPACK_USE_BLAS_ )

    if ( LT(B) ) {                   // full matrix * lower triangle
#ifdef DEBUG
        cout << "GM*LT\n";
#endif
        checksquare(B);

        // copy A to C to protect from overwriting
        copyvec(C.Store(),A.Store(),A.Elements());

        charT   side('L'), uplo('U'), transc('N'), diag('N');
        intT    m(C.Cols()), n(C.Rows()),
                ldb(B.Cols()), ldc(C.Cols());
        doubleT alpha(1.0);
        
        F77NAME(dtrmm)(&side,&uplo,&transc,&diag,&m,&n,
                       &alpha,B.Store(),&ldb, C.Store(),&ldc);


    } else if ( UT(B) ) {             // full matrix * upper triangle
#ifdef DEBUG
        cout << "GM*UT\n";
#endif
        checksquare(B);

        // copy A to C to protect from overwriting
        copyvec(C.Store(),A.Store(),A.Elements());

        charT   side('L'), uplo('L'), transc('N'), diag('N');
        intT    m(C.Cols()), n(C.Rows()),
                ldb(B.Cols()), ldc(C.Cols());
        doubleT alpha(1.0);
        
        F77NAME(dtrmm)(&side,&uplo,&transc,&diag,&m,&n,
                       &alpha,B.Store(),&ldb, C.Store(),&ldc);


    } else if ( LT(A) ) {            // lower triangle * full matrix
#ifdef DEBUG
        cout << "LT*GM\n";
#endif

        checksquare(A);

        // copy B to C to protect from overwriting
        copyvec(C.Store(),B.Store(),B.Elements());

        charT   side('R'), uplo('U'), transc('N'), diag('N');
        intT    m(C.Cols()), n(C.Rows()),
                ldb(A.Cols()), ldc(C.Cols());
        doubleT alpha(1.0);
        
        F77NAME(dtrmm)(&side,&uplo,&transc,&diag,&m,&n,
                       &alpha,A.Store(),&ldb, C.Store(),&ldc);



    } else if ( UT(A) ) {            // upper triangle * full matrix
#ifdef DEBUG
        cout << "UT*GM\n";
#endif
        checksquare(A);

        // copy A to C to protect from overwriting
        copyvec(C.Store(),B.Store(),B.Elements());

        charT   side('R'), uplo('L'), transc('N'), diag('N');
        intT    m(C.Cols()), n(C.Rows()),
                ldb(A.Cols()), ldc(C.Cols());
        doubleT alpha(1.0);
        
        F77NAME(dtrmm)(&side,&uplo,&transc,&diag,&m,&n,
                       &alpha,A.Store(),&ldb, C.Store(),&ldc);

    } else /* GM(A) and GM(B) */ {   // GM*GM: full matrix * full matrix
#ifdef DEBUG
        cout << "GM*GM\n";
#endif

        charT   t('N');
        intT    m(B.Cols()), n(A.Rows()), k(B.Rows()),
                lda(A.Cols()), ldb(B.Cols()), ldc(C.Cols());
        doubleT alpha(1.0), beta(0.0);
        
        F77NAME(dgemm)(&t,&t, &m,&n,&k,
                       &alpha,B.Store(),&ldb, A.Store(),&lda, 
                       &beta,C.Store(),&ldc);
    }

    //------------------------------------------------------------------------//
    // the non-BLAS version
    //------------------------------------------------------------------------//

#else
    int  cl = A.cl,   ch = A.ch,
        arl = A.rl,  arh = A.rh,
        bcl = B.cl,  bch = B.ch;

    // avoid call to index operator that optimizes very badely
    double **a = A.M, **b = B.M, **c = C.M;
    for (int i = arl; i <= arh; i++)  {
        for (int j = bcl; j <= bch; j++) c[i][j] = 0.0;
        for (int l = cl; l <= ch; l++) {
            if ( a[i][l] != 0.0 ) {
                double temp = a[i][l];
                for (int j = bcl; j <= bch; j++)
                    c[i][j] += temp * b[l][j];
            }
        }
    }

#endif

    return C.Value();
}