本文整理汇总了C#中IBoard.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# IBoard.ContainsKey方法的具体用法?C# IBoard.ContainsKey怎么用?C# IBoard.ContainsKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IBoard
的用法示例。
在下文中一共展示了IBoard.ContainsKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeDecision
public int MakeDecision(IBoard board)
{
var boardContent = board.Content;
if (boardContent.Count < 1)//first player
{
return GetRandomIndexForACorner();
}
if (boardContent.Count < 4) //Attack
{
if (!board.ContainsKey(4))
{
return 4;
}
if (boardContent.Count == 1)
{
return GetRandomIndexForACorner();
}
return CheckSquaresAndGetAttackIndex(boardContent);
}
//Defend
//1. play to win,
//OR
//2. Block opponent
//OR
//3. Play to the corner, and if corners are filled play to the edge
//1. play to win
var computerSquares = boardContent.Where(x => x.Value == "O").ToDictionary();
for (int i = 0; i < 8; i++)
{
int a = winningIndex[i, 0], b = winningIndex[i, 1], c = winningIndex[i, 2];
int count = 0;
int[] winningRow = {a, b, c};
for (int j = 0; j < winningRow.Length; j++)
{
if (computerSquares.ContainsKey(winningRow[j]))
{
count++;
}
}
if (count > 1)
{
foreach (int rowIndex in winningRow)
{
if (!board.ContainsKey(rowIndex))
{
return rowIndex;
}
}
}
}
//2. Block opponent
var opponentSquares = boardContent.Where(x => x.Value == "X").ToDictionary();
for (int i = 0; i < 8; i++)
{
int a = winningIndex[i, 0], b = winningIndex[i, 1], c = winningIndex[i, 2];
int count = 0;
int[] winningRow = { a, b, c };
for (int j = 0; j < winningRow.Length; j++)
{
if (opponentSquares.ContainsKey(winningRow[j]))
{
count++;
}
}
if (count > 1)
{
foreach (int rowIndex in winningRow)
{
if (!board.ContainsKey(rowIndex))
{
return rowIndex;
}
}
}
}
//3. Play to the corner, and if corners are filled play to the edge
return IndexForEdgeoOrCorner(boardContent);
}