本文整理汇总了C#中GameState.Undo方法的典型用法代码示例。如果您正苦于以下问题:C# GameState.Undo方法的具体用法?C# GameState.Undo怎么用?C# GameState.Undo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameState
的用法示例。
在下文中一共展示了GameState.Undo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AlphaBetaSearch
private int AlphaBetaSearch(GameState s, int alpha, int beta, int deep, ref Position res_turn)
{
Position turn = new Position(0, 0);
if (deep >= maxDepth || s.GameOver)
{
return costFunction.EvaluateState(s);
}
if (deep % 2 == 0)
{
foreach( Position p in turnsGenerator.GenerateTurns(s))
{
GameState.ChangeSet ch = s.Advance(p, Utils.FlipSide(s.Player));
int score = AlphaBetaSearch(s, alpha, beta, deep + 1, ref turn) - deep * 20;
s.Undo(ch);
if (deep == 0)
{
var hscore = hf.EvaluateTurn(s, p);
Debug.WriteLine("Considering ({0},{1}) with ab_cost = {2}, h_cost = {3}", p.X, p.Y, score, hscore);
}
if (score > alpha)
{
res_turn = p;
alpha = score;
}
if (alpha >= beta) break;
}
return alpha;
}
else
{
foreach (Position p in turnsGenerator.GenerateTurns(s))
{
GameState.ChangeSet ch = s.Advance(p, Utils.FlipSide(s.Player));
int score = AlphaBetaSearch(s, alpha, beta, deep + 1, ref turn) - deep * 20;
s.Undo(ch);
if (score < beta)
{
beta = score;
res_turn = p;
}
if (alpha >= beta) break;
}
return beta;
}
}
示例2: checkUndoRedo
void checkUndoRedo(GameState gs, Position p, Side side)
{
string before = gs.ToString();
GameState.ChangeSet change = gs.Advance(p, side);
string after = gs.ToString();
Console.WriteLine("BEFORE:");
Console.WriteLine(before);
Console.WriteLine("AFTER:");
Console.WriteLine(after);
Confirm.Different(before, after);
gs.Undo(change);
Console.WriteLine("UNDO:");
Console.WriteLine(gs);
Confirm.Equal(before, gs.ToString());
gs.Advance(p, side);
Confirm.Equal(after, gs.ToString());
}
示例3: MinMaxSearch
private int MinMaxSearch(GameState s, int deep, ref Position turn)
{
int cost = costFunction.EvaluateState(s);
if (deep == maxDepth || cost <= costFunction.LoseValue || cost >= costFunction.WinValue)
{
return cost;
}
if (deep % 2 == 0)
{
int max = int.MinValue;
Position sub_turn = new Position(0, 0);
foreach (Position p in turnsGenerator.GenerateTurns(s))
{
string hash = s.ToString();
GameState.ChangeSet ch = s.Advance(p, Utils.FlipSide(s.Player));
int score = MinMaxSearch(s, deep + 1, ref sub_turn);
s.Undo(ch);
Debug.Assert(s.ToString() == hash);
if (deep == 0)
{
Debug.WriteLine(intend(deep) + "max: ({0},{1}) avaluated as {2}\n", p.X, p.Y, score);
}
if (score > max)
{
max = score;
turn = p;
}
}
return max;
}
else
{
int min = int.MaxValue;
Position sub_turn = new Position(0, 0);
foreach (Position p in turnsGenerator.GenerateTurns(s))
{
string hash = s.ToString();
GameState.ChangeSet ch = s.Advance(p, Utils.FlipSide(s.Player));
int score = MinMaxSearch(s, deep + 1, ref sub_turn);
//if (deep == 1)
// Debug.WriteLine(intend(deep) + "min: ({0},{1}) avaluated as {2}", p.X, p.Y, score);
s.Undo(ch);
Debug.Assert(s.ToString() == hash);
if (score < min)
{
min = score;
turn = p;
}
}
return min;
}
}