I have just completed a Doubling video of Blackjack AI.
My implementation of Play
on humanAI
is the same as the one in video (as far as I see).
func (ai humanAI) Play(hand []deck.Card, dealer deck.Card) Move {
for {
fmt.Println("Player:", hand)
fmt.Println("Dealer:", dealer)
fmt.Println("What will you do? (h)it, (s)tand, (d)ouble")
var input string
fmt.Scanf("%s\n", &input)
switch input {
case "h":
return MoveHit // <- note this
case "s":
return MoveStand // <- this
case "d":
return MoveDouble // <- and this
default:
fmt.Println("Invalid option:", input)
}
}
}
In Game.Play
in game.go
I’m getting move(g) (no value) used as value
when I’m assigning err := move(g)
.
move(g) (no value) used as value
A little research on the above error says that I need to return something from ai.Play
. But I am already returning Move there.
But at these places:
case "h":
return MoveHit
case "s":
return MoveStand
case "d":
return MoveDouble
I’m getting:
cannot use MoveHit (value of type func(g *Game) error) as Move value in return statement
Please point out what I am doing wrong?
Here is the link to the complete ai.go
and game.go
: https://github.com/santosh/gophercises/tree/7249c69822e759138f7059905ca2c25b4c5a3541/blackjack