gokultp / go-four-in-a-row

A simple command-line implementation of the game `four in the row`
MIT License
12 stars 13 forks source link

Index out of range when changing board size #18

Closed bertoort closed 6 years ago

bertoort commented 6 years ago

Describe the bug When I update the size of the board from 10x10 to 7x6, the game crashes after a move.

To Reproduce Steps to reproduce the behavior:

  1. Go to ./cmd/four-in-a-row/main.go
  2. Change game board to g := game.NewGame(7, 6).
  3. Run game
  4. See error

Error Message

panic: runtime error: index out of range

goroutine 1 [running]:
github.com/gokultp/go-four-in-a-row/pkg/game.(*Game).isWon(0xc0000f4000, 0x4, 0x5, 0x1, 0x10c7cac)
    /Users/berto/go/src/github.com/gokultp/go-four-in-a-row/pkg/game/game.go:132 +0xa0a
github.com/gokultp/go-four-in-a-row/pkg/game.(*Game).addEntry(0xc0000f4000, 0x4, 0x1)
    /Users/berto/go/src/github.com/gokultp/go-four-in-a-row/pkg/game/game.go:123 +0x15b
github.com/gokultp/go-four-in-a-row/pkg/game.(*Game).Input(0xc0000f4000, 0x4)
    /Users/berto/go/src/github.com/gokultp/go-four-in-a-row/pkg/game/game.go:245 +0x3e
main.main()
    /Users/berto/go/src/github.com/gokultp/go-four-in-a-row/cmd/four-in-a-row/main.go:38 +0x1bc
exit status 2

Additional context I'm pretty sure it has to do with the vertical check using width. I changed it to use g.Height and it seemed fixed. There were other issues not detecting diagonal wins after that. It's inconsistent and tedious to replicate.

gokultp commented 6 years ago

will check this