⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 listing1.cpp

📁 C人工智能游戏开发的一些实例源代码 C Game development in artificial intelligence source code of some examples
💻 CPP
字号:
/* Copyright (C) Jonty Barnes and Jason Hutchens, 2001. 
 * All rights reserved worldwide.
 *
 * This software is provided "as is" without express or implied
 * warranties. You may freely copy and compile this source into
 * applications you distribute provided that the copyright text
 * below is included in the resulting source code, for example:
 * "Portions Copyright (C) Jonty Barnes and Jason Hutchens, 2001"
 */

// C source of a character-level 1st-order Markov model.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc,char** argv) {
   int C[258][258],context,thresh,c=256,i,j;
   FILE* file;
   for(i=0; i<258; ++i)
      for(j=0; j<258; ++j)
         C[i][j]=0;
   if(argc!=2) return 1;
   file=fopen(argv[1],"r");
   if(!file) return 2;
   while(!feof(file)) {
      context=c; c=fgetc(file);
      if(c==-1) c=256;
      ++C[context][c]; ++C[context][257];
   }
   fclose(file);
   srand(time(NULL));
   do {
      context=c; c=-1;
      thresh=rand()%C[context][257];
      do {
         thresh-=C[context][++c];
} while(thresh>=0);
      fprintf(stdout,"%c",(char)c);
   } while(c!=256);
   return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -