// File: kobanium[P]Ray/src/mcts/Simulation.cpp
// Function: Simulation(game_info_t*, int, std::mersenne_twister_engine<unsigned long, 64ul, 312ul, 156ul, 31ul, 13043109905998158313ul, 29ul, 6148914691236517205ul, 17ul, 8202884508482404352ul, 37ul, 18444473444759240704ul, 43ul, 6364136223846793005ul>&)
void
Simulation( game_info_t *game, int starting_color, std::mt19937_64 &mt )
{
  int color = starting_color, pos = -1;
  int pass_count = 0;

  // シミュレーション打ち切り手数を設定
  int length = MAX_MOVES - game->moves;

  if (length < 0) {
    return;
  }

  // レートの初期化  
  std::fill_n(game->sum_rate, 2, 0);
  std::fill(game->sum_rate_row[0], game->sum_rate_row[2], 0);
  std::fill(game->rate[0], game->rate[2], 0);

  // 黒番のレートの計算
  Rating(game, S_BLACK, &game->sum_rate[0], game->sum_rate_row[0], game->rate[0]);
  // 白番のレートの計算
  Rating(game, S_WHITE, &game->sum_rate[1], game->sum_rate_row[1], game->rate[1]);

  // 終局まで対局をシミュレート
  while (length-- && pass_count < 2) {
    // 着手を生成する
    pos = RatingMove(game, color, mt);
    // 石を置く
    PoPutStone(game, pos, color);
    // パスの確認
    pass_count = (pos == PASS) ? (pass_count + 1) : 0;
    // 手番の入れ替え
    color = GetOppositeColor(color);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl $0xffffffff, -0x20(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x24(%rbp)
movq -0x8(%rbp), %rcx
movl $0x43a, %eax            # imm = 0x43A
subl 0x43b0(%rcx), %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jge 0x85284
jmp 0x853e3
movq -0x8(%rbp), %rdi
addq $0x9dea8, %rdi          # imm = 0x9DEA8
movl $0x0, -0x2c(%rbp)
movl $0x2, %esi
leaq -0x2c(%rbp), %rdx
callq 0x853f0
movq -0x8(%rbp), %rdi
addq $0x9dcd8, %rdi          # imm = 0x9DCD8
movq -0x8(%rbp), %rsi
addq $0x9dcd8, %rsi          # imm = 0x9DCD8
addq $0x1d0, %rsi            # imm = 0x1D0
movl $0x0, -0x30(%rbp)
leaq -0x30(%rbp), %rdx
callq 0x85440
movq -0x8(%rbp), %rdi
addq $0x9a848, %rdi          # imm = 0x9A848
movq -0x8(%rbp), %rsi
addq $0x9a848, %rsi          # imm = 0x9A848
addq $0x3490, %rsi           # imm = 0x3490
movl $0x0, -0x34(%rbp)
leaq -0x34(%rbp), %rdx
callq 0x85440
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rdx
addq $0x9dea8, %rdx          # imm = 0x9DEA8
movq -0x8(%rbp), %rcx
addq $0x9dcd8, %rcx          # imm = 0x9DCD8
movq -0x8(%rbp), %r8
addq $0x9a848, %r8           # imm = 0x9A848
movl $0x1, %esi
callq 0x848e0
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rdx
addq $0x9dea8, %rdx          # imm = 0x9DEA8
addq $0x8, %rdx
movq -0x8(%rbp), %rcx
addq $0x9dcd8, %rcx          # imm = 0x9DCD8
addq $0xe8, %rcx
movq -0x8(%rbp), %r8
addq $0x9a848, %r8           # imm = 0x9A848
addq $0x1a48, %r8            # imm = 0x1A48
movl $0x2, %esi
callq 0x848e0
movl -0x28(%rbp), %ecx
movl %ecx, %eax
addl $-0x1, %eax
movl %eax, -0x28(%rbp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x35(%rbp)
je 0x8538d
cmpl $0x2, -0x24(%rbp)
setl %al
movb %al, -0x35(%rbp)
movb -0x35(%rbp), %al
testb $0x1, %al
jne 0x85396
jmp 0x853e3
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
movq -0x18(%rbp), %rdx
callq 0x83370
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movl -0x20(%rbp), %esi
movl -0x1c(%rbp), %edx
callq 0x9e1e0
cmpl $0x0, -0x20(%rbp)
jne 0x853c9
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x853d0
xorl %eax, %eax
movl %eax, -0x3c(%rbp)
jmp 0x853d0
movl -0x3c(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x1c(%rbp), %edi
callq 0x25810
movl %eax, -0x1c(%rbp)
jmp 0x8536e
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)