コード例 #1
0
        next_states = circuit.GetNextStates(current_state)
        current_state = next_states[random.choice(xrange(len(next_states)))]
        if _Done(current_state):
          break
    if current_state.status == STATUS_CRASHED:
      score = _GetDistanceScore(circuit, current_state) + _CRASH_SCORE
    elif current_state.status == STATUS_FINISHED:
      score = float(current_state.round) + _MINIMUM_SCORE
    else:
      score = _GetDistanceScore(circuit, current_state)
    if best_index is None or score < best_score:  # Smaller is better.
      best_index = index
      best_score = score
  return best_score, best_index


if __name__ == '__main__':
  parser = argparse.ArgumentParser()
  parser.add_argument("--circuit_directory", metavar='DIRECTORY', type=str, required=False, help="The directory where the circuit files are located.")
  parser.add_argument("--circuit_name", metavar='NAME', type=str, required=False, help="The name of the circuit to analyze.")
  args = parser.parse_args()
  if args.circuit_directory:
    Circuit.SetPath(args.circuit_directory)
  circuit = circuit_analyzer.GetAnalyzableCircuit(args.circuit_name)
  p = MonteCarloPlayer()
  p.SetAllowedMoves(circuit, [])
  index = p.Play(circuit, [])
  # print 'Best index:', index
  # print 'Re-running a second time to test caching...'
  index = p.Play(circuit, [])