Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>1) Any and all of those solutions will work; you just have to use somewhat different logic to deal with each one.</p> <p>2) ThreadPool is also useful when you have a set of things that can be executed on multiple threads (for example, in a Chinese Checkers game, you could run 5 different AI simulations via ThreadPool and it would run optimally on a computer that has two cores whereas using Threads would slow the process down due to context switching). It certainly works for your case - you'd just queue a second AIEvaluation or whatever and it would start executing ASAP.</p> <p>3) Well, not really. The computer can't really make its move until after running alphabeta (presumably with some cutoff depth :P) so the AI thread would be done with its work anyhow. You could just use ThreadPool/BackgroundWorker each time.</p> <p>Some general info about BackgroundWorker: it runs when you have "extra" CPU time, so if your main thread is hogging CPU for some reason, it won't do a whole lot. It may be better to use normal ThreadPool.</p> <p>Let's say your program calls AIAct() when it's the AI's turn on the main thread. Also, let timerTick be a timer of the sort that exists in Windows Forms. Moreover, let there be the classes AIState and GameBoard that encapsulate the functionality needed for alpha-beta.</p> <pre><code>using System.Threading; const int CUTOFF_DEPTH = 6;//Maximum plys for alpha-beta AIState state; void AIAct() { state = new AIState( this.GameBoard.GetState() ); ThreadPool.QueueUserWorkItem(RunMinimax, state); //assume that timerTick is a Timer (Windows Forms Timer) that ticks every 100 ms timerTick.Enabled = true; } void timerTick_Tick(object sender, EventArgs e) { if (state.IsComplete) { ExecuteAction(state.Result); timerTick.Enabled = false; //whatever else you need to do } } private static void RunMinimax(object args) { AIState state = args as AIState; if (state == null) { //error handling of some sort Thread.CurrentThread.Abort(); } //run your minimax function up to max depth of CUTOFF_DEPTH state.Result = Minimax( /* */ ); state.IsComplete = true; } private class AIState { public AIState(GameBoard board) { this.Board = board; } public readonly GameBoard Board; public AIAction Result; public volatile bool IsComplete; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload