func TestGoesForTheWin(t *testing.T) { board := board.NewBoard(rules.THREE_BY_THREE) impossiblePlayer := ImpossiblePlayer{Mark: rules.SECOND_PLAYER} testhelper.AddMarkToPositions(board, rules.FIRST_PLAYER, 0, 5, 2) testhelper.AddMarkToPositions(board, rules.SECOND_PLAYER, 1, 4) assert.Equal(t, 7, impossiblePlayer.GetMove(board, rules.SECOND_PLAYER, rules.FIRST_PLAYER)) }
func GameTick(playerOneType, playerTwoType string, boardSize int, movesPlayed []int) gamestate.GameState { playerOne := createFirstPlayer(playerOneType) playerTwo := createSecondPlayer(playerTwoType) board := board.NewBoard(boardSize) rebuildBoard(board, movesPlayed) return gamestate.GameState{ MovesPlayed: takeTurn(board, playerOne, playerTwo, movesPlayed), PlayerOneType: playerOneType, PlayerTwoType: playerTwoType, CurrentPlayer: gamestate.GetCurrentPlayer(board, playerOne, playerTwo), BoardSize: boardSize, BoardState: board.Slots, Board: board, } }
func TestItHasAWinnerIfSameMarkInRightToLeftDiagonal(t *testing.T) { board := board.NewBoard(THREE_BY_THREE) testhelper.AddMarkToPositions(board, FIRST_PLAYER, 2, 4, 6) assert.True(t, DiagonalWinner(board, FIRST_PLAYER)) }
func TestNoDiagonalWinnerIfBoardEmpty(t *testing.T) { board := board.NewBoard(THREE_BY_THREE) assert.False(t, DiagonalWinner(board, FIRST_PLAYER)) }
func TestItHasAWinnerIfSameMarkInThirdColumn(t *testing.T) { board := board.NewBoard(THREE_BY_THREE) testhelper.AddMarkToPositions(board, FIRST_PLAYER, 2, 5, 8) assert.True(t, ColumnWinner(board, FIRST_PLAYER)) }
func TestItDoesNotHaveWinnerWhenNoCombinationsFoundForColumn(t *testing.T) { board := board.NewBoard(THREE_BY_THREE) testhelper.AddMarkToPositions(board, FIRST_PLAYER, 3, 1, 8) assert.False(t, ColumnWinner(board, FIRST_PLAYER)) }
func TestGetsTheCenterMove(t *testing.T) { board := board.NewBoard(rules.THREE_BY_THREE) impossiblePlayer := ImpossiblePlayer{Mark: rules.SECOND_PLAYER} testhelper.AddMarkToPositions(board, rules.FIRST_PLAYER, 0) assert.Equal(t, 4, impossiblePlayer.GetMove(board, rules.SECOND_PLAYER, rules.FIRST_PLAYER)) }
func TestScoreWhenOpponentWins(t *testing.T) { board := board.NewBoard(rules.THREE_BY_THREE) testhelper.AddMarkToPositions(board, rules.SECOND_PLAYER, 0, 1, 2) assert.Equal(t, -10, Score(board, rules.FIRST_PLAYER, rules.SECOND_PLAYER)) }
func TestReturnsMovesRemainingOnBoard(t *testing.T) { board := board.NewBoard(THREE_BY_THREE) board.PlaceMove(4, FIRST_PLAYER) assert.Equal(t, []int{0, 1, 2, 3, 5, 6, 7, 8}, MovesAvailable(board)) }
func TestGetsTieIfNoWinner(t *testing.T) { board := board.NewBoard(THREE_BY_THREE) testhelper.AddMarkToPositions(board, FIRST_PLAYER, 0, 1, 5, 6, 8) testhelper.AddMarkToPositions(board, SECOND_PLAYER, 2, 3, 4, 7) assert.Equal(t, "Tie", GetResult(board)) }
func TestGetsWinnerMarkSecondPlayer(t *testing.T) { board := board.NewBoard(THREE_BY_THREE) testhelper.AddMarkToPositions(board, SECOND_PLAYER, 0, 1, 2) assert.Equal(t, SECOND_PLAYER, GetResult(board)) }
func TestGetsWinnerMark(t *testing.T) { board := board.NewBoard(THREE_BY_THREE) testhelper.AddMarkToPositions(board, FIRST_PLAYER, 0, 1, 2) assert.Equal(t, FIRST_PLAYER, GetResult(board)) }
func TestGameIsOverWhenSecondPlayerWins(t *testing.T) { board := board.NewBoard(THREE_BY_THREE) testhelper.AddMarkToPositions(board, SECOND_PLAYER, 0, 1, 2) assert.True(t, IsGameOver(board)) }
func TestGameIsOverWhenBoardIsFull(t *testing.T) { board := board.NewBoard(THREE_BY_THREE) testhelper.AddMarkToPositions(board, FIRST_PLAYER, 0, 1, 2, 3, 4, 5, 6, 7, 8) assert.True(t, IsGameOver(board)) }
func TestAllMovesAvailableWhenBoardIsEmpty(t *testing.T) { board := board.NewBoard(THREE_BY_THREE) assert.Equal(t, []int{0, 1, 2, 3, 4, 5, 6, 7, 8}, MovesAvailable(board)) }
func TestItReturnsTrueWhenThereIsAWinningCombinationDiagonallyForMark(t *testing.T) { board := board.NewBoard(THREE_BY_THREE) testhelper.AddMarkToPositions(board, FIRST_PLAYER, 0, 4, 8) assert.True(t, IsWinner(board, FIRST_PLAYER)) }
func TestScoreWhenNeitherPlayerWins(t *testing.T) { board := board.NewBoard(rules.THREE_BY_THREE) assert.Equal(t, 0, Score(board, rules.FIRST_PLAYER, rules.SECOND_PLAYER)) }
func TestItHasAWinnerIfSameMarkInSecondRow(t *testing.T) { board := board.NewBoard(THREE_BY_THREE) testhelper.AddMarkToPositions(board, FIRST_PLAYER, 3, 4, 5) assert.True(t, RowWinner(board, FIRST_PLAYER)) }
func TestGetsTheFirstMove(t *testing.T) { board := board.NewBoard(rules.THREE_BY_THREE) impossiblePlayer := ImpossiblePlayer{Mark: rules.SECOND_PLAYER} assert.Equal(t, 0, impossiblePlayer.GetMove(board, rules.FIRST_PLAYER, rules.SECOND_PLAYER)) }
func TestItHasNoWinnerIfOnlyOneMoveWasMade(t *testing.T) { board := board.NewBoard(THREE_BY_THREE) testhelper.AddMarkToPositions(board, FIRST_PLAYER, 1) assert.False(t, ColumnWinner(board, FIRST_PLAYER)) assert.False(t, RowWinner(board, FIRST_PLAYER)) }
func TestNoColumnWinnerOnEmptyBoard(t *testing.T) { board := board.NewBoard(THREE_BY_THREE) assert.False(t, ColumnWinner(board, FIRST_PLAYER)) }
func TestAlwaysReturnsZero(t *testing.T) { board := board.NewBoard(rules.THREE_BY_THREE) player := NewHumanPlayer(rules.FIRST_PLAYER) assert.Equal(t, 0, player.GetMove(board, rules.FIRST_PLAYER, rules.SECOND_PLAYER)) }