Пример #1
0
func takeTurn(board board.Board, playerOne, playerTwo iplayer.Player, movesPlayed []int) []int {
	currentPlayer := gamestate.GetCurrentPlayer(board, playerOne, playerTwo)
	if currentPlayer.IsComputer() {
		move := currentPlayer.GetMove(board, currentPlayer.GetMark(), gamestate.GetOpponentMark(currentPlayer.GetMark()))
		board.PlaceMove(move, currentPlayer.GetMark())
		movesPlayed = append(movesPlayed, move)
	}
	return movesPlayed
}
Пример #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,
	}
}