MCPcopy
hub / github.com/inancgumus/learngo / loop

Function loop

x-tba/tictactoe-experiments/04-with-methods/main.go:44–73  ·  view source on GitHub ↗
(in *bufio.Scanner)

Source from the content-addressed store, hash-verified

42}
43
44func loop(in *bufio.Scanner) {
45 g := newGame()
46
47 for {
48 g.prompt()
49
50 if !in.Scan() {
51 break
52 }
53
54 // Atoi already return 0 on error; no need to check
55 // it for the following switch to work
56 pos, _ := strconv.Atoi(in.Text())
57
58 msg := g.play(pos)
59 if msg != "" {
60 fmt.Println("\n>>>", msg)
61 continue
62 }
63
64 g.turn++
65 if msg := g.finito(); msg != "" {
66 g.print()
67 fmt.Printf("\n%s\n", msg)
68 break
69 }
70
71 g.player = switchTo(g.player)
72 }
73}
74
75func newGame() game {
76 return game{

Callers 1

mainFunction · 0.70

Calls 8

PrintlnMethod · 0.80
PrintfMethod · 0.80
newGameFunction · 0.70
switchToFunction · 0.70
printMethod · 0.65
promptMethod · 0.45
playMethod · 0.45
finitoMethod · 0.45

Tested by

no test coverage detected