/***************************************
가위바위보 게임 *******************
이 게임은 2차 배열을 생성함으로서 컴퓨터가 전략
적인 기술을 선보입니다 어려우실껄요 ㅎㅎ **
그럼 ㅅㄱ 하세요 (벌써 밤 11:00 네요 ㅠ,ㅠ) *
**************************************/
#include <stdio.h>
int main()
{
int man,computer,M,judge;
static int table[3][3] = {{0,0,0},{0,0,0},{0,0,0}}, //2차 배열생성
hist[3]={0,0,0};
static char *hand[3] = {"가위","바위","보"};
M=0;
while(1){
if(table[M][0]>table[M][1] && table[M][0]>table[M][2])
computer=1;
else if(table[M][1]>table[M][2])
computer=2;
else
computer=0;
printf("밤에 뻘짓을 \n 엔터를 누르면 시작합니다\n");
getch();
printf("0: 가위 , 1:바위 , 2:보\n");
printf("뭘 내시겠습니까 :");scanf("%d",&man);
printf("컴퓨터의 손 : %s\n",hand[computer]);
judge=(computer-man+3)%3; /* 컴퓨터의
switch(judge){ 학습 */
case 0:printf("비김");break;
case 1:printf("컴퓨터의 승리\n");break;
case 2:printf("당신의 승\n");break;
}
hist[judge]++;
table[M][man]++;
M=man;
printf(" %d승 %d무 %d패\n\n", hist[2],hist[1],hist[0]);
}
return 0;
}
아 ; 제생각 입니다
만약 3차 배열로 만들면 더 어려울듯 ...... |