private void AutoMovePiece() { var ai = new AiTree(pieceBoard.Board, CurrentColor); var record = ai.GetBestRecord(2); lock (autoMoveLock) { autoMoveRecord = record; } }
private void UpdateAutoMoveRecord() { lock (autoMoveLock) { if (autoMoveRecord != null) { MovePiece(autoMoveRecord); autoMoveRecord = null; } } }
private string EncodeRecord(ChessRecord record) { // TODO temp code. var sourcePoint = record.SelectPiece.PiecePoint; var targetPoint = record.TargetPiece.PiecePoint; var sourcePiece = pieceBoard.GetPieceOnBoard(sourcePoint); var selectPiece = record.SelectPiece; var index = GetBasePiecesIndex(sourcePiece, selectPiece); var message = string.Format("move {0} {1} {2} {3} {4}", sourcePoint.X, sourcePoint.Y, index, targetPoint.X, targetPoint.Y); return(message); }
private void MovePieceTest(ChessRecord record) { if (pieceBoard.MovePieceIsOK(record)) { if (PVPModel) { var message = EncodeRecord(record); Bluetooth.Instance.Send(message); } MovePiece(record); } else { new Toast("move_not").Show(); PlaySound("illegal"); } }
private void UpdateRecord(ChessRecord record, bool regret = false) { var actionRecord = regret ? record.ReverseRecord : record; var sourcePoint = actionRecord.SelectPiece.PiecePoint; var oldSourcePiece = GetPieceOnBoard(sourcePoint); var targetPoint = actionRecord.TargetPiece.PiecePoint; var oldTargetPiece = GetPieceOnBoard(targetPoint); if (regret) { board.RegretPiece(record); } else { board.MovePiece(record); } var newSourcePieceInfo = board.GetPieceInfo(sourcePoint); if (newSourcePieceInfo.IsBlank()) { DestroyPiece(sourcePoint); pieces.Remove(sourcePoint); } else { oldSourcePiece.PieceInfo = newSourcePieceInfo; } var newSelectPiece = CreatePiece(sourcePoint, record.SelectPiece.PieceInfo); pieces[targetPoint] = newSelectPiece; var newTargetPieceInfo = board.GetPieceInfo(targetPoint); var newTargetPiece = new ChessPiece(targetPoint, newTargetPieceInfo); newSelectPiece.UpdatePiece(newTargetPiece, oldTargetPiece); }
public AiAction(ChessRecord record) { Record = record; }
private void MovePiece(ChessRecord record) { pieceBoard.MovePiece(record); recorder.PushRecord(record); PlaySound("move"); }
public void RegretPiece(ChessRecord record) { UpdateRecord(record, true); }
public void MovePiece(ChessRecord record) { UpdateRecord(record); }
public bool MovePieceIsOK(ChessRecord record) { return(board.MovePieceIsOK(record, CurrentColor)); }
public void PushRecord(ChessRecord record) { chessRecords.Push(record); UpdateSelects(); }