int main(){ const int NP=256; // Number of points in curve const int N1=31, N2=N1*N1; // Size of graph float pixels[N2]; // Accumulation buffer // Use two complex oscillators as harmonics of curve CSine<> csin1(1./NP), csin2; // Plot several harmonics summed with fundamental for(int j=1; j<8; ++j){ printf("\ne^iw + e^%diw\n\n", j); mem::zero(pixels, N2); csin2.freq(j/(float)NP); // Harmonic rotating in tandem with fundamental csin2.amp(1./j); // Amplitude is 1/f to give equal energy float r = 0.99/(1. + 1./j); // Factor to normalize sum of partials for(int i=0; i<NP; ++i){ Complex<> c = csin1() + csin2(); int ix = posToInd( c.r * r, N1); // map real component to x int iy = posToInd(-c.i * r, N1); // map imag component to y pixels[iy*N1 + ix] += 0.1; } print2D(pixels, N1, N1); printf("\n"); } }
int main(){ const int NP=256; // Number of points in curve const int N1=17, N2=N1*N1; // Size of graph float pixels[N2]; // Accumulation buffer CSine<> osc(1./NP); SineR<> oscAM; for(int k=2; k<5; ++k){ for(int j=0; j<3; ++j){ mem::zero(pixels, N2); float w = j*0.3 + 0.2; // "petalness" factor oscAM.set(k/(float)NP, w); for(int i=0; i<NP; ++i){ Complex<> c = osc() * (1-w + oscAM()); int ix = posToInd( c.r, N1); int iy = posToInd(-c.i, N1); pixels[iy*N1 + ix] += 0.1; } print2D(pixels, N1, N1); printf("\n"); }} }
int main(int argc, char* argv[]){ const int NP=256; // Number of points in curve const int N1=31, N2=N1*N1; // Size of graph float pixels[N2]; // Accumulation buffer Complex<double> phase(1,0), freq; printf("\nUnit circle\n"); mem::zero(pixels, N2); freq.fromPhase(M_2PI/NP); for(int i=0; i<NP; ++i){ int ix = posToInd(phase[0], N1); int iy = posToInd(phase[1], N1); phase *= freq; pixels[iy*N1 + ix] += 0.125; } print2D(pixels, N1, N1); printf("\nHalf circle\n"); mem::zero(pixels, N2); phase(0.5, 0); freq.fromPhase(M_2PI/NP); for(int i=0; i<NP; ++i){ int ix = posToInd(phase[0], N1); int iy = posToInd(phase[1], N1); phase *= freq; pixels[iy*N1 + ix] += 0.125; } print2D(pixels, N1, N1); return 0; }
int main(int argc, char* argv[]){ const int NP=256; // Number of points in curve const int N1=15, N2=N1*N1; // Size of graph float pixels[N2]; // Accumulation buffer SineR<> sineX, sineY; for(int k=1; k<4; ++k){ for(int j=1; j<4; ++j){ mem::zero(pixels, N2); sineX.set(float(j)/NP, 1); sineY.set(float(k)/NP, 1); printf("\nx:y = %d:%d\n\n", j,k); for(int i=0; i<NP; ++i){ int ix = posToInd( sineX(), N1); int iy = posToInd(-sineY(), N1); pixels[iy*N1 + ix] += 0.125; } print2D(pixels, N1, N1); printf("\n"); }} return 0; }
int main(){ const int NP=256; // Number of points in curve const int N1=31, N2=N1*N1; // Size of graph float pixels[N2]; // Accumulation buffer CSine<> csin; // Plot several winding and damping amounts for(int k=1; k<4; ++k){ for(int j=1; j<4; ++j){ printf("\nwinding=%d, decay=%d\n\n", k, j); mem::zero(pixels, N2); csin.decay(NP*j); // Number of iterations for amp to decay by 0.0001 csin.freq(k/(float)NP); // Winding number csin.reset(); // Reset oscillator to (1,0) for(int i=0; i<NP; ++i){ Complex<> c = csin(); int ix = posToInd( c.r, N1); // map real component to x int iy = posToInd(-c.i, N1); // map imag component to y pixels[iy*N1 + ix] += 0.1; } print2D(pixels, N1, N1); printf("\n"); }} }
/*sets the piece of the color in the position on the board checks if the position is legal checks if there aren't too many pieces of the given type*/ void set(char* board, pos p, char type, int color){ if (!isLegalPos(p)) // illegal pos { print_message(WRONG_POSITION); return; } int count = 0; pos searcher; for (int x = 'a'; x < 'i'; x++) // counts how many pieces of the given type are on the board { searcher.x = x; for (int y = 1; y < 9; y++) { searcher.y = y; if (board[posToInd(searcher)] == type) { count++; } } } int maxCount; // max amount of pieces of the given type if (type == WHITE_P || type == BLACK_P) { maxCount = 8; } else if (type == WHITE_K || type == BLACK_K || type == WHITE_Q || type == BLACK_Q) { maxCount = 1; } else { maxCount = 2; } if (count >= maxCount){ // too many pieces of the same type print_message(NO_PIECE); // illegal board return; } board[posToInd(p)] = type; // set the piece }
int scoreBest(char* board,int player){ linkedList *moves = getMoves(board, BLACK); if (moves->first == NULL){ // no possible moves for other player if (isCheck(board, BLACK)){ // check freeList(moves); return 2*kingScore; // the player wins } else // not in check { freeList(moves); return -0; // tie } } freeList(moves); moves = getMoves(board, WHITE); if (moves->first == NULL){ // no possible moves if (isCheck(board, WHITE)){ // check freeList(moves); return -2 * kingScore; // the player lost } else // not in check { freeList(moves); return -0; // tie } } freeList(moves); int score = 0; pos p; for (char x = 'a'; x <= 'h'; x++) { p.x = x; for (int y = 1; y <= 8; y++) { p.y = y; int ind = posToInd(p); char type = tolower(board[ind]); if (type == EMPTY) { continue; } int color = colorOfLoc(board, ind); int ind64 = color == WHITE ? posToBoard64(p) : 64 - posToBoard64(p); if (type == 'm') { score += pawnScore * (2 * color - 1); score += pawnTable[ind64]; } else if (type == 'n'){ score += knightScore * (2 * color - 1); score += knightTable[ind64]; } else if (type == 'b'){ score += bishopScore * (2 * color - 1); score += bishoptTable[ind64]; } else if (type == 'r'){ score += rookScore * (2 * color - 1); score += rookTable[ind64]; } else if (type == 'q'){ score += queenScore * (2 * color - 1); score += queenTable[ind64]; } } } return score * (2 * player - 1); }