Example #1
0
straight plane::cross(const plane &pl) const 
{
  pvecerror("point plane::cross(plane &pl)");
  point plpiv=pl.Gpiv();
  vec pldir=pl.Gdir();
  vec a=dir || pldir; //direction of the overall straight lines
  if(length(a)==0)
  {
    if(plpiv == piv || check_par(pldir, dir, 0.0)!=0)
    {       // planes coinsides
      vecerror=3; return straight();
    }
    else
    {
//		cerr<<"plane::cross : straight is parallel to plane\n";
      vecerror=2; return straight();
    }
  }
  a=unit_vec(a);
  vec c=a || dir;  //perpend. for ov. str.
  straight st(piv,c);
  point pt=pl.cross(st);   //one point on ov. str.
  return straight(pt,a);     //overall straight
}
static void
vrml_bezier(GVJ_t *job, pointf * A, int n, int arrow_at_start, int arrow_at_end, int filled)
{
    obj_state_t *obj = job->obj;
    edge_t *e = obj->u.e;
    double fstz, sndz;
    pointf p1, V[4];
    int i, j, step;

    assert(e);

    fstz = Fstz = obj->tail_z; 
    sndz = Sndz = obj->head_z;
    if (straight(A,n)) {
	doSegment (job, A, gvrender_ptf(job, ND_coord(agtail(e))),Fstz,gvrender_ptf(job, ND_coord(aghead(e))),Sndz);
	return;
    }

    gvputs(job,   "Shape { geometry Extrusion  {\n");
    gvputs(job,   "  spine [");
    V[3] = A[0];
    for (i = 0; i + 3 < n; i += 3) {
	V[0] = V[3];
	for (j = 1; j <= 3; j++)
	    V[j] = A[i + j];
	for (step = 0; step <= BEZIERSUBDIVISION; step++) {
	    p1 = Bezier(V, 3, (double) step / BEZIERSUBDIVISION, NULL, NULL);
	    gvprintf(job, " %.3f %.3f %.3f", p1.x, p1.y,
		    interpolate_zcoord(job, p1, A[0], fstz, A[n - 1], sndz));
	}
    }
    gvputs(job,   " ]\n");
    gvprintf(job, "  crossSection [ %.3f %.3f, %.3f %.3f, %.3f %.3f, %.3f %.3f ]\n",
	    (obj->penwidth), (obj->penwidth), -(obj->penwidth),
	    (obj->penwidth), -(obj->penwidth), -(obj->penwidth),
	    (obj->penwidth), -(obj->penwidth));
    gvputs(job,   "}\n");
    gvprintf(job, " appearance DEF E%ld Appearance {\n", AGSEQ(e));
    gvputs(job,   "   material Material {\n");
    gvputs(job,   "   ambientIntensity 0.33\n");
    gvprintf(job, "   diffuseColor %.3f %.3f %.3f\n",
	    obj->pencolor.u.rgba[0] / 255.,
	    obj->pencolor.u.rgba[1] / 255.,
	    obj->pencolor.u.rgba[2] / 255.);
    gvputs(job,   "   }\n");
    gvputs(job,   " }\n");
    gvputs(job,   "}\n");
}
Example #3
0
bool WayMergeManipulation::_directConnect(const OsmMapPtr& map, WayPtr w) const
{
  boost::shared_ptr<LineString> ls = ElementConverter(map).convertToLineString(w);

  CoordinateSequence* cs = GeometryFactory::getDefaultInstance()->getCoordinateSequenceFactory()->
    create(2, 2);

  cs->setAt(map->getNode(w->getNodeId(0))->toCoordinate(), 0);
  cs->setAt(map->getNode(w->getLastNodeId())->toCoordinate(), 1);

  // create a straight line and buffer it
  boost::shared_ptr<LineString> straight(GeometryFactory::getDefaultInstance()->createLineString(cs));
  boost::shared_ptr<Geometry> g(straight->buffer(w->getCircularError()));

  // is the way in question completely contained in the buffer?
  return g->contains(ls.get());
}
Example #4
0
File: adlint.c Project: gembaf/wint
// テイクによる制限をかける関数 制限する必要が無いならDEFAULT_NUM(10)を返す
int limit_take(int cg, int tk, Handcard hands[], Cards remain_card, Cards hand_card, Cards deck_card, int hd[])
{
  int t;
  int k; // 反復変数
  int flag = 0; 

  if ( tk == 0 ) {
    if ( check_straight(remain_card, hand_card) >= 1 ) { flag = 1; }
    for ( k = 0; k < 4; k++ ) { if ( hand_card.sut[k] >= 4 ) { flag = 1; } }
    if ( poker_point(hd) >= P3 ) { flag = 1; }
    if ( flag == 0 ) { return -1; }
  }

  if ( tk == 1 ) {
    for ( k = 0; k < 4; k++ ) { if ( hand_card.sut[k] >= 4 ) { flag = 1; } }
    if ( check_straight(remain_card, hand_card) >= 3 ) { flag = 1; }
    if ( poker_point(hd) >= P3 ) { flag = 1; }
    if ( flag == 0 ) { return -1; }
  }

  if ( tk == 4 && deck_card.amount <= 11 ) { return -1; }
  if ( tk == 3 && deck_card.amount <= 22 ) { return -1; }
  /* if ( tk == 2 && deck_card.amount <= 33 ) { return -1; } */

  // テイクによる交換回数の制限
  if ( tk < 3 && cg >= 4 ) {
    for ( k = 0; k < 4; k++ ) {
      if ( hand_card.sut[k] >= 4 ) {
        return flush(hands, hand_card, deck_card, cg);
      }
    }
    if ( check_straight(remain_card, hand_card) >= 1 ) {
      return straight(hands, remain_card, hand_card, deck_card, cg);
    }
    if ( poker_point(hd) >= P3 ) {
      return pair(hands, hand_card, deck_card, remain_card);
    }
    return -1;
  }
  // 最後のtakeは別関数
  if ( tk == 5 ) { return final_attack(hands, remain_card, hand_card, deck_card, cg); }
  return DEFAULT_NUM;
}
Example #5
0
//get the card power, as follow:
//royal flush: 900 + all the cards values
//straight flush: 800 + all the cards values
//four of a kind: 700 + all the cards values
//full house: 600 + all the cards values
//flush: 500 + all the cards values
//straight: 400 + all the cards values
//three of a kind: 300 + all the cards values
//two pairs: 200 + all the cards values
//pair: 100 + all the cards values
//high card: sum of all the cards value (5 * 13 will never be more than 100 so...)
int getHandPower(Card c[5]) {
    p = sumCardNums(c, 0);
    p += sumCardNums(c, 1);
    sortCards(c);

    if(royalFlush(c)) {
        p += 900;
        return p;
    }
    if(straightFlush(c)) {
        p += 800;
        return p;
    }
    if(fourOfAKind(c)) {
        p += 700;
        return p;
    }
    if(fullHouse(c)) {
        p += 600;
        return p;
    }
    if(flush(c)) {
        p += 500;
        return p;
    }
    if(straight(c)) {
        p += 400;
        return p;
    }
    if(threeOfAKind(c)) {
        p += 300;
        return p;
    }
    if(twoPairs(c)) {
        p += 200;
        return p;
    }
    if(pair(c)) {
        p += 100;
        return p;
    }
    return p; 
}
Example #6
0
/**
 *  Determines an integer value which represents the quality of a hand. The higher the number the better the hand.
 *
 *  @param hand  array of integers which represent cards in a deck
 *  @param wFace character array representing face names
 *  @param wSuit character array representing suit names
 *
 *  @return a integer value representing the quality of the hand
 */
