static void pinit(antmazestruct *mp) { glClearDepth(1.0); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_POSITION, position0); glLightfv(GL_LIGHT1, GL_AMBIENT, ambient); glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT1, GL_POSITION, position1); glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05); glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.001); glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1); glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.05); glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.001); glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 0.1); /* glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); */ /* glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); */ glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_NORMALIZE); glFrontFace(GL_CCW); glCullFace(GL_BACK); /* antmaze */ glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glDisable(GL_TEXTURE_2D); /* setup textures */ makeCheckImage(mp); makeBrushedImage(mp); build_board(mp, 0); build_board(mp, 1); /* makeCheckImage(); */ /* glPixelStorei(GL_UNPACK_ALIGNMENT, 1); */ /* glTexImage2D(GL_TEXTURE_2D, 0, 3, checkImageWidth, */ /* checkImageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, checkers); */ /* glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); */ /* glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); */ /* glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); */ /* glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); */ /* glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); */ glEnable(GL_TEXTURE_2D); /* glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess); */ /* glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular); */ }
void Board::build_board(int rows, int cols) { //cout << "enter readBoard" << endl; string row_string; unsigned int read_cols; cin >> rows; cin >> cols; //cout << "rows: " << rows << endl; //cout << "cols: " << cols << endl; read_cols = cols; build_board(); for (int i = 0; i < rows; ++i){ if(cin >> row_string && row_string.length() == read_cols){ for (int j = 0; j < cols; ++j){ board[i][j].l.c = toupper(row_string[j]); board[i][j].l.row = i; board[i][j].l.col = j; board[i][j].visited = false; } } else { return false; } }
gameClient::gameClient() { ClientCorner temps; vector<int> tempvec; // corner_index = xy; for (int x = 0; x < MAX_NUM_ACTIVE_TILES; x++) { for (int xy = 0; xy < 6; xy++) { temps.corner_index = xy; temps.players_connected = tempvec; temps.property_owner = 0; temps.property_type = 0; temps.road_connected = 0; board[x].init_corners(temps); } } build_board(); }
/* * Send a board update message to all connected clients * * Excludes the user with write acces if the parameter * excl_w is set to 1. If the blackbpard should be broadcasted to all * connected clients, excl_w shoul be 0. */ void broadcast_blackboard(char *blackboard, int bsem_id, int excl_w) { struct cl_entry *current; struct net_board *board; int ret; int length; /* * Prepare the blackboard message */ lock_sem(bsem_id); length = strlen(blackboard); board = build_board(blackboard, length); unlock_sem(bsem_id); /* * Iterate over the complete client list * This locks the mutex of the client list */ current = start_iteration(); while (current != NULL) { /* Don't broadcast to the user with write access */ if ((current == get_write_user()) && excl_w) { current = iteration_next(); continue; } ret = send(current->cdata->sfd, board, sizeof(struct net_header) + length, 0); if (ret < 0) { perror("send"); } /* Select next client in list */ current = iteration_next(); } /* Unlock mutex of client list */ end_iteration(); free(board); log_debug("broadcasting agent: blackboard sent to all connected clients"); }
static void update_ants(antmazestruct *mp) { int i; GLfloat df[4]; df[0] = df[1] = df[2] = 0.8*mp->fadeout; df[3] = 1.0; /* fade out */ if(mp->fadeoutspeed < -0.00001) { if(mp->fadeout <= 0.0) { /* switch boards: rebuild old board, increment current */ mp->currentboard = (mp->currentboard+1)%BOARDCOUNT; build_board(mp, mp->currentboard); mp->fadeoutspeed = 0.02; } mp->fadeout += mp->fadeoutspeed; glLightfv(GL_LIGHT0, GL_DIFFUSE, df); glLightfv(GL_LIGHT1, GL_DIFFUSE, df); } /* fade in */ if(mp->fadeoutspeed > 0.0001) { mp->fadeout += mp->fadeoutspeed; if(mp->fadeout >= 1.0) { mp->fadeout = 1.0; mp->fadeoutspeed = 0.0; mp->entroducing = 12; } glLightfv(GL_LIGHT0, GL_DIFFUSE, df); glLightfv(GL_LIGHT1, GL_DIFFUSE, df); } for(i = 0; i < ANTCOUNT; ++i) { if(!mp->anton[i] && mp->elevator < 1.0) { /* turn on ant */ if(mp->entroducing > 0 && mp->introduced <= 0 && random()%100 == 0) { mp->anton[i] = 1; mp->part[i] = 0; mp->antsize[i] = 0.0; mp->antposition[i][0] = -4.0; mp->antposition[i][1] = 5.0; mp->antdirection[i] = PI/2.0; mp->bposition[i][0] = 0; mp->bposition[i][1] = 8; mp->introduced = 300; mp->entroducing--; } continue; } if(mp->part[i] == 0 && mp->antsize[i] < 1.0) { mp->antsize[i] += 0.02; continue; } if(mp->part[i] > mp->antpathlength[i] && mp->antsize[i] > 0.0) { mp->antsize[i] -= 0.02; if(mp->antvelocity[i] > 0.0) { mp->antvelocity[i] -= 0.02; } else { mp->antvelocity[i] = 0.0; } continue; } if(mp->part[i] > mp->antpathlength[i] && mp->antsize[i] <= 0.0) { mp->antvelocity[i] = 0.02; /* if(i != 0) { */ antmaterial[i] = materials[random()%MATERIALS]; /* } */ mp->antdirection[i] = PI/2.0; mp->bposition[i][0] = 0; mp->bposition[i][1] = 8; mp->part[i] = 0; mp->antsize[i] = 0.0; mp->anton[i] = 0; mp->antposition[i][0] = -4.0; mp->antposition[i][1] = 5.0; /* /\* reset camera *\/ */ /* if(i == focus) { */ /* started = 0; */ /* ant_step = 0.0; */ /* } */ /* check for the end */ if(mp->entroducing <= 0) { int ao = 0, z = 0; for(z = 0; z < ANTCOUNT; ++z) { if(mp->anton[z]) { ao = 1; break; } } if(ao == 0) { mp->fadeoutspeed = -0.02; } } } /* near goal, bend path towards next step */ if(near(mp->antposition[i], mp->antpath[i][mp->part[i]])) { ++mp->part[i]; /* /\* special first ant *\/ */ /* if(i == 0 && part[i] > antpathlength[i]) { */ /* if(fir) */ /* first_ant_step = ant_step; */ /* antvelocity[i] = 0.0; */ /* /\* antposition[i][2] += 0.025; *\/ */ /* elevator += 0.025; */ /* /\* set light *\/ */ /* double l1 = 1.0 - (elevator < 1.0 ? elevator : 2.0 - elevator); */ /* GLfloat df[4] = {0.8*l1, 0.8*l1, 0.8*l1, 1.0}; */ /* glLightfv(GL_LIGHT0, GL_DIFFUSE, df); */ /* glLightfv(GL_LIGHT1, GL_DIFFUSE, df); */ /* /\* draw next board *\/ */ /* if(elevator > 1.0) { */ /* if(makenew == 1) { */ /* int re; */ /* /\* switch boards: rebuild old board, increment current *\/ */ /* currentboard = (currentboard+1)%BOARDCOUNT; */ /* build_board(currentboard); */ /* for(re = 1; re < ANTCOUNT; ++re) { */ /* anton[re] = 0; */ /* antmaterial[re] = materials[random()%MATERIALS]; */ /* } */ /* makenew = 0; */ /* } */ /* /\* draw the other board *\/ */ /* glEnable(GL_TEXTURE_2D); */ /* glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray6); */ /* glPushMatrix(); */ /* glTranslatef(-(-(BOARDSIZE-3.5)+(BOARDSIZE-1)/2.0), 0.0, */ /* -(2.4+BOARDSIZE+(BOARDSIZE-1)/2.0)); */ /* draw_board(mi, mp); */ /* glPopMatrix(); */ /* glDisable(GL_TEXTURE_2D); */ /* } */ /* /\* reset *\/ */ /* if(elevator > 2.0) { */ /* antposition[i][0] = -4.0;/\*-= -(-(BOARDSIZE-3.5)+(BOARDSIZE-1)/2.0);*\//\*= -4.0;*\/ */ /* antposition[i][1] = 5.5;/\*-(2.4+BOARDSIZE+(BOARDSIZE-1)/2.0);*\/ */ /* /\* antposition[i][2] = 0.15; *\/ */ /* antdirection[i] = PI/2.0; */ /* bposition[i][0] = 0; */ /* bposition[i][1] = 8; */ /* part[i] = 0; */ /* antvelocity[i] = 0.02; */ /* fir = 0; */ /* antmaterial[i] = MaterialRed; */ /* makenew = 1; */ /* elevator = 0.0; */ /* introduced = 200; */ /* } */ /* else { */ /* part[i]--; */ /* } */ /* } */ } /* move toward goal, correct ant direction if required */ else { /* difference */ double dx = mp->antpath[i][mp->part[i]][0] - mp->antposition[i][0]; double dz = - mp->antpath[i][mp->part[i]][1] + mp->antposition[i][1]; double theta, ideal; if(dz > EPSILON) theta = atan(dz/dx); else theta = dx > EPSILON ? 0.0 : PI; ideal = theta - mp->antdirection[i]; if(ideal < -Pi/2.0) ideal += Pi; /* compute correction */ { double dt = sign(ideal) * min(fabs(ideal), PI/90.0); mp->antdirection[i] += dt; if(mp->antdirection[i] > 2.0*PI) mp->antdirection[i] = 0.0; } } mp->antposition[i][0] += mp->antvelocity[i] * cos(mp->antdirection[i]); mp->antposition[i][1] += mp->antvelocity[i] * sin(-mp->antdirection[i]); } }
int main(void) { identify(build_board(bufferize())); return (0); }