Skip to content

Commit

Permalink
all: fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gucio321 committed Mar 27, 2022
1 parent 83bec6e commit b67d0db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 4 additions & 4 deletions pkg/core/pcplayer/pc_player_engine.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package pcplayer provides megods for simple-AI logic
// Package pcplayer provides methods for simple-AI logic
// used in Tic-Tac-Go for calculating PC-player's move.
package pcplayer

Expand Down Expand Up @@ -68,7 +68,7 @@ O-player lost.
func canWinTwoMoves(gameBoard *board.Board, player letter.Letter) (result []int) {
// nolint:gomnd // look a scheme above - in the second one, the chain is by 2 less than max
minimalChainLen := gameBoard.ChainLength() - 2
if minimalChainLen <= 0 { // nolint:gomnd // processing this values doesn't make sense with chain smaller than 3
if minimalChainLen <= 0 {
return nil
}

Expand All @@ -92,13 +92,13 @@ validatingChains:
potentiallyAvailableChains := gameBoard.GetWinBoard(gameBoard.ChainLength() + 1)
for _, potentialPlace := range potentiallyAvailableChains {
for _, chain := range availableWinningChains {
//if potentialPlace[1] == chain[0] && potentialPlace[2] == chain[1] {
if reflect.DeepEqual(potentialPlace[1:len(chain)+1], chain) {
result = append(result, potentialPlace[len(potentialPlace)-2])

break
//} else if potentialPlace[2] == chain[0] && potentialPlace[3] == chain[1] {
} else if reflect.DeepEqual(potentialPlace[2:len(chain)+2], chain) {
result = append(result, potentialPlace[1])

break
}
}
Expand Down
10 changes: 7 additions & 3 deletions scripts/draw-board/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package main

import (
"errors"
"flag"
"fmt"
"github.com/gucio321/tic-tac-go/pkg/core/board/letter"
"strconv"

"github.com/gucio321/tic-tac-go/pkg/core/board/letter"

"github.com/gucio321/tic-tac-go/pkg/core/board"
)

Expand All @@ -14,6 +16,8 @@ const (
defaultChainLen = 3
)

var errIncorrectLetter = errors.New("incorrect number")

var _ flag.Value = &lettersValue{}

type lettersValue []int
Expand All @@ -25,13 +29,13 @@ func (l *lettersValue) String() string {
func (l *lettersValue) Set(value string) (err error) {
for _, letter := range value {
if letter < '0' || letter > '9' {
return fmt.Errorf("invalid letter: %v", letter)
return fmt.Errorf("%w %v", errIncorrectLetter, letter)
}
}

x, err := strconv.Atoi(value)
if err != nil {
return err
return fmt.Errorf("converting string to int: %w", err)
}

*l = append(*l, x)
Expand Down

0 comments on commit b67d0db

Please sign in to comment.