Refactoring evaluate functions

[?]
Dec 28, 2020, 4:35 PM
HSJSKGY7352JHEI4LAMO3F2RCZTVI5ZKQUCHU4UYCTLD7EGL3FQAC

Dependencies

  • [2] TYELLGSA Rename checkDiag to checkDiagLR and add checkDiagRL. Add more tests
  • [3] G5KXCVIL tictactoe: initial import
  • [4] UWVAMBIJ Fix couple of tests, add more

Change contents

  • edit in snippets/tictactoe/tictactoe.go at line 20
    [3.255]
    [3.255]
    // Board represents the board the game played on
    type Board [][]rune
  • replacement in snippets/tictactoe/evaluate_test.go at line 12
    [3.2232][3.2232:2255]()
    board [][]rune
    [3.2232]
    [3.2255]
    board Board
  • replacement in snippets/tictactoe/evaluate_test.go at line 24
    [3.2729][3.2729:2781]()
    assert.Equal(t, tc.expected, evaluate(tc.board))
    [3.2729]
    [3.2781]
    assert.Equal(t, tc.expected, tc.board.evaluate())
  • replacement in snippets/tictactoe/evaluate.go at line 3
    [3.2826][3.2826:2979]()
    func evaluate(board [][]rune) int {
    for row := range board {
    for col := range board[row] {
    if checkRow(board, row, col, WinSize, Pl1) == WinSize {
    [3.2826]
    [3.2979]
    func (b Board) evaluate() int {
    for row := range b {
    for col := range b[row] {
    if b.checkRow(row, col, WinSize, Pl1) == WinSize {
  • replacement in snippets/tictactoe/evaluate.go at line 8
    [3.2994][3.2994:3060]()
    } else if checkRow(board, row, col, WinSize, Pl2) == WinSize {
    [3.2994]
    [3.3060]
    } else if b.checkRow(row, col, WinSize, Pl2) == WinSize {
  • replacement in snippets/tictactoe/evaluate.go at line 11
    [3.3080][3.3080:3139]()
    if checkCol(board, row, col, WinSize, Pl1) == WinSize {
    [3.3080]
    [3.3139]
    if b.checkCol(row, col, WinSize, Pl1) == WinSize {
  • replacement in snippets/tictactoe/evaluate.go at line 13
    [3.3154][3.3154:3220]()
    } else if checkCol(board, row, col, WinSize, Pl2) == WinSize {
    [3.3154]
    [3.3220]
    } else if b.checkCol(row, col, WinSize, Pl2) == WinSize {
  • replacement in snippets/tictactoe/evaluate.go at line 16
    [3.3240][2.384:446]()
    if checkDiagLR(board, row, col, WinSize, Pl1) == WinSize {
    [3.3240]
    [2.446]
    if b.checkDiagLR(row, col, WinSize, Pl1) == WinSize {
  • replacement in snippets/tictactoe/evaluate.go at line 18
    [2.461][2.461:530]()
    } else if checkDiagLR(board, row, col, WinSize, Pl2) == WinSize {
    [2.461]
    [2.530]
    } else if b.checkDiagLR(row, col, WinSize, Pl2) == WinSize {
  • replacement in snippets/tictactoe/evaluate.go at line 21
    [2.550][2.550:612]()
    if checkDiagRL(board, row, col, WinSize, Pl1) == WinSize {
    [2.550]
    [3.3300]
    if b.checkDiagRL(row, col, WinSize, Pl1) == WinSize {
  • replacement in snippets/tictactoe/evaluate.go at line 23
    [3.3315][2.613:682]()
    } else if checkDiagRL(board, row, col, WinSize, Pl2) == WinSize {
    [3.3315]
    [3.3382]
    } else if b.checkDiagRL(row, col, WinSize, Pl2) == WinSize {
  • replacement in snippets/tictactoe/evaluate.go at line 31
    [3.3422][3.3422:3505]()
    func checkRow(board [][]rune, row, col, winsize int, player rune) (goodness int) {
    [3.3422]
    [3.3505]
    func (b Board) checkRow(row, col, winsize int, player rune) (goodness int) {
  • replacement in snippets/tictactoe/evaluate.go at line 33
    [3.3537][3.3537:3604]()
    if row+i < len(board[col]) {
    if board[row+i][col] == player {
    [3.3537]
    [3.3604]
    if row+i < len(b[col]) {
    if b[row+i][col] == player {
  • replacement in snippets/tictactoe/evaluate.go at line 44
    [3.3683][3.3683:3766]()
    func checkCol(board [][]rune, row, col, winsize int, player rune) (goodness int) {
    [3.3683]
    [3.3766]
    func (b Board) checkCol(row, col, winsize int, player rune) (goodness int) {
  • replacement in snippets/tictactoe/evaluate.go at line 46
    [3.3798][3.3798:3865]()
    if col+j < len(board[row]) {
    if board[row][col+j] == player {
    [3.3798]
    [3.3865]
    if col+j < len(b[row]) {
    if b[row][col+j] == player {
  • replacement in snippets/tictactoe/evaluate.go at line 57
    [3.3944][2.683:769]()
    func checkDiagLR(board [][]rune, row, col, winsize int, player rune) (goodness int) {
    [3.3944]
    [3.4028]
    func (b Board) checkDiagLR(row, col, winsize int, player rune) (goodness int) {
  • replacement in snippets/tictactoe/evaluate.go at line 59
    [3.4060][3.4060:4156]()
    if row+k < len(board[col]) && col+k < len(board[row]) {
    if board[row+k][col+k] == player {
    [3.4060]
    [3.4156]
    if row+k < len(b[col]) && col+k < len(b[row]) {
    if b[row+k][col+k] == player {
  • replacement in snippets/tictactoe/evaluate.go at line 70
    [2.771][2.771:857]()
    func checkDiagRL(board [][]rune, row, col, winsize int, player rune) (goodness int) {
    [2.771]
    [2.857]
    func (b Board) checkDiagRL(row, col, winsize int, player rune) (goodness int) {
  • replacement in snippets/tictactoe/evaluate.go at line 72
    [2.889][2.889:972]()
    if row+k < len(board[col]) && col-k >= 0 {
    if board[row+k][col-k] == player {
    [2.889]
    [2.972]
    if row+k < len(b[col]) && col-k >= 0 {
    if b[row+k][col-k] == player {