Y #6256(2008/05/04 12:41 GMT) [ Mathematica ] Rating0/0=0.00
wins:勝ちのパターン isWinner:勝者かどうか judge:ゲームの終了判定 operators:可能な手を返す game:2つの戦略を対戦させる randomDecision:ランダム・プレーヤーの戦略 対戦させると、マルの5877勝2835敗1288分 Timing[ result=Table[game[randomDecision,randomDecision],{10000}]; Count[result,#]&/@{1,-1,0} ] {7.688 Second, {5877, 2835, 1288}}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
wins={{1,2,3},{4,5,6},{7,8,9},{1,4,7},{2,5,8},{3,6,9},{1,5,9},{3,5,7}}; isWinner[player_]:=MemberQ[Length[Intersection[player,#]]&/@wins,3] judge[{p1_,p2_}]:= If[isWinner@p1,1, If[isWinner@p2,-1, If[Length@p1==5,0,Null]]] operators[state_]:=Complement[Range@9,Flatten@state] game[decision1_,decision2_]:=Module[{state={{},{}},result=Null}, While[result===Null, If[Length@state[[1]]==Length@state[[2]], AppendTo[state[[1]],decision1[Sort/@state]], AppendTo[state[[2]],decision2[Sort/@state]]]; result=judge@state]; result] randomDecision[state_]:=With[{x=operators@state}, x[[Random[Integer,{1,Length@x}]]]]
Rating0/0=0.00-0+
[ reply ]
Y
#6256()
[
Mathematica
]
Rating0/0=0.00
wins:勝ちのパターン isWinner:勝者かどうか judge:ゲームの終了判定 operators:可能な手を返す game:2つの戦略を対戦させる randomDecision:ランダム・プレーヤーの戦略 対戦させると、マルの5877勝2835敗1288分 Timing[ result=Table[game[randomDecision,randomDecision],{10000}]; Count[result,#]&/@{1,-1,0} ] {7.688 Second, {5877, 2835, 1288}}wins={{1,2,3},{4,5,6},{7,8,9},{1,4,7},{2,5,8},{3,6,9},{1,5,9},{3,5,7}}; isWinner[player_]:=MemberQ[Length[Intersection[player,#]]&/@wins,3] judge[{p1_,p2_}]:= If[isWinner@p1,1, If[isWinner@p2,-1, If[Length@p1==5,0,Null]]] operators[state_]:=Complement[Range@9,Flatten@state] game[decision1_,decision2_]:=Module[{state={{},{}},result=Null}, While[result===Null, If[Length@state[[1]]==Length@state[[2]], AppendTo[state[[1]],decision1[Sort/@state]], AppendTo[state[[2]],decision2[Sort/@state]]]; result=judge@state]; result] randomDecision[state_]:=With[{x=operators@state}, x[[Random[Integer,{1,Length@x}]]]]Rating0/0=0.00-0+
[ reply ]