public Move findBestMoveForCurrentPlayerNoDoUndo(int sec) { Move m0 = null, result = null; if (this.CurrentTurn < 2 && this.CurrentColor == Piece.Color.White) { if (rand.Next(1, 10) <= 3) return new Move("a2-a3"); return new Move("b2-b3"); } if (this.CurrentTurn < 2 && this.CurrentColor == Piece.Color.Black) { if (lastMoves.Count > 0) { PreviousMove pm = lastMoves.Pop(); switch (pm.Move.ToString()) { case "a2-a3": case "d2-d3": m0 = new Move("d5-d4"); break; default: m0 = new Move("a5-a4"); break; } lastMoves.Push(pm); return m0; } } if (!cache.HasLoadedFile) { cache.TryASyncLoad(); } TimeSpan t = TimeSpan.FromSeconds(sec); int d0 = 2, a0 = 0, v0 = 0, v = 0, negaresult = 0; List<Move> moves = this.getMoves(this.CurrentColor); DateTime start = DateTime.Now; Board board; while (t > DateTime.Now - start) { a0 = -100000; v = -100000; foreach (Move m in moves) { if (t < DateTime.Now - start) { if (result == null) //if we didn't even have time to evaluate one level down, panic and just pick one. result = m; Console.WriteLine("Depth: {0}", d0); return result; } board = new Board(this); if (board.makeMove(m)) { if (board.State != BoardState.Playing) { if (board.State == BoardState.BlackWinner || board.State == BoardState.WhiteWinner) { Console.WriteLine("Depth: {0}", d0); return m; //this move is a winner, pick it! } } negaresult = AI.negaMaxNodoUndo(board, d0, -100000, -a0, (t - (DateTime.Now - start)).TotalSeconds); v0 = Math.Max(v, -negaresult); a0 = Math.Max(a0, v0); if (v0 >= v) m0 = m; v = Math.Max(v, v0); } } ++d0; result = m0; } Console.WriteLine("Depth: {0}", d0); return result; }