private Tuple <int, Tuple <int, int> > AlphaBeta(BoardLR root, int depth, int minOrMax, int parentValue) { root.DefPossibleShot(); if (depth == 0 || root.Final()) { return(new Tuple <int, Tuple <int, int> >(root.Eval(), null)); } int optVal = minOrMax * -1 * int.MaxValue; Tuple <int, int> optOp = null; foreach (var op in root.possibleShot) { BoardLR child = new BoardLR(this); child.PlayMove(op.Item1, op.Item2, child.actualVal == pWhite); var tpl = AlphaBeta(child, depth - 1, -1 * minOrMax, optVal); var val = tpl.Item1; if (val * minOrMax > optVal * minOrMax) { optVal = val; optOp = op; if (optVal * minOrMax > parentValue * minOrMax) { break; } } } return(new Tuple <int, Tuple <int, int> >(optVal, optOp)); }
public BoardLR(BoardLR old) { this.name = old.name; this.width = old.width; this.height = old.height; this.actualVal = 1 - actualVal; //Next turn this.game = new int[width, height]; for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { this.game[x, y] = old.game[x, y]; } } }