-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
746 lines (630 loc) · 19.7 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
package main
import (
"fmt"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/dustin/go-humanize/english"
"golang.org/x/exp/slices"
"os"
"strings"
)
var version = "dev"
const gridWidth = 8
const gridHeight = 8
type vector2d struct {
x int
y int
}
type player int
const (
DarkPlayer player = iota
LightPlayer
Blank = -1
)
func (p player) String() string {
return [...]string{"Dark Player", "Light Player"}[p]
}
func (p player) toSymbol() string {
return [...]string{"X", "O"}[p]
}
type rules int
const (
ReversiRules rules = iota
OthelloRules
)
func (r rules) String() string {
return [...]string{"Reversi", "Othello"}[r]
}
type grid [gridHeight][gridWidth]player
type view int
const (
PointSelection view = iota
PointSelectionComputer
PointConfirmation
TitleView
QuitConfirmation
GameOverView
PassView
)
type playerMode int
const (
OnePlayer playerMode = iota
TwoPlayer
)
func (pm playerMode) String() string {
return [...]string{"1-Player", "2-Player"}[pm]
}
type model struct {
grid grid
selectedPoint vector2d
view view
currentPlayer player
disksFlipped []vector2d
windowSize vector2d
availablePoints []vector2d
rules rules
playerMode playerMode
}
func newGrid(r rules) *grid {
var g grid
for i := 0; i < gridHeight; i++ {
for j := 0; j < gridWidth; j++ {
g[i][j] = Blank
}
}
if r == OthelloRules {
g[3][3] = LightPlayer
g[4][4] = LightPlayer
g[3][4] = DarkPlayer
g[4][3] = DarkPlayer
}
return &g
}
func createInitialModel(r rules, pm playerMode) model {
initialPlayer := DarkPlayer
g := *newGrid(r)
return model{
grid: g,
selectedPoint: vector2d{3, 3},
view: TitleView,
currentPlayer: initialPlayer,
disksFlipped: make([]vector2d, 0),
availablePoints: getAvailablePoints(g, initialPlayer, r),
rules: r,
playerMode: pm,
}
}
func initialModel() model {
return createInitialModel(OthelloRules, OnePlayer)
}
func (m model) Init() tea.Cmd {
return nil
}
func isComputerTurn(m model) bool {
if m.playerMode == OnePlayer && m.currentPlayer == LightPlayer {
return true
}
return false
}
func flipSelectedPoint(m *model) {
m.grid[m.selectedPoint.y][m.selectedPoint.x] = m.currentPlayer
}
func takeTurn(m *model) {
if slices.Contains(m.availablePoints, m.selectedPoint) {
flipSelectedPoint(m)
pointsToFlip := getPointsToFlip(m.grid, m.selectedPoint, m.currentPlayer)
flip(&m.grid, pointsToFlip, m.currentPlayer)
m.disksFlipped = pointsToFlip
m.view = PointConfirmation
}
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch m.view {
case PointSelection:
switch msg.String() {
case "ctrl+c", "q":
m.view = QuitConfirmation
case "up", "w":
m.selectedPoint.y--
m.selectedPoint.y = (m.selectedPoint.y + gridHeight) % gridHeight
case "down", "s":
m.selectedPoint.y++
m.selectedPoint.y = (m.selectedPoint.y + gridHeight) % gridHeight
case "left", "a":
m.selectedPoint.x--
m.selectedPoint.x = (m.selectedPoint.x + gridWidth) % gridWidth
case "right", "d":
m.selectedPoint.x++
m.selectedPoint.x = (m.selectedPoint.x + gridWidth) % gridWidth
case "enter", " ":
takeTurn(&m)
}
case PointSelectionComputer:
takeTurn(&m)
case PointConfirmation:
// Update current player *after* displaying PointConfirmation view
m.currentPlayer = toggleCurrentPlayer(m.currentPlayer)
// Update available points
availablePointsByPlayer := make(map[player][]vector2d)
availablePointsByPlayer[DarkPlayer] = getAvailablePoints(m.grid, DarkPlayer, m.rules)
availablePointsByPlayer[LightPlayer] = getAvailablePoints(m.grid, LightPlayer, m.rules)
m.availablePoints = availablePointsByPlayer[m.currentPlayer]
// If no available moves for current player then it's game over (for Reversi) or skip turn (for Othello)
// If no available moves for either player then it's game over
// Otherwise continue game and switch to PointSelection view
playersCanMove := make(map[player]bool)
playersCanMove[DarkPlayer] = len(availablePointsByPlayer[DarkPlayer]) > 0
playersCanMove[LightPlayer] = len(availablePointsByPlayer[LightPlayer]) > 0
if !playersCanMove[DarkPlayer] && !playersCanMove[LightPlayer] {
m.view = GameOverView
} else if !playersCanMove[m.currentPlayer] {
if m.rules == ReversiRules {
m.view = GameOverView
} else {
m.view = PassView
}
} else {
if isComputerTurn(m) {
m.view = PointSelectionComputer
m.selectedPoint = computeBestPoint(m)
flipSelectedPoint(&m)
} else {
m.view = PointSelection
}
}
case TitleView:
switch msg.String() {
case "r":
m.rules = toggleRules(m.rules)
return createInitialModel(m.rules, m.playerMode), nil
case "p":
m.playerMode = togglePlayerMode(m.playerMode)
default:
m.view = PointSelection
}
case QuitConfirmation:
switch msg.String() {
case "enter":
return m, tea.Quit
default:
m.view = PointSelection
}
case GameOverView:
switch msg.String() {
case "enter":
return createInitialModel(m.rules, m.playerMode), nil
default:
return m, tea.Quit
}
case PassView:
m.currentPlayer = toggleCurrentPlayer(m.currentPlayer)
m.view = PointSelection
m.availablePoints = getAvailablePoints(m.grid, m.currentPlayer, m.rules)
}
case tea.WindowSizeMsg:
m.windowSize = vector2d{
x: msg.Width,
y: msg.Height,
}
}
return m, nil
}
func computeBestPoint(m model) vector2d {
var bestPoint vector2d
maxFlippedPointsCount := -1 // Initialising to -1 so `bestPoint` is always assigned even if `flippedPointsCount` is 0
for _, p := range m.availablePoints {
flippedPointsCount := len(getPointsToFlip(m.grid, p, m.currentPlayer))
if flippedPointsCount > maxFlippedPointsCount {
bestPoint = p
maxFlippedPointsCount = flippedPointsCount
}
}
return bestPoint
}
func toggleCurrentPlayer(currentPlayer player) player {
if currentPlayer == DarkPlayer {
return LightPlayer
}
return DarkPlayer
}
func toggleRules(r rules) rules {
if r == ReversiRules {
return OthelloRules
}
return ReversiRules
}
func togglePlayerMode(pm playerMode) playerMode {
if pm == OnePlayer {
return TwoPlayer
}
return OnePlayer
}
func getNonBlankPoints(g grid) []vector2d {
nonBlankPoints := make([]vector2d, 0)
for i, row := range g {
for j, cell := range row {
if cell != Blank {
nonBlankPoints = append(nonBlankPoints, vector2d{j, i})
}
}
}
return nonBlankPoints
}
func getAvailablePoints(g grid, currentPlayer player, r rules) []vector2d {
// Get all non-blank points in grid
nonBlankPoints := getNonBlankPoints(g)
// Using Reversi rules, the first 4 disks must be placed with the centre 2x2 square in the grid
if r == ReversiRules && len(nonBlankPoints) < 4 {
availablePoints := []vector2d{
{3, 3},
{4, 4},
{3, 4},
{4, 3},
}
// Keep only points that are blank and inside the grid
filteredAvailablePoints := make([]vector2d, 0, len(availablePoints))
for _, p := range availablePoints {
if isPointInsideGrid(p) && g[p.y][p.x] == Blank {
filteredAvailablePoints = append(filteredAvailablePoints, p)
}
}
return filteredAvailablePoints
}
// Get all neighbours of non-blank points in grid
neighbors := make(map[vector2d]bool)
for _, nonBlankPoint := range nonBlankPoints {
for i := -1; i <= 1; i++ {
for j := -1; j <= 1; j++ {
if i != 0 || j != 0 {
neighbor := vector2d{nonBlankPoint.x + j, nonBlankPoint.y + i}
neighbors[neighbor] = true
}
}
}
}
// Keep only neighbours that are blank, inside the grid and will result in at least one flipped point
filteredNeighbors := make(map[vector2d]bool)
for neighbor := range neighbors {
if isPointInsideGrid(neighbor) && g[neighbor.y][neighbor.x] == Blank &&
len(getPointsToFlip(g, neighbor, currentPlayer)) > 0 {
filteredNeighbors[neighbor] = true
}
}
filteredNeighborsList := make([]vector2d, 0, len(filteredNeighbors))
for neighbor := range filteredNeighbors {
filteredNeighborsList = append(filteredNeighborsList, neighbor)
}
return filteredNeighborsList
}
func isPointInsideGrid(p vector2d) bool {
return p.x >= 0 && p.x < gridWidth && p.y >= 0 && p.y < gridHeight
}
func getPointsToFlip(g grid, selectedPoint vector2d, currentPlayer player) []vector2d {
// Maybe generate these automatically
directions := []vector2d{
{0, 1},
{1, 0},
{1, 1},
{0, -1},
{-1, 0},
{-1, -1},
{1, -1},
{-1, 1},
}
disksFlipped := make([]vector2d, 0, 10)
for _, d := range directions {
currentPoint := selectedPoint
isInsideGrid := isPointInsideGrid(currentPoint)
isNotBlank := true
isCurrentPlayer := false
pointsToFlip := make([]vector2d, 0)
for isInsideGrid && isNotBlank && !isCurrentPlayer {
currentPoint = vector2d{x: currentPoint.x + d.x, y: currentPoint.y + d.y}
isInsideGrid = isPointInsideGrid(currentPoint)
if !isInsideGrid {
break
}
isNotBlank = g[currentPoint.y][currentPoint.x] != Blank
isCurrentPlayer = g[currentPoint.y][currentPoint.x] == currentPlayer
if isInsideGrid && isNotBlank && !isCurrentPlayer {
pointsToFlip = append(pointsToFlip, currentPoint)
}
}
// If disk of current player's colour is reached, change all the intermediate disks to the current player's colour
// If blank cell or edge of grid is reached, don't change any disks
if isCurrentPlayer {
disksFlipped = append(disksFlipped, pointsToFlip...)
}
}
return disksFlipped
}
func flip(g *grid, points []vector2d, currentPlayer player) {
for _, p := range points {
// Flip disk
g[p.y][p.x] = currentPlayer
}
}
const accentColor1 = lipgloss.Color("63")
const accentColor2 = lipgloss.Color("105")
var darkPlayerStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("#ffffff")).
Background(lipgloss.Color("#000000"))
var lightPlayerStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("#000000")).
Background(lipgloss.Color("#ffffff"))
var selectedDarkPlayerStyle = lipgloss.NewStyle().
Underline(true).
Bold(true).
Foreground(accentColor2).
Background(lipgloss.Color("#000000"))
var selectedLightPlayerStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("#000000")).
Background(accentColor2)
var selectedBlankStyle = lipgloss.NewStyle().
Background(accentColor2)
const highlightedColor = lipgloss.Color("#666666")
var highlightedDarkPlayerStyle = lipgloss.NewStyle().
Foreground(highlightedColor).
Background(lipgloss.Color("#000000"))
var highlightedLightPlayerStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("#000000")).
Background(highlightedColor)
var availablePointStyle = lipgloss.NewStyle().
Background(lipgloss.Color("#404040"))
var secondaryTextStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("241"))
var accent1TextStyle = lipgloss.NewStyle().
Foreground(accentColor1).
Bold(true)
var successTextStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("#00cc00"))
var errorTextStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("#cc0000"))
func computeScores(g grid) map[player]int {
m := make(map[player]int)
for _, row := range g {
for _, cell := range row {
if cell != Blank {
m[cell]++
}
}
}
return m
}
func (m model) View() string {
scores := computeScores(m.grid)
gridString := createGridView(m)
var text string
maxTextWidth := m.windowSize.x - ((gridWidth * 2) - 1) - 14
switch m.view {
case TitleView:
text = createTitleView(maxTextWidth, m.rules, m.playerMode)
case QuitConfirmation:
text = createQuitConfirmationView(maxTextWidth)
case GameOverView:
text = createGameOverView(m, scores, maxTextWidth)
case PointSelection:
text = createPointSelectionView(m, scores, maxTextWidth, false)
case PointConfirmation:
text = createPointConfirmationView(m, scores, maxTextWidth)
case PassView:
text = createPassView(m, maxTextWidth)
case PointSelectionComputer:
text = createPointSelectionView(m, scores, maxTextWidth, true)
}
return lipgloss.NewStyle().
Padding(2, 6).
Render(lipgloss.JoinHorizontal(lipgloss.Top, gridString, text))
}
func createGridView(m model) string {
var gridStringBuilder strings.Builder
for i, row := range m.grid {
for j, cell := range row {
point := vector2d{j, i}
if (m.view == PointSelection || m.view == PointSelectionComputer) && point == m.selectedPoint {
switch cell {
case DarkPlayer:
gridStringBuilder.WriteString(selectedDarkPlayerStyle.Render("X"))
case LightPlayer:
gridStringBuilder.WriteString(selectedLightPlayerStyle.Render("O"))
default:
gridStringBuilder.WriteString(selectedBlankStyle.Render(" "))
}
} else if (m.view == PointConfirmation && m.grid[point.y][point.x] != Blank && !slices.Contains(m.disksFlipped, point)) ||
(m.view == PointSelectionComputer && m.grid[point.y][point.x] != Blank && point != m.selectedPoint) {
switch cell {
case DarkPlayer:
gridStringBuilder.WriteString(highlightedDarkPlayerStyle.Render("X"))
case LightPlayer:
gridStringBuilder.WriteString(highlightedLightPlayerStyle.Render("O"))
}
} else {
switch cell {
case DarkPlayer:
gridStringBuilder.WriteString(darkPlayerStyle.Render("X"))
case LightPlayer:
gridStringBuilder.WriteString(lightPlayerStyle.Render("O"))
default:
if slices.Contains(m.availablePoints, point) {
gridStringBuilder.WriteString(availablePointStyle.Render(" "))
} else {
gridStringBuilder.WriteString(" ")
}
}
}
if j < len(row)-1 {
gridStringBuilder.WriteString(" ")
}
}
if i < len(m.grid)-1 {
gridStringBuilder.WriteString("\n")
}
}
return lipgloss.NewStyle().
BorderStyle(lipgloss.RoundedBorder()).
BorderForeground(accentColor1).
MarginRight(6).
Render(gridStringBuilder.String())
}
func createTitleView(maxWidth int, r rules, pm playerMode) string {
title := fmt.Sprintf(` ____ _
| _ \ _____ _____ _ __ ___(_)
| |_) / _ \ \ / / _ \ '__/ __| |
| _ < __/\ V / __/ | \__ \ |
|_| \_\___| \_/ \___|_| |___/_| %s`,
secondaryTextStyle.Render(version))
textStrings := []string{
"",
createRadioButton([]playerMode{OnePlayer, TwoPlayer}, pm, "Player mode", "P"),
createRadioButton([]rules{OthelloRules, ReversiRules}, r, "Rules", "R"),
"",
"Press any other key to start...",
"",
secondaryTextStyle.Render("p: toggle player mode • r: toggle rules • any other key: continue"),
}
text := lipgloss.NewStyle().
Width(maxWidth).
Render(lipgloss.JoinVertical(lipgloss.Left, textStrings...))
return lipgloss.JoinVertical(lipgloss.Left, title, text)
}
func createQuitConfirmationView(maxWidth int) string {
textStrings := []string{
"Are you sure you want to quit?",
"",
"Any game progress will be lost.",
"",
secondaryTextStyle.Render("enter: quit • any other key: cancel"),
}
return lipgloss.NewStyle().
Width(maxWidth).
Render(lipgloss.JoinVertical(lipgloss.Left, textStrings...))
}
func createGameOverView(m model, scores map[player]int, maxWidth int) string {
var resultString string
if scores[LightPlayer] == scores[DarkPlayer] {
resultString = "Tie!"
} else if scores[DarkPlayer] > scores[LightPlayer] {
resultString = fmt.Sprintf("%s won!", DarkPlayer)
} else if scores[LightPlayer] > scores[DarkPlayer] {
resultString = fmt.Sprintf("%s won!", LightPlayer)
}
scoreString := fmt.Sprintf("%s: %d; %s: %d", DarkPlayer.String(), scores[DarkPlayer], LightPlayer.String(),
scores[LightPlayer])
var infoString string
if m.rules == ReversiRules {
infoString = fmt.Sprintf("No available moves for %s.", m.currentPlayer)
} else {
infoString = "No available moves for either player."
}
textStrings := []string{
accent1TextStyle.Render("Game over!"),
"",
infoString,
"",
resultString,
scoreString,
"",
secondaryTextStyle.Render("enter: play again • any other key: quit"),
}
return lipgloss.NewStyle().
Width(maxWidth).
Render(lipgloss.JoinVertical(lipgloss.Left, textStrings...))
}
func createPointSelectionView(m model, scores map[player]int, maxWidth int, isComputerTurn bool) string {
textStrings := make([]string, 0, 7)
textStrings = append(textStrings, createTurnText(m.currentPlayer))
textStrings = append(textStrings, createGameStatusText(scores))
textStrings = append(textStrings, "")
if isComputerTurn {
textStrings = append(textStrings, "Computer places disk here")
textStrings = append(textStrings, "", secondaryTextStyle.Render("any key: continue"))
} else {
textStrings = append(textStrings, "Choose where to place your disk")
if slices.Contains(m.availablePoints, m.selectedPoint) {
textStrings = append(textStrings, successTextStyle.Render("Can place disk here"))
textStrings = append(textStrings, "", secondaryTextStyle.Render("arrow keys: move • enter: place tile • q: exit"))
} else {
textStrings = append(textStrings, errorTextStyle.Render("Cannot place disk here"))
textStrings = append(textStrings, "", secondaryTextStyle.Render("arrow keys: move • q: exit"))
}
}
return lipgloss.NewStyle().
Width(maxWidth).
Render(lipgloss.JoinVertical(lipgloss.Left, textStrings...))
}
func createPointConfirmationView(m model, scores map[player]int, maxWidth int) string {
textStrings := make([]string, 0, 6)
textStrings = append(textStrings, createTurnText(m.currentPlayer))
textStrings = append(textStrings, createGameStatusText(scores))
if len(m.disksFlipped) == 0 {
textStrings = append(textStrings, "", "No disks flipped this time")
} else {
textStrings = append(textStrings, "", fmt.Sprintf("%s flipped %s!", m.currentPlayer, english.Plural(len(m.disksFlipped), "disk", "")))
}
textStrings = append(textStrings, "", secondaryTextStyle.Render("any key: continue"))
return lipgloss.NewStyle().
Width(maxWidth).
Render(lipgloss.JoinVertical(lipgloss.Left, textStrings...))
}
type radioButtonItem interface {
comparable
String() string
}
func createRadioButton[T radioButtonItem](options []T, selected T, label string, key string) string {
var builder strings.Builder
builder.WriteString(label)
builder.WriteString(": ")
for i, option := range options {
if option == selected {
builder.WriteString(lipgloss.NewStyle().
Foreground(accentColor2).
Render(option.String() + " [▪]"))
} else {
builder.WriteString(option.String() + " [ ]")
}
if i != len(options)-1 {
builder.WriteString(";")
}
builder.WriteString(" ")
}
builder.WriteString(secondaryTextStyle.Render(fmt.Sprintf("(press %s)", strings.ToUpper(key))))
return builder.String()
}
func createPassView(m model, maxWidth int) string {
textStrings := make([]string, 0, 6)
textStrings = []string{
createTurnText(m.currentPlayer),
fmt.Sprintf("No available moves for %s; skipping turn...", m.currentPlayer),
"",
secondaryTextStyle.Render("any key: continue"),
}
return lipgloss.NewStyle().
Width(maxWidth).
Render(lipgloss.JoinVertical(lipgloss.Left, textStrings...))
}
func createTurnText(currentPlayer player) string {
return accent1TextStyle.Render(fmt.Sprintf("%s (%s)'s turn", currentPlayer.String(), currentPlayer.toSymbol()))
}
func createGameStatusText(scores map[player]int) string {
var scoreStringBuilder strings.Builder
if scores[LightPlayer] == scores[DarkPlayer] {
scoreStringBuilder.WriteString("Tie")
} else if scores[DarkPlayer] > scores[LightPlayer] {
scoreStringBuilder.WriteString(fmt.Sprintf("%s winning!", DarkPlayer))
} else if scores[LightPlayer] > scores[DarkPlayer] {
scoreStringBuilder.WriteString(fmt.Sprintf("%s winning!", LightPlayer))
}
scoreStringBuilder.WriteString("\n")
scoreStringBuilder.WriteString(fmt.Sprintf("%s: %d; %s: %d", DarkPlayer.String(), scores[DarkPlayer], LightPlayer.String(),
scores[LightPlayer]))
return scoreStringBuilder.String()
}
func main() {
p := tea.NewProgram(initialModel())
if _, err := p.Run(); err != nil {
fmt.Printf("Error: %v", err)
os.Exit(1)
}
}