Fallout 3 and Fallout: New Vegas hacker assistant
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
963B

  1. package main
  2. func getPartialGuesses(guesses []Guess) []Guess {
  3. partialGuesses := []Guess{}
  4. for _, guess := range guesses {
  5. if guess.CorrectCount != nil {
  6. partialGuesses = append(partialGuesses, guess)
  7. }
  8. }
  9. return partialGuesses
  10. }
  11. func numOfSameLetters(first, second Guess) uint {
  12. var num uint
  13. for i := 0; i < len(first.Word); i++ {
  14. if first.Word[i] == second.Word[i] {
  15. num++
  16. }
  17. }
  18. return num
  19. }
  20. func filterByPartialGuess(guesses []Guess, partial Guess) []Guess {
  21. filtered := []Guess{}
  22. for _, guess := range guesses {
  23. if partial.CorrectCount == nil {
  24. return guesses
  25. }
  26. if guess.Word != partial.Word && numOfSameLetters(partial, guess) == *partial.CorrectCount {
  27. filtered = append(filtered, guess)
  28. }
  29. }
  30. return filtered
  31. }
  32. func filterGuesses(guesses []Guess) []Guess {
  33. partialGuesses := getPartialGuesses(guesses)
  34. for _, partial := range partialGuesses {
  35. guesses = filterByPartialGuess(guesses, partial)
  36. }
  37. return guesses
  38. }