From fcc3c99e5376348d1abc645393c43bdd604b61f6 Mon Sep 17 00:00:00 2001 From: gucio321 <73652197+gucio321@users.noreply.github.com> Date: Mon, 28 Mar 2022 18:11:06 +0200 Subject: [PATCH] pcplayer: fix lint errors progress on #154 --- pkg/core/pcplayer/pc_player_engine.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/core/pcplayer/pc_player_engine.go b/pkg/core/pcplayer/pc_player_engine.go index 6e25f15..1d41b9d 100644 --- a/pkg/core/pcplayer/pc_player_engine.go +++ b/pkg/core/pcplayer/pc_player_engine.go @@ -111,15 +111,13 @@ searching: // - take opponent's opposite corner // - take center // - take random side -// nolint:funlen,gocognit,gocyclo // https://github.com/gucio321/tic-tac-go/issues/154 +// nolint:gocognit,gocyclo // https://github.com/gucio321/tic-tac-go/issues/154 func GetPCMove(gameBoard *board.Board, pcLetter letter.Letter) (i int) { playerLetter := pcLetter.Opposite() - var options []int = make([]int, 0) - // attack: try to win now if ok, indexes := canWin(gameBoard, pcLetter); ok { - options = getAvailableOptions(gameBoard, indexes) + options := getAvailableOptions(gameBoard, indexes) if len(options) > 0 { return getRandomNumber(options) @@ -128,14 +126,14 @@ func GetPCMove(gameBoard *board.Board, pcLetter letter.Letter) (i int) { // defense: check, if user can win if ok, indexes := canWin(gameBoard, playerLetter); ok { - options = getAvailableOptions(gameBoard, indexes) + options := getAvailableOptions(gameBoard, indexes) if len(options) > 0 { return getRandomNumber(options) } } - options = getAvailableOptions(gameBoard, canWinTwoMoves(gameBoard, pcLetter)) + options := getAvailableOptions(gameBoard, canWinTwoMoves(gameBoard, pcLetter)) if len(options) > 0 { return getRandomNumber(options) } @@ -220,6 +218,7 @@ func getRandomNumber(numbers []int) int { func getAvailableOptions(gameBoard *board.Board, candidates []int) (available []int) { available = make([]int, 0) + for _, i := range candidates { if gameBoard.IsIndexFree(i) { available = append(available, i)