public void AI() { if (aiThink) { return; } if (IsXTurn) { TurnL.Text = "X turn"; return; } if (ended) { return; } TurnL.Text = "AI thinks"; if (difficulity == (Difficulity)0) { TurnL.Text = "O turn"; return; } Ai.difficulity = this.difficulity; EventArgs e = new AddingNewEventArgs("AI"); Position p = Ai.DoTurn(game); TurnL.Invoke(new Action(() => { CC <object> .CenterVertical(TurnL); })); if (difficulity == Difficulity.easy) { Thread.Sleep(1); } if (difficulity == Difficulity.medium) { Thread.Sleep(125); } if (difficulity == Difficulity.hard) { Thread.Sleep(500); } if (p.row != -1) { this.Invoke(new Action(() => { CellClick(cellsP[p.row, p.col], e); })); } //ThreadPool.Abort(ThreadPool.FindIndex("AI")); }
void AiTurn() { ai.DoTurn(); CancelInvoke("AiTurn"); }