void UmlOperation::generate_index() { unsigned n = opers.size(); if (n != 0) { sort(opers); start_file("public_operations", "Public Operations Index", TRUE); fw.write("<table>\n"); fw.write("<tr bgcolor=\"#f0f0f0\"><td align=\"center\"><b>Operation</b></td><td align=\"center\"><b>Class</b></td><td align=\"center\"><b>Description</b></td></tr>\n"); for (unsigned i = 0; i != n; i += 1) { UmlItem * op = opers.elementAt(i); fw.write("<tr bgcolor=\"#f0f0f0\"><td>"); op->write(); fw.write("</td><td>"); op->parent()->write(); fw.write("</td><td>"); writeq(op->description()); fw.write("</td></tr>\n"); } fw.write("</table>\n"); end_file(); } }
//! Namely: //! - The king and the rook towards which the king moves have not moved during the game. //! - The king is not in check. //! - All of the squares between the king and rook are vacant. //! - The king does not cross a square that is attacked by an opponent's piece. //! \param board The board on which castling is being considered. //! \returns Whether the current board position allows for castling. bool Castle::move_specific_legal(const Board& board) const { auto skipped_file = (start_file() + end_file())/2; return ! board.piece_has_moved(start_file(), start_rank()) && ! board.piece_has_moved(rook_starting_file, start_rank()) && ! board.king_is_in_check() && board.all_empty_between(start_file(), start_rank(), rook_starting_file, start_rank()) && board.safe_for_king(skipped_file, start_rank(), board.whose_turn()); }
int main(int argc, char* argv[]) { if (argc < 5) usage("Too few parameters"); if (argc > 7) usage("Too many parameters"); logacct = getpwnam(argv[1]); maindir = argv[2]; logdir = argv[3]; if (maindir[0] != '/' || logdir[0] != '/') die1(1, "Directory names must start with /."); cvmpath = argv[4]; if (argc > 5) { ip = argv[5]; if (argc > 6) dochroot = argv[6]; } if (!logacct) die1(1, "Unknown logacct user name"); umask(0); if (mkdir(maindir, 0755) == -1) die1sys(1, "Error creating main directory"); if (chmod(maindir, 01755) == -1) die1sys(1, "Error setting permissions on main directory"); if (mkdir(logdir, 0700) == -1) die1sys(1, "Error creating log directory"); if (chown(logdir, logacct->pw_uid, logacct->pw_gid) == -1) die1sys(1, "Error setting owner on log directory"); if (chdir(maindir) == -1) die1sys(1, "Error changing to main directory"); if (mkdir("log", 0755) == -1) die1sys(1, "Error creating log service directory"); if (mkdir("env", 0755) == -1) die1sys(1, "Error creating env directory"); start_file("run", 0755); obuf_put5s(&conf_out, "#!/bin/sh\n" "exec 2>&1\n" "umask 022\n" "exec \\\n" "tcpserver -DRHv -llocalhost ", ip, " 21 \\\n" "envdir ", maindir, "/env \\\n"); obuf_put7s(&conf_out, "softlimit -m 2000000 \\\n", conf_bin, "/twoftpd-auth \\\n", cvmpath, " \\\n", conf_bin, "/twoftpd-xfer"); end_file(); make_file("log/run", 0755, "#!/bin/sh\n" "exec \\\n" "setuidgid ", logacct->pw_name, " \\\n" "multilog t ", logdir, 0, 0, 0); if (dochroot) make_fileu("env/CHROOT", 1); return 0; }
static int emit_header(lcmgen_t *lcm, lcm_struct_t *ls) { start_file("_new"); // define the class emit(0, "function S = %s_new()", sn); emit(1, "S = struct(..."); // data members int const members = g_ptr_array_size(ls->members); for (unsigned int mx = 0; mx < members; mx++) { lcm_member_t *lm = (lcm_member_t *) g_ptr_array_index(ls->members, mx); char* lm_tnc = dots_to_double_colons(lm->type->lctypename); emit_start(2, "'%s', ", lm->membername); int const dimensions = g_ptr_array_size(lm->dimensions); int const primitive = lcm_is_primitive_type(lm->type->lctypename); if (0 == dimensions) { emit_continue("%s%s", map_type_name(lm_tnc) , primitive ? "(0)" : "_new()"); } else { emit_continue("repmat( %s%s, [", map_type_name(lm_tnc), primitive ? "(0)" : "_new()"); for (int dx = 0; dx < dimensions - 1; ++dx) { lcm_dimension_t *dim = (lcm_dimension_t *) g_ptr_array_index(lm->dimensions, dx); emit_continue("%s, ", dim->size); } lcm_dimension_t *dim = (lcm_dimension_t*) g_ptr_array_index(lm->dimensions, dimensions - 1); emit_continue("%s%s] )", dim->size, dimensions == 1 ? ", 1" : ""); } emit_end("%s", (members == mx + 1 ? " );" : ",...")); } emit(0, "%%endfunction"); emit(0, ""); // // constants TODO // if (g_ptr_array_size(ls->constants) > 0) { // emit(1, "public:"); // for (unsigned int i = 0; i < g_ptr_array_size(ls->constants); i++) { // lcm_constant_t *lc = (lcm_constant_t *) g_ptr_array_index(ls->constants, i); // assert(lcm_is_legal_const_type(lc->lctypename)); // // const char *suffix = ""; // if (!strcmp(lc->lctypename, "int64_t")) // suffix = "LL"; // char const * mapped_typename = map_type_name(lc->lctypename); // emit(2, "static const %-8s %s = %s%s;", mapped_typename, // lc->membername, lc->val_str, suffix); // //free(mapped_typename); // } // emit(0, ""); // } // emit(9, "};"); // // free(tn_); end_file(); }
static int emit_encoded_size_nohash(lcmgen_t *lcm, lcm_struct_t *ls) { start_file("_encodedSize_nohash"); emit(0, "function s = %s_encodedSize_nohash(S)", sn); emit(1, "s = uint32(0);"); for (unsigned int m = 0; m < g_ptr_array_size(ls->members); m++) { lcm_member_t *lm = (lcm_member_t *) g_ptr_array_index(ls->members, m); char* lm_tnc = dots_to_double_colons(lm->type->lctypename); int const encsize = encoded_size(lm_tnc); int const dimensions = g_ptr_array_size(lm->dimensions); if (encsize > -1) {//known constant size emit_start(1, "s = s + %d", encsize); for (int dx = 0; dx < dimensions; ++dx) { lcm_dimension_t *dim = (lcm_dimension_t*) g_ptr_array_index(lm->dimensions, dx); emit_continue(" * %s", dim->size); } emit_end(";"); } else { if (0 == dimensions) { emit(1, "s = s + %s_encodedSize_nohash(S.%s);", map_type_name(lm_tnc), lm->membername); } else { //emit: for each dimension for (int dx = 0; dx < dimensions; ++dx) { lcm_dimension_t *dim = (lcm_dimension_t*) g_ptr_array_index(lm->dimensions, dx); emit(1 + dx, "for dx%d = 1:%s", dx, dim->size); } {//do emit_start(1 + dimensions, "s = s + %s_encodedSize_nohash(S.%s(", map_type_name(lm_tnc), lm->membername); for (int dx = 0; dx < dimensions - 1; ++dx) { emit_continue("dx%d,", dx); } emit_end("dx%d));", dimensions - 1); } //end for (int dx = dimensions; dx > 0; --dx) { emit(dx, "end"); } } } free(lm_tnc); } emit(0, "%%endfunction"); emit(0, ""); end_file(); }
static int emit_encoded_size(lcmgen_t *lcm, lcm_struct_t *ls) { start_file("_encodedSize"); emit(0, "function bytes = %s_encodedSize(S)", sn); emit(1, "bytes = uint32(8) + %s_encodedSize_nohash(S);", sn); emit(0, "%%endfunction"); emit(0, ""); end_file(); }
static int emit_encode(lcmgen_t *lcm, lcm_struct_t *ls) { start_file("_encode"); emit(0, "function [buf, pos] = %s_encode(buf, pos, maxlen, S)", sn); emit(1, "hash = %s_hash();", sn); emit(1, "[buf, pos] = int64_encode_nohash(buf, pos, maxlen, hash, 1);"); emit(1, "[buf, pos] = %s_encode_nohash(buf, pos, maxlen, S, 1);", sn); emit(0, "%%endfunction"); emit(0, ""); end_file(); }
static int emit_decode_nohash(lcmgen_t *lcm, lcm_struct_t *ls) { start_file("_decode_nohash"); emit(0, "function [pos, S] = %s_decode_nohash(buf, pos, maxlen, S, elems)", sn); emit(1, "for ix = 1:elems"); for (unsigned int m = 0; m < g_ptr_array_size(ls->members); m++) { lcm_member_t *lm = (lcm_member_t *) g_ptr_array_index(ls->members, m); char* lm_tnc = dots_to_double_colons(lm->type->lctypename); int const dimensions = g_ptr_array_size(lm->dimensions); if (0 == dimensions) { emit(2, "[pos, t] = %s_decode_nohash(buf, pos, maxlen, S(ix).%s, 1);", map_type_name(lm_tnc), lm->membername); emit(2, "S(ix).%s = t(1);", lm->membername); } else { //emit: for each dimension for (int dx = 0; dx < dimensions - 1; ++dx) { lcm_dimension_t *dim = (lcm_dimension_t*) g_ptr_array_index(lm->dimensions, dx); emit(2 + dx, "for dx%d = 1:%s", dx, dim->size); } {//do emit_start(1 + (dimensions > 1 ? dimensions : 1), "[pos, t] = %s_decode_nohash(buf, pos, maxlen, S(ix).%s(", map_type_name(lm_tnc), lm->membername); for (int dx = 0; dx < dimensions - 1; ++dx) { emit_continue("dx%d,", dx); } lcm_dimension_t *dim = (lcm_dimension_t*) g_ptr_array_index(lm->dimensions, dimensions - 1); emit_end(":), %s);", dim->size); emit_start(1 + (dimensions > 1 ? dimensions : 1), "S(ix).%s(", lm->membername); for (int dx = 0; dx < dimensions - 1; ++dx) { emit_continue("dx%d,", dx); } emit_end(":) = t(1:%s);", dim->size); } //end for (int dx = dimensions - 1; dx > 0; --dx) { emit(1 + dx, "end"); } } free(lm_tnc); } emit(1, "end"); emit(0, "%%endfunction"); end_file(); }
static int emit_get_hash(lcmgen_t *lcm, lcm_struct_t *ls) { start_file("_hash"); emit(0, "function hash = %s_hash()", sn); emit(1, "hash = uint32([0, 0]);"); emit(1, "persistent %s_hash_value;", sn); emit(1, "if isempty(%s_hash_value)", sn); emit(2, "%s_hash_value = %s_computeHash([]);", sn, sn); emit(1, "end"); emit(1, "hash = %s_hash_value;", sn); emit(0, "%%endfunction"); emit(0, ""); end_file(); }
void UmlClass::html() { QCString s; UmlCom::message(name()); if (stereotype() == "stereotype") start_file("stereotype" + s.setNum((unsigned) getIdentifier()), "Stereotype " + name(), TRUE); else if (stereotype() == "metaclass") start_file("metaclass" + s.setNum((unsigned) getIdentifier()), "Metaclass " + name(), TRUE); else start_file("class" + s.setNum((unsigned) getIdentifier()), "Class " + name(), TRUE); define(); gen_html("", 0, 0); end_file(); unload(FALSE, FALSE); }
void UmlClass::generate_index() { UmlItem::generate_index(classes, "Classes", "classes"); int n = classes.size(); start_file("classes_list", "Classes", FALSE); fw.write("<table border=\"0\" width=\"100%\">\n<tr>\n<td nowrap=\"nowrap\">"); for (int i = 0; i != n; i += 1) { classes.elementAt(i)->write("projectFrame"); fw.write("<br />\n"); } fw.write("</td>\n</tr>\n</table>\n"); end_file(); }
static int emit_compute_hash(lcmgen_t *lcm, lcm_struct_t *ls) { start_file("_computeHash"); emit(0, "function hash = %s_computeHash(parents)", sn); emit(1, "parents_len = length(parents);"); emit(1, "parents = [parents, %zu, '%s'];", strlen(sn), sn); emit(0, ""); emit(1, "hash = hex2int64('%016"PRIx64"');", ls->hash); for (unsigned int m = 0; m < g_ptr_array_size(ls->members); m++) { lcm_member_t *lm = (lcm_member_t *) g_ptr_array_index(ls->members, m); if(!lcm_is_primitive_type(lm->type->lctypename)) { char* lm_tnc = dots_to_double_colons(lm->type->lctypename); emit(1, "visit = true;"); emit(1, "ix = uint32(1);"); emit(1, "while ix < parents_len"); emit(2, "p_len = uint32(parents(ix));"); emit(2, "if %zu == p_len && strcmp(parents(ix + 1: ix + p_len), '%s')", strlen(lm_tnc), lm_tnc); emit(3, "visit = false;"); emit(3, "break"); emit(2, "end"); emit(2, "ix = ix + p_len + 1;"); emit(1, "end"); emit(1, "if visit"); emit(2, "hash = add_overflow(hash, %s_computeHash(parents));", lm_tnc); emit(1, "end"); emit(0, ""); free(lm_tnc); } } emit(1, "%%wrap around shift"); emit(1, "overflowbit = bitshift(hash(2), -31);"); emit(1, "bigendbit = bitshift(hash(1), -31);"); emit(1, "hash = bitshift(hash, 1);"); emit(1, "hash(1) = bitor(hash(1), overflowbit);"); emit(1, "hash(2) = bitor(hash(2), bigendbit);"); emit(0, "%%endfunction"); emit(0, ""); end_file(); }
static int emit_decode(lcmgen_t *lcm, lcm_struct_t *ls) { start_file("_decode"); emit(0, "function [pos, S] = %s_decode(buf, pos, maxlen, S)", sn); emit(1, "hash = uint32([0, 0]);"); emit(1, "hash(1:2) = %s_hash();", sn); emit(1, "readHash = uint32([0, 0]);"); emit(1, "[pos, readHash] = int64_decode_nohash(buf, pos, maxlen, readHash, 1);"); emit(1, "if pos < 1 || readHash(1) ~= hash(1) || readHash(2) ~= hash(2)"); emit(2, "pos = -1;"); emit(1, "else"); emit(2, "[pos, S] = %s_decode_nohash(buf, pos, maxlen, S, 1);", sn); emit(1, "end"); emit(0, "%%endfunction"); emit(0, ""); end_file(); }
void xm_from() { unsigned long data_size, rsrc_size; char text[64]; if(receive_sync() == ACK) { receive_part(info, DATABYTES, 1); transname(info + I_NAMEOFF + 1, text, info[I_NAMEOFF]); define_name(text); data_size = get4(info + I_DLENOFF); rsrc_size = get4(info + I_RLENOFF); start_info(info, rsrc_size, data_size); start_data(); receive_part(out_buffer, data_size, 1); start_rsrc(); receive_part(out_buffer, rsrc_size, 0); end_file(); } }
bool Alan_Turing_AI::is_considerable(const Move& move, const Board& board) const { // Recapture is considerable if(board.last_move_captured() && board.move_captures(move)) { auto last_move = board.game_record().back(); if(last_move->end_file() == move.end_file() && last_move->end_rank() == move.end_rank()) { return true; } } auto attacking_piece = board.piece_on_square(move.start_file(), move.start_rank()); auto attacked_piece = board.piece_on_square(move.end_file(), move.end_rank()); if(attacked_piece) { // Capturing an undefended piece is considerable auto temp_board = board; auto result = temp_board.submit_move(move); if(temp_board.safe_for_king(move.end_file(), move.end_rank(), attacking_piece->color())) { return true; } // Capturing with a less valuable piece is considerable if(piece_value(attacked_piece) > piece_value(attacking_piece)) { return true; } // A move resulting in checkmate is considerable if(result.winner() == board.whose_turn()) { return true; } } return false; }