int qualityOfHand(int hand[], const char *wFace[], const char *wSuit[]){
    int quality = 0;
    if(straight(hand, wFace) == 1){
        quality = 6;
    }else if(flush(hand, wSuit) == 1){
        quality = 5;
    }else if(fourOfAKind(hand, wFace) == 1){
        quality = 4;
    }else if(threeOfAKind(hand, wFace) == 1){
        quality = 3;
    }else if(twoPair(hand, wFace) == 1){
        quality = 2;
    }else if(onePair(hand, wFace) == 1){
        quality = 1;
    }else{
        quality = 0;
    }
    return quality;
}
Example #7
0
void firstlap()
{
	if(myposX == startX && myposY == startY && mydirection == 1 && !start)
	{
		stopp();
		onelap = 1;
		start = 1;

		straight();

		start_request = 1;
		TransmitComm(firstdone); // Berätta för komm att första varvet är klart
		start_request = 0;
	}
	else
	{
		regulateright();
	}
}
Example #8
0
//Move forward a number of blocks at fastest posible speed
void moveForwardBlocks(int count)
{
	//Make the robot go forward
	setDirection(0, 0);

	int mouseFastSpeed = 2500;
	
	//Adjust speed based off of set speed mode
	if(mouse.speedMode == SLOW_MODE)
		mouseFastSpeed = 2500;
	else if(mouse.speedMode == MEDIUM_MODE)
		mouseFastSpeed = 3500;
	else if(mouse.speedMode == FAST_MODE)
		mouseFastSpeed = 6000;
	else if(mouse.speedMode == SUPER_MODE)
		mouseFastSpeed = 8000;
	
	//Move mouse
	straight(762*count-0, mouse.velocity, mouseFastSpeed, mouse.maxVelocity, mouse.acceleration, mouse.deceleration);
}
Example #9
0
/**
 *  Takes a array array of cards and distributes them among each player
 *
 *  @param hands array of hands to be filled
 *  @param wDeck array of cards
 *  @param wFace character array representing face names
 *  @param wSuit character array representing suit names
 */
void deal(int hands[][5], unsigned int wDeck[][FACES], const char *wFace[],const char *wSuit[]){
    size_t card; // card counter
    size_t row; // row counter
    size_t column; // column counter
    
    for(int player = 0; player < PLAYERS; player++){
        printf("Player %d: \n\n", player + 1);
        // deal each of the cards
        for ( card = 0; card < 5; card++ ) {
            // loop through rows of wDeck
            for ( row = 0; row < SUITS; ++row ) {
                // loop through columns of wDeck for current row
                for ( column = 0; column < FACES; column++ ) {
                    // if slot contains current card, display card
                    if ( wDeck[ row ][ column ] == card + 1 + (player * 5)) {
                        printf( "%5s of %-8s\n", wFace[column], wSuit[row]);
                        hands[player][card] = (int)((column) + (row * FACES));
                    }
                }
            }
        }
        
        printf("\n"); //Spacer
        if(straight(hands[player], wFace) == 1){
            printf("> [You have a striaght]\n\n");
        }else if(flush(hands[player], wSuit) == 1){
            printf("> [You have flush]\n\n");
        }else if(fourOfAKind(hands[player], wFace) == 1){
            printf("> [You have four of a kind]\n\n");
        }else if(threeOfAKind(hands[player], wFace) == 1){
            printf("> [You have three of a kind]\n\n");
        }else if(twoPair(hands[player], wFace) == 1){
            printf("> [You have two pairs]\n\n");
        }else if(onePair(hands[player], wFace) == 1){
            printf("> [You have a pair]\n\n");
        }else{
            printf("> [You have nothing]\n\n");
        }
    }
}
Example #10
0
int main(void)
{
	TRISA = 0xFC; /* A 0,1:output, 2,3,4:input */
	TRISB = 0xC7; /* B0,1,2:input, B3,4,5:LEDoutput, other bits input */
	PORTB = 0;    /* PORTB clear */
	PORTA = 0;    /* PORTA clear */
	last_time=STRAIGHT;
	while(RA4==1){
		led_sens();
	}
	while(1){/* 無限ループ */
		led_sens();
		if(RB0==1 && RB1==1 && RB2==1 && last_time==LEFT_DOWN){
			left_down();  /*"White White White" and "LEFT_DOWN last time"*/
			last_time=LEFT_DOWN;	     /* turn left */
		}
		else if(RB0==1 && RB1==1 && RB2==1 && last_time==RIGHT_DOWN){
			right_down(); /*"White White White" and "RIGHT_DOWN last time"*/
			last_time=RIGHT_DOWN;	     /* turn right */
		}
		else if(RB0==0 && RB1==0 && RB2==1){ /* Black Black White */
			small_left_down();           /* turn left a little */
			last_time=LEFT_DOWN;
		}
		else if(RB0==0 && RB1==1 && RB2==1){ /* Black White White */
			left_down();                 /* turn left */
			last_time=LEFT_DOWN;
		}
		else if(RB0==1 && RB1==0 && RB2==0){ /* White Black Black */
			small_right_down();          /* turn right a little */
			last_time=RIGHT_DOWN;
		}
		else if(RB0==1 && RB1==1 && RB2==0){ /* White White Black */
			right_down();                /* turn right */
			last_time=RIGHT_DOWN;
		}
		else{                                /* The other case */
			straight();                  /* go to straight */
			last_time=STRAIGHT;
}	}	}
Example #11
0
File: comcut.c Project: gembaf/wint
int strategy(const int hd[], const int fd[], int cg, int tk, const int ud[], int us) {
  int i, k, decide;
  int sut[4] = {0};
  int num[13] = {0};
  int usut[4] = {0};
  int unum[13] = {0};
  for ( k = 0; k < HNUM; k++ ) { i = hd[k] / 13; sut[i]++; }
  for ( k = 0; k < HNUM; k++ ) { i = hd[k] % 13; num[i]++; }
  for ( k = 0; k < us; k++ ) { i = ud[k] / 13; usut[i]++; }
  for ( k = 0; k < us; k++ ) { i = ud[k] % 13; unum[i]++; }
  if (tk == 5 && us-cg >= 37) { return take6_hand(hd, ud, us); }
  if (poker_point(hd) >= 16) { return -1; }
  if (poker_point(hd) >= 8 && tk < 4) { return -1; }
  decide = flashreach(hd, sut, usut);
  if (decide != -1) {
    return decide;
  }
  decide = straight(hd, num, unum, sut, usut);
  if (decide != -1) {
    return decide;
  }
  if (tk < 2) { return -1; }
  decide = flash(hd, num, unum, sut, usut);
  if (decide != -1) {
    return decide;
  }
  if (tk == 4 && 52-5-us <= 11) {
    return -1;
  }
  if (tk == 3 && 52-5-us <= 22) {
    return -1;
  }
  decide = pair(hd, num, unum,sut);
  if (decide != -1) {
    return decide;
  }
  return -1;
}
Example #12
0
File: adlint.c Project: gembaf/wint
int strategy(const int hd[], const int fd[], int cg, int tk, const int ud[], int us)
{
  int disc_num;  // 捨てるカードの番号(-1:捨てない)
  int t;
  int k, k1, k2; // 反復変数
  Handcard hands[5]; // 手札を保管
  Cards hand_card, deck_card, remain_card;

  // 手札の情報を格納
  for (k1 = 0; k1 < HNUM; k1++ ) {
    hands[k1].num_val = hd[k1];
    hands[k1].num     = hd[k1] % 13;
    hands[k1].sut     = hd[k1] / 13;
    hands[k1].pos     = k1;
    for ( k2 = 0; k2 < 11; k2++ ) { hands[k1].exp[k2] = 0; }
  }
  calc_card(hands, &remain_card, &deck_card, &hand_card, ud, us);
  //フルハウス以上は確定
  if ( tk != 5 && poker_point(hd) >= P6 ) { return -1; }

  disc_num = limit_take(cg, tk, hands, remain_card, hand_card, deck_card, hd);  if ( disc_num != DEFAULT_NUM ) { return disc_num; }
  // ストレートリーチならストレートを狙う
  if ( check_straight(remain_card, hand_card) >= 1 ) {
    return straight(hands, remain_card, hand_card, deck_card, cg);
  }
  // フラッシュリーチならフラッシュを狙う
  for (k1 = 0; k1 < HNUM; k1++ ) {
    if ( hand_card.sut[k1] >= 4 && deck_card.sut[k1] >= 2 ) {
      return flush(hands, hand_card, deck_card, cg);
    }
  }
  /* // 3カード以上ならペア系を狙う */
  if ( poker_point_pair(hand_card.num) == P3 ) {
    return pair(hands, hand_card, deck_card, remain_card);
  }
  return decide_discard(hands, remain_card, hand_card, deck_card, cg, tk);
}
Example #13
0
void main(){

Lcd_init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR);               // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
I2C1_Init(100000);
TRISB.F0=0;
TRISB.F1=0;

