Example #1
0
func playAIMove(game *chess.Game, role search.Role, level uint) {
	result := search.AlphaBetaSearch(game, role, level)
	// TODO: annoying, but AlphaBetaSearch doesn't release the
	// moves cached for the root node.
	game.Release()
	fmt.Println(result)
	action := result.Actions[len(result.Actions)-1]
	game.MakeMove(action.(chess.Move))
}
Example #2
0
func main() {
	fmt.Println(shouldProfile)
	if shouldProfile {
		f, _ := os.Create("main.pprof")
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	game := chess.NewGame()

	var result search.SearchResult
	switch method {
	case "dfs":
		chess.SetIsThreaded()
		result = search.DepthFirstSearch(
			game,
			search.Maximizer,
			searchDepth,
			1)
	case "alphaBeta":
		result = search.AlphaBetaSearch(
			game,
			search.Maximizer,
			searchDepth)
	case "threadedAlphaBeta":
		chess.SetIsThreaded()
		result = search.ThreadedAlphaBetaSearch(
			game,
			search.Maximizer,
			searchDepth)
	default:
		fmt.Println("Invalid method!")
		return
	}

	// Check for memory leaks. Right now just leaks 1 array, which
	// is the root's.
	fmt.Println(chess.NumLoanedMoveArrays)
	fmt.Println(result.Actions)
	fmt.Println(result.Value)
}