Comment detail

マルバツゲーム (Nested Flatten)

This comment is reply for 6204 turugina: ○×ゲームなのに視覚的なものはほとんど考...(マルバツゲーム). Go to thread root.

drawを先に判定しちゃダメじゃん...

というわけで、100万回試行の結果がちゃんと

player 1 won : 585255(0.585255)
player 2 won : 287878(0.287878)
draw : 126867(0.126867)

になりました。

 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
int
board_checker::operator()(board& b)
  const
{
  if ( int id = b(1,1) )
    if ((b(0,0) == id && b(2,2) == id ) ||
        (b(0,2) == id && b(2,0) == id) ||
        (b(0,1) == id && b(2,1) == id) ||
        (b(1,0) == id && b(1,2) == id) )
      return id;
  if ( int id = b(0,0) )
    if ((b(0,1) == id && b(0,2) == id) ||
        (b(1,0) == id && b(2,0) == id) )
      return id;
  if ( int id = b(2,2) )
    if ((b(1,2) == id && b(0,2) == id) ||
        (b(2,1) == id && b(2,0) == id) )
      return id;

  bool draw=true;
  for (int x = 0; draw && x < 3; ++x )
    for (int y = 0; draw && y < 3; ++y )
      draw = b(x,y) != 0;
  if ( draw )
    return -1;
  // not finish
  return 0;
}

Index

Feed

Other

Link

Pathtraq

loading...