while(1){

   Read_Compass();
   WordToStr(angle,to_LCD);
   Lcd_Out(1,1,to_LCD);
   straight();
   // delay_ms(500);
  // Lcd_Out(1,1,"Piyumal");
   //delay_ms(1000);
   
}



}
int main(void)
{

    /*TCCR1A=0xA1;
	TCCR1B=0x05;
	
	
	
	OCR1A=150;				//Left Motor PWM
	OCR1B=150;				//Right Motor PWM
	
	DDRD=0x30;				//Declaring PD4,PD5 as output*/
	
	
	DDRA=0X00;				//Sensor Input
	PORTA=0X07;
	
	DDRB=0x0F;
	

    while(1)
    {
	  switch(PINA & 0X07)
	  {
		case 0x00: //0
		{
			left();
		}
		break;
		
		case 0x01: //1
		{
			left();
		}
		break;
		
		case 0x02: //2
		{
			straight();
		}
		break;
		
		case 0x03: //3
		{
			left();
		}
		break;
		
		
		case 0x04: //4
		{
			right();
		}
		break;
		
		case 0x05: //5
		{
			straight();
		}
		break;
		
		case 0x06: //6
		{
			right();
		}
		break;
		
		case 0x07: //7
		{
			u_turn();
		}
		break; 
		}
    }


    return 0;
}
Example #15
0
// This may get called twice, if blackoutFlag is set. It will get once called
// with blackoutFlag set and another time with no blackoutFlag.
void GfxTransitions::doTransition(int16 number, bool blackoutFlag) {
	if (number != SCI_TRANSITIONS_FADEPALETTE) {
		setNewPalette(blackoutFlag);
	}

	_transitionStartTime = g_system->getMillis();
	switch (number) {
	case SCI_TRANSITIONS_VERTICALROLL_FROMCENTER:
		verticalRollFromCenter(blackoutFlag);
		break;
	case SCI_TRANSITIONS_VERTICALROLL_TOCENTER:
		verticalRollToCenter(blackoutFlag);
		break;
	case SCI_TRANSITIONS_HORIZONTALROLL_FROMCENTER:
		horizontalRollFromCenter(blackoutFlag);
		break;
	case SCI_TRANSITIONS_HORIZONTALROLL_TOCENTER:
		horizontalRollToCenter(blackoutFlag);
		break;
	case SCI_TRANSITIONS_DIAGONALROLL_TOCENTER:
		diagonalRollToCenter(blackoutFlag);
		break;
	case SCI_TRANSITIONS_DIAGONALROLL_FROMCENTER:
		diagonalRollFromCenter(blackoutFlag);
		break;

	case SCI_TRANSITIONS_STRAIGHT_FROM_RIGHT:
	case SCI_TRANSITIONS_STRAIGHT_FROM_LEFT:
	case SCI_TRANSITIONS_STRAIGHT_FROM_BOTTOM:
	case SCI_TRANSITIONS_STRAIGHT_FROM_TOP:
		straight(number, blackoutFlag);
		break;

	case SCI_TRANSITIONS_PIXELATION:
		pixelation(blackoutFlag);
		break;

	case SCI_TRANSITIONS_BLOCKS:
		blocks(blackoutFlag);
		break;

	case SCI_TRANSITIONS_FADEPALETTE:
		if (!blackoutFlag) {
			fadeOut(); setNewScreen(blackoutFlag); fadeIn();
		}
		break;

	case SCI_TRANSITIONS_SCROLL_RIGHT:
	case SCI_TRANSITIONS_SCROLL_LEFT:
	case SCI_TRANSITIONS_SCROLL_UP:
	case SCI_TRANSITIONS_SCROLL_DOWN:
		scroll(number);
		break;

	case SCI_TRANSITIONS_NONE_LONGBOW:
	case SCI_TRANSITIONS_NONE:
		setNewScreen(blackoutFlag);
		break;

	default:
		warning("Transitions: ID %d not implemented", number);
		setNewScreen(blackoutFlag);
	}
}
Example #16
0
int Checks::determinecpuhand(vector<int> cvalues, vector<char>csuits)
{
	//gotoxy(30, 20);          // checking the hands starting with the highest possible hand and going down from there.
	dvalues.empty();
	dsuits.empty();

	dvalues = cvalues;
	dsuits = csuits;

	sort(dvalues.begin(), dvalues.end());
	if ((flush(dsuits)) && (straight(dvalues)))
	{


		if (dvalues[4] == 14)
		{
			chand = " ROYAL FLUSH!!!";
			return 100;
		}
		else
		{
			chand = "STRAIGHT FLUSH!";
			return 90;
		}
	}

	else if (flush(dsuits) == 1)
	{
		chand = "Flush!";
		return 80;

	}
	else if (straight(dvalues) == 1)
	{
		chand = "Straight!";
		return 70;

	}

	else if (fourofakind(dvalues) == 1)
	{
		chand = "Four of a Kind!";
		return 60;

	}
	else if (fullhouse(dvalues) == 1)
	{
		chand = "Full House!";
		return 50;

	}

	else if (threeofakind(dvalues) == 1)
	{
		chand = "Three of a Kind!";
		return 40;

	}
	else if (ispair(dvalues) == 2)
	{
		chand = "Two Pair";
		return 30;
	}
	else if (ispair(dvalues) == 1)
	{
		chand = "Pair!";
		return 20;

	}

	else if(ispair(dvalues) == 0)
	{

		chand = "Absolutely nothing!";
		return 4;
		
	}
	return dvalues.back();
}
Example #17
0
int getWinner(char player1[10], char player2[10]) {
    // Different hands ranked from 0 to 9
    int rank1;
    int rank2;
    
    // RKS NOTE: Ranking Player 1
    if (royal(player1)) {
        rank1 = 9;
    } else if (straightf(player1) > 0) {
        rank1 = 8;
    } else if (fourkind(player1) > 0) {
        rank1 = 7;
    } else if (fullh(player1) > 0) {
        rank1 = 6;
    } else if (flush(player1) > 0) {
        rank1 = 5;
    } else if (straight(player1) > 0) {
        rank1 = 4;
    } else if (threekind(player1) > 0) {
        rank1 = 3;
    } else if (twopair(player1) > 0) {
        rank1 = 2;
    } else if (onepair(player1) > 0) {
        rank1 = 1;
    } else {
        rank1 = 0;
    }
    

    // RKS NOTE: Ranking Player 2
    if (royal(player2)) {
        rank2 = 9;
    } else if (straightf(player2) > 0) {
        rank2 = 8;
    } else if (fourkind(player2) > 0) {
        rank2 = 7;
    } else if (fullh(player2) > 0) {
        rank2 = 6;
    } else if (flush(player2) > 0) {
        rank2 = 5;
    } else if (straight(player2) > 0) {
        rank2 = 4;
    } else if (threekind(player2) > 0) {
        rank2 = 3;
    } else if (twopair(player2) > 0) {
        rank2 = 2;
    } else if (onepair(player2) > 0) {
        rank2 = 1;
    } else {
        rank2 = 0;
    }

    if (rank1 > rank2) {
        return 0;
    } else if (rank2 > rank1) {
        return 1;
    } else if (rank1 == rank2) {
        if (rank1 == 8) {
            if (straightf(player1) > straightf(player2)) {
                return 0;
            } else if (straightf(player1) < straightf(player2)) {
                return 1;
            } else {
                return todeath(player1, player2);
            }
        } else if (rank1 == 7)  {
            if (fourkind(player1) > fourkind(player2)) {
                return 0;
            } else if (fourkind(player2)>fourkind(player1)) {
                return 1;
            } else {
                return todeath(player1, player2);
            }
        } else if (rank1 == 6) {
            if (fullh(player1) > fullh(player2)) {
                return 0;
            } else if (fullh(player1)>fullh(player2))
                return 1;
            } else {
                return todeath(player1, player2);
            }
        } else if (rank1 == 5) {
            return todeath(player1, player2);
        } else if (rank1 == 4) {
            if (straight(player1) > straight(player2)) {
                return 0;
            } else if (straight(player1) < straight(player2)) {
                return 1;
            } else {
                return todeath(player1, player2);
            }
        } else if (rank1 == 3) {
            if (threekind(player1) > threekind(player2)) {
                return 0;
            } else if (threekind(player1) < threekind(player2)) {
                return 1;
            } else {
                return todeath(player1, player2);
            }
        } else if (rank1 == 2) {
            if (twopair(player1) > twopair(player2)) {
                return 0;
            } else if (twopair(player1) < twopair(player2)) {
                return 1;
            } else {
                return todeath(player1, player2);
            }
        } else if (rank1 == 1) {
            if (onepair(player1)>onepair(player2)) {
                return 0;
            } else if (onepair(player1)<onepair(player2)) {
                return 1;
            } else {
                return todeath(player1, player2);
            }
        } else if (rank1 == 0) {
            return todeath(player1, player2);
        }
    
    return -1;
}
Example #18
0
void transportPos(int forward_speed, int reverse_speed){
	straight(1800, forward_speed);
	printf("forward\n");
	back(1800, reverse_speed);
	printf("back\n");
}
Example #19
0
int splane::range(const trajestep& fts, vfloat* crange, point* cpt,
                  int* s_ext) const {
  mfunname("int splane::range(...)");
  if (fts.s_range_cf == 0) {
    // straight line
    point pt = pn.cross(straight(fts.currpos, fts.dir));
    if (vecerror != 0) {
      vecerror = 0;
      return 0;
    }
    vfloat rng = length(pt - fts.currpos);
    if (pt == fts.currpos || check_par(pt - fts.currpos, fts.dir, 0.01) == 1) {
        //                                   looks like not matter ^
      // otherwise the point is behind plane
      if (fts.mrange >= rng) {
        // otherwise it can not reach the plane
        cpt[0] = pt;
        crange[0] = rng;
        vfloat t = cos2vec(fts.dir, dir_ins);
        if (t < 0)
          s_ext[0] = 1;
        else if (t > 0)
          s_ext[0] = 0;
        else
          s_ext[0] = 2;
        return 1;
      }
      return 0;
    } else
      return 0;
  } else {
    point pt[2];
    circumf cf(fts.currpos + fts.relcen,
               fts.dir || fts.relcen,  // if to us, moving against clock
               length(fts.relcen));
    int q = cf.cross(pn, pt, 0.0);
    if (q == -1)  // total circle lyes in the plane
        {
      cpt[0] = fts.currpos;
      crange[0] = 0.0;
      s_ext[0] = 2;
      return 1;
    }
    if (q == 0) return 0;
    if (q == 1) {
      vec r1 = -fts.relcen;
      vec r2 = pt[0] - cf.Gpiv();
      vfloat angle = ang2projvec(r1, r2, cf.Gdir());
      vfloat rng = cf.Grad() * angle;
      if (fts.mrange >= rng) {
        cpt[0] = pt[0];
        crange[0] = rng;
        vfloat c = cos2vec(dir_ins, fts.relcen);
        if (angle == 0.0) {
          // cross in the current point
          if (c > 0)
            s_ext[0] = 0;
          else if (c < 0)
            s_ext[0] = 1;
          else
            s_ext[0] = 2;
        } else {
          if (c > 0)
            s_ext[0] = 1;
          else if (c < 0)
            s_ext[0] = 0;
          else
            s_ext[0] = 2;
        }
        return 1;
      } else
        return 0;
    }
    if (q == 2) {
      int qq = 0;
      vec r = -fts.relcen;
      vec vcr[2];
      vcr[0] = pt[0] - cf.Gpiv();
      vcr[1] = pt[1] - cf.Gpiv();
      vfloat angle[2];
      angle[0] = ang2projvec(r, vcr[0], cf.Gdir());
      angle[1] = ang2projvec(r, vcr[1], cf.Gdir());
      if (angle[0] > angle[1]) {  // ordering
        vfloat a = angle[0];
        angle[0] = angle[1];
        angle[1] = a;
        point p = pt[0];
        pt[0] = pt[1];
        pt[1] = p;
      }
      vfloat rng;
      rng = cf.Grad() * angle[0];
      if (fts.mrange >= rng) {
        // find out what the first point means
        int ins = 0;  // 1 if the point inside and exits
        vec td = fts.dir;
        td.turn(cf.Gdir(), angle[0]);  // local dir in the crossing point
        vfloat t = cos2vec(td, dir_ins);
        if (t < 0)
          ins = 1;  // means the point was inside and now exiting
        else
          ins = 0;
        cpt[0] = pt[0];
        crange[0] = rng;
        s_ext[0] = ins;
        qq++;
        rng = cf.Grad() * angle[1];
        if (fts.mrange >= rng) {
          cpt[1] = pt[1];
          crange[1] = rng;
          s_ext[1] = (ins == 0 ? 1 : 0);
          qq++;
        }
      }
      return qq;
    }
  }
  return 0;
}
Example #20
0
int main (void)
{
	int game = 0, money = 1000;
	system("Color 24");//Color: Background: Green, Text: Red
	welcome_screen();
	do{//while player1 has money
	/* initialize suit array */
	const char *suit[4] = {"Hearts", "Diamonds", "Clubs", "Spades"};
	const char *suits[4] = {"\3", "\4", "\5", "\6"};
	/* initialize face array */
	const char *face[13] = {"Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight",
		"Nine", "Ten", "Jack", "Queen", "King"};
	char faces[13] = {"A234567890JQK"};
	char raise = '\0' , ten = ' ';
	Card hand1[5];
	Card hand2[5];
	/* initalize deck array */
	int deck[4][13] = {0};
	int is_pair = 0, is_two_pair = 0, is_three = 0, is_four = 0, is_full = 0, is_flush = 0, is_straight = 0, score1 = 0, score2 = 0,
		x = 0, y = 0, i = 0, j = 0, count = 10, count1 = 0, count2 = 0, bet = 0, bet2 = 0;
	srand ((unsigned) time (NULL)); /* see random-number generator */
	
	hand1[0].is_active = 1; hand1[1].is_active = 1; hand1[2].is_active = 1; hand1[3].is_active = 1; hand1[4].is_active = 1;
	hand2[0].is_active = 1; hand2[1].is_active = 1; hand2[2].is_active = 1; hand2[3].is_active = 1; hand2[4].is_active = 1;

//0 = Black 8 = Gray
//1 = Blue 9 = Light Blue
//2 = Green a = Light Green
//3 = Aqua b = Light Aqua
//4 = Red c = Light Red
//5 = Purple d = Light Purple
//6 = Yellow e = Light Yellow
//7 = White f = Bright White
	
	do{//Places blind bet	
	printf("Money: $%d\n", money);
	printf("Place your blind: \n");
	scanf("%d", &bet);
	if(bet > money)
	{
		printf("You don't have that much money!\n");
		system("Pause");
		system("cls");
	}
	}while(bet > money);
	shuffle (deck);
	deal(deck, face, faces, suit, suits, hand1, hand2, count, count1, count2);
	//Initial Deal
	printf("\nMoney: $%d", money - bet);
	bet = raise_bet(money, bet);//First round of betting - Raise before 'draw'
	count = select_cards(hand1, count);//how many cards to redeal
	count1 = count - 10;
	//deal(deck, face, suit, hand1, hand2, count);
	//Simulates Dealer, decides which cards the dealer keeps
	sort_hand(hand2);	
	is_pair = pair(hand2, face, 0);
	is_two_pair = two_pair(hand2, face, 0);
	is_three = three_of_a_kind(hand2, face, 0);
	is_four = four_of_a_kind(hand2, face, 0);
	is_full = full_house(hand2, face, 0);
	is_flush = flush(hand2, face, 0);
	is_straight = straight(hand2, face, 0);
	for(i = 0; i < 5; i++)//Counts how many cards to redeal to dealer
	{
		if(hand2[i].is_active == 1)
		{
			count++;
			count2++;
		}
	}
	//printf("\n%d %d %d %d %d\n", hand1[0].is_active, hand1[1].is_active, hand1[2].is_active, hand1[3].is_active, hand1[4].is_active);
	//printf("\n%d %d %d %d %d\n", hand2[0].is_active, hand2[1].is_active, hand2[2].is_active, hand2[3].is_active, hand2[4].is_active);
	system("Pause");
	system("cls");	
	printf("Money: $%d\n", money - bet);
	printf("Pot: $%d", 2*bet);
	deal(deck, face, faces, suit, suits, hand1, hand2, count, count1, count2);
	//Draw and Redeal
	sort_hand(hand1);
	sort_hand(hand2);

	printf("\nHand#1\n");
	for(y = 0; y < 5; y++)//Prints hand1
	{
		if(hand1[y].face == 9)//Prints '10' instead of just '0'
		{
			ten = '1';
		}
		if(hand1[y].face != 9)
		{
			ten = ' ';
		}
		printf("Card#%d %5s of %-8s %c%c%s\n", y + 1, face[hand1[y].face], suit[hand1[y].suit], ten, faces[hand1[y].face], suits[hand1[y].suit]);
	}
	//money = money - bet;
	bet = raise_bet(money, bet);//Second round of betting - before 'showdown'
	money = money - bet;
	printf("Money: $%d\n", money);
	/*SHOWDOWN!!!*/
	printf("Pot: $%d\n", 2*bet);
	system("Pause");
	system("cls");
	printf("\nHand#1\n");
	for(y = 0; y < 5; y++)
	{
		if(hand1[y].face == 9)
		{
			ten = '1';
		}
		if(hand1[y].face != 9)
		{
			ten = ' ';
		}
		printf("Card#%d %5s of %-8s %c%c%s\n", y + 1, face[hand1[y].face], suit[hand1[y].suit], ten, faces[hand1[y].face], suits[hand1[y].suit]);
	}
	printf("\nHand#2\n");
	for(j = 0; j < 5; j++)
	{
		if(hand2[j].face == 9)
		{
			ten = '1';
		}
		if(hand2[j].face != 9)
		{
			ten = ' ';
		}
		printf("Card#%d %5s of %-8s %c%c%s\n", j + 1, face[hand2[j].face], suit[hand2[j].suit], ten, faces[hand2[j].face], suits[hand2[j].suit]);
	}
	hand1[0].high_card = hand1[4].face;//Starts by assuming 'high card' is hand[4]
	hand2[0].high_card = hand2[4].face;//'high card' is changed if there is a pair, two pair, etc. 

	printf("\nPlayer #1\t"); //Evaluates Player1's hand
	is_pair = pair(hand1, face, 1);
	is_two_pair = two_pair(hand1, face, 1);
	is_three = three_of_a_kind(hand1, face, 1);
	is_four = four_of_a_kind(hand1, face, 1);
	is_full = full_house(hand1, face, 1);
	is_flush = flush(hand1, face, 1);
	is_straight = straight(hand1, face, 1);
	//printf("\nHand #1:\nPair: %d\t\tTwo Pair: %d\tThree: %d\tFour: %d\t\tFlush: %d\tStraight: %d\n", is_pair, is_two_pair, is_three, is_four, is_flush, is_straight);
	score1 = calc_score(is_pair, is_two_pair, is_three, is_four, is_flush, is_straight, face, hand1);
	
	printf("\nPlayer#2\t");//Evaluates Dealer's hand
	is_pair = pair(hand2, face, 1);
	is_two_pair = two_pair(hand2, face, 1);
	is_three = three_of_a_kind(hand2, face, 1);
	is_four = four_of_a_kind(hand2, face, 1);
	is_full = full_house(hand2, face, 1);
	is_flush = flush(hand2, face, 1);
	is_straight = straight(hand2, face, 1);
	//printf("\nHand #2:\nPair: %d\t\tTwo Pair: %d\tThree: %d\tFour: %d\t\tFlush: %d\tStraight: %d\n", is_pair, is_two_pair, is_three, is_four, is_flush, is_straight);
	score2 = calc_score(is_pair, is_two_pair, is_three, is_four, is_flush, is_straight, face, hand2);

	if(score1 == score2)//If both hands have pair, two pair, etc.
	{
		score1 = hand1[0].high_card;//Note: If a hand has a pair, the highcard is the face value of the pair
		score2 = hand2[0].high_card;
	}
	x = 4;
	do{
	if(score1 == score2)//If both hands have the same high card
	{
		score1 = hand1[x].face;
		score2 = hand2[x].face;
		if(score1 != score2)
		{
			printf("\nPlayer #1 New High Card: %5s\n", face[hand1[x].face]);
			printf("Player #2 New High Card: %5s\n", face[hand2[x].face]);
		}
	}
	x--;
	}while((x >= 0)&&(score1 == score2));
	//printf("\n\nPlayer1 Score: %d\tPlayer2 Score: %d", score1, score2);
	if(score1 > score2)
	{
		printf("\n\nPlayer1 Wins: $%d\n", 2*bet);
		money = money + 2*bet;
	}
	if(score1 < score2)
	{
		printf("\nPlayer2 Wins: $%d\n", 2*bet);
		//money = money - 2*bet;
	}
	//printf("Money: $%d\n", money);
	system("Pause");
	system("cls");
	}while(money > 0);
	if(money <= 0)
	{
		printf("Game Over. . .\n");
	}
	return 0;
}
Example #21
0
void regulateright()
{
	transmit();
	//REGLERING
	//Omvandling till centimeter

	sensor1r = shortsensor(storedValues[1]);
	sensor2r = shortsensor(storedValues[2]);
	sensorfront = shortsensor(storedValues[3]);
	sensormeanr = ((sensor1r + sensor2r) / 2) + 4 ;
	
	// Uppdatera kommunikationsmodulen med sensorvärden innan reglering börjar
	if(firstRR == 1)
	{
		firstRR = 0;
		TransmitComm(update);

		stopp();
	}
	else
	{
		//till PD-reglering
		Td = 5; //85000000; //128000000
		K = 5;
		if(sensorfront <= 15)
		{
			if(posdistance > 25)
			{
				updatepos();
			}
			straight();
			rotate90left();
			straight();
		}
		if(sensor1r < 25 && sensor2r < 25)
		{
			startregulate = 1;
			PORTC = 0x01;
			PORTD = 0x20;
			rightpwm = speed + K * ((15 - sensormeanr)) + Td * (sensor2r - sensor1r);
			leftpwm = speed - K * ((15 - sensormeanr)) - Td * (sensor2r - sensor1r);

			if (rightpwm > 150)
			{
				OCR2B = 150;
			}
			else if(rightpwm < 0)
			{
				OCR2B = 0;
			}
			else
			{
				OCR2B = rightpwm;
			}
			if (leftpwm > 150)
			{
				OCR2A = 150;
			}
			else if (leftpwm < 0)
			{
				OCR2A = 0;
			}
			else
			{
				OCR2A = leftpwm;
			}
			
		}// Tappat konakt med bakhöger men inte framhöger
		else if(sensor2r > 20 && sensor1r < 20 )
		{
			driveF();
		}
		else // Tappat kontakt med framhöger
		{
			//har vi reglerat mot vägg innan
			if(startregulate == 1)
			{
				
				startregulate = 0;
				drive(20); // Kör fram till mitten av ruta
				updatepos();
				rotate90right(); // sväng höger
				drivefromstill(35); // Kör så att du har vägg att reglera mot
				updatepos();

				straight(); // korrigera om roboten står snett efter sväng
			}
			else
			{
				stopp();
			}
		}
	}

}
void inPlaceTurn(int degrees, int maxSpeed, int accel, int decel)
{	
	setDirection(0, 1);
	straight(degrees * 42, 0, maxSpeed, 0, accel, decel);
}
Example #23
0
//called every 1 ms
interrupt void WDT_interval_handler(){
	int leftDist = get_latest_left();
	int rightDist = get_latest_right();
	int frontDist = get_latest_front();
	bool iAmStuck = false;
	sensor_conversions_side--;
	sensor_conversions_front--;
	stuckCounter--;
	if (camera_timeout == 1) {
		camera_timeout = 0;
		set_camera_gpio(false);
	} else if (camera_timeout > 0) {
		camera_timeout--;
	}
	//trigger the front sensor every 100ms
	if (sensor_conversions_side == 0) {
		sensor_conversions_side = SENSOR_LOOPS_SIDE;
		ADC10CTL0 |= ADC10SC;  // trigger a conversion
	}
	//trigger an ADC conversion on left and right sensors every 20ms
	if (sensor_conversions_front == 0) {
		sensor_conversions_front = SENSOR_LOOPS_FRONT;
		make_front_measurement();
	}
	//keep track of the last 18 sensor measurements
	if (stuckCounter == 0) {
		stuckCounter = STUCK_COUNT;
		//keep track of the current sensor values
		char current = idx%20;
		char prev = (idx-1)%20;
		lastData[current][0] = abs(lastData[prev][0] - rightDist);
		lastData[current][1] = abs(lastData[prev][1] - leftDist);
		lastData[current][2] = abs(lastData[prev][2] - frontDist);
		idx++;

		//if the car hasnt moved in the last 18 sensor measurements
		iAmStuck = amIStuck();
	}

	//if the car isnt stopped, take a picture every 1000ms
	if (ps != STOPPED) {
		if (pictureTimer <= 0) {
			pictureTimer = PICTURE_TIMER;
			bool success = take_picture();
		}
	}

	//automated driving logic
	pictureTimer--;
	switch (ps) {
	case STOPPED:
		//start moving, just go for it
		forward(defaultPWM);
		straight();
		ps = F_STRAIGHT;
		break;
	case F_STRAIGHT:
		//stuck, car hasnt moved in 3 seconds
		if (iAmStuck) {
			reverse(defaultPWM);
			straight();
			ps = R_STRAIGHT;
			turningAround = 1;
			turnAroundCounter = TURNAROUND_LENGTH;
			init_lastData();
			iAmStuck = false;
			break;
		}
		//up against a wall
		if (frontDist <= FRONT_THRESHOLD) {
			reverse(defaultPWM);
			straight();
			ps = R_STRAIGHT;
			turningAround = 1;
			turnAroundCounter = TURNAROUND_LENGTH;
		}
		//looking down and open hallway
		else if (leftDist > BIG_THRESHOLD) {
			left();
			ps = F_LEFT;
		}
		else if (rightDist > BIG_THRESHOLD) {
			right();
			ps = F_RIGHT;
		}
		//off center in a hallway
		else if (leftDist - rightDist > TURN_THRESHOLD) {
			left();
			ps = F_LEFT;
		}
		else if (rightDist - leftDist > TURN_THRESHOLD) {
			right();
			ps = F_RIGHT;
		}
		break;
	case F_LEFT:
		last_turn = F_LEFT;
		if (iAmStuck) {
			reverse(defaultPWM);
			straight();
			ps = R_STRAIGHT;
			turningAround = 1;
			turnAroundCounter = TURNAROUND_LENGTH;
			init_lastData();
			iAmStuck = false;
			break;
		}
		//in the process of turning around
		if (turningAround == 1) {
			turnAroundCounter--;
			if (turnAroundCounter <= TURNAROUND_LENGTH/2) {
				forward(defaultPWM);
				straight();
				turnAroundCounter = 0;
				ps = F_STRAIGHT;
				turningAround = 0;
			}
		}
		//turning back to center wheels
		else if (turningBack == 1) {
			turnBackCounter--;
			if (turnBackCounter <= 0) {
				straight();
				ps = F_STRAIGHT;
				turnBackCounter = 0;
				turningBack = 0;
			}
		}
		//stop turning, we are now centered in hallway
		else if (rightDist >= leftDist) {
			right();
			ps = F_RIGHT;
			turningBack = 1;
			turnBackCounter = TURNBACK_LENGTH;
		}
		break;
	case F_RIGHT:
		last_turn = F_RIGHT;
		if (iAmStuck) {
			reverse(defaultPWM);
			straight();
			ps = R_STRAIGHT;
			turningAround = 1;
			turnAroundCounter = TURNAROUND_LENGTH;
			init_lastData();
			iAmStuck = false;
			break;
		}
		if (turningAround == 1) {
			turnAroundCounter--;
			if (turnAroundCounter <= TURNAROUND_LENGTH/2) {
				forward(defaultPWM);
				straight();
				turnAroundCounter = 0;
				ps = F_STRAIGHT;
				turningAround = 0;
			}
		}
		else if (turningBack == 1) {
			turnBackCounter--;
			if (turnBackCounter <= 0) {
				straight();
				ps = F_STRAIGHT;
				turnBackCounter = 0;
				turningBack = 0;
			}
		}
		else if (leftDist >= rightDist) {
			left();
			ps = F_LEFT;
			turningBack = 1;
			turnBackCounter = TURNBACK_LENGTH;
		}
		break;
	case R_STRAIGHT:
		turnAroundCounter--;
		if (frontDist >= 3*FRONT_THRESHOLD || turnAroundCounter <= 0) {
			turnAroundCounter = TURNAROUND_LENGTH;
			if (last_turn == F_RIGHT) {
				ps = R_RIGHT;
				right();
			}
			else {
				ps = R_LEFT;
				left();
			}
		}
		break;
	case R_RIGHT:
		if (turningAround == 1) {
			turnAroundCounter--;
			if (turnAroundCounter <= 0) {
				forward(defaultPWM);
				left();
				turnAroundCounter = TURNAROUND_LENGTH;
				ps = F_LEFT;
			}
		}
		break;
	case R_LEFT:
		if (turningAround == 1) {
			turnAroundCounter--;
			if (turnAroundCounter <= 0) {
				forward(defaultPWM);
				right();
				turnAroundCounter = TURNAROUND_LENGTH;
				ps = F_RIGHT;
			}
		}
		break;
	default:
		stop();
		straight();
		ps = STOPPED;
		break;
	}

}
Example #24
0
int main()
{
	//wait_for_light(1);//initialization
	printf("version 1.9.5\n");
	shut_down_in(115);
	
	
	int servo_counter=0;
	while(servo_counter<=3){
		enable_servo(servo_counter);
		servo_counter++;
	}
	//	initialize routine
	set_servo_position(0,2047);
	armUp();
	clawClose();
	//get in front of transport

	straight(1.8,  170);
	rightC(0.28, 100);
	leftC(0.28, -100);
	straight(1.65, 170);
	leftC(0.44, 100);
	printf("completed first dead reckoning\n");
	
	
	//until distance is 5 centimeter
	/*
	int claw_threshold = 13;
	while(analog10(ETport)>claw_threshold){
		back(0.1, -10);
		msleep(1000);
		printf("move once\n");
		printf("%i\n", analog10(ETport));
	}*/
	back(0.25, -20);//pushes against transport
	msleep(2000);
	set_servo_position(0, 500);//puts claw on transport
	msleep(1000);
	printf("done with attaching to transport\n");
	while(digital(8)==0)//goes forward with transport until it hits the wall
	{
		straight(0.1, 100);
		msleep(10);
	}
	printf("at wall\n");
	back(0.15, -50);//backs  up from wall to deposit transport
	set_servo_position(0, 2047);//raises claw
	msleep(1500);
	while(digital(8)==0){//goes forward until it hits wall for second time
		straight(0.1, 100);
		msleep(10);
	}
	
	printf("at wall 2\n");
	
	back(0.35, -100);//goes back and turns left in order to be oriented with left inner wall
	leftC(0.6, 142);
	
	int bump_counter=0;	
	
	while(digital(8)==0){//hits side wall
		straight(0.1, 100);
		msleep(10);
	}
	
	bump_counter++;//has one bump


    int i=0;
    while(i<10){//if hits side wall, pause
		stop(0.2);
		i++;
	}
	
	/*
	==========================
	==========End of routine 1======
	KIPR at the wall
	==========================
	*/
	// Pause here to wait for Create to drop POMS
	
	msleep(1*1000);
	//
	int start=seconds();//  start time
	
	printf("will get out of corner\n");
	
	back(0.5, -100);
	
	while(seconds()-start<=3){//separates back from right angle
		stop(0.1);
	}
	
	right_angle(left);
	
	while(seconds()-start<=5){//separates right angle from straight
		stop(0.1);
	}
	
	double start_drive=seconds();
	
	straight(0.7, 100);//go to poms
	
	
	stop(0.5);
	
	camera_open(LOW_RES);
	
	
	
	/*while(seconds()-start<=20){
		int update_counter=0;
		while(update_counter<10){
			camera_update();
			update_counter++;
		}
		if(get_object_count(chan)==0){
			stop(0.1);
		}
		int x=get_object_center(chan, 0).x;
		int area=get_object_area(chan, 0);	
		if(area<=400){
			navigate(x);
		}
		if(area>=800){
			//if objects are clumped are clumped, area will be automatically larger.
			//this means that KIPR will start earlier than it should. We counter this here
			//straight(0.18, 100);
			straight(0.1, 100);
			break;
		}
	
	}*/
	
	stop(0.1);
	
	printf("object seen\n");

	double end_drive=seconds();//only for simulation. real end and start times would have to be taken from whole routine
	//pick up POMS that are right there
	pickup();
	int offset=(end_drive-start_drive)*(3.0/4.0);;//half of distance from back of launch area to border of launch area
	back((end_drive-start_drive)+1.5,  -100);//go to the back of wall plus a little more to straighten out
	printf("at back wall\n");
	straight(2.0, 100);//goes halway between border and back of launch area
	right_angle(left);//faces transport
	int starpof=seconds();//time after right angle
	while(seconds()-starpof<=2){
		motor(motorL, 0);
		motor(motorR, 0);
	}
	while(digital(8)==0){
		straight(0.1, 100);
	}
	straight(0.1, 100);
	
	printf("touching transport\n");
	
	motor(motorL, 0);
	motor(motorR, 0);
	
	dropoff();//drops poms in launch area
	
	printf("poms in transport\n");
	
	back(0.25, -100);
	int starfop=seconds();
	while(seconds()-starfop<=2){
		motor(motorL, 0);
		motor(motorR, 0);
	}
	int turns=1;
	while(turns<=2){
		right_angle(right);
		stop(0.3);
		turns++;
	}
	

	
	
	/*
	======================
	======Part 2 of routine 2====
	======================
	*/
	while(1){

		stop(0.5);//
		
		while(digital(8)==0){
			straight(0.1, 100);
		}
		back(0.3, -100);
		right_angle(left);
		pickup();
		back((end_drive-start_drive)+1.5, -100);
		straight(2.2, 100);
		right_angle(left);
		while(digital(8)==0){
			straight(0.1, 100);
		}
		dropoff();
		back(0.5, -100);
		right_angle(left);
		right_angle(left);
	}
	
	
	/*while(1){
	
		start=0;
		while(digital(8)==0){
			straight(0.1, 80);
        }
		back(0.5, -100);
		right_angle(right);
		straight(0.5, 100);
		right_angle(right);
		right_angle(right);
		
		while(seconds()-start<=20){
			int update_counter=0;
			while(update_counter<10){
				camera_update();
				update_counter++;
			}
			if(get_object_count(chan)==0){
				stop(0.1);
			}
			int x=get_object_center(chan, 0).x;
			int area=get_object_area(chan, 0);	
			if(area<=400){
				navigate(x);
			}
			if(area>=800){
				//if objects are clumped are clumped, area will be automatically larger.
				//this means that KIPR will start earlier than it should. We counter this here
				//straight(0.18, 100);
				straight(0.1, 100);
				break;
			}
		}
		int servo_counter=1;
	while(servo_counter<=3){
		enable_servo(servo_counter);
		printf("servo %d enabled\n", servo_counter);
		servo_counter++;
	}
	pickup();
	int offset=(end_drive-start_drive)*(3.0/4.0);;//half of distance from back of launch area to border of launch area
	back((end_drive-start_drive)+1.5,  -100);//go to the back of wall plus a little more to straighten out
	printf("at back wall\n");
	straight(1.8, 100);//goes halway between border and back of launch area
	right_angle(left);//faces transport
	int starpof=seconds();//time after right angle
	while(seconds()-starpof<=2){
		motor(motorL, 0);
		motor(motorR, 0);
	}
	while(digital(8)==0){
		straight(0.1, 100);
	}
	straight(0.1, 100);
	
	printf("touching transport\n");
	
	motor(motorL, 0);
	motor(motorR, 0);
	
	dropoff();//drops poms in launch area
	
	printf("poms in transport\n");
	
	back(0.25, -100);
	int starfop=seconds();
	while(seconds()-starfop<=2){
		motor(motorL, 0);
		motor(motorR, 0);
	}
	int turns=1;
	while(turns<=2){
		right_angle(right);
		turns++;
	}
		
	
		repeat_runs++;
		
    }*/
	
	while(1){
		
		int servo_counter=0;//enables servos
		while(servo_counter<=3){
			enable_servo(servo_counter);
			servo_counter++;
		}
		armUp();//raises arm at start

		stop(0.5);
		
		while(digital(TOUCH_SENSOR)==0){//go forward until left wall is contacted
			straight(0.1, 100);
		}
		stop(0.1);
		back(0.3, -100);//back up
		stop(0.1);
		right_angle2(left);//face poms
		stop(0.1);
		back(3+1.5, -100);//back up to rocket wall to straighten out
		stop(0.1);
		straight(3+1.5, 100);//go to poms
		stop(0.1);
		pickup();//pick poms up
		stop(0.1);
		back(3+1.5, -100);// back up until rocket wall
		stop(0.1);
		straight(2.2, 100);//go forward
		stop(0.1);
		right_angle2(left);//turn to face transport
		stop(0.1);
		while(digital(TOUCH_SENSOR)==0){//go forward until transport contacted
			straight(0.1, 100);
		}
		stop(0.1);
		dropoff();//drop poms off
		stop(0.1);
		back(0.5, -100);//back up from transpor
		stop(0.1);
		right_angle2(right);//orient for next iteration
		stop(0.1);
		right_angle2(right);
	}
	
	return 0;
}
Example #25
0
// This may get called twice, if blackoutFlag is set. It will get once called
// with blackoutFlag set and another time with no blackoutFlag.
void GfxTransitions::doTransition(int16 number, bool blackoutFlag) {
	if (number != SCI_TRANSITIONS_FADEPALETTE) {
		setNewPalette(blackoutFlag);
	}

	_transitionStartTime = g_system->getMillis();
	switch (number) {
	case SCI_TRANSITIONS_VERTICALROLL_FROMCENTER:
		verticalRollFromCenter(blackoutFlag);
		break;
	case SCI_TRANSITIONS_VERTICALROLL_TOCENTER:
		verticalRollToCenter(blackoutFlag);
		break;
	case SCI_TRANSITIONS_HORIZONTALROLL_FROMCENTER:
		horizontalRollFromCenter(blackoutFlag);
		break;
	case SCI_TRANSITIONS_HORIZONTALROLL_TOCENTER:
		horizontalRollToCenter(blackoutFlag);
		break;
	case SCI_TRANSITIONS_DIAGONALROLL_TOCENTER:
		diagonalRollToCenter(blackoutFlag);
		break;
	case SCI_TRANSITIONS_DIAGONALROLL_FROMCENTER:
		diagonalRollFromCenter(blackoutFlag);
		break;

	case SCI_TRANSITIONS_STRAIGHT_FROM_RIGHT:
	case SCI_TRANSITIONS_STRAIGHT_FROM_LEFT:
	case SCI_TRANSITIONS_STRAIGHT_FROM_BOTTOM:
	case SCI_TRANSITIONS_STRAIGHT_FROM_TOP:
		straight(number, blackoutFlag);
		break;

	case SCI_TRANSITIONS_PIXELATION:
		pixelation(blackoutFlag);
		break;

	case SCI_TRANSITIONS_BLOCKS:
		blocks(blackoutFlag);
		break;

	case SCI_TRANSITIONS_FADEPALETTE:
		if (!blackoutFlag) {
			fadeOut(); setNewScreen(blackoutFlag); fadeIn();
		}
		break;

	case SCI_TRANSITIONS_SCROLL_RIGHT:
	case SCI_TRANSITIONS_SCROLL_LEFT:
	case SCI_TRANSITIONS_SCROLL_UP:
	case SCI_TRANSITIONS_SCROLL_DOWN:
		scroll(number);
		break;

	case SCI_TRANSITIONS_NONE_LONGBOW:
	case SCI_TRANSITIONS_NONE:
		setNewScreen(blackoutFlag);
		break;

	default:
		warning("Transitions: ID %d not implemented", number);
		setNewScreen(blackoutFlag);
	}
	// Just to make sure that the current frame is shown in case we skipped the last update-call b/c of timing
	updateScreen();
	debugC(kDebugLevelGraphics, "Transition took %d milliseconds", g_system->getMillis() - _transitionStartTime);
}
Example #26
0
int Pokerhand::straight_flush() {
    if (straight() && flush())
        return high_card();
    return 0;
}
Example #27
0
int main()
{
	printf("version 1.9.5\n");
	shut_down_in(0.010*1000);
	int start=seconds();//starting time for two minutes
	enable_servo(0);
	set_servo_position(0,2047);
	straight(1.8,  170);//gets in front of transport
	rightC(0.28, 100);
	leftC(0.28, -100);
	straight(1.65, 170);
	leftC(0.44, 100);
	printf("completed first dead reckoning\n");
	set_analog_pullup(ETport,  0);
	
	//until distance is 5 centimeter
	/*
	int claw_threshold = 13;
	while(analog10(ETport)>claw_threshold){
		back(0.1, -10);
		msleep(1000);
		printf("move once\n");
		printf("%i\n", analog10(ETport));
	}*/
	back(0.25, -20);//pushes against transport
	msleep(2000);
	set_servo_position(0, 500);//puts claw on transport
	msleep(1000);
	printf("done with attaching to transport\n");
	while(digital(8)==0)//goes forward with transport until it hits the wall
	{
		straight(0.1, 100);
		msleep(10);
	}
	printf("at wall\n");
	back(0.25, -50);//backs  up from wall to deposit transport
	set_servo_position(0, 2047);//raises claw
	msleep(1500);
	while(digital(8)==0){//goes forward until it hits wall for second time
		straight(0.1, 100);
		msleep(10);
	}
	
	printf("at wall 2\n");
	
	back(0.35, -100);//goes back and turns left in order to be oriented with left inner wall
	leftC(0.6, 142);
	
	int bump_counter=0;	
	
	while(digital(8)==0){//hits side wall
		straight(0.1, 100);
		msleep(10);
	}
	
	bump_counter++;//has one bump


    int i=0;
    while(i<10){//if hits side wall, pause
		stop(0.2);
		i++;
	}
	
	back(0.25, -100);
	leftC(0.46, 100);
	
	camera_open(LOW_RES);
	
	armUp();
	clawOpen();
   double start_wait=seconds();
   while((seconds()-start_wait)<=25){//wait for poms or for 25 seconds
       int i=0;
       while(i<10){//picks latest image from the buffer
	   camera_update();
	   i++;
       }
       if(get_object_count(chan)>0){//if camera sees objects, skip the 25 seconds and go onto picking up stuff
           break;
       }else{//if camera doesn't see any objects, keep waiting until 25 seconds is up
           stop(0.1);
       }
   }
   int x=get_object_center(chan, 0).x;//declares global unchanging variable for the x location of the largest object
   while((seconds()-start)<=120){//while there is still time left
	   int area=get_object_area(chan, 0);//creates local changing variable. this is th area of the largest object camera sees
	   if(area<=600){//if the object is small enough(far enough), navigate towards object. 600 is threshold
		   int i=0;
		   while(i<10){//buffer updating
			   camera_update();
			   i++;
		   }
		  
		   navigate_poms(x);//similar to line followig function; gets to poms.
		 
      
	   }
	   
	   armDown();
	   clawClose();
	   armUp();
	   
	   /*
	   leftF(0.5, 100, 80);//turn and go forward until transport is contacted
	   while(digital(8)==0){
	   straight(0.1, 100);*/
   
   }

   

	/*
	back(1.5, 100);
	leftC(0.44, 100);
	
	while(digital(8)==0 && digital(9)==1){
		straight(0.1, 100);
		msleep(10);
			if(digital(9)==0){
				rightF(0.1, 100, 40);
				left(0.1, 100);
				msleep(10);
			}
	}
	straight(2, 200);
	rightC(0.44, 100);
	straight(1, 80);
	rightC(0.92, 100);
	while(analog10(ETport<=600)){
			msleep(10);
	}
	msleep(10000);
	straight(1, 80);
	leftC(0.44, 100);
	straight(2, 200);
	*/
	
	return 0;
}
void navigation(void){
	int i;
  IR_Read ir;
	Data_t data;
  List_t *list=NULL;
  ringInit(&list,RINGSIZE);

  /* Get initial readings */
  for(i=0;i<RINGSIZE;i++)
  {
    /* Read from IRs */
		readIR(&ir);

		/* Convert to distance */
    convertFullDistance(&ir,&data);
    data.trackState = DEFAULT;
    /* Push data onto the ring */
    ringPush(&list,data);

    delay(20);
  }

  //delay(9000);
  setSpeed();
  i=0;
	while(1)
  {
    if(i>80)
    {
      setSpeed();
      i=0;
    }
    data.trackState = DEFAULT;
    if(cooldown(list)) turnstate = STRAIGHT;
		/* Read from IRs */
		readIR(&ir);

		/* Convert to distance */
    convertFullDistance(&ir,&data);


    /* Determine track state */
    trackDetection(list,&data);

    if(analogRead(AIN4)*0.0114 < 10)
    {
      digitalWrite(P8_9,HIGH);
    }
    else
    {
      digitalWrite(P8_9,LOW);
    }

    ringPush(&list,data);

    if(turnstate==FOLLOWRIGHT)
    {
      data.turn_angle = right(&data,&list->data);
    }
    else if(turnstate==FOLLOWLEFT)
    {
      data.turn_angle = left(&data,&list->data);
    }
    else if(turnstate==STRAIGHT)
    {
      data.turn_angle = straight(&data,&list->data);
    }

		/* Update servo */
	  setSteeringAngle(data.turn_angle);

    // printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
    // printf("Front Left Distance: %f, Front Left Sensor: %d\n",data.frontLeft,ir.FrontLeft);
    // printf("Front Right Distance: %f, Front Right Sensor: %d\n",data.frontRight,ir.FrontRight);
    // printf("Back Left Distance: %f, Back Left Sensor: %d\n",data.backLeft,ir.BackLeft);
    // printf("Back Right Distance: %f, Back Right Sensor: %d\n",data.backRight,ir.BackRight);
    // printf("Turn angle calculated: %d\n\n",data.turn_angle);


    delay(60);
    // if(data.trackState==FOLLOWRIGHT) turn_angle=trackStateHandling;
    // else printf("Follow left\n");
    // printf("Cooldown: %d\n",*cooldown);
    i+=1;
	}
}
Example #29
0
void firsteight(){
    getIRDist();

    goStraight();

    //turnRight(90, TURNSPEED);
    turnRight(100, TURNSPEED);

    straight(70, SPEED);  

    //turnRight(45,TURNSPEED);
    turnRight(55, TURNSPEED);

    goStraight();

    turnRight(90, TURNSPEED);
    straight(30, SPEED);
    //straight(50, SPEED);
    //turnRight(45, TURNSPEED);
    turnRight (55, TURNSPEED);

    getIRDist();
     while (1){
        if (rightSideIR < 40)
            {
                break;}
        straight(18, SPEED);
        getIRDist();
    }

    goStraight();

    // The second bit 
    straight(15, SPEED);
    //straight(18, SPEED);
    turnLeft(90, TURNSPEED);

    getIRDist();
    while (1){
        if (leftSideIR < 40)
            {
                break;}
        straight(18, SPEED);
        getIRDist();
    }

    goStraightLeft();

    if (SPEED <= 20)
        { straight(25, SPEED); } 

    turnLeft(90, TURNSPEED);
    
    if (SPEED <= 20)
        { straight(80, SPEED); }
    else { 
        //straight(40, SPEED);
        straight(25, SPEED);
    }

    //turnLeft (45, TURNSPEED);
    turnLeft(55, TURNSPEED);

/*
    //for speed 40
    getIRDist();
    while (1){
        if (leftSideIR < 40)
            { straight(15, SPEED);
                break;
            }
        straight(10, SPEED);
        getIRDist();
    }
    
*/
    straight(15, SPEED);
    goStraightLeft();
    
    turnLeft(90, TURNSPEED);

    //straight(25, SPEED);
    straight (60, SPEED);

    //turnLeft(45, TURNSPEED);
    turnLeft(55, TURNSPEED);

    getIRDist();
    while (1){
        if (leftSideIR < 40)
            { 
                break;
            }
        straight(10, SPEED);
        getIRDist();
    }


    goStraightLeft();
    //For 60 only
    straight(25, SPEED);

    turnRight(90, TURNSPEED);
    getIRDist();
        while (1){
        if (rightSideIR < 40)
            {   straight (25, SPEED); 
                break;}
        straight(18, SPEED);
        getIRDist();
    }

 
}
Example #30
0
// determing hand checks
int Checks::determinehand(vector<int >pvalues, vector<char>psuits)
{
	dvalues.empty();
	dsuits.empty();
	dvalues = pvalues;
	dsuits = psuits;
	if(foldc = true)
	{
		inhand = "FOLD!";
	}

	//gotoxy(30, 20);          // checking the hands starting with the highest possible hand and going down from there.
	sort(dvalues.begin(), dvalues.end());
	if ((flush(dsuits)) && (straight(dvalues)))
	{


		if (dvalues[7] = 14)
		{
			inhand = "Royal Flush!!";
			return 100;
		}
		else
		{
			inhand = "Straight Flush!!";
			return 90;
		}
	}

	else if (flush(dsuits) == 1)
	{
		inhand = "Flush!!";
		return 80;

	}
	else if (straight(dvalues) == 1)
	{
		inhand = "Straight!!";
		return 70;

	}

	else if (fourofakind(dvalues) == 1)
	{
		inhand = "Four of a Kind!!";
		return 60;

	}
	else if (fullhouse(dvalues) == 1)
	{
		inhand = "Fullhouse!!";
		return 50;

	}

	else if (threeofakind(dvalues) == 1)
	{
		inhand = "Three of a Kind!!";
		return 40;

	}
	else if (ispair(dvalues) == 2)
	{
		inhand = "Two Pair!!";
		return 30;
	}
	else if (ispair(dvalues) == 1)
	{
		inhand = "Pair!!";
		return 20;

	}





	else {

		inhand = "Absolutely Nothing!!";


		return dvalues.back();
	}
}