public static ChessMove nextDraw() { ChessMove finalMove = new ChessMove(new Position(0, 0), new Position(0, 0)); Random rnd = new Random(); double best = -10000; List <Piece> blackPieces = Chess.blackPieces(); foreach (Piece piece in blackPieces) { Piece p = blackPieces.Find(x => x.Equals(piece)); Dictionary <Position, bool?> moves = Chess.validMoves(p); foreach (KeyValuePair <Position, bool?> move in moves) { double value = 0; if (move.Value != false) { value = Chess.board.at(move.Key).getValue() + rnd.NextDouble() * 4; if (isThreatened(p.getPosition())) { value += p.getValue(); if (isProtected(p.getPosition())) { int low = lowestThreathener(p.getPosition(), "white"); int val = p.getValue(); value -= low < val ? low : val; } } int previousValue = p.getValue(); Chess.tempMove(p.getPosition(), move.Key); value += p.getValue() - previousValue; if (isThreatened(p.getPosition())) { value -= p.getValue(); if (isProtected(p.getPosition())) { int low = lowestThreathener(p.getPosition(), "white"); int val = p.getValue(); value += low < val ? low : val; } } if (Chess.IsChecked("white")) { value += rnd.NextDouble() * 5; } Chess.undo(); } else if (move.Value == false) { value = -10000; } if (value > best) { best = value; finalMove = new ChessMove(piece.getPosition(), move.Key); } } } return(finalMove); }