예제 #1
0
static void
CheerWinner (void)
{
  int winner;
  int i;
  gint pos;
  gchar *message;

  ShowoffPlayer (ScoreList, CurrentPlayer, 0);

  winner = FindWinner ();

  /* draw. The score is returned as a negative value */
  if (winner < 0) {
    for (i = 0; i < NumberOfPlayers; i++) {
      if (total_score (i) == -winner) {
	ShowoffPlayer (ScoreList, i, 1);
      }
    }

    say (_("The game is a draw!"));
    return;
  }

  ShowoffPlayer (ScoreList, winner, 1);

  if (winner < NumberOfHumans) {
    pos = games_scores_add_plain_score (highscores, (guint32) WinningScore);

    if (pos > 0) {
      games_scores_update_score (highscores, players[winner].name);
      if (dialog) {
        gtk_window_present (GTK_WINDOW (dialog));
      } else {
        dialog = games_scores_dialog_new (GTK_WINDOW (window), highscores, _("Tali Scores"));
        message =
  	  g_strdup_printf ("<b>%s</b>\n\n%s", _("Congratulations!"),
                           pos == 1 ? _("Your score is the best!") :
                           _("Your score has made the top ten."));
        games_scores_dialog_set_message (GAMES_SCORES_DIALOG (dialog), message);
        g_free (message);
      }
      games_scores_dialog_set_hilight (GAMES_SCORES_DIALOG (dialog), pos);

      gtk_dialog_run (GTK_DIALOG (dialog));
      gtk_widget_hide (dialog);
    }
  }

  if (players[winner].name)
    say (ngettext ("%s wins the game with %d point",
		   "%s wins the game with %d points", WinningScore),
	 players[winner].name, WinningScore);
  else
    say (_("Game over!"));

}
예제 #2
0
/*-----------------------------------------------------------------------------\*
 Add background based on the new image and return the current model if asked for
 \*-----------------------------------------------------------------------------*/
