From a1bf6ec0ffba3455e5bab3fc33024dd85e1fb4a9 Mon Sep 17 00:00:00 2001 From: bvanvugt <1531419+bvanvugt@users.noreply.github.com> Date: Sun, 19 Feb 2023 17:12:03 +0000 Subject: [PATCH] Update go version and linting. --- .github/workflows/test.yml | 8 ++++++-- .gitignore | 1 - .golangci.yaml | 5 +++++ maps/solo_maze.go | 40 +++++++++++++++++--------------------- 4 files changed, 29 insertions(+), 25 deletions(-) create mode 100644 .golangci.yaml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 43753a8..da65a72 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,7 +3,7 @@ name: Test on: [push, pull_request] env: - GO_VERSION: 1.18.1 + GO_VERSION: 1.20 jobs: @@ -15,6 +15,7 @@ jobs: - uses: actions/setup-go@main with: go-version: '${{ env.GO_VERSION }}' + check-latest: true - name: Run gofmt run: test -z $(gofmt -l .) || (gofmt -d . && exit 1) @@ -27,9 +28,10 @@ jobs: - uses: actions/setup-go@main with: go-version: '${{ env.GO_VERSION }}' + check-latest: true - name: Run golangci-lint run: | - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.45.2 + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.51.1 golangci-lint run -v ./... test: @@ -41,6 +43,7 @@ jobs: - uses: actions/setup-go@main with: go-version: '${{ env.GO_VERSION }}' + check-latest: true - name: Run go test run: go test -race ./... @@ -53,6 +56,7 @@ jobs: - uses: actions/setup-go@main with: go-version: '${{ env.GO_VERSION }}' + check-latest: true - name: Run go build run: | go build ./cli/battlesnake diff --git a/.gitignore b/.gitignore index 089e7fe..8dae406 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ # Editors -.cmd .devcontainer .vscode .idea diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..89bdde5 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,5 @@ +issues: + exclude-rules: + - linters: + - staticcheck + text: "SA1019:" diff --git a/maps/solo_maze.go b/maps/solo_maze.go index 5d5afb7..80c3d2b 100644 --- a/maps/solo_maze.go +++ b/maps/solo_maze.go @@ -13,11 +13,11 @@ import ( ) // When this is flipped to `true` TWO things happen -// 1. More println style debugging is done -// 2. We print out the current game board in between each room sub-division, -// and wait for the CLI User to hit enter to sub-divide the next room. This -// allows you to see the maze get generated in realtime, which was super useful -// while debugging issues in the maze generation +// 1. More println style debugging is done +// 2. We print out the current game board in between each room sub-division, +// and wait for the CLI User to hit enter to sub-divide the next room. This +// allows you to see the maze get generated in realtime, which was super useful +// while debugging issues in the maze generation const DEBUG_MAZE_GENERATION = false const INITIAL_MAZE_SIZE = 7 @@ -216,9 +216,9 @@ func (m SoloMazeMap) SubdivideRoom(tempBoardState *rules.BoardState, rand rules. if DEBUG_MAZE_GENERATION { log.Print("\n\n\n") - log.Print(fmt.Sprintf("Subdividing room from %v to %v", lowPoint, highPoint)) - log.Print(fmt.Sprintf("disAllowedVertical %v", disAllowedVertical)) - log.Print(fmt.Sprintf("disAllowedHorizontal %v", disAllowedHorizontal)) + log.Printf("Subdividing room from %v to %v", lowPoint, highPoint) + log.Printf("disAllowedVertical %v", disAllowedVertical) + log.Printf("disAllowedHorizontal %v", disAllowedHorizontal) printMap(tempBoardState) fmt.Print("Press 'Enter' to continue...") _, e := bufio.NewReader(os.Stdin).ReadBytes('\n') @@ -245,7 +245,7 @@ func (m SoloMazeMap) SubdivideRoom(tempBoardState *rules.BoardState, rand rules. if len(verticalChoices) > 0 { verticalWallPosition = verticalChoices[rand.Intn(len(verticalChoices))] if DEBUG_MAZE_GENERATION { - log.Print(fmt.Sprintf("drawing Vertical Wall at %v", verticalWallPosition)) + log.Printf("drawing Vertical Wall at %v\n", verticalWallPosition) } for y := lowPoint.Y; y <= highPoint.Y; y++ { @@ -265,7 +265,7 @@ func (m SoloMazeMap) SubdivideRoom(tempBoardState *rules.BoardState, rand rules. if len(horizontalChoices) > 0 { horizontalWallPosition = horizontalChoices[rand.Intn(len(horizontalChoices))] if DEBUG_MAZE_GENERATION { - log.Print(fmt.Sprintf("drawing horizontal Wall at %v", horizontalWallPosition)) + log.Printf("drawing horizontal Wall at %v\n", horizontalWallPosition) } for x := lowPoint.X; x <= highPoint.X; x++ { @@ -289,7 +289,7 @@ func (m SoloMazeMap) SubdivideRoom(tempBoardState *rules.BoardState, rand rules. disAllowedHorizontal = append(disAllowedHorizontal, hole.Y) } if DEBUG_MAZE_GENERATION { - log.Print(fmt.Sprintf("Vertical Cuts are at %v", verticalHoles)) + log.Printf("Vertical Cuts are at %v\n", verticalHoles) } newNewHorizontalWall, horizontalHoles := cutHoleSingle(newHorizontalWall, intersectionPoint, rand) @@ -298,7 +298,7 @@ func (m SoloMazeMap) SubdivideRoom(tempBoardState *rules.BoardState, rand rules. disAllowedVertical = append(disAllowedVertical, hole.X) } if DEBUG_MAZE_GENERATION { - log.Print(fmt.Sprintf("Horizontal Cuts are at %v", horizontalHoles)) + log.Printf("Horizontal Cuts are at %v\n", horizontalHoles) } } else if len(newVerticalWall) > 1 { if DEBUG_MAZE_GENERATION { @@ -310,7 +310,7 @@ func (m SoloMazeMap) SubdivideRoom(tempBoardState *rules.BoardState, rand rules. disAllowedHorizontal = append(disAllowedHorizontal, hole.Y) if DEBUG_MAZE_GENERATION { - log.Print(fmt.Sprintf("Cuts are at %v from index %v", hole, segmentToRemove)) + log.Printf("Cuts are at %v from index %v", hole, segmentToRemove) } } else if len(newHorizontalWall) > 1 { if DEBUG_MAZE_GENERATION { @@ -322,16 +322,12 @@ func (m SoloMazeMap) SubdivideRoom(tempBoardState *rules.BoardState, rand rules. disAllowedVertical = append(disAllowedVertical, hole.X) if DEBUG_MAZE_GENERATION { - log.Print(fmt.Sprintf("Cuts are at %v from index %v", hole, segmentToRemove)) + log.Printf("Cuts are at %v from index %v", hole, segmentToRemove) } } - for _, point := range newVerticalWall { - tempBoardState.Hazards = append(tempBoardState.Hazards, point) - } - for _, point := range newHorizontalWall { - tempBoardState.Hazards = append(tempBoardState.Hazards, point) - } + tempBoardState.Hazards = append(tempBoardState.Hazards, newVerticalWall...) + tempBoardState.Hazards = append(tempBoardState.Hazards, newHorizontalWall...) /// We have both so need 4 sub-rooms if verticalWallPosition != -1 && horizontalWallPosition != -1 { @@ -359,7 +355,7 @@ func (m SoloMazeMap) AdjustPosition(mazePosition rules.Point, actualBoardSize in yAdjust := int((boardHeight - actualBoardSize) / 2) if DEBUG_MAZE_GENERATION { - fmt.Println(fmt.Sprintf("currentLevel: %v, boardHeight: %v, boardWidth: %v, xAdjust: %v, yAdjust: %v", actualBoardSize, boardHeight, boardWidth, xAdjust, yAdjust)) + fmt.Printf("currentLevel: %v, boardHeight: %v, boardWidth: %v, xAdjust: %v, yAdjust: %v\n", actualBoardSize, boardHeight, boardWidth, xAdjust, yAdjust) } return rules.Point{X: mazePosition.X + xAdjust, Y: mazePosition.Y + yAdjust} @@ -399,7 +395,7 @@ func (m SoloMazeMap) WriteBitState(boardState *rules.BoardState, state int64, ed } } -/// Return value is first the wall that has been cut, the second is the holes we cut out +// Return value is first the wall that has been cut, the second is the holes we cut out func cutHoles(s []rules.Point, intersection rules.Point, rand rules.Rand) ([]rules.Point, []rules.Point) { holes := make([]rules.Point, 0)