<commit_before>library Mastermind;

import "dart:math";

part "code.dart";
part "code-breaker.dart";
part "permutation.dart";

void main(List<String> args) {  
  // Be sure the user supplied at least two digits for the code.
  if(args.length < 2) {
    print("The Code must be at least 2 digits long.");
    return;
  }
  
  // Create the actual code.
  List<int> inputCode = new List();
  for(String arg in args) {
    // Try to parse the info, but don't trust the user to give you correct input.
    try {
      // Parse the digit to add and if it's a good value, add it.
      int digitToAdd = int.parse(arg);
      if(digitToAdd <= Code.MAX_VAL && digitToAdd >= 0)
        inputCode.add(digitToAdd);
      else
        throw new Exception();
      
      // If the user supplied bad input, tell them.
    } catch(e) {
      print("The code can only be single digit numbers, from 0 - ${Code.MAX_VAL}");
      return;
    }
  }
  
  // userCode is the code the program is trying to crack.
  // This is only used to see if the guessed code is correct, and to provide
  // feedback to the CodeBreaker, so the user doesn't have to do it.
  Code userCode = new Code(inputCode);
  
  // Create the object that will break the code.
  CodeBreaker cb = new CodeBreaker(Code.MAX_VAL, userCode.length);
  
  // This will become true when the code is cracked.
  bool guessed = false;
  
  // Try 10 times at the most to guess the code.
  for(int i=0; i<10; i++) {
    // Guess a number.
    Code guess = cb.guessNumber();
    print("Guess #${i + 1}: $guess");
    
    // If the number was guessed, tell the user.
    if(guess == userCode) {
      print("Guessed it in ${i+1} tries. The code was: $guess");
      guessed = true;
      break;
    }
    
    // If the number was not guessed, give the CodeBreaker
    // feedback and try again.
    else {
      int numCorrect = userCode.numCorrect(guess);
      int numClose = userCode.numClose(guess);
      
      cb.giveFeedback(numCorrect, numClose);
    }
  }
  
  // If it somehow manages to fail, let the user know.
  if(!guessed) {
    print("The program has failed to guess the code in under 10 tries.");
  }
}<commit_msg>It now prints the number of correct/close hits for each guess.<commit_after>library Mastermind;

import "dart:math";

part "code.dart";
part "code-breaker.dart";
part "permutation.dart";

void main(List<String> args) {  
  // Be sure the user supplied at least two digits for the code.
  if(args.length < 2) {
    print("The Code must be at least 2 digits long.");
    return;
  }
  
  // Create the actual code.
  List<int> inputCode = new List();
  for(String arg in args) {
    // Try to parse the info, but don't trust the user to give you correct input.
    try {
      // Parse the digit to add and if it's a good value, add it.
      int digitToAdd = int.parse(arg);
      if(digitToAdd <= Code.MAX_VAL && digitToAdd >= 0)
        inputCode.add(digitToAdd);
      else
        throw new Exception();
      
      // If the user supplied bad input, tell them.
    } catch(e) {
      print("The code can only be single digit numbers, from 0 - ${Code.MAX_VAL}");
      return;
    }
  }
  
  // userCode is the code the program is trying to crack.
  // This is only used to see if the guessed code is correct, and to provide
  // feedback to the CodeBreaker, so the user doesn't have to do it.
  Code userCode = new Code(inputCode);
  
  // Create the object that will break the code.
  CodeBreaker cb = new CodeBreaker(Code.MAX_VAL, userCode.length);
  
  // This will become true when the code is cracked.
  bool guessed = false;
  
  // Try 10 times at the most to guess the code.
  for(int i=0; i<10; i++) {
    // Guess a number.
    Code guess = cb.guessNumber();
    
    // If the number was guessed, tell the user.
    if(guess == userCode) {
      print("Guessed it in ${i+1} tries. The code was: $guess");
      guessed = true;
      break;
    }
    
    // If the number was not guessed, give the CodeBreaker
    // feedback and try again.
    else {
      int numCorrect = userCode.numCorrect(guess);
      int numClose = userCode.numClose(guess);
      print("Guess #${i + 1}: $guess.");
      print("\tCorrect hits: $numCorrect");
      print("\tClose hits  : $numClose");
      
      cb.giveFeedback(numCorrect, numClose);
    }
  }
  
  // If it somehow manages to fail, let the user know.
  if(!guessed) {
    print("The program has failed to guess the code in under 10 tries.");
  }
}
{'fraction_non_alphanumeric': 0.10915178571428572, 'fraction_numerical': 0.005803571428571429, 'mean_word_length': 2.436349693251534, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '308065', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1400, 'n_words': 552}