Skip to content

Commit

Permalink
pcplayer: fix lint errors
Browse files Browse the repository at this point in the history
progress on #154
  • Loading branch information
gucio321 committed Mar 28, 2022
1 parent 38cfea7 commit fcc3c99
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pkg/core/pcplayer/pc_player_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fcc3c99

Please sign in to comment.