int main() { int i, off=0, on=1, lports[]=LIGHT_PORTS, pcnt, w=40, m=5; float s; graphics_open(320,240); for(i=0;i<256;i+=5) { graphics_fill(i,i,i); graphics_update(); } SplashBG(320, 240); msleep(1000); graphics_close(); pcnt=NPORTS(lports); for(i=8;i<16;i++) { // change the digital ports to output set_digital_output(i,1); } srand(time(NULL)); // prime random number generation while(1) { table_lights(lports,pcnt,off); // shut off table lights setup(); // team setup (light calibration w/time out option) // setup done, including any time outs so proceed with judge's setup //get_shelf_positions(); // display orange/yellow block set up for judges - 2014 get_bgal_pod_positions(); // display left-right positions for Botgal & pod - 2015 set_a_button_text("QUIT"); set_b_button_text("-"); set_c_button_text("-"); graphics_close(); // close any open graphics graphics_open(3*w,62); display_clear(); display_printf(0,0,"************** BOTBALL 2015 **************"); display_printf(0,1," LIGHTS ON IN"); display_printf(0,2,"******************************************"); display_printf(0,9," Press QUIT to stop count down"); if (countdown_sd(5,1,BLUE,YELLOW,m,w)) continue; s=seconds(); // 2015 table_lights(lports,pcnt,on); // on for 115 seconds display_printf(0,1," GAME CLOCK - LIGHTS ON TILL 5"); if (countdown(120,11,GREEN,BLUE,m,w)) continue; // end 2015 /* // 2014 table_lights(lports,pcnt,on); // on for 15 seconds display_printf(0,1," GAME CLOCK - LIGHTS ON TILL 105"); if (countdown(120,106,GREEN,BLUE,m,w)) continue; table_lights(lports,pcnt,off); // of for 100 seconds display_printf(0,1," GAME CLOCK - LIGHTS OFF TILL 5"); if (countdown(105,11,LTBLUE,RED,m,w)) continue; // end 2014 */ if (countdown(10,6,LTORANGE,BLUE,m,w)) continue; display_printf(0,1," GAME CLOCK - LIGHTS BLINK TILL 0"); i=5+(seconds()-s); if (blinkdown(5,0,RED,YELLOW,m,w,lports,pcnt)) continue; display_printf(0,1," GAME CLOCK - %d ",i); display_printf(0,9," ***** GAME OVER! ***** "); table_lights(lports,pcnt,off); // shut off table lights msleep(5000); // pause display } return 0; }
/* dumpE: */ void dumpE(graph_t * g, int derived) { Agnode_t *n; Agedge_t *e; Agedge_t **ep; Agedge_t *el; int i; int deg; prIndent(); fprintf(stderr, "Graph %s : %d nodes %d edges\n", g->name, agnnodes(g), agnedges(g)); for (n = agfstnode(g); n; n = agnxtnode(g, n)) { deg = 0; for (e = agfstout(g, n); e; e = agnxtout(g, e)) { deg++; prIndent(); fprintf(stderr, " %s -- %s\n", e->tail->name, e->head->name); if (derived) { for (i = 0, ep = (Agedge_t **) ED_to_virt(e); i < ED_count(e); i++, ep++) { el = *ep; prIndent(); fprintf(stderr, " %s -- %s\n", el->tail->name, el->head->name); } } } if (deg == 0) { /* no out edges */ if (!agfstin(g, n)) /* no in edges */ fprintf(stderr, " %s\n", n->name); } } if (!derived) { bport_t *pp; if ((pp = PORTS(g))) { int sz = NPORTS(g); fprintf(stderr, " %d ports\n", sz); while (pp->e) { fprintf(stderr, " %s : %s -- %s\n", pp->n->name, pp->e->tail->name, pp->e->head->name); pp++; } } } }
/* initPositions: * Create initial layout of nodes * TODO : * Position nodes near neighbors with positions. * Use bbox to reset K. */ static pointf initPositions (graph_t* g, bport_t* pp) { int nG = agnnodes (g) - NPORTS (g); double size; Agnode_t* np; int n_pos = 0; /* no. of nodes with position info */ box bb; pointf ctr; /* center of boundary ellipse */ long local_seed; double PItimes2 = M_PI * 2.0; for (np = agfstnode(g); np; np = agnxtnode(g,np)) { if (ND_pinned(np)) { if (n_pos) { bb.LL.x = MIN(ND_pos(np)[0],bb.LL.x); bb.LL.y = MIN(ND_pos(np)[1],bb.LL.y); bb.UR.x = MAX(ND_pos(np)[0],bb.UR.x); bb.UR.y = MAX(ND_pos(np)[1],bb.UR.y); } else { bb.UR.x = bb.LL.x = ND_pos(np)[0]; bb.UR.y = bb.LL.y = ND_pos(np)[1]; } n_pos++; } } size = T_K * (sqrt((double)nG) + 1.0); Wd = Ht = expFactor*(size/2.0); if (n_pos == 1) { ctr.x = bb.LL.x; ctr.y = bb.LL.y; } else if (n_pos > 1) { double alpha, area, width, height, quot; ctr.x = (bb.LL.x + bb.UR.x)/2.0; ctr.y = (bb.LL.y + bb.UR.y)/2.0; width = expFactor*(bb.UR.x - bb.LL.x); height = expFactor*(bb.UR.y - bb.LL.y); area = 4.0*Wd*Ht; quot = (width*height)/area; if (quot >= 1.0) { /* If bbox has large enough area, use it */ Wd = width/2.0; Ht = height/2.0; } else if (quot > 0.0) { /* else scale up to have enough area */ quot = 2.0*sqrt(quot); Wd = width/quot; Ht = height/quot; } else { /* either width or height is 0 */ if (width > 0) { height = area/width; Wd = width/2.0; Ht = height/2.0; } else if (height > 0) { width = area/height; Wd = width/2.0; Ht = height/2.0; } /* If width = height = 0, use Wd and Ht as defined above for * the case the n_pos == 0. */ } /* Construct enclosing ellipse */ alpha = atan2 (Ht, Wd); Wd = Wd/cos(alpha); Ht = Ht/sin(alpha); } else { ctr.x = ctr.y = 0; } Wd2 = Wd*Wd; Ht2 = Ht*Ht; /* Set seed value */ if (smode == seed_val) local_seed = T_seed; else { #ifdef MSWIN32 local_seed = time(NULL); #else local_seed = getpid() ^ time(NULL); #endif } srand48(local_seed); /* If ports, place ports on and nodes within an ellipse centered at origin * with halfwidth Wd and halfheight Ht. * If no ports, place nodes within a rectangle centered at origin * with halfwidth Wd and halfheight Ht. Nodes with a given position * are translated. Wd and Ht are set to contain all positioned points. * The reverse translation will be applied to all * nodes at the end of the layout. * TODO: place unfixed points using adjacent ports or fixed pts. */ if (pp) { while (pp->e) { /* position ports on ellipse */ np = pp->n; ND_pos(np)[0] = Wd * cos(pp->alpha); ND_pos(np)[1] = Ht * sin(pp->alpha); ND_pinned(np) = P_SET; pp++; } for (np = agfstnode(g); np; np = agnxtnode(g,np)) { if (IS_PORT(np)) continue; if (ND_pinned(np)) { ND_pos(np)[0] -= ctr.x; ND_pos(np)[1] -= ctr.y; } else { double angle = PItimes2 * drand48(); double radius = 0.9 * drand48(); ND_pos(np)[0] = radius * Wd * cos(angle); ND_pos(np)[1] = radius * Ht * sin(angle); } } } else { if (n_pos) { /* If positioned nodes */ for (np = agfstnode(g); np; np = agnxtnode(g,np)) { if (ND_pinned(np)) { ND_pos(np)[0] -= ctr.x; ND_pos(np)[1] -= ctr.y; } else { ND_pos(np)[0] = Wd * (2.0*drand48() - 1.0); ND_pos(np)[1] = Ht * (2.0*drand48() - 1.0); } } } else { /* No ports or positions; place randomly */ for (np = agfstnode(g); np; np = agnxtnode(g,np)) { ND_pos(np)[0] = Wd * (2.0*drand48() - 1.0); ND_pos(np)[1] = Ht * (2.0*drand48() - 1.0); } } } return ctr; }