diff --git a/board-shared/src/ai.rs b/board-shared/src/ai.rs index de2553c..438cf18 100644 --- a/board-shared/src/ai.rs +++ b/board-shared/src/ai.rs @@ -44,16 +44,18 @@ pub fn generate_valid_combinations(hand: &Hand) -> Vec> { // Then try to place the equals sign at each possible position // Since equality is commutative, we only need to try half of the positions for equals_idx in 0..(nb_digits / 2) { - for operators in operators.iter().permutations(nb_digits - 2) { - merge_expression(&digits, &operators, equals_idx, &mut trial); - if let Ok(tokens) = lexer(&trial) { - if let Ok(expressions) = parse(&tokens) { - if are_valid_expressions(&expressions) { - combinations.push(trial.clone()); + for nb_operators in 0..=(nb_digits - 2) { + for operators in operators.iter().permutations(nb_operators) { + merge_expression(&digits, &operators, equals_idx, &mut trial); + if let Ok(tokens) = lexer(&trial) { + if let Ok(expressions) = parse(&tokens) { + if are_valid_expressions(&expressions) { + combinations.push(trial.clone()); + } } } + trial.clear(); } - trial.clear(); } } }