Skip to content

Commit

Permalink
Update main.go
Browse files Browse the repository at this point in the history
Add function to detect correct, but incomplete answers in
learning-writing mode
  • Loading branch information
Jero075 committed May 24, 2023
1 parent 9daeb6f commit 48f485a
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"math/rand"
"os"
"strconv"
"strings"
)

const (
Expand Down Expand Up @@ -129,6 +130,35 @@ func edit(set Set) Set {
return set
}

func checkAnswer(answer string, correct string) bool {
answer = strings.ReplaceAll(strings.TrimSpace(answer), " ", "")
correct = strings.ReplaceAll(strings.TrimSpace(correct), " ", "")
if answer == correct {
return true
}
if strings.Contains(correct, "(") && strings.Contains(correct, ")") {
correctWithoutBrackets := strings.Split(correct, "(")[0] + strings.Split(correct, ")")[1]
if answer == correctWithoutBrackets {
return true
}
}
if strings.Contains(correct, "/") {
for _, correctAnswer := range strings.Split(correct, "/") {
if answer == correctAnswer {
return true
}
}
}
if strings.Contains(correct, "|") {
for _, correctAnswer := range strings.Split(correct, "|") {
if answer == correctAnswer {
return true
}
}
}
return false
}

func Create(name string) {
if name[len(name)-5:] != ".ofmp" {
name += ".ofmp"
Expand Down Expand Up @@ -231,6 +261,15 @@ func Learn(name string) {
fmt.Println("Invalid stage")
return
}
var fullBool bool
fmt.Println("Full answers? [y]es/[N]o")
scanner.Scan()
full := scanner.Text()
if full == "y" || full == "Y" {
fullBool = true
} else {
fullBool = false
}
var cards int
nums := randList(len(set.Flashcards))
for i := 0; i < len(set.Flashcards); i++ {
Expand All @@ -257,6 +296,15 @@ func Learn(name string) {
} else {
fmt.Println("Correct, but you used help")
}
} else if checkAnswer(answer, set.Flashcards[nums[i]].A) && !fullBool {
if !helpUsed {
set.Flashcards[nums[i]].LearningStage++
fmt.Println("Correct")
fmt.Println("Full answer: " + set.Flashcards[nums[i]].A)
} else {
fmt.Println("Correct, but you used help")
fmt.Println("Full answer: " + set.Flashcards[nums[i]].A)
}
} else {
fmt.Println("Wrong")
fmt.Println("Correct answer: " + set.Flashcards[nums[i]].A)
Expand Down

0 comments on commit 48f485a

Please sign in to comment.