void PixelSOM::AddBackground(int nIteration, IplImage* img, IplImage *bgImage,
        IplImage* fgImage) {
    // Check if we are in training mode 
    bool bIsTraining = m_pSOBSParams->bIsTraining(nIteration);

    // Temporary variables 
    std::vector<double> vecFeatures;
    int nRow = 0;
    int nCol = 0;
    int nGridX = 0;
    int nGridY = 0;
    bool bIsBackground = false;
    HSVModel *pWinnerModel = NULL;
    int nCount = 0;
    int nCastShadow = 0;

    for (int i = 0; i < m_nNumberOfPixels; ++i) {
        // Get the pixel 
        nRow = i / m_nWidth;
        nCol = i % m_nWidth;
        GetPixel(img, nRow, nCol, vecFeatures);

        // Find the winner model for the pixel 
        bIsBackground = FindWinner(bIsTraining, nRow, nCol, vecFeatures,
                &nGridX, &nGridY, &pWinnerModel);

        // Adapt the models if it is background 
        if (bIsBackground)
            Learn(m_pSOBSParams->fAlpha(nIteration), nGridX, nGridY,
                    vecFeatures);
        else if (m_pSOBSParams->bCheckCastShadow
                && IsCastShadow(vecFeatures, nRow, nCol)) {
            bIsBackground = true;
            nCastShadow++;
        }

        // Create foreground mask 
        if (fgImage != NULL)
            ((uchar *) (fgImage->imageData + nRow * fgImage->widthStep))[nCol] =
                    bIsBackground ? 0 : 255;

        // Set the background image 
        if (bgImage != NULL)
            SetModel(bgImage, nRow, nCol);

        // Increment the 
        if (!bIsBackground)
            ++nCount;
    }
}
예제 #3
0
파일: LVQ.CPP 프로젝트: rischanlab/LVQ
void LVQ::Run(){
  int pat,np,i;
  int Winner;
printf("\n");
np=Pattern->NumPatterns;
for (pat=0; pat<np; pat++){     //Traverse all patterns
   LoadInLayer(pat);
   Winner=FindWinner();
   printf("Responding neuron %d is of class %d \n",Winner,zClass[Winner]);
   printf("The desired class for pattern %d is: %d\n",pat,Pattern->QueryClass(pat));
   printf("The distances to each of the output layer neurons are:\n");
   for (i=0;i<YoutSize ; i++) {
      printf("distance from pattern %d to neuron %d is: %f\n",pat,i,EucNorm(i));
      } /* endfor */
   printf("\n");
   }
}
예제 #4
0
파일: LVQ.CPP 프로젝트: rischanlab/LVQ
void LVQ::RunTrn(){
int pat,np;
int k,z;
int Winner;
epoch=0;
np=Pattern->NumPatterns;
while (epoch<=MAXEPOCHS){
   if( (epoch<=50) || (25*(epoch/25)==epoch) ) {        //output control
      printf("EPOCH=%d\n",epoch);
      printf("eta=%f\n",eta);
      }
   for (pat=0; pat<np; pat++){     //Traverse all patterns
     LoadInLayer(pat);
     Winner=FindWinner();
     if( (epoch<=50) || (25*(epoch/25)==epoch) ) {        //output control
        printf("winner=%d/pat=%d\n",Winner,pat);
        printf("winner class=%d/pat class=%d\n",zClass[Winner],Pattern->QueryClass(pat));
        }
     Train(Winner,pat);
     if( (epoch<=50) || (25*(epoch/25)==epoch) ) {        //output control
        printf("W[%d]=",Winner);
        z=1;
        for (k=0; k<YinSize; k++) {
           printf("%f ",W[k][Winner]);
           if (z>4){
              printf("\n     ");
              z=1;
              }
            else
              z++;
           } /* endfor */
        printf("\n\n");
        }
     }
   epoch++;                       //keep track of epochs
   if (StochFlg)                  // if desired
     Pattern->ReShuffle(np);      //   reorder training patterns
   AdaptParms();                  //Adjust the learning rate
   }
}
예제 #5
0
int OnTheGame()
{
	int turn = 0;

	struct card dillers[10];//딜러가 받는 카드
	int dillCardIndex = 0;

	struct card users[10];//사용자가 받는 카드
	int userCardIndex = 0;

	int isSame = 0; //0은 같은 카드 없음, 1은 같은 카드 있음

	//카드 수 합을 저장할 변수
	int sumOfUsers = 0;
	int sumOfDillers = 0;

	//더 받는가 안 받는가
	int dillerStay = 0;//0은 받음, 1은 안 받음
	int userStay = 0;

	int whosWin = 3;// 0은 딜러 우승, 1은 사용자 우승, 2는 무승부

	while (1){
		//딜러가 먼저 시작
		if (turn % 2 == 0){

			if (dillerStay != 1){
				while (1){
					//RandomNumGenerater에 4를 넣어 4가지의 임의의 수로 카드의 문양을 결정
					dillers[dillCardIndex].cardShape = RandomNumGenerater(4);
					//RandomNumGenerater에 13을 넣어 13가지의 임의의 수로 카드의 수를 결정
					dillers[dillCardIndex].cardNum = RandomNumGenerater(13);

					isSame = IsThereSameCard(dillers, users);

					if (isSame == 0)
						break;
				}

				if ((dillers[dillCardIndex].cardShape == 0) || (dillers[dillCardIndex].cardNum == 0))
					printf("시스템 오류가 발생했습니다.\n");

				//갖고 있는 카드의 수를 모두 더함
				if (dillers[dillCardIndex].cardNum >= 11)
					sumOfDillers += 10;
				else 
					sumOfDillers += dillers[dillCardIndex].cardNum;

				//카드의 수 합이 16이상 21미만 또는 21, 21초과인지 판별
				if ((sumOfDillers >= 17) && (sumOfDillers <= 20)){
					printf("딜러가 스테이를 외쳤습니다!\n\n");
					dillerStay = 1;
				}

				dillCardIndex++;
			}
		}



		else{
			if (userStay != 1){
				while (1){
					//RandomNumGenerater에 4를 넣어 4가지의 임의의 수로 카드의 문양을 결정
					users[userCardIndex].cardShape = RandomNumGenerater(4);
					//RandomNumGenerater에 13을 넣어 13가지의 임의의 수로 카드의 수를 결정
					users[userCardIndex].cardNum = RandomNumGenerater(13);

					isSame = IsThereSameCard(dillers, users);

					if (isSame == 0)
						break;
				}

				if ((users[userCardIndex].cardShape == 0) || (users[userCardIndex].cardNum == 0))
					printf("시스템 오류가 발생했습니다.\n");



				//갖고 있는 카드의 수를 모두 더함
				if (users[userCardIndex].cardNum >= 11)
					sumOfUsers += 10;
				else
					sumOfUsers += users[userCardIndex].cardNum;

				printf("\n현재 카드 수의 총 합: %d \n", sumOfUsers);

				//카드의 수 합이 16이상 21미만 또는 21, 21초과인지 판별
				if ((sumOfUsers >= 16) && (sumOfUsers < 21)){
					printf("\n더 받으시려면 0을, 그만 받으시려면 1을 입력하십시오: ");
					scanf("%d", &userStay);
					printf("\n");
				}


				userCardIndex++;
			}
		}
		if ((userStay == 1) && (dillerStay == 1))
			whosWin = FindWinner(sumOfDillers, sumOfUsers);

		if (sumOfDillers > 21)
			whosWin = 1;
		else if (sumOfUsers > 21)
			whosWin = 0;
		
		if ((sumOfDillers > 21) && (sumOfUsers > 21))
			whosWin = 2;

		if (whosWin != 3)
			break;

		/*
		딜러의 인공지능을 이 cpp파일 안에서 만들 것인지 다른 cpp파일을 만들고 거기에서 구현하고 여기로 가져다 쓸 것인지 의견 내주십시오.
		*/

		turn++;
	}
	
	printf("\n딜러의 카드 수 합: %d\n\n", sumOfDillers);

	return whosWin;
}