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))
}
Example #2
0
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,
	}
}
Example #3
0
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))
}
Example #4
0
func TestNoDiagonalWinnerIfBoardEmpty(t *testing.T) {
	board := board.NewBoard(THREE_BY_THREE)
	assert.False(t, DiagonalWinner(board, FIRST_PLAYER))
}
Example #5
0
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))
}
Example #6
0
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))
}
Example #9
0
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))
}
Example #10
0
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))
}
Example #11
0
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))
}
Example #12
0
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))
}
Example #13
0
func TestGameIsOverWhenSecondPlayerWins(t *testing.T) {
	board := board.NewBoard(THREE_BY_THREE)
	testhelper.AddMarkToPositions(board, SECOND_PLAYER, 0, 1, 2)
	assert.True(t, IsGameOver(board))
}
Example #14
0
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))
}
Example #15
0
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))
}
Example #16
0
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))
}
Example #18
0
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))
}
Example #20
0
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))
}
Example #21
0
func TestNoColumnWinnerOnEmptyBoard(t *testing.T) {
	board := board.NewBoard(THREE_BY_THREE)
	assert.False(t, ColumnWinner(board, FIRST_PLAYER))
}
Example #22
0
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))
}