0e4db5d7466b35578c951a98f43aa85fffc7d4e9 — Trevor Slocum 16 days ago 5c15b73 master
Print garbage sent/received on one line
5 files changed, 18 insertions(+), 23 deletions(-)

M README.md
M cmd/netris/gui_title.go
M pkg/game/game.go
M pkg/mino/matrix.go
M pkg/mino/mino.go
M README.md => README.md +1 -1
@@ 60,4 60,4 @@ The following libraries are used to build netris:
 
 Tetris is a registered trademark of the Tetris Holding, LLC.
 
-netris is no way affiliated with Tetris Holding, LLC.
+netris is in no way affiliated with Tetris Holding, LLC.

M cmd/netris/gui_title.go => cmd/netris/gui_title.go +1 -1
@@ 271,7 271,7 @@ func handleTitle() {
 			}
 
 			for _, m := range p.Mino {
-				if titleMatrixR.Block(p.X+m.X, p.Y+m.Y) != mino.BlockNone {
+				if !titleMatrixR.ValidPoint(p.X+m.X, p.Y+m.Y) || titleMatrixR.Block(p.X+m.X, p.Y+m.Y) != mino.BlockNone {
 					continue
 				}
 

M pkg/game/game.go => pkg/game/game.go +9 -4
@@ 465,12 465,17 @@ func (g *Game) handleDistributeMatrixes() {
 
 				g.WriteAllL(&GameCommandGameOver{Winner: winner})
 
-				g.WriteMessage("Game over - winner: " + winner)
-				g.WriteMessage("Garbage sent/received:")
-				for _, p := range players {
-					g.WriteMessage(p.Name + " - " + strconv.Itoa(p.totalGarbageSent) + "/" + strconv.Itoa(p.totalGarbageReceived))
+				var garbageMessage strings.Builder
+				for i, p := range players {
+					if i > 0 {
+						garbageMessage.WriteString(", ")
+					}
+
+					garbageMessage.WriteString(fmt.Sprintf("%s %d/%d", p.Name, p.totalGarbageSent, p.totalGarbageReceived))
 				}
 
+				g.WriteMessage(fmt.Sprintf("Winner: %s - Garbage sent/received: %s", winner, garbageMessage.String()))
+
 				if len(g.Players) < 2 {
 					g.WriteMessage("Game will start when there are at least two players")
 				}

M pkg/mino/matrix.go => pkg/mino/matrix.go +7 -3
@@ 63,7 63,7 @@ type Matrix struct {
 
 func I(x int, y int, w int) int {
 	if x < 0 || x >= w || y < 0 {
-		log.Fatalf("failed to calculate matrix index %d %d %d", x, y, w)
+		log.Panicf("failed to retrieve index for %d,%d width %d: invalid coordinates", x, y, w)
 	}
 
 	return (y * w) + x


@@ 452,8 452,8 @@ func (m *Matrix) DrawActivePieceL() {
 }
 
 func (m *Matrix) Block(x int, y int) Block {
-	if x < 0 || x >= m.W || y < 0 || y >= m.H+m.B {
-		return BlockGarbage
+	if y >= m.H+m.B {
+		log.Panicf("failed to retrieve block at %d,%d: invalid y coordinate", x, y)
 	}
 
 	index := I(x, y, m.W)


@@ 886,6 886,10 @@ func (m *Matrix) HardDropPiece() {
 	m.finishLandingPiece()
 }
 
+func (m *Matrix) ValidPoint(x int, y int) bool {
+	return x >= 0 && x < m.W && y >= 0 && y < m.H+m.B
+}
+
 func (m *Matrix) Replace(newmtx *Matrix) {
 	m.Lock()
 	defer m.Unlock()

M pkg/mino/mino.go => pkg/mino/mino.go +0 -14
@@ 64,20 64,6 @@ func NewMino(points string) Mino {
 	return m
 }
 
-func (m Mino) Equal(other Mino) bool {
-	if len(m) != len(other) {
-		return false
-	}
-
-	for i := 0; i < len(m); i++ {
-		if !m.HasPoint(other[i]) {
-			return false
-		}
-	}
-
-	return true
-}
-
 func (m Mino) String() string {
 	sort.Sort(m)