예제 #1
0
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))
}
예제 #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,
	}
}
예제 #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))
}
예제 #4
0
func TestNoDiagonalWinnerIfBoardEmpty(t *testing.T) {
	board := board.NewBoard(THREE_BY_THREE)
	assert.False(t, DiagonalWinner(board, FIRST_PLAYER))
}
예제 #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))
}
예제 #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))
}
예제 #7
0
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))
}
예제 #8
0
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))
}
예제 #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))
}
예제 #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))
}
예제 #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))
}
예제 #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))
}
예제 #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))
}
예제 #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))
}
예제 #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))
}
예제 #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))
}
예제 #17
0
func TestScoreWhenNeitherPlayerWins(t *testing.T) {
	board := board.NewBoard(rules.THREE_BY_THREE)
	assert.Equal(t, 0, Score(board, rules.FIRST_PLAYER, rules.SECOND_PLAYER))
}
예제 #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))
}
예제 #19
0
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))
}
예제 #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))
}
예제 #21
0
func TestNoColumnWinnerOnEmptyBoard(t *testing.T) {
	board := board.NewBoard(THREE_BY_THREE)
	assert.False(t, ColumnWinner(board, FIRST_PLAYER))
}
예제 #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))
}