Skip to content

Commit aeb3cb4

Browse files
committed
the stone are now placed on the intersections
1 parent 14d0fbb commit aeb3cb4

File tree

1 file changed

+30
-42
lines changed

1 file changed

+30
-42
lines changed

cmd/game/gui.go

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Gui struct {
2121
}
2222

2323
var FieldStateName = map[FieldState]string{
24-
Empty: " ",
24+
Empty: "",
2525
Black: "○", // Unicode empty circle for black stone
2626
White: "●", // Unicode filled circle for white stone
2727
}
@@ -53,58 +53,46 @@ func (g *Gui) Refresh() {
5353
}
5454

5555
func (g *Gui) DrawGridToWriter(w io.Writer, cursorRow, cursorCol int) {
56-
// Draw column labels
57-
fmt.Fprint(w, " ")
58-
for j := range [9]int{} {
59-
fmt.Fprint(w, j+1)
60-
if j < 8 {
61-
fmt.Fprint(w, " ")
62-
}
56+
// Column labels
57+
fmt.Fprint(w, " ")
58+
for j := 0; j < 9; j++ {
59+
fmt.Fprintf(w, " %c ", 'A'+j)
6360
}
6461
fmt.Fprintln(w)
65-
// Draw top border
66-
fmt.Fprint(w, " ┌")
67-
for j := range [9]int{} {
68-
fmt.Fprint(w, "───")
69-
if j < 8 {
70-
fmt.Fprint(w, "┬")
71-
}
72-
}
73-
fmt.Fprintln(w, "┐")
74-
for i := range [9]int{} {
75-
// Draw row label
76-
fmt.Fprintf(w, "%2d │", i+1)
77-
for j := range [9]int{} {
78-
char := g.Grid[i][j].String()
62+
63+
for i := 0; i < 9; i++ {
64+
// Row label
65+
fmt.Fprintf(w, "%2d ", i+1)
66+
for j := 0; j < 9; j++ {
67+
stone := g.Grid[i][j].String()
68+
cell := fmt.Sprintf("-%s-", stone)
69+
if j == 0 {
70+
cell = fmt.Sprintf(" %s-", stone)
71+
} else if j == 8 {
72+
cell = fmt.Sprintf("-%s ", stone)
73+
}
74+
7975
if i == cursorRow && j == cursorCol {
80-
fmt.Fprint(w, "[", char, "]")
81-
} else {
82-
fmt.Fprint(w, " ", char, " ")
76+
// Use a different background or brackets, but keep width 3
77+
cell = fmt.Sprintf("[%s]", stone)
8378
}
79+
fmt.Fprint(w, cell)
80+
// Draw horizontal line except after last column
8481
if j < 8 {
85-
fmt.Fprint(w, "")
82+
fmt.Fprint(w, "")
8683
}
8784
}
88-
fmt.Fprintln(w, "│")
89-
// Draw row separator or bottom border
85+
fmt.Fprintln(w)
86+
// Draw vertical lines except after last row
9087
if i < 8 {
91-
fmt.Fprint(w, " ├")
92-
for j := range [9]int{} {
93-
fmt.Fprint(w, "───")
94-
if j < 8 {
95-
fmt.Fprint(w, "┼")
96-
}
97-
}
98-
fmt.Fprintln(w, "┤")
99-
} else {
100-
fmt.Fprint(w, " └")
101-
for j := range [9]int{} {
102-
fmt.Fprint(w, "───")
88+
fmt.Fprint(w, " ")
89+
for j := 0; j < 9; j++ {
90+
fmt.Fprint(w, " │ ")
10391
if j < 8 {
104-
fmt.Fprint(w, "")
92+
fmt.Fprint(w, " ")
10593
}
10694
}
107-
fmt.Fprintln(w, "┘")
95+
fmt.Fprintln(w)
10896
}
10997
}
11098
}

0 commit comments

Comments
 (0)