void getsliders(int f, int r, int df, int dr, int color) { square s1 = SQ(f,r); chesspiece p; for (;;) { f += df; r += dr; if (offboardp(f,r)) return; p = getpiece(f,r); if (p == empty) pushmove(MV(s1, SQ(f,r))); else if (chesspiececolor(p)==color) return; else { pushmove(MV(s1, SQ(f,r))); return; } } }
/* generate pawn captures and promotions */ void genattacksp(int f, int r, int c) { int forward = dir(c); square loc = SQ(f,r); r += forward; if (f<7) { chesspiece p = getpiece(f+1, r); if (p&&chesspiececolor(p)!=c) pushmove(MV(loc, SQ(f+1, r))); } if (f>0) { chesspiece p = getpiece(f-1,r); if (p&&chesspiececolor(p)!=c) pushmove(MV(loc, SQ(f-1, r))); } if (c==WHITE) { if ((r==6)&&emptyp(f,r)) pushmove(MV(loc, SQ(f,r))); } else { if ((r==1)&&emptyp(f,r)) pushmove(MV(loc, SQ(f,r))); } /* get en passante */ if (doublepushp()) { square start; square end; move m; m = lastmove(); start = FR(m); end = TO(m); r -= forward; /* restore to original r */ if (R(end) == r) { if (((f+1) == F(start))|| ((f-1) == F(start))) pushmove(MV(loc, SQ(F(start),forward+r))); } } }
ContactPairPoint^ ContactPairPoint::ToManaged(PxContactPairPoint unmanaged) { auto managed = gcnew ContactPairPoint(); managed->Position = MV(unmanaged.position); managed->Separation = unmanaged.separation; managed->Normal = MV(unmanaged.normal); managed->InternalFaceIndex0 = unmanaged.internalFaceIndex0; managed->InternalFaceIndex1 = unmanaged.internalFaceIndex1; managed->Impulse = MV(unmanaged.impulse); return managed; }
void getmovesp(int f, int r, int c) { int forward = dir(c); square loc = SQ(f,r); r += forward; // captures if ((f<7) && (oppenentp (f+1, r, c))) { push_pawn_move(loc, SQ(1+f, r)); } if ((f>0) && (oppenentp (f-1, r, c))) { push_pawn_move(loc, SQ(f-1, r)); } if (emptyp(f,r)) { int startrank = ((c == WHITE) ? 2 : 5); push_pawn_move(loc, SQ(f,r)); /* can go two on first move */ if ((r == startrank)&&(emptyp(f,r+forward))) pushmove(MV(loc, SQ(f,r+forward))); } // if last move was double push we can possibly do an en passante if (doublepushp()) { square start; square end; move m; m = lastmove(); start = FR(m); end = TO(m); r -= forward; /* restore to original r */ if (R(end) == r) { if (((f+1) == F(start))|| ((f-1) == F(start))) pushmove(MV(loc, SQ(F(start),forward+r))); } } }
void gensliderattacksDEC(square s, int dd, int color) { chesspiece p; square s2 = s; for (;;) { s2 += dd; /* dd should be negative */ if ((s2&001)==0) /* if at RANK 8 then we have looped */ break; if ((s2&~(077))!=0) break; p = getpiece__(s2); if (p) { if (chesspiececolor(p) != color) { pushmove(MV(s, s2)); return; } return; } } }
void gensliderattacksINC(square s, int dd, int color) { chesspiece p; square s2 = s; for (;;) { s2 += dd; if ((s2&007)==0) /* if at RANK 1 we have looped */ break; if ((s2&~(077))!=0) break; p = getpiece__(s2); if (p) { if (chesspiececolor(p) != color) { pushmove(MV(s, s2)); return; } return; } } }
void gensliderattacks(int f, int r, int df, int dr, int color) { chesspiece p; square s1=SQ(f,r); for (;;) { f += df; r += dr; if (offboardp (f,r)) return; p = getpiece(f,r); if (p) { if (chesspiececolor(p) != color) { pushmove(MV(s1, SQ(f,r))); return; } return; } } }
void getmovesn(int f, int r, int c) { int i, nf, nr; int o; chesspiece p; square s1; s1 = SQ(f,r); o = opp(c); for (i=0;i<8;i++) { nf = f+df[i]; nr = r+dr[i]; if (offboardp(nf,nr)) continue; p = getpiece(nf, nr); if (!p || (c != chesspiececolor(p))) { pushmove(MV(s1, SQ(nf, nr))); } } }
static void mdlOutputs(SimStruct *S, int_T tid) { double sp_original; double meas_scaled; double manip_original_in; double xi_in; int mode; double K; double Ti; double h; double LO_y; double HI_y; double LO_u; double HI_u; int action; int P_only; double rel_lo; double rel_hi; double hys; double hi_flag_in; double *manip_original; double *xi; double *hi_flag; #ifdef DEBUG debug("mdlOutputs entered.\n"); #endif sp_original = SETPOINT(S); meas_scaled = INPUT(S); manip_original_in = MV(S); xi_in = XI(S); mode = MODE(S); K = GAIN(S); Ti = RESET(S); h = SAMPLING(S); LO_y = LOWMEAS(S); HI_y = HIGHMEAS(S); LO_u = LOWMV(S); HI_u = HIGHMV(S); action = PGAIN(S); P_only = PONLY(S); rel_lo = RELLO(S); rel_hi = RELHI(S); hys = HYS(S); hi_flag_in = HIFLAG(S); manip_original = &OUTPUT(S); xi = &XO(S); hi_flag = &FLAG(S); controller(manip_original, xi, hi_flag, sp_original, meas_scaled, manip_original_in, xi_in, mode, K, Ti, h, LO_y, HI_y, LO_u, HI_u, action, P_only, rel_lo, rel_hi, hys, hi_flag_in); #ifdef DEBUG debug("mdlOutputs left.\n"); #endif } /* mdlOutputs */
inline void push_pawn_move(square start, square end) { if ((R(end) == 7)||(R(end)==0)) { pushmove(MV_PR(start, end, queen)); pushmove(MV_PR(start, end, knight)); pushmove(MV_PR(start, end, rook)); pushmove(MV_PR(start, end, bishop)); } else { pushmove(MV(start,end)); } }
void getmovesk_nocastles(int f, int r, int c) { int df, dr, nf, nr; int o; chesspiece p; square s1 = SQ(f,r); o = opp(c); for (df=-1;df<2;df++) for (dr=-1;dr<2;dr++) { if (!df && !dr) continue; nf = f+df; nr = r+dr; p = getpiece(nf, nr); if (!offboardp(nf, nr) && (!p || (c != chesspiececolor(p)))) pushmove(MV(s1, SQ(nf, nr))); } }
/* ex. cd (cxd) */ move decode_pawn_cap(char *s) { static char *c_index = "abcdefgh"; int r, sf, ef; sf = strchr(c_index, s[0]) - c_index; ef = strchr(c_index, s[1]) - c_index; for (r=0;r<7;r++) { chesspiece p = getpiece(sf,r); if ((COLOR(p) == tomove()) && (VALUE(p) == pawn)) { chesspiece a = getpiece(ef, r+dir(COLOR(p))); if (COLOR(a) != tomove()) return MV(SQ(sf,r),SQ(ef,r+dir(COLOR(p)))); } } return dummymove; }
static void mime_type__type_add(Mime_types_data *mime, unsigned char type) { MALLOC_CHECK_SZ_MEM(mime->types, mime->type_sz); ASSERT(mime->type_num <= mime->type_sz); if (mime->type_num >= mime->type_sz) { unsigned char *tmp = NULL; unsigned int sz = mime->type_sz * 2; if (!MV(mime->types, tmp, sz)) { mime->ents->malloc_bad = TRUE; return; } mime->type_sz = sz; } mime->types[mime->type_num++] = type; ASSERT(mime->type_num <= mime->type_sz); }
static void test_pgn_save(void) { const char game1[] = "[Event \"\"]\n" "[Site \"\"]\n" "[Date \"\"]\n" "[Round \"\"]\n" "[White \"\"]\n" "[Black \"\"]\n" "[Result \"*\"]\n" "\n" "*\n"; const char game2[] = "[Event \"World Chess Championship 1886\"]\n" "[Site \"New Orleans, USA\"]\n" "[Date \"1886.01.21\"]\n" "[Round \"20\"]\n" "[White \"Steinitz, Wilhelm\"]\n" "[Black \"Zukertort, Johannes\"]\n" "[Result \"1-0\"]\n" "[PlyCount \"37\"]\n" "\n" "1. e4 e5 2. Nc3 Nc6 3. f4 exf4 4. d4 d5 5. exd5 Qh4+ 6. Ke2 Qe7+" " 7. Kf2 Qh4+ 8. g3 fxg3+ 9. Kg2 Nxd4 10. hxg3 Qg4 11. Qe1+ Be7" " 12. Bd3 Nf5 13. Nf3 Bd7 14. Bf4 f6 15. Ne4 Ngh6 16. Bxh6 Nxh6" " 17. Rxh6 gxh6 18. Nxf6+ Kf8 19. Nxg4 1-0\n"; const ChessMove game2_moves[] = { MV(E2,E4), MV(E7,E5), MV(B1,C3), MV(B8,C6), MV(F2,F4), MV(E5,F4), MV(D2,D4), MV(D7,D5), MV(E4,D5), MV(D8,H4), MV(E1,E2), MV(H4,E7), MV(E2,F2), MV(E7,H4), MV(G2,G3), MV(F4,G3), MV(F2,G2), MV(C6,D4), MV(H2,G3), MV(H4,G4), MV(D1,E1), MV(F8,E7), MV(F1,D3), MV(D4,F5), MV(G1,F3), MV(C8,D7), MV(C1,F4), MV(F7,F6), MV(C3,E4), MV(G8,H6), MV(F4,H6), MV(F5,H6), MV(H1,H6), MV(G7,H6), MV(E4,F6), MV(E8,F8), MV(F6,G4), }; ChessGame* game; ChessGameIterator iter; ChessBufferWriter writer; int i; chess_buffer_writer_init(&writer); game = chess_game_new(); chess_pgn_save(game, (ChessWriter*)&writer); ASSERT_BUFFER_VALUE(&writer, game1); chess_buffer_writer_clear(&writer); chess_game_reset(game); chess_game_set_event(game, "World Chess Championship 1886"); chess_game_set_site(game, "New Orleans, USA"); chess_game_set_date(game, "1886.01.21"); chess_game_set_round(game, "20"); chess_game_set_white(game, "Steinitz, Wilhelm"); chess_game_set_black(game, "Zukertort, Johannes"); chess_game_iterator_init(&iter, game); for (i = 0; i < sizeof(game2_moves) / sizeof(ChessMove); i++) chess_game_iterator_append_move(&iter, game2_moves[i]); chess_game_set_result(game, CHESS_RESULT_WHITE_WINS); chess_game_set_tag(game, "PlyCount", "37"); chess_pgn_save(game, (ChessWriter*)&writer); ASSERT_BUFFER_VALUE(&writer, game2); chess_buffer_writer_cleanup(&writer); chess_game_iterator_cleanup(&iter); chess_game_destroy(game); }
/// /// Creates a new project from an ElmerModuleDriver base /// /// This program is designed to make a new IllinoisRocstar /// software project starting from an intallation of the /// ElmerModuleDriver project template. /// /// Usage of this program should go like the following: /// 1. Get and Install the ElmerModuleDriver template. /// <blockquote> /// svn co $IRREPO/ElmerModuleDriver/trunk ElmerModuleDriver\n /// mkdir elmermoduledriver_build\n /// cd elmermoduledriver_build\n /// cmake ../ElmerModuleDriver\n /// make\n /// cd ../\n /// </blockquote> /// 2. Create the new project, <NewProject>, with the "make_project" command. /// <blockquote> /// elmermoduledriver_build/bin/make_project ElmerModuleDriver <NewProject>\n /// </blockquote> /// /// @note Be sure to replace <NewProject> with your new project name. /// /// The usage for the make_project command is: /// <blockquote> /// make_project usage:\n /// /// make_project \<template name\> \<new project\> [verb level]\n /// /// This program will read the project template from the \<template name\>\n /// directory and create a new "blank" IllinoisRocstar project\n /// named \<new name\>, in a directory named \<new name\>.\n /// An optional verblevel of 1 or 2 can be given to make the process\n /// more verbose.\n /// </blockquote> /// int MakeProject(int argc,char *argv[]) { if(argc < 3){ std::cout << "ElmerModuleDriver:MakeProject: " << std::endl << "Usage:" << std::endl << std::endl << argv[0] << " <template name> <new name> [verb level]" << std::endl << std::endl << "This program will read the project template from the <template name> " << std::endl << "directory and create a new \"blank\" IllinoisRocstar project" << std::endl << "named <new name>, in a directory named <new name>." << std::endl << "An optional verblevel of 1 or 2 can be given to make the process" << std::endl << "more verbose." << std::endl; return(0); } std::string OriginalName(argv[1]); std::string NewName(argv[2]); int verb = 0; if(argv[3]){ verb = 1; int v = atoi(argv[3]); if(v > 0) verb = v; } std::vector<std::string> ProtectedFiles; ProtectedFiles.push_back("AUTHORS"); ProtectedFiles.push_back("CTestConfig.cmake"); ProtectedFiles.push_back("LICENSE"); ProtectedFiles.push_back(".svn"); std::vector<std::string> CommonFiles; CommonFiles.push_back("CMakeLists.txt"); int syserr = 0; std::string olower(OriginalName); std::string oupper(OriginalName); std::string nlower(NewName); std::string nupper(NewName); std::transform(olower.begin(),olower.end(),olower.begin(),tolower); std::transform(oupper.begin(),oupper.end(),oupper.begin(),toupper); std::transform(nlower.begin(),nlower.end(),nlower.begin(),tolower); std::transform(nupper.begin(),nupper.end(),nupper.begin(),toupper); if(verb) std::cout << "ElmerModuleDriver:MakeProject:" << std::endl << " Creating a new project (" << NewName << ") from project template (" << OriginalName << ")." << std::endl << std::endl << "Creating top level project directories..."; std::string dirname(NewName); if(!IRAD::Sys::FILEEXISTS(NewName)){ if(verb > 1) std::cout << "ElmerModuleDriver:MakeProject: Creating directory " << dirname << "..."; syserr = IRAD::Sys::CreateDirectory(dirname); if(syserr){ std::cout << "ElmerModuleDriver:MakeProject: Unable to create directory " << dirname << "." << std::endl; return(1); } if(verb > 1) std::cout << "done." << std::endl; } dirname += "/branches"; if(!IRAD::Sys::FILEEXISTS(dirname)){ if(verb > 1) std::cout << "ElmerModuleDriver:MakeProject: Creating directory " << dirname << "..."; syserr = IRAD::Sys::CreateDirectory(dirname); if(syserr){ std::cout << "ElmerModuleDriver:MakeProject: Unable to create directory " << dirname << "." << std::endl; return(1); } if(verb > 1) std::cout << "ElmerModuleDriver:MakeProject: done." << std::endl; } dirname = NewName+"/tags"; if(!IRAD::Sys::FILEEXISTS(dirname)){ if(verb > 1) std::cout << "ElmerModuleDriver:MakeProject: Creating directory " << dirname << "..."; syserr = IRAD::Sys::CreateDirectory(dirname); if(syserr){ std::cout << "ElmerModuleDriver:MakeProject: Unable to create directory " << dirname << "." << std::endl; return(1); } if(verb > 1) std::cout << "ElmerModuleDriver:MakeProject: done." << std::endl; } dirname.assign(NewName+"/examples"); if(!IRAD::Sys::FILEEXISTS(dirname)){ if(verb > 1) std::cout << "ElmerModuleDriver:MakeProject: Creating directory " << dirname << "..."; syserr = IRAD::Sys::CreateDirectory(dirname); if(syserr){ std::cout << "ElmerModuleDriver:MakeProject: Unable to create directory " << dirname << "." << std::endl; return(1); } if(verb > 1) std::cout << "ElmerModuleDriver:MakeProject: done." << std::endl; } bool protect_svn = false; dirname = NewName+"/trunk"; std::vector<std::string>::iterator pfi = ProtectedFiles.begin(); while(pfi != ProtectedFiles.end()){ std::string ProtectThisFile(dirname+"/"+*pfi++); std::string ProtectedFile(ProtectThisFile+".backup"); if(IRAD::Sys::FILEEXISTS(ProtectThisFile)) IRAD::Sys::Rename(ProtectThisFile,ProtectedFile); } pfi = CommonFiles.begin(); while(pfi != CommonFiles.end()){ std::string ProtectThisFile(dirname+"/"+*pfi++); std::string ProtectedFile(ProtectThisFile+".backup"); if(IRAD::Sys::FILEEXISTS(ProtectThisFile)) IRAD::Sys::Rename(ProtectThisFile,ProtectedFile); } std::ostringstream ComStr; if(!IRAD::Sys::FILEEXISTS(dirname)){ if(verb > 1) std::cout << "ElmerModuleDriver:MakeProject: Creating directory " << dirname << "..."; ComStr << "cp -r " << OriginalName << " " << dirname; } else { if(verb > 1) std::cout << "ElmerModuleDriver:MakeProject: Making project files from template ..."; ComStr << "cp -r " << OriginalName << "/* " << dirname; } IRAD::Sys::InProcess System(ComStr.str()); std::string comline; while(std::getline(System,comline)){ if(verb > 1) std::cout << comline << std::endl; } if(verb) std::cout << "ElmerModuleDriver:MakeProject: done." << std::endl; if(verb) std::cout << "ElmerModuleDriver:MakeProject: Cleaning up ..."; ComStr.str(""); ComStr << "rm -rf " << dirname << "/.svn"; System.Execute(ComStr.str()); int n = 0; while(std::getline(System,comline)) n++; pfi = ProtectedFiles.begin(); while(pfi != ProtectedFiles.end()){ std::string ProtectThisFile(dirname+"/"+*pfi++); std::string ProtectedFile(ProtectThisFile+".backup"); if(IRAD::Sys::FILEEXISTS(ProtectedFile)){ if(IRAD::Sys::FILEEXISTS(ProtectThisFile)) IRAD::Sys::Remove(ProtectThisFile); IRAD::Sys::Rename(ProtectedFile,ProtectThisFile); } } pfi = CommonFiles.begin(); while(pfi != CommonFiles.end()){ std::string ProtectThisFile(dirname+"/"+*pfi++); std::string ProtectedFile(ProtectThisFile+".backup"); std::string CommonFileTemplate(ProtectThisFile+".template"); if(IRAD::Sys::FILEEXISTS(ProtectedFile)){ if(IRAD::Sys::FILEEXISTS(ProtectThisFile)) IRAD::Sys::Rename(ProtectThisFile,CommonFileTemplate); IRAD::Sys::Rename(ProtectedFile,ProtectThisFile); } } if(verb) std::cout << "ElmerModuleDriver:MakeProject: done." << std::endl; if(verb > 1) std::cout << "ElmerModuleDriver:MakeProject: Done creating new project files." << std::endl; if(verb) std::cout << "ElmerModuleDriver:MakeProject: Renaming project..."; if(IRAD::Sys::ChDir(dirname)){ std::cout << "ElmerModuleDriver:MakeProject: Something went wrong, cannot find new project directory." << std::endl; return(1); } ComStr.str(""); ComStr << "grep -i " << OriginalName << " -r * | cut -d \":\" -f 1 | sort | uniq"; if(verb > 1) std::cout << " " << ComStr.str() << std::endl; System.Execute(ComStr.str()); std::vector<std::string> filenames; if(verb > 1) std::cout << "ElmerModuleDriver:MakeProject: Files to change:" << std::endl; while(std::getline(System,comline)){ if(!Excluded(comline)){ filenames.push_back(comline); if(verb > 1) std::cout << " " << comline << std::endl; } } std::vector<std::string>::iterator fni = filenames.begin(); if(verb > 1) std::cout << "ElmerModuleDriver:MakeProject: Processing files...."; while(fni != filenames.end()){ std::string filename(*fni++); if(verb > 1) std::cout << "ElmerModuleDriver:MakeProject: File: " << filename << std::endl; ComStr.str(""); ComStr << "sed -i 's/" << OriginalName << "/" << NewName << "/g' " << filename; if(verb > 1) std::cout << "ElmerModuleDriver:MakeProject: " << ComStr.str() << std::endl; System.Execute(ComStr.str()); int n = 0; while(std::getline(System,comline)) n++; ComStr.str(""); ComStr << "sed -i 's/" << oupper << "/" << nupper << "/g' " << filename; if(verb > 1) std::cout << " " << ComStr.str() << std::endl; // std::cout << ComStr.str() << std::endl; System.Execute(ComStr.str()); while(std::getline(System,comline)) n++; ComStr.str(""); ComStr << "sed -i 's/" << olower << "/" << nlower << "/g' " << filename; if(verb > 1) std::cout << " " << ComStr.str() << std::endl; // std::cout << ComStr.str() << std::endl; System.Execute(ComStr.str()); while(std::getline(System,comline)) n++; } if(verb > 1) std::cout << "ElmerModuleDriver:MakeProject: Done processing file contents." << std::endl << " Renaming files..." << std::endl; ComStr.str(""); // Now the inside of all files is fixed, need to fix filenames ComStr << "find . -name \"*" << OriginalName << "*\""; System.Execute(ComStr.str()); std::string::size_type olen = OriginalName.length(); std::string::size_type nlen = NewName.length(); while(std::getline(System,comline)){ if(verb > 1) std::cout << "ElmerModuleDriver:MakeProject: Renaming " << comline << " to "; std::string newname(comline); std::string::size_type x = newname.find(OriginalName); while(x != std::string::npos){ newname.replace(x,olen,NewName); x = newname.find(OriginalName); } ComStr.str(""); if(verb > 1) std::cout << newname << std::endl; ComStr << "mv " << comline << " " << newname; // std::cout << ComStr.str() << std::endl; IRAD::Sys::InProcess MV(ComStr.str()); } if(verb > 1) std::cout << "done." << std::endl; return(0); }
static void test_pgn_load_subvariations(void) { const char pgn1[] = "1. e4 (1. d4 Nf6) e5 *"; const char pgn2[] = "1. d4 d5 (1... Nf6) (1... g6) 2. c4 *"; const char pgn3[] = "1. c4 e5 (1... g6 2. d4 (2. Nf3)) *"; ChessBufferReader reader; ChessGame* game; ChessVariation* variation, *subvariation; ChessPgnLoadResult result; /* Test 1 */ game = chess_game_new(); chess_buffer_reader_init(&reader, pgn1); result = chess_pgn_load((ChessReader*)&reader, game); CU_ASSERT_EQUAL(CHESS_PGN_LOAD_OK, result); chess_buffer_reader_cleanup(&reader); variation = chess_game_root_variation(game); variation = variation->first_child; CU_ASSERT_EQUAL(MV(E2,E4), variation->move); subvariation = variation->right; CU_ASSERT_EQUAL(MV(D2,D4), subvariation->move); subvariation = subvariation->first_child; CU_ASSERT_EQUAL(MV(G8,F6), subvariation->move); CU_ASSERT_EQUAL(NULL, subvariation->first_child); variation = variation->first_child; CU_ASSERT_EQUAL(MV(E7,E5), variation->move); CU_ASSERT_EQUAL(NULL, variation->first_child); chess_game_destroy(game); /* Test 2 */ game = chess_game_new(); chess_buffer_reader_init(&reader, pgn2); result = chess_pgn_load((ChessReader*)&reader, game); CU_ASSERT_EQUAL(CHESS_PGN_LOAD_OK, result); chess_buffer_reader_cleanup(&reader); variation = chess_game_root_variation(game); variation = variation->first_child; CU_ASSERT_EQUAL(MV(D2,D4), variation->move); variation = variation->first_child; CU_ASSERT_EQUAL(MV(D7,D5), variation->move); subvariation = variation->right; CU_ASSERT_EQUAL(MV(G8,F6), subvariation->move); CU_ASSERT_EQUAL(NULL, subvariation->first_child); subvariation = subvariation->right; CU_ASSERT_EQUAL(MV(G7,G6), subvariation->move); CU_ASSERT_EQUAL(NULL, subvariation->first_child); CU_ASSERT_EQUAL(NULL, subvariation->right); variation = variation->first_child; CU_ASSERT_EQUAL(MV(C2,C4), variation->move); CU_ASSERT_EQUAL(NULL, variation->first_child); chess_game_destroy(game); /* Test 3 */ game = chess_game_new(); chess_buffer_reader_init(&reader, pgn3); result = chess_pgn_load((ChessReader*)&reader, game); CU_ASSERT_EQUAL(CHESS_PGN_LOAD_OK, result); chess_buffer_reader_cleanup(&reader); variation = chess_game_root_variation(game); variation = variation->first_child; CU_ASSERT_EQUAL(MV(C2,C4), variation->move); variation = variation->first_child; CU_ASSERT_EQUAL(MV(E7,E5), variation->move); CU_ASSERT_EQUAL(NULL, variation->first_child); subvariation = variation->right; CU_ASSERT_EQUAL(MV(G7,G6), subvariation->move); subvariation = subvariation->first_child; CU_ASSERT_EQUAL(MV(D2,D4), subvariation->move); CU_ASSERT_EQUAL(NULL, subvariation->first_child); subvariation = subvariation->right; CU_ASSERT_EQUAL(MV(G1,F3), subvariation->move); CU_ASSERT_EQUAL(NULL, subvariation->first_child); CU_ASSERT_EQUAL(NULL, subvariation->right); chess_game_destroy(game); }
void getmovesk(int f, int r, int c) { int df, dr, nf, nr; int o; chesspiece p; square s1 = SQ(f,r); o = opp(c); for (df=-1; df<2; df++) for (dr=-1; dr<2; dr++) { if (!df && !dr) continue; nf = f+df; nr = r+dr; p = getpiece(nf, nr); if (!offboardp(nf, nr) && (!p || (c != chesspiececolor(p)))) pushmove(MV(s1, SQ(nf, nr))); } if (c==WHITE) { if (wqcastlep()&& !getpiece__(D1)&& !getpiece__(C1)&& !getpiece__(B1)&& !incheckp(c)&& !wouldbeincheckp(THRUWQ)) { pushmove(WQC); } if (wkcastlep()&& !getpiece__(F1)&& !getpiece__(G1)&& !incheckp(c)&& !wouldbeincheckp(THRUWK)) { pushmove(WKC); } } else { if (bqcastlep()&& !getpiece__(D8)&& !getpiece__(C8)&& !getpiece__(B8)&& !incheckp(c)&& !wouldbeincheckp(THRUBQ)) { pushmove(BQC); } if (bkcastlep()&& !getpiece__(F8)&& !getpiece__(G8)&& !incheckp(c)&& !wouldbeincheckp(THRUBK)) { pushmove(BKC); } } }
void GLES2Renderer::bindMeshContext(const RendererMeshContext &context) { physx::PxMat44 model = physx::PxMat44::createIdentity(); physx::PxMat44 modelView; if(context.transform) model = *context.transform; GLfloat glmvp[16]; GLfloat glmodel[16]; GLfloat glview[16]; GLfloat glmodelview[16]; GLES2RendererMaterial::shaderProgram& program = g_hackCurrentMat->m_program[g_hackCurrentMat->m_currentPass]; // if we don't use MojoShader if (program.modelMatrixUniform != -1) { PxToGL(glmodel, model); glUniformMatrix4fv(program.modelMatrixUniform, 1, GL_FALSE, glmodel); } if (program.viewMatrixUniform != -1) { PxToGL(glview, m_viewMatrix); glUniformMatrix4fv(program.viewMatrixUniform, 1, GL_FALSE, glview); } if (program.projMatrixUniform != -1) { glUniformMatrix4fv(program.projMatrixUniform, 1, GL_FALSE, m_glProjectionMatrix); } if (program.modelViewMatrixUniform != -1) { modelView = m_viewMatrix * model; PxToGL(glmodelview, modelView); glUniformMatrix4fv(program.modelViewMatrixUniform, 1, GL_FALSE, glmodelview); } if (program.modelViewProjMatrixUniform != -1) { modelView = m_viewMatrix * model; physx::PxMat44 MVP = PxMat44(m_glProjectionMatrix).getTranspose(); MVP = MVP * modelView; PxToGLColumnMajor(glmvp, MVP); glUniformMatrix4fv(program.modelViewProjMatrixUniform, 1, GL_FALSE, glmvp); } // if we use MojoShader if(program.vertexMojoResult || program.fragmentMojoResult) { // model matrix { const RendererMaterial::Variable* var = g_hackCurrentMat->findVariable("g_modelMatrix", RendererMaterial::VARIABLE_FLOAT4x4); if(var) { if (context.shaderData) { memcpy(&glmodel, context.shaderData, 16 * sizeof(PxF32)); } else { PxToGL(glmodel, model); } g_hackCurrentMat->bindVariable(g_hackCurrentMat->m_currentPass, *var, glmodel); } } // model-view matrix { const RendererMaterial::Variable* var = g_hackCurrentMat->findVariable("g_modelViewMatrix", RendererMaterial::VARIABLE_FLOAT4x4); if(var) { modelView = m_viewMatrix * model; PxToGL(glmodelview, modelView); g_hackCurrentMat->bindVariable(g_hackCurrentMat->m_currentPass, *var, glmodelview); } } // model-view-project matrix { const RendererMaterial::Variable* var = g_hackCurrentMat->findVariable("g_MVP", RendererMaterial::VARIABLE_FLOAT4x4); if(var) { physx::PxMat44 MVP = physx::PxMat44(m_glProjectionMatrix); modelView = m_viewMatrix * model; PxToGL(glmodelview, modelView); physx::PxMat44 MV(glmodelview); MVP = MV * MVP; memcpy(glmvp, MVP.front(), sizeof(MVP)); g_hackCurrentMat->bindVariable(g_hackCurrentMat->m_currentPass, *var, glmvp); } } } g_hackCurrentMat->submitUniforms(); switch(context.cullMode) { case RendererMeshContext::CLOCKWISE: glFrontFace( GL_CW ); glCullFace( GL_BACK ); glEnable( GL_CULL_FACE ); break; case RendererMeshContext::COUNTER_CLOCKWISE: glFrontFace( GL_CCW ); glCullFace( GL_BACK ); glEnable( GL_CULL_FACE ); break; case RendererMeshContext::NONE: glDisable( GL_CULL_FACE ); break; default: RENDERER_ASSERT(0, "Invalid Cull Mode"); } RENDERER_ASSERT(context.numBones <= RENDERER_MAX_BONES, "Too many bones."); if(context.boneMatrices && context.numBones>0 && context.numBones <= RENDERER_MAX_BONES && program.boneMatricesUniform != -1) { GLfloat glbonematrix[16*RENDERER_MAX_BONES]; for(PxU32 i=0; i<context.numBones; i++) { PxToGL(glbonematrix+(16*i), context.boneMatrices[i]); } glUniformMatrix4fv(program.boneMatricesUniform, context.numBones, GL_FALSE, glbonematrix); } }
Vector3 BoxObstacle::HalfExtents::get() { return MV(this->UnmanagedPointer->mHalfExtents); }
move easydecode(char *str) { if (!strcmp(str,"o")||!strcmp(str,"o-o")|| !strcmp(str,"0-0")||!strcmp("O-O",str)) { return (tomove() == WHITE) ? WKC : BKC; } if (!strcmp(str,"o-")||!strcmp(str,"o-o-o")|| !strcmp(str,"0-0-0")||!strcmp("O-O-O",str)) { return (tomove() == WHITE) ? WQC : BQC; } strip(str); if (strlen(str)==5) { /* assume this is the form a7a8q */ /* get promo and remove from string */ chesspiece p = lookup(str[4]); promopiece = chesspiecevalue(p); if ((promopiece<=0)||(promopiece>king)) return dummymove; str[4]=0; } /* e4 */ if (strlen(str)==2) { int ef, er; square s1, s2; ef = str[0]-'a'; er = str[1]-'1'; if (strchr("abcdefgh", str[0]) && strchr("abcdefgh", str[1])) { return decode_pawn_cap(str); } if (offboardp(ef, er)) return dummymove; s2 = SQ(ef,er); s1 = findstart(makepiece(tomove(), pawn), ef, er, 8, 8); return MV(s1,s2); } /* Pe4 ab4 */ if (strlen(str)==3) { int sf, ef, er; square s1 = dummymove, s2; ef = str[1]-'a'; er = str[2]-'1'; if (offboardp(ef, er)) return dummymove; s2 = SQ(ef,er); if (str[0]=='b') { /* if its a valid pawn move it, else look for valid Bishop move */ int v = chesspiecevalue(lookup(str[0])); sf = str[0] - 'a'; s1 = findstart(makepiece(tomove(), pawn), ef, er, sf, 8); if (s1!=dummysq) { return MV(s1,s2); } else if (v) { s1 = findstart(makepiece(tomove(), v), ef, er, 8, 8); return MV(s1,s2); } else return dummysq; } else if (lookup(str[0])) { int v = chesspiecevalue(lookup(str[0])); s1 = findstart(makepiece(tomove(), v), ef, er, 8, 8); } else { sf = str[0] - 'a'; s1 = findstart(makepiece(tomove(), pawn), ef, er, sf, 8); } return (MV(s1,s2)); } /* e2e4 Nbd7 N8d7*/ else if (strlen(str)==4) { int sf, sr, ef, er, v; square s1, s2; sf = str[0]-'a'; sr = str[1]-'1'; ef = str[2]-'a'; er = str[3]-'1'; if (offboardp(ef, er)) return dummymove; if (!offboardp(sf, sr)) return MV(SQ(sf,sr),SQ(ef,er)); s2 = SQ(ef, er); s1 = SQ(sf, sr); switch (str[0]) { case 'P': case 'p': case 'N': case 'n': case 'B': case 'b': case 'R': case 'r': case 'Q': case 'q': case 'K': case 'k': sf = str[1]-'a'; sr = str[1]-'1'; v = chesspiecevalue(lookup(str[0])); if ((sf>=0)&&(sf<=7)) { s1 = findstart(makepiece(tomove(), v), ef, er, sf, 8); return MV(s1, s2); } else { s1 = findstart(makepiece(tomove(), v), ef, er, 8, sr); return MV(s1, s2); } default: return dummymove; } } else return dummymove; }
void cmd_fen(char *s) { char pos[80]; char color; char castling[4]; char enpassante[2]; int halfmove, fullmove; int f, r, i; FILE *in = fopen(s+1, "r"); if (!in) { printf("cmd_fen(): error opening %s\n", s+1); return; } change_gamemode(MIDGAME, 1); fscanf(in, "%s %c %s %s %d %d", pos, &color, castling, enpassante, &halfmove, &fullmove); printf("pos: %s\ncolor: %c\ncastling: %s\nenpassante: %s\n", pos, color, castling, enpassante); for (i=0;i<64;i++) setpiece__(i,empty); f = 0; r = 7; for (i=0;i<strlen(pos);i++) { chesspiece p; if (pos[i]=='/') { r--; f=0; printf("new rank: %d\n", r); } else if ((pos[i]>='1')&&(pos[i]<='9')) { f += pos[i]-'0'; } else if ((p=lookup(pos[i]))) { setpiece(f,r,p); printf("%c @ %c%d\n", rep(p), f+'a',r); f++; } else { printf("unknown character in fen position string: %s[%d]\n", pos, i); exit(EXIT_FAILURE); } } countmaterial(); board->flags = 0; ply = 0; if (!strcmp(enpassante, "-")) { gamestack[ply]=dummymove; } else { int file = enpassante[0]-'a'; int rank = enpassante[1]-'1'; board->flags |= enp; if (rank == 4) gamestack[ply] = MV(SQ(file,6), SQ(file,4)); else if (rank==3) gamestack[ply] = MV(SQ(file,1), SQ(file,3)); else printf("cmd_fen(): error parsing enpassante square\n"); } ply++; if (strchr(castling, 'Q')) board->flags |= wqc; if (strchr(castling, 'K')) board->flags |= wkc; if (strchr(castling, 'q')) board->flags |= bqc; if (strchr(castling, 'k')) board->flags |= bkc; if (color=='w') board->flags &= ~turn_flag; else if (color=='b') board->flags |= turn_flag; else printf("cmd_fen(): error parsing color\n"); }