こう。 #6215(2008/04/24 11:24 GMT) [ C ] Rating0/0=0.00
結果の検証用に打ち筋をすべてたどってみました。 先攻勝ち:131184(51.4%) 後攻勝ち:77904(30.5%) 引き分け:46080(18.1%) の255168通りでした。 乱数で勝負させたものは確かにsyatさんの数字に近くなったんですが・・・。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
#include <stdio.h> #include <stdlib.h> typedef struct { int data; int turn; } CELL; /* [0][1][2] [3][4][5] [6][7][8] cell data cellの内容 0:空白 1:o 2:x turn 打たれたターン数 */ //勝敗チェック // 0 :決着まだ // not 0:勝負あり int check(CELL a[],int w){ int i; //縦横 for(i=0;i<3;i++){ if((a[i*3].data==w)&&(a[i*3+1].data==w)&&(a[i*3+2].data==w)|| (a[i].data==w)&&(a[i+3].data==w)&&(a[i+6].data==w)) return -1; } //斜め if((a[0].data==w)&&(a[4].data==w)&&(a[8].data==w)|| (a[2].data==w)&&(a[4].data==w)&&(a[6].data==w)) return -1; return 0; } int result[3]; int analyze(CELL a[],int t,int turn){ int i; if(turn==10){ //引き分け result[0]++; return -1; } //進行 for(i=0;i<9;i++){ if(a[i].data==0){ //置けるなら置く a[i].data=t; a[i].turn=turn; //勝負判定 if(check(a,t)){ //決着 result[t]++; }else{ //続行 analyze(a,3-t,turn+1); } //一手戻す a[i].data=0; a[i].turn=0; } } return 0; } int main(){ int i; CELL a[9]; //盤面初期化 for(i=0;i<9;i++){ a[i].data=0; a[i].turn=0; } for(i=0;i<3;i++){ result[i]=0; } analyze(a,1,1); i=result[0]+result[1]+result[2]; printf("o win:%d(%2.1f%%) x win:%d(%2.1f%%) draw:%d(%2.1f%%)\n", result[1],100.0*result[1]/i, result[2],100.0*result[2]/i, result[0],100.0*result[0]/i); return 0; }
Rating0/0=0.00-0+
1 reply [ reply ]
こう。 #6215() [ C ] Rating0/0=0.00
Rating0/0=0.00-0+