本文整理匯總了C#中Board.MakeMove方法的典型用法代碼示例。如果您正苦於以下問題:C# Board.MakeMove方法的具體用法?C# Board.MakeMove怎麽用?C# Board.MakeMove使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Board
的用法示例。
在下文中一共展示了Board.MakeMove方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetRowValues_Setting7And9_Returns7And9
public void GetRowValues_Setting7And9_Returns7And9()
{
// arrange
var v = new Board();
v.MakeMove(new Move(Columns.A, Rows.One, Values.One));
v.MakeMove(new Move(Columns.G, Rows.One, Values.Nine));
// act
var result = v.GetRowValues(Rows.One);
// assert
Assert.AreEqual(Values.One | Values.Nine, result);
}
示例2: GetCellValue_SettingCellTo9_Returns9
public void GetCellValue_SettingCellTo9_Returns9()
{
// arrange
var b = new Board();
b.MakeMove(new Move(Columns.A, Rows.Seven, Values.Nine));
// act
var result = b.GetCellValue(Columns.A, Rows.Seven);
// assert
Assert.AreEqual(Values.Nine, result);
}
示例3: Search
public override SearchResult Search(Board board, int color,int depth)
{
SearchResult searchResult = new SearchResult();
//board.CurrentColor = color;
//PrepareToSolve(board);
int alpha = -MaxScore - 1;
int beta = MaxScore + 1;
int opp = color.Opp();
Clock clock = new Clock();
clock.Start();
//Roulette roulette = new Roulette();
//board.RefreshHash();
int score = -MaxScore;
int eval;
//是否調用零窗口的標誌
bool foundPv = false;
var moves = rule.FindFlips(board, color).ToList();
if (moves.Count == 0) {
return new SearchResult() { Move = -1 };
}
//if (moves.Count == 1) {
// return new SearchResult() { Move = moves.First().Pos };
//}
for (int i = 0; i < moves.Count; i++) {
var pos = moves[i].Pos;
//下棋
//---------------------------
int flipCount = board.MakeMove(pos, color);
searchResult.Nodes++;
//檢測
if (foundPv) {
//調用零窗口
eval = -FastestFirstSolve(board, -alpha - 1, -alpha, depth - 1, searchResult, opp, color);
if ((eval > alpha) && (eval < beta)) {
eval = -FastestFirstSolve(board, -beta, -eval, depth - 1, searchResult, opp, color);
//eval = -FastestFirstMidSolve( -beta, -alpha, oppcolor, depth - 1);
}
}
else {
eval = -FastestFirstSolve(board, -beta, -alpha, depth - 1, searchResult, opp, color);
}
//em.ReLink();
//---------------------------
//Eval.StepsPop(color);
//恢複到上一步
board.Reback(pos, flipCount, opp);
searchResult.Message += string.Format("({0}:{1})", pos, eval);
if (eval > score) {
score = eval;
//更新位置
searchResult.Move = pos;
searchResult.Score = score;
if (eval > alpha) {
if (eval >= beta) {
//剪枝
break;
}
alpha = eval;
foundPv = true;
}
}
}
clock.Stop();
searchResult.TimeSpan = clock.Elapsed;
return searchResult;
}
示例4: FastestFirstSolve
/// <summary>
/// 最快優先搜索
/// </summary>
private int FastestFirstSolve(Board board, int alpha, int beta, int depth, SearchResult searchResult, int cur, int opp, bool prevmove = true)
{
lock (this) {
//計算搜索的結點數
searchResult.Nodes++;
/*
//嘗試置換表裁剪,並得到置換表走法
HashResult hashResult = board.ReadHash(alpha, beta, depth);
if (hashResult != null) {
Message.Hits++;
return hashResult.Score;
}
*/
if (board.EmptyCount == 0) {//遊戲結束
return EndEval(board,cur);
}
//葉子節點,局麵估分
if (depth == 0) {
return Eval(board, cur);
}
int mvBest = 0;
int score = -MaxScore;
//是否調用零窗口的標誌
bool foundPv = false;
int eval;
#region hash code
/*
//int mvHash = hashResult.Move;
//初始化最佳值和最佳走法
HashType hashType = HashType.LOWER_BOUND;
//初始化走法排序結構
board.InitMoves(); //board.InitMoves(mvHash);
int quickMove = board.GetQuickMove();
// if (moveDefend > Evalation.Defend_FreeThree)
// return moveDefend;
//if (board.MoveHash != 0)
// quickMove = board.MoveHash;
//else if ((board.MoveKiller1 != board.MoveHash) && (board.MoveKiller1 != 0) && board.CanMove(board.MoveKiller1))
// quickMove = board.MoveKiller1;
//else if ((board.MoveKiller2 != board.MoveHash) && (board.MoveKiller2 != 0) && board.CanMove(board.MoveKiller2))
// quickMove = board.MoveKiller2;
if (quickMove != 0) {
//---------------------------
board.MakeMove(quickMove);
eval = -FastestFirstSolve(board, -beta, -alpha, depth - 1);
//恢複到上一步
board.Reback(quickMove);
if (eval > alpha) {
if (eval >= beta) {
//----------------------
hashType = HashType.UPPER_BOUND;
// 記錄到置換表
board.StoreHash(hashType, eval, depth, quickMove);
//TODO:有點懷疑是否需要這個條件
if (mvBest != 0) {
// 如果不是Alpha走法,就將最佳走法保存到曆史表
board.StoreBestMove(quickMove, depth);
}
//剪枝
return eval;
}
//----------------
hashType = HashType.EXACT;
alpha = eval;
foundPv = true;
}
}
Roulette roulette = new Roulette();
int gness;
int moves = roulette.CalculateGoodness(out gness);
if (gness == Evalation.InfScore) {
return gness;
}
*/
#endregion
var moves = rule.FindFlips(board, cur).ToList();
if (moves.Count == 0) {
if (!prevmove) {//遊戲結束
return EndEval(board,cur);
/*
if (discdiff > 0)//自己贏
//.........這裏部分代碼省略.........
示例5: TestMove
public void TestMove( string boardStr, Move move, bool expectedValid, string expected )
{
var board = new Board();
board.Load( boardStr );
bool valid = board.MakeMove( move );
Assert.AreEqual( expectedValid, valid );
if ( valid )
{
Assert.AreEqual( expected, board.ToString() );
}
else
{
// Make sure it hasn't changed
Assert.AreEqual( boardStr, board.ToString() );
}
}
示例6: TestCantMoveOnSolvedBoard
public void TestCantMoveOnSolvedBoard( string boardStr, Move move )
{
var board = new Board();
board.Load( boardStr );
Assert.IsFalse( board.MakeMove( move ) );
}
示例7: PlaybackMoves
private static Board PlaybackMoves( string boardStr, Move[] moveList )
{
var board = new Board();
board.Load( boardStr );
foreach ( Move move in moveList )
{
bool valid = board.MakeMove( move );
Assert.IsTrue( valid );
}
return board;
}
示例8: MakeMove_MovingKingE1E2
public void MakeMove_MovingKingE1E2()
{
// arrange
var board = new Board(
new Side(
"E1",
new PieceSet<Queen>(Bitboard.Empty),
new PieceSet<Bishop>(Bitboard.Empty),
new PieceSet<Knight>(Bitboard.Empty),
new PieceSet<Rook>(Bitboard.Empty),
new WhitePawns(Bitboard.Empty)
),
new Side(
"E8",
new PieceSet<Queen>(Bitboard.Empty),
new PieceSet<Bishop>(Bitboard.Empty),
new PieceSet<Knight>(Bitboard.Empty),
new PieceSet<Rook>(Bitboard.Empty),
new WhitePawns(Bitboard.Empty)
));
// act
Board result = board.MakeMove("E1", "E2");
// assert
result.White.KingLocation.Should().Be(
new Square("E2")
);
}
示例9: MakeMove_NumberRepetitionInColumn_ThrowsInvalidOperationException
public void MakeMove_NumberRepetitionInColumn_ThrowsInvalidOperationException()
{
// arrange
Board b = new Board();
// act
b.MakeMove(new Move(Columns.A, Rows.One, Values.Nine));
b.MakeMove(new Move(Columns.A, Rows.Seven, Values.Nine));
// assert
}
示例10: UnmakeMove_MakeAndUnmake9InA1_EmptyA1
public void UnmakeMove_MakeAndUnmake9InA1_EmptyA1()
{
Board b = new Board();
b.MakeMove(new Move(Columns.A, Rows.One, Values.Nine));
b.UnmakeMove(new Move(Columns.A, Rows.One, Values.Nine));
Assert.AreEqual(Values.None, b.GetCellValue(Columns.A, Rows.One));
Assert.AreEqual(Values.None, b.GetColumnValues(Columns.A));
Assert.AreEqual(Values.None, b.GetRowValues(Rows.One));
}
示例11: TestMove
public void TestMove(string startFen, string endFen, bool valid, string from, string to, string description)
{
var board = new Board(startFen);
var move = board.MakeMove(from, to);
Assert.AreEqual(valid, move.Valid, description);
Assert.AreEqual(endFen, board.FEN, description);
}
示例12: Gen
private void Gen(TextWriter writer, Board board, int color, bool prevmove = true)
{
if (Records >= Limit) {
return;
}
if (board.EmptyCount == EndGameDepth) {
var searchResult = Engine.Search(board.Copy(), color, this.SearchDepth);
WriteRecord(writer, board, searchResult.Score, searchResult.Move, color);
Records++;
//每1000條記錄就Flush一次
if (Records % 1000 == 0) {
Console.WriteLine("Write Records: {0}", Records);
writer.Flush();
}
return;
}
int opp = color.Opp();
var moves = rule.FindFlips(board, color).ToList();
if (moves.Count == 0) {
if (prevmove) {
Gen(writer, board, opp, false);
}
return;
}
foreach (var move in moves) {
int flipCount = board.MakeMove(move.Pos, color);
Gen(writer, board, opp);
board.Reback(move.Pos, flipCount, opp);
}
}
示例13: Fight
private FightResult Fight(IEngine engineA, IEngine engineB, Board board, int color = StoneType.Black)
{
Clock clock = new Clock();
clock.Start();
IEngine[] engines = new[] { engineA, engineB };
int[] stoneTypes = new[] { StoneType.Black, StoneType.White };
int turn = color - 1; //0;
Console.WriteLine(board);
while (true) {
//board.CurrentColor = stoneTypes[turn];
var searchResult = engines[turn].Search(board.Copy(), stoneTypes[turn], (Constants.StoneCount - 4) / 2);
Console.WriteLine("[{0}] {1}", engines[turn].Name, searchResult);
Console.Out.Flush();
if (searchResult.Move < 0 ||
searchResult.Move >= Constants.StoneCount ||
!rule.CanFlip(board[searchResult.Move], stoneTypes[turn])) {
clock.Stop();
//下棋異常
Console.WriteLine(board);
return new FightResult() {
WinnerName = engines[1 - turn].Name,
LoserName = engines[turn].Name,
WinnerStoneType = (turn == 0 ? StoneType.Black : StoneType.White),
Score = 1,
TimeSpan = clock.TotalMilliseconds
};
}
else {
board.MakeMove(searchResult.Move, stoneTypes[turn]);
Console.WriteLine(board);
}
turn = 1 ^ turn;
var canFlip = rule.CanFlip(board, stoneTypes[turn]);
if (!canFlip) {
//對方無棋可下,輪換
turn = 1 ^ turn;
canFlip = rule.CanFlip(board, stoneTypes[turn]);
if (!canFlip) {
//雙方都無棋可下,結束
break;
}
}
}
clock.Stop();
//Console.WriteLine(board);
return new FightResult(board, engines) {
TimeSpan = clock.TotalMilliseconds
};
}