public static Tuple <Connect6Move, double> GetBestMove(Connect6State state) { if (state.IsFinal()) { if (state.IsSix(state.currentPlayer)) { return(new Tuple <Connect6Move, double>(null, double.PositiveInfinity)); } if (state.IsTied()) { return(new Tuple <Connect6Move, double>(null, 0)); } else { return(new Tuple <Connect6Move, double>(null, double.NegativeInfinity)); } } double bestscore = double.NegativeInfinity; Connect6Move bestmove = new Connect6Move(null, null); foreach (Connect6Move move in state.AllPossibleMoves()) { double score = -GetBestMove(state.Apply(move)).Item2; if (score > bestscore) { bestscore = score; bestmove = move; } } return(new Tuple <Connect6Move, double>(bestmove, bestscore)); }
public static double BestMoveDepthLimited(Connect6State state, int depth) { if (state.IsFinal()) { if (state.IsSix(state.currentPlayer)) { return(double.PositiveInfinity); } else { return(state.IsTied() ? 0 : double.NegativeInfinity); } } if (depth == 0) { return(Evaluation(state)); } double bestscore = double.NegativeInfinity; foreach (Connect6Move move in state.AllPossibleMoves()) { double score = -BestMoveDepthLimited(state.Apply(move), depth - 1); if (score > bestscore) { bestscore = score; } } return(bestscore); }
public static double BestMove(Connect6State state) { if (state.IsFinal()) { if (state.IsSix(state.currentPlayer)) { return(double.PositiveInfinity); } else { return(state.IsTied() ? 0 : double.NegativeInfinity); } } double bestscore = double.NegativeInfinity; foreach (Connect6Move move in state.AllPossibleMoves()) { double score = -BestMove(state.Apply(move)); if (score > bestscore) { bestscore = score; } } return(bestscore); }