Exemple #1
0
def play(action):
    global board, ko, turn
    if action == 0:
        pass
    elif action == ko:
        return '?'
    else:
        valid, ko = play_go.PlayGo(board, turn, action)
    turn = play_go.FlipTurn(turn)
    return '='
Exemple #2
0
    winner = GetWinner(summary, sequence)
    surrendered = WinBySurrender(winner, summary)
    win_count[winner] = win_count[winner] + 1

    board, ko, turn = play_go.InitBoard()
    seq_cnt = 0
    for move in sequence:
        # Print before play.
        if len(move) == 0:
            continue
        turn, action = ParseMove(move)
        discount = min(1, seq_cnt / (len(sequence) * 1.0))
        feature = play_go.ToFeature(board, ko, turn, action, winner,
                                    RICH_OUTPUT, RICH_OUTPUT)
        print(','.join(list(map(str, feature))))

        valid, ko = play_go.PlayGo(board, turn, action)
        # TODO(neochio): fix encode.
        #if ko == None:
        #  ko = 0
        #else:
        #  ko = ko[0] * 9 + ko[1] - 9
        seq_cnt = seq_cnt + 1
    if surrendered:
        feature = play_go.ToFeature(board, ko, play_go.FlipTurn(turn),
                                    play_go.SURRENDER, winner, RICH_OUTPUT,
                                    RICH_OUTPUT)
        print(','.join(list(map(str, feature))))
logging.warning('win_count: %s' % str(win_count))
Exemple #3
0
      continue

  winner = GetWinner(summary, sequence)
  surrendered = WinBySurrender(winner, summary)
  win_count[winner] += 1

  board, ko, turn = play_go.InitBoard()
  seq_cnt = 0
  for move in sequence:
    seq_cnt += 1
    # Print before play.
    if len(move) == 0:
      continue
    turn, action = ParseMove(move)
    if seq_cnt == len(sequence) and not surrendered:
      feature = play_go.ToFeature(board, ko, turn, action, winner, RICH_OUTPUT, RICH_OUTPUT)
    else:
      feature = play_go.ToFeature(board, ko, turn, action, 0, RICH_OUTPUT, RICH_OUTPUT)
    print(','.join(list(map(str, feature))))

    valid, ko = play_go.PlayGo(board, turn, action)
    # TODO(neochio): fix encode.
    #if ko == None:
    #  ko = 0
    #else:
    #  ko = ko[0] * 9 + ko[1] - 9
  if surrendered:
    feature = play_go.ToFeature(board, ko, play_go.FlipTurn(turn), play_go.SURRENDER, winner, RICH_OUTPUT, RICH_OUTPUT)
    print(','.join(list(map(str, feature))))
logging.warning('win_count: %s' % str(win_count))
Exemple #4
0
  for i in range(len(probabilities)):
    actions.append([train_lib.UnpackAction(i) if i > 0 and i < 82
                    else ACTION_CODE[i], probabilities[i]])

  actions[0][1] = actions[0][1] / 5  # suppress pass
  sorted_actions = sorted(actions, key=lambda x:x[1], reverse = True)
  print(sorted_actions[:5])
  if sorted_actions[0][0] == 'P':
    move_sequences.append('%s[]' % STONE_CODE[turn])
    ko = 0
    if passed:
      print('Both passed')
      break
    print('Passed')
    passed = True
    turn = play_go.FlipTurn(turn)
    continue
  rand = random.random() * epsilon
  for a in sorted_actions:
    action = a[0]
    if action == 'S':
      print('Surrender signal, but will continue for test')
      continue
    if action == 'P':
      continue
    if rand > a[1]:
      rand -= a[1]
      continue
    # TODO: Should should check Ko in PlayGo()
    if action == ko:
